|
From: <ian...@us...> - 2007-08-16 17:04:44
|
Revision: 243
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=243&view=rev
Author: iansmith
Date: 2007-08-16 10:04:44 -0700 (Thu, 16 Aug 2007)
Log Message:
-----------
Fixes to enhance chances of automation.
1) Fixed database mapping problem for MySql 5 that was causing timestamp problems. We now use a long in the DB.
2) Fixed a bug in MessageProxy that kept the heartbeat thread going after the service was supposed to shutdown. Now we shutdown cleanly. Added a bunch of debugging support for this so we get better error messages as we are going down and there are problems.
3) Incorporated changes in the build.xml and began support for ant-oriented automated testing.
Modified Paths:
--------------
spaces/trunk/build.xml
spaces/trunk/docs/properties-example.txt
spaces/trunk/src/com/ogoglio/client/ClientTests.java
spaces/trunk/src/com/ogoglio/client/WebAPIClient.java
spaces/trunk/src/com/ogoglio/client/WebAPIClientWire.java
spaces/trunk/src/com/ogoglio/client/WebAPITests.java
spaces/trunk/src/com/ogoglio/message/NetworkChannelServer.java
spaces/trunk/src/com/ogoglio/message/TCPChannel.java
spaces/trunk/src/com/ogoglio/persist/AccountPersistTasks.java
spaces/trunk/src/com/ogoglio/persist/AccountRecord.java
spaces/trunk/src/com/ogoglio/persist/HibernateBase.java
spaces/trunk/src/com/ogoglio/persist/Persist.hbm.xml
spaces/trunk/src/com/ogoglio/persist/SpacePersistTasks.java
spaces/trunk/src/com/ogoglio/sim/site/SimServlet.java
spaces/trunk/src/com/ogoglio/site/AccountServlet.java
spaces/trunk/src/com/ogoglio/site/AuthServlet.java
spaces/trunk/src/com/ogoglio/site/MessageProxy.java
spaces/trunk/src/com/ogoglio/site/SpaceServlet.java
spaces/trunk/src/com/ogoglio/util/PrepareDatabase.java
spaces/trunk/src/com/ogoglio/xml/AccountDocument.java
spaces/trunk/src/com/ogoglio/xml/XMLTests.java
Modified: spaces/trunk/build.xml
===================================================================
--- spaces/trunk/build.xml 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/build.xml 2007-08-16 17:04:44 UTC (rev 243)
@@ -2,10 +2,22 @@
<project default="war" basedir=".">
<property name="source" value="src" />
<property name="dest" value="war/WEB-INF/classes" />
- <property name="tomcatHome" value="../../tomcat/" />
<property name="webLibDir" value="./war/WEB-INF/lib/" />
<property name="warName" value="ogoglio.war" />
+
+ <echo message="reading properties from ${user.home}/.ogoglio-properties"/>
+ <loadproperties srcFile="${user.home}/.ogoglio-properties">
+ <filterchain>
+ <linecontains>
+ <contains value="ant."/>
+ </linecontains>
+ </filterchain>
+ </loadproperties>
+
+
+ <echo message="tomcat 5.5 dir found to be ${ant.tomcatDir}"/>
+
<target name="clean">
<delete>
<fileset dir="${dest}" includes="**/*" />
@@ -142,6 +154,16 @@
<bottom><![CDATA[<i>Copyright © 2007 Transmutable. All Rights Reserved.</i>]]></bottom>
</javadoc>
</target>
-
+
+ <target name="insureNoServer">
+ <exec executable="${ant.tomcatDir}/bin/shutdown.sh" failonerror="false"
+ errorProperty="ignored" outputProperty="ignoredalso"/>
+ </target>
+
+ <target name="test" depends="war,insureNoServer">
+ <exec executable="${ant.tomcatDir}/bin/startup.sh" failonerror="true"/>
+ <sleep seconds="5"/>
+ <exec executable="${ant.tomcatDir}/bin/shutdown.sh" failonerror="true"/>
+ </target>
</project>
Modified: spaces/trunk/docs/properties-example.txt
===================================================================
--- spaces/trunk/docs/properties-example.txt 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/docs/properties-example.txt 2007-08-16 17:04:44 UTC (rev 243)
@@ -8,7 +8,7 @@
# TOMCAT
#
# pointer to your tomcat 5.5 install
-tomcat_dir = /usr/share/tomcat5.5
+ant.tomcatDir = /usr/share/tomcat5.5
#
# LOCALHOST
Modified: spaces/trunk/src/com/ogoglio/client/ClientTests.java
===================================================================
--- spaces/trunk/src/com/ogoglio/client/ClientTests.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/client/ClientTests.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -135,9 +135,10 @@
assertEquals(AccountRecord.ACCOUNT_LEVEL_ADMIN, accountDoc.getAccountLevel());
accountDoc.setFrozenUntil(new Date(1000));
accountDoc.setAccountLevel(AccountRecord.ACCOUNT_LEVEL_BASIC);
- adminWebClient.updateAccount(accountDoc);
- accountDoc = adminWebClient.getAccountDocument(username);
- assertTrue(accountDoc.getFrozenUntil() == null);
+ accountDoc=adminWebClient.updateAccount(accountDoc);
+ AccountDocument ac2= adminWebClient.getAccountDocument(username);
+ assertNull(accountDoc.getFrozenUntil());
+ assertNull(ac2.getFrozenUntil());
assertEquals(AccountRecord.ACCOUNT_LEVEL_BASIC, accountDoc.getAccountLevel());
} catch (Exception e) {
@@ -163,30 +164,31 @@
checkNoConnectionToSpaceWithoutAuth(spaceDocument.getSpaceID());
checkAuthDoc(auth1, auth2);
-
+
spaceDocument = checkSpaceSeaLevel(webClient1, spaceDocument);
-
+
checkSettings(spaceDocument.getSpaceID(), webClient1);
-
+
checkBody(webClient1, auth1);
checkSpaceMembership(spaceDocument.getSpaceID(), webClient1);
checkSpaceAuthWithMembership(auth2, webClient2, webClient1, spaceDocument);
-
+
TemplateDocument newTemplateDoc = checkTemplateScriptAPI(webClient1);
ThingDocument[] thingDocs = checkTemplateGeomMaterialsAndPossessions(webClient1, newTemplateDoc, spaceDocument);
-
+
+
//IES CHECK: after messing around above, verify we are are ok
thingDocs = webClient1.getThingDocuments(spaceDocument.getSpaceID());
assertEquals(1, thingDocs.length);
checkPageManipulation(webClient1, thingDocs[0], spaceDocument);
-
+
//figure out the last template added
TemplateDocument[] templateDocs = webClient1.getTemplateDocuments(USERNAME1);
long lastTemplateID = templateDocs[templateDocs.length - 1].getTemplateID();
-
+
checkDoors(webClient1, spaceDocument, lastTemplateID);
spaceClient1 = checkConnectedUsersToSpace(auth1, webClient1, spaceDocument);
@@ -199,7 +201,7 @@
guestSpaceClient1 = checkGuestCookieOperation(spaceDocument.getSpaceID(), webClient1, AuthServlet.GUEST_COOKIE_PREFIX + "Test_Suite_Guest");
checkDeletingSpaceDestroysThings(spaceDocument.getSpaceID(), webClient1, USERNAME1);
-
+
} catch (IOException e) {
e.printStackTrace();
fail();
@@ -282,10 +284,13 @@
private void checkSettings(long spaceID, WebAPIClient webClient1) throws IOException {
String key1 = "ogoglio.key.1";
String value1 = "This is a very fine value which is < 1";
- assertNull(webClient1.getSpaceSetting(spaceID, key1));
+ Object v = webClient1.getSpaceSetting(spaceID, key1);
+
+ assertNull(v);
+
webClient1.putSpaceSetting(spaceID, key1, value1);
assertEquals(value1, webClient1.getSpaceSetting(spaceID, key1));
-
+
String key2 = "ogoglio.key.2";
String value2 = "This is a very fine value & it's value is > 2";
assertNull(webClient1.getSpaceSetting(spaceID, key2));
@@ -297,6 +302,7 @@
assertNull(webClient1.getSpaceSetting(spaceID, key1));
webClient1.removeSpaceSetting(spaceID, key2);
assertNull(webClient1.getSpaceSetting(spaceID, key2));
+
}
private void checkBody(WebAPIClient webClient1, WebAPIAuthenticator authenticator) throws IOException {
Modified: spaces/trunk/src/com/ogoglio/client/WebAPIClient.java
===================================================================
--- spaces/trunk/src/com/ogoglio/client/WebAPIClient.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/client/WebAPIClient.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -31,6 +31,7 @@
import nanoxml.XMLElement;
+import com.ogoglio.persist.AccountRecord;
import com.ogoglio.site.AuthServlet;
import com.ogoglio.site.SpaceServlet;
import com.ogoglio.util.ArgumentUtils;
@@ -66,7 +67,7 @@
}
public AccountDocument createAccount(String username, String accountLevel, String firstName, String lastName, String homepage, String email, String password) throws IOException {
- AccountDocument newAccountDoc = new AccountDocument(username, accountLevel, firstName, lastName, homepage, password, email, null, null, null, null, -1);
+ AccountDocument newAccountDoc = new AccountDocument(username, accountLevel, firstName, lastName, homepage, password, email, null, AccountRecord.NO_TIME_VALUE, null, AccountRecord.NO_TIME_VALUE, -1);
XMLElement result = wire.sendAuthenticatedXML(descriptor.getAccountURI(), newAccountDoc.toString(), "POST", authenticator.getAuthCookie());
return new AccountDocument(result);
}
Modified: spaces/trunk/src/com/ogoglio/client/WebAPIClientWire.java
===================================================================
--- spaces/trunk/src/com/ogoglio/client/WebAPIClientWire.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/client/WebAPIClientWire.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -18,8 +18,9 @@
public class WebAPIClientWire {
- private boolean printedCacheComplaint = false;
-
+ private boolean printedCacheComplaint = false;
+ private static final String BAD_SUN_VERSION = "1.6;";
+
public InputStream performPUT(URI uri, InputStream input, String type, int length, String authCookie) throws IOException {
HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
connection.setRequestMethod("PUT");
@@ -140,7 +141,7 @@
public DecoratedInputStream performGET(URI uri, String authCookie, boolean requestCompression) throws IOException {
String version = System.getProperty("java.version");
- if ((version == null) || version.startsWith("1.6")) {
+ if ((version == null) || version.startsWith(BAD_SUN_VERSION)) {
//THIS IS TO WORK AROUND SUN'S ABSOLUTELY BROKEN APPLET CACHE IN JRE 1.6u1 & 2
String uriString = uri.toASCIIString();
try {
@@ -211,7 +212,7 @@
public DecoratedInputStream performGET(URI uri, String authCookie) throws IOException {
String version = System.getProperty("java.version");
- if ((version == null) || version.startsWith("1.6")) {
+ if ((version == null) || version.startsWith(BAD_SUN_VERSION)) {
//THIS IS TO WORK AROUND SUN'S ABSOLUTELY BROKEN APPLET CACHE IN JRE 1.6u1
String uriString = uri.toASCIIString();
try {
Modified: spaces/trunk/src/com/ogoglio/client/WebAPITests.java
===================================================================
--- spaces/trunk/src/com/ogoglio/client/WebAPITests.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/client/WebAPITests.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -42,7 +42,7 @@
notAuthedAuthDoc = new AuthDocument("Ian", false);
authedAuthDoc = new AuthDocument("Ian", true);
- accountDoc = new AccountDocument(authedAuthDoc.getUsername(), AccountRecord.ACCOUNT_LEVEL_ADVANCED, null, null, null, null, null, null, null, null, null, -1);
+ accountDoc = new AccountDocument(authedAuthDoc.getUsername(), AccountRecord.ACCOUNT_LEVEL_ADVANCED, null, null, null, null, null, null, AccountRecord.NO_TIME_VALUE, null, AccountRecord.NO_TIME_VALUE, -1);
} catch (URISyntaxException e) {
fail("Bad URIL: " + e);
}
Modified: spaces/trunk/src/com/ogoglio/message/NetworkChannelServer.java
===================================================================
--- spaces/trunk/src/com/ogoglio/message/NetworkChannelServer.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/message/NetworkChannelServer.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -122,6 +122,7 @@
try {
serverSocket.close();
} catch (Exception e) {
+ System.out.println("Trying to close server socket of NCServer:"+e.getMessage());
// don't care
}
TCPChannel[] channels = getChannels();
Modified: spaces/trunk/src/com/ogoglio/message/TCPChannel.java
===================================================================
--- spaces/trunk/src/com/ogoglio/message/TCPChannel.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/message/TCPChannel.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -86,10 +86,12 @@
try {
readerThread.cleanup();
} catch (Exception e) {
+ System.out.println("TCPChannel: Trying to cleanup to readerThread:"+(e.getClass().getName())+":"+e.getMessage());
}
try {
senderQueue.cleanup();
} catch (Exception e) {
+ System.out.println("TCPChannel: Trying to cleanup to senderQueue:"+(e.getClass().getName())+":"+e.getMessage());
}
listener.channelClosed(this);
}
Modified: spaces/trunk/src/com/ogoglio/persist/AccountPersistTasks.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/AccountPersistTasks.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/persist/AccountPersistTasks.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -21,168 +21,193 @@
public class AccountPersistTasks {
- public static final String ACCOUNT_BY_USERNAME = "com.ogoglio.persist.accountByUsername";
- public static final String ACCOUNT_BY_EMAIL = "com.ogoglio.persist.accountByEmail";
+ public static final String ACCOUNT_BY_USERNAME = "com.ogoglio.persist.accountByUsername";
+ public static final String ACCOUNT_BY_EMAIL = "com.ogoglio.persist.accountByEmail";
- public static final String ACCOUNT_BY_COOKIE = "com.ogoglio.persist.accountByCookie";
+ public static final String ACCOUNT_BY_COOKIE = "com.ogoglio.persist.accountByCookie";
- public static boolean update(final AccountRecord record, final AccountDocument document, SessionFactory sessionFactory) throws PersistException {
- HibernateTask task = new HibernateTask() {
- public Object run(Session hibernateSession) {
- boolean dirty = false;
- if (document.getAccountLevel() != null && !equals(record.getAccountlevel(), document.getAccountLevel())) {
- dirty = true;
- record.setAccountlevel(document.getAccountLevel());
- }
-
- if (document.getHomepage() != null && !equals(record.getHomepage(), document.getHomepage())) {
- dirty = true;
- record.setHomepage(document.getHomepage());
- }
+ public static boolean update(final AccountRecord record,
+ final AccountDocument document, SessionFactory sessionFactory)
+ throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session hibernateSession) {
+ boolean dirty = false;
+ if (document.getAccountLevel() != null
+ && !equals(record.getAccountlevel(), document
+ .getAccountLevel())) {
+ dirty = true;
+ record.setAccountlevel(document.getAccountLevel());
+ }
- if (document.getFirstName() != null && !equals(record.getFirstName(), document.getFirstName())) {
- dirty = true;
- record.setFirstName(document.getFirstName());
- }
+ if (document.getHomepage() != null
+ && !equals(record.getHomepage(), document.getHomepage())) {
+ dirty = true;
+ record.setHomepage(document.getHomepage());
+ }
- if (document.getLastName() != null && !equals(record.getLastName(), document.getLastName())) {
- dirty = true;
- record.setLastName(document.getLastName());
- }
+ if (document.getFirstName() != null
+ && !equals(record.getFirstName(), document
+ .getFirstName())) {
+ dirty = true;
+ record.setFirstName(document.getFirstName());
+ }
- if (document.getPassword() != null && !equals(record.getPassword(), document.getPassword())) {
- if (AccountRecord.cleanPassword(document.getPassword()) != null) {
- dirty = true;
- record.setPassword(document.getPassword());
- }
- }
+ if (document.getLastName() != null
+ && !equals(record.getLastName(), document.getLastName())) {
+ dirty = true;
+ record.setLastName(document.getLastName());
+ }
- if(document.getDefaultBodyID() != -1) {
- Query bodyQuery = hibernateSession.getNamedQuery(BodyPersistTasks.BODY_BY_ID);
- bodyQuery.setLong("bodyID", document.getDefaultBodyID());
- BodyRecord bodyRec = (BodyRecord)bodyQuery.uniqueResult();
- if(bodyRec != null && bodyRec.getOwnerUsername().equals(record.getUsername())) {
- dirty = true;
- record.setDefaultBodyID(document.getDefaultBodyID());
- }
- }
+ if (document.getPassword() != null
+ && !equals(record.getPassword(), document.getPassword())) {
+ if (AccountRecord.cleanPassword(document.getPassword()) != null) {
+ dirty = true;
+ record.setPassword(document.getPassword());
+ }
+ }
- if(document.getFrozenUntil() != null && !equals(record.getFrozenUntil(), document.getFrozenUntil())) {
- dirty = true;
- if(document.getFrozenUntil().getTime() < System.currentTimeMillis()) {
- record.setFrozenUntil(null);
- } else {
- record.setFrozenUntil(document.getFrozenUntil());
- }
- }
+ if (document.getDefaultBodyID() != -1) {
+ Query bodyQuery = hibernateSession
+ .getNamedQuery(BodyPersistTasks.BODY_BY_ID);
+ bodyQuery.setLong("bodyID", document.getDefaultBodyID());
+ BodyRecord bodyRec = (BodyRecord) bodyQuery.uniqueResult();
+ if (bodyRec != null
+ && bodyRec.getOwnerUsername().equals(
+ record.getUsername())) {
+ dirty = true;
+ record.setDefaultBodyID(document.getDefaultBodyID());
+ }
+ }
- if (dirty) {
- hibernateSession.update(record);
- return Boolean.TRUE;
- }
- return Boolean.FALSE;
- }
- };
- task.setSessionFactory(sessionFactory);
- return "true".equals(task.execute().toString());
- }
+
+ if (document.getFrozenUntil() != null) {
+ if (record.getFrozenUntil()!=document.getFrozenUntil().getTime()) {
+ dirty = true;
+ if (document.getFrozenUntil().getTime() < System.currentTimeMillis()) {
+ record.setNotFrozen();
+ } else {
+ record.setFrozenUntil(document.getFrozenUntil().getTime());
+ }
+ }
+ }
+ if (dirty) {
+ hibernateSession.update(record);
+ return Boolean.TRUE;
+ }
+ return Boolean.FALSE;
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return "true".equals(task.execute().toString());
+ }
- public static void update(final AccountRecord record, SessionFactory sessionFactory) throws PersistException {
- HibernateTask task = new HibernateTask() {
- public Object run(Session hibernateSession) {
- hibernateSession.update(record);
- return null;
- }
- };
- task.setSessionFactory(sessionFactory);
- task.execute();
- }
+ public static void update(final AccountRecord record,
+ SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session hibernateSession) {
+ hibernateSession.update(record);
+ return null;
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ task.execute();
+ }
- public static AccountRecord findAccountByCookie(final String cookie, SessionFactory sessionFactory) throws PersistException {
- HibernateTask task = new HibernateTask() {
- public Object run(Session hibernateSession) {
- Query query = hibernateSession.getNamedQuery(ACCOUNT_BY_COOKIE);
- query.setParameter("cookie", cookie);
- AccountRecord rec=(AccountRecord)query.uniqueResult();
- return rec;
- }
- };
- task.setSessionFactory(sessionFactory);
- return (AccountRecord) task.execute();
- }
+ public static AccountRecord findAccountByCookie(final String cookie,
+ SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session hibernateSession) {
+ Query query = hibernateSession.getNamedQuery(ACCOUNT_BY_COOKIE);
+ query.setParameter("cookie", cookie);
+ AccountRecord rec = (AccountRecord) query.uniqueResult();
+ return rec;
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return (AccountRecord) task.execute();
+ }
- public static AccountRecord[] findAllAccounts(SessionFactory sessionFactory) throws PersistException {
- HibernateTask task = new HibernateTask() {
- public Object run(Session hibernateSession) {
- Query query = hibernateSession.getNamedQuery("com.ogoglio.persist.accounts");
- return query.list().toArray(new AccountRecord[0]);
- }
- };
- task.setSessionFactory(sessionFactory);
- return (AccountRecord[]) task.execute();
- }
+ public static AccountRecord[] findAllAccounts(SessionFactory sessionFactory)
+ throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session hibernateSession) {
+ Query query = hibernateSession
+ .getNamedQuery("com.ogoglio.persist.accounts");
+ return query.list().toArray(new AccountRecord[0]);
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return (AccountRecord[]) task.execute();
+ }
- public static AccountRecord createAccount(final String username, final String accountlevel, final String email, SessionFactory sessionFactory) throws PersistException {
- HibernateTask task = new HibernateTask() {
- public Object run(Session hibernateSession) {
- final String cleanedUsername = AccountRecord.cleanUsername(username);
- Query query = hibernateSession.getNamedQuery(ACCOUNT_BY_USERNAME);
- query.setParameter("username", cleanedUsername);
-
- AccountRecord record = (AccountRecord)query.uniqueResult();
- if(record != null) {
- return null; // XXX really weird semantic: try to create something and get null because it's there?
- }
-
- //IES:debug because unique constraint on this field!
- final String cleanedEmail = AccountRecord.cleanEmail(email);
- query = hibernateSession.getNamedQuery(ACCOUNT_BY_EMAIL);
- query.setParameter("email", email);
- record = (AccountRecord)query.uniqueResult();
- if (record!=null) {
- System.err.println("Whoa! Bad email value!"+email);
- }
-
-
- record = new AccountRecord(username, accountlevel, email);
- hibernateSession.save(record);
- BodyRecord bodyRec = new BodyRecord("Body", record.getUsername());
- hibernateSession.save(bodyRec);
-
- record.setDefaultBodyID(bodyRec.getBodyID());
- hibernateSession.update(record);
- return record;
- }
- };
- task.setSessionFactory(sessionFactory);
- return (AccountRecord) task.execute();
- }
+ public static AccountRecord createAccount(final String username,
+ final String accountlevel, final String email,
+ SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session hibernateSession) {
+ final String cleanedUsername = AccountRecord
+ .cleanUsername(username);
+ Query query = hibernateSession
+ .getNamedQuery(ACCOUNT_BY_USERNAME);
+ query.setParameter("username", cleanedUsername);
- public static AccountRecord findAccountByUsername(String username, SessionFactory sessionFactory) throws PersistException {
- final String cleanedUsername = AccountRecord.cleanUsername(username);
- if (cleanedUsername == null) {
- return null;
- }
- HibernateTask task = new HibernateTask() {
- public Object run(Session hibernateSession) {
- Query query = hibernateSession.getNamedQuery(ACCOUNT_BY_USERNAME);
- query.setParameter("username", cleanedUsername);
- return query.uniqueResult();
- }
- };
- task.setSessionFactory(sessionFactory);
- return (AccountRecord) task.execute();
- }
+ AccountRecord record = (AccountRecord) query.uniqueResult();
+ if (record != null) {
+ return null; // XXX really weird semantic: try to create something and get null because it's there?
+ }
- public static void delete(final AccountRecord accRec,SessionFactory sessionFactory) throws PersistException {
- HibernateTask task = new HibernateTask() {
- public Object run(Session hibernateSession) {
- hibernateSession.delete(accRec);
- return null;
- }
- };
- task.setSessionFactory(sessionFactory);
- task.execute();
-
- }
+ //IES:debug because unique constraint on this field!
+ final String cleanedEmail = AccountRecord.cleanEmail(email);
+ query = hibernateSession.getNamedQuery(ACCOUNT_BY_EMAIL);
+ query.setParameter("email", email);
+ record = (AccountRecord) query.uniqueResult();
+ if (record != null) {
+ System.err.println("Whoa! Bad email value!" + email);
+ }
+
+ record = new AccountRecord(username, accountlevel, email);
+ hibernateSession.save(record);
+ BodyRecord bodyRec = new BodyRecord("Body", record
+ .getUsername());
+ hibernateSession.save(bodyRec);
+
+ record.setDefaultBodyID(bodyRec.getBodyID());
+ hibernateSession.update(record);
+ return record;
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return (AccountRecord) task.execute();
+ }
+
+ public static AccountRecord findAccountByUsername(String username,
+ SessionFactory sessionFactory) throws PersistException {
+ final String cleanedUsername = AccountRecord.cleanUsername(username);
+ if (cleanedUsername == null) {
+ return null;
+ }
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session hibernateSession) {
+ Query query = hibernateSession
+ .getNamedQuery(ACCOUNT_BY_USERNAME);
+ query.setParameter("username", cleanedUsername);
+ return query.uniqueResult();
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return (AccountRecord) task.execute();
+ }
+
+ public static void delete(final AccountRecord accRec,
+ SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session hibernateSession) {
+ hibernateSession.delete(accRec);
+ return null;
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ task.execute();
+
+ }
}
Modified: spaces/trunk/src/com/ogoglio/persist/AccountRecord.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/AccountRecord.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/persist/AccountRecord.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -17,6 +17,8 @@
public class AccountRecord {
+ public static final long NO_TIME_VALUE=-97;
+
public static final String ACCOUNT_LEVEL_BASIC = "basic";
public static final String ACCOUNT_LEVEL_ADVANCED = "advanced";
@@ -43,11 +45,11 @@
private String secret = null;
- private Date creationDate = null;
+ private long creationDate = NO_TIME_VALUE;
private String cookie = null;
- private Date frozenUntil = null;
+ private long frozenUntil = NO_TIME_VALUE;
private long defaultBodyId = 1;
@@ -185,11 +187,11 @@
this.cookie = cookie;
}
- public Date getCreationDate() {
- return creationDate;
+ public long getCreationDate() {
+ return creationDate;
}
- public void setCreationDate(Date creationDate) {
+ public void setCreationDate(long creationDate) {
this.creationDate = creationDate;
}
@@ -209,16 +211,16 @@
this.firstName = firstName;
}
- public Date getFrozenUntil() {
+ public long getFrozenUntil() {
return frozenUntil;
}
- public void setFrozenUntil(Date frozenUntil) {
+ public void setFrozenUntil(long frozenUntil) {
this.frozenUntil = frozenUntil;
}
public boolean isFrozen() {
- return frozenUntil != null && System.currentTimeMillis() < frozenUntil.getTime();
+ return frozenUntil != NO_TIME_VALUE && System.currentTimeMillis() < frozenUntil;
}
public String getLastName() {
@@ -260,4 +262,8 @@
public void setDefaultBodyID(long defaultBodyID) {
this.defaultBodyId = defaultBodyID;
}
+
+ public void setNotFrozen() {
+ this.frozenUntil=NO_TIME_VALUE;
+ }
}
Modified: spaces/trunk/src/com/ogoglio/persist/HibernateBase.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/HibernateBase.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/persist/HibernateBase.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -43,13 +43,14 @@
if (autoDDL!=null) {
- config.setProperty("hibernate.hbm2ddl.auto", "create");
+ config.setProperty("hibernate.hbm2ddl.auto", autoDDL);
}
config.setProperty("hibernate.dialect", dialect);
config.setProperty("hibernate.connection.driver_class", driver);
config.setProperty("hibernate.connection.url", URI);
config.setProperty("hibernate.connection.username", user);
config.setProperty("hibernate.connection.password", pw);
+ config.setProperty("hibernate.show_sql","true");
//always want these
config.setProperty("hibernate.connection.shutdown","true");
config.setProperty("hibernate.connection.pool_size", poolSize);
Modified: spaces/trunk/src/com/ogoglio/persist/Persist.hbm.xml
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/Persist.hbm.xml 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/persist/Persist.hbm.xml 2007-08-16 17:04:44 UTC (rev 243)
@@ -82,7 +82,7 @@
<property name="firstName"/>
<property name="lastName"/>
<property name="homepage"/>
- <property name="creationDate" update="false" />
+ <property name="creationDate" update="false"/>
<property name="cookie"/>
<property name="secret"/>
<property name="frozenUntil"/>
Modified: spaces/trunk/src/com/ogoglio/persist/SpacePersistTasks.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/SpacePersistTasks.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/persist/SpacePersistTasks.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -13,8 +13,8 @@
limitations under the License. */
package com.ogoglio.persist;
+import java.util.Date;
import java.util.Random;
-import java.util.Vector;
import org.hibernate.Query;
import org.hibernate.Session;
@@ -217,7 +217,8 @@
}
if (account != null) {
- if (account.getFrozenUntil() != null && account.getFrozenUntil().getTime() < System.currentTimeMillis()) {
+ if (account.isFrozen()) {
+ //if (account.getFrozenUntil() != null && account.getFrozenUntil().getTime() > System.currentTimeMillis()) {
return Boolean.FALSE;
}
Modified: spaces/trunk/src/com/ogoglio/sim/site/SimServlet.java
===================================================================
--- spaces/trunk/src/com/ogoglio/sim/site/SimServlet.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/sim/site/SimServlet.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -87,6 +87,7 @@
public void destroy() {
super.destroy();
sim.cleanup();
+ System.out.println("Destroy called on SimServlet. Cleaning up sim...");
}
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Modified: spaces/trunk/src/com/ogoglio/site/AccountServlet.java
===================================================================
--- spaces/trunk/src/com/ogoglio/site/AccountServlet.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/site/AccountServlet.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -146,7 +146,6 @@
public void doGet(HttpServletRequest request, HttpServletResponse response, String[] pathElements, AccountRecord authedAccount) throws PersistException, ServletException, IOException {
String usernameParam = pathElements[pathElements.length - 1];
-
if (usernameParam == null || usernameParam.trim().length() == 0) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
@@ -160,7 +159,6 @@
}
AccountDocument result = createAccountDocument(requestedAccount, authedAccount.equals(requestedAccount) || AccountRecord.ACCOUNT_LEVEL_ADMIN.equals(authedAccount.getAccountlevel()));
-
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("text/xml");
response.getOutputStream().write(result.toString().getBytes());
@@ -169,7 +167,6 @@
public void doPost(HttpServletRequest request, HttpServletResponse response, String[] pathElements, AccountRecord authedAccount) throws PersistException, ServletException, IOException {
String usernameParam = pathElements[pathElements.length - 1];
-
if (usernameParam == null || usernameParam.trim().length() == 0) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
@@ -199,12 +196,12 @@
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}
- if (requestedAccount.getFrozenUntil() != null && !requestedAccount.getFrozenUntil().equals(updatedDocument.getFrozenUntil())) {
+ if (requestedAccount.getFrozenUntil() != AccountRecord.NO_TIME_VALUE && requestedAccount.getFrozenUntil()!=updatedDocument.getFrozenUntil().getTime()) {
System.err.println("User tried to update own freeze: " + requestedAccount.getUsername());
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}
- if (requestedAccount.getFrozenUntil() == null && updatedDocument.getFrozenUntil() != null) {
+ if (requestedAccount.getFrozenUntil() !=AccountRecord.NO_TIME_VALUE && updatedDocument.getFrozenUntil() != null) {
System.err.println("User tried to freeze themselves: " + requestedAccount.getUsername());
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
@@ -213,10 +210,11 @@
//TODO if this returns false we really should reflect that in the response
- AccountPersistTasks.update(requestedAccount, updatedDocument, getSessionFactory());
-
+ if (!AccountPersistTasks.update(requestedAccount, updatedDocument, getSessionFactory())) {
+ System.out.println("Warning: ACCOUNT update failed:"+requestedAccount.getUsername());
+ }
+ //AccountPersistTasks.findAccountByUsername(usernameParam, getSessionFactory());
AccountDocument result = createAccountDocument(requestedAccount, true);
-
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("text/xml");
response.getOutputStream().write(result.toString().getBytes());
Modified: spaces/trunk/src/com/ogoglio/site/AuthServlet.java
===================================================================
--- spaces/trunk/src/com/ogoglio/site/AuthServlet.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/site/AuthServlet.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -74,7 +74,7 @@
if (accountRecord == null) {
return null;
}
- if (accountRecord.getFrozenUntil() != null && accountRecord.getFrozenUntil().getTime() > System.currentTimeMillis()) {
+ if (accountRecord.getFrozenUntil() != AccountRecord.NO_TIME_VALUE && accountRecord.getFrozenUntil() > System.currentTimeMillis()) {
return null;
}
if (password != null && !password.equals(accountRecord.getPassword())) {
Modified: spaces/trunk/src/com/ogoglio/site/MessageProxy.java
===================================================================
--- spaces/trunk/src/com/ogoglio/site/MessageProxy.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/site/MessageProxy.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -96,6 +96,7 @@
public void cleanup() {
channelServer.cleanup();
+ heartbeatTimer.cancel();
Object[] channels = (Object[]) simChannels.getValues();
for (int i = 0; i < channels.length; i++) {
((TCPChannel) channels[i]).cleanup();
Modified: spaces/trunk/src/com/ogoglio/site/SpaceServlet.java
===================================================================
--- spaces/trunk/src/com/ogoglio/site/SpaceServlet.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/site/SpaceServlet.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -68,6 +68,7 @@
if (messageProxy != null) {
messageProxy.cleanup();
}
+ System.out.println("Destroy called on SpaceServlet. Cleaning up proxy....");
} catch (Throwable e) {
e.printStackTrace();
}
Modified: spaces/trunk/src/com/ogoglio/util/PrepareDatabase.java
===================================================================
--- spaces/trunk/src/com/ogoglio/util/PrepareDatabase.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/util/PrepareDatabase.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -30,15 +30,17 @@
System.exit(1);
}
PrepareDatabase db= new PrepareDatabase();
+ db.start(false);
db.start(true);
- db.start(false);
System.out.println("Completed successfully. DBs are now ready.");
}
public void setupSessionFactory(boolean isServer) {
+ String autoDDL = "create";
+
if (isServer) {
if (OgoglioProperties.getOgoglioProperty(OgoglioProperties.WHICH_DB).equals(OgoglioProperties.WHICH_MYSQL)) {
- setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml", "create",
+ setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml", autoDDL,
OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_DIALECT),
OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_DRIVER),
OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_SERVER_URI),
@@ -47,7 +49,7 @@
"5");
} else {
- setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml", "create",
+ setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml", autoDDL,
OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_DIALECT),
OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_DRIVER),
OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_SERVER_URI),
@@ -57,7 +59,7 @@
}
} else {
if (OgoglioProperties.getOgoglioProperty(OgoglioProperties.WHICH_DB).equals(OgoglioProperties.WHICH_MYSQL)) {
- setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml", "create",
+ setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml", autoDDL,
OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_DIALECT),
OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_DRIVER),
OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_TEST_URI),
@@ -66,7 +68,7 @@
"5");
} else {
- setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml", "create",
+ setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml", autoDDL,
OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_DIALECT),
OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_DRIVER),
OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_TEST_URI),
@@ -81,6 +83,7 @@
String host = "127.0.0.1";
String siteInfo = "http://"+host+":8080/og"; //configured in server.xml
SessionFactory sessionFactory = getSessionFactory();
+ System.out.println("start:"+isServer+": with session Factory:"+sessionFactory.toString());
try {
ServiceInitializationPersistTasks.initializeLocalSim(new URI(siteInfo), sessionFactory);
ServiceInitializationPersistTasks.initializeLibraryAccount(sessionFactory,host);
Modified: spaces/trunk/src/com/ogoglio/xml/AccountDocument.java
===================================================================
--- spaces/trunk/src/com/ogoglio/xml/AccountDocument.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/xml/AccountDocument.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -17,6 +17,8 @@
import java.net.URISyntaxException;
import java.util.Date;
+import com.ogoglio.persist.AccountRecord;
+
import nanoxml.XMLElement;
public class AccountDocument {
@@ -49,7 +51,7 @@
XMLElement data = null;
- public AccountDocument(String username, String accountLevel, String firstName, String lastName, String homepage, String password, String email, String secret, Date creationDate, String cookie, Date frozenUntil, long defaultBodyID) {
+ public AccountDocument(String username, String accountLevel, String firstName, String lastName, String homepage, String password, String email, String secret, long creationDate, String cookie, long frozenUntil, long defaultBodyID) {
data = new XMLElement(NAME);
if (username == null) {
@@ -76,10 +78,10 @@
if (cookie != null)
data.setAttribute(COOKIE, cookie);
- if (creationDate != null)
- data.setAttribute(CREATION_DATE, creationDate.getTime());
- if (frozenUntil != null)
- data.setAttribute(FROZEN_UNTIL, frozenUntil.getTime());
+ if (creationDate != AccountRecord.NO_TIME_VALUE)
+ data.setAttribute(CREATION_DATE, creationDate);
+ if (frozenUntil!=AccountRecord.NO_TIME_VALUE)
+ data.setAttribute(FROZEN_UNTIL, frozenUntil);
if(defaultBodyID > -1)
data.setAttribute(DEFAULT_BODY_ID, defaultBodyID);
}
@@ -95,7 +97,7 @@
}
public AccountDocument(String username) { //used when updating the document, with absent items indicating no change
- this(username, null, null, null, null, null, null, null, null, null, null, 1);
+ this(username, null, null, null, null, null, null, null, AccountRecord.NO_TIME_VALUE, null, AccountRecord.NO_TIME_VALUE, 1);
}
public XMLElement toElement() {
Modified: spaces/trunk/src/com/ogoglio/xml/XMLTests.java
===================================================================
--- spaces/trunk/src/com/ogoglio/xml/XMLTests.java 2007-08-09 23:56:22 UTC (rev 242)
+++ spaces/trunk/src/com/ogoglio/xml/XMLTests.java 2007-08-16 17:04:44 UTC (rev 243)
@@ -52,11 +52,11 @@
private String secret1 = "cat's cradle";
- private Date creationDate1 = new Date();
+ private long creationDate1 = new Date().getTime();
private String cookie1 = "tr1234";
- private Date frozenUntil1 = new Date(System.currentTimeMillis() - 6000000);
+ private long frozenUntil1 = new Date(System.currentTimeMillis() - 6000000).getTime();
private long spaceID1;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|