|
From: <ian...@us...> - 2007-08-06 17:34:15
|
Revision: 235
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=235&view=rev
Author: iansmith
Date: 2007-08-06 10:34:13 -0700 (Mon, 06 Aug 2007)
Log Message:
-----------
Fixed the problems identified in Trevor's previous message
with respect to tests and DB configuration.
--------------------- Significant Change ------------------
There is a new file in the docs directory, "properties.example.txt' which should be copied and moved to your home directory as .ogoglio-properties. You'll need to update the values in this file to point to the correct database you are using for development.
-------------------- Data Issue ---------------------------
I removed the (bogus) file MigrateDB_TemplateTables. This file was wrong in both theory and practice. If you have data that was created in a server prior to the change in the Template data format, you should wait until we have new and better thought out data migration tool.
Modified Paths:
--------------
spaces/trunk/docs/server.xml
spaces/trunk/src/com/ogoglio/client/ClientTests.java
spaces/trunk/src/com/ogoglio/persist/AccountPersistTasks.java
spaces/trunk/src/com/ogoglio/persist/HibernateBase.java
spaces/trunk/src/com/ogoglio/persist/HibernateTests.java
spaces/trunk/src/com/ogoglio/persist/Persist.hbm.xml
spaces/trunk/src/com/ogoglio/persist/PersistTests.java
spaces/trunk/src/com/ogoglio/persist/ServiceInitializationPersistTasks.java
spaces/trunk/src/com/ogoglio/persist/SimPersistTasks.java
spaces/trunk/src/com/ogoglio/persist/SpacePersistTasks.java
spaces/trunk/src/com/ogoglio/site/AccountServlet.java
spaces/trunk/src/com/ogoglio/site/AuthServlet.java
spaces/trunk/src/com/ogoglio/templatesync/SyncToolSpec.java
spaces/trunk/src/com/ogoglio/templatesync/SyncToolTest.java
spaces/trunk/src/com/ogoglio/templatesync/TemplateServerSideTests.java
Added Paths:
-----------
spaces/trunk/docs/properties-example.txt
spaces/trunk/src/com/ogoglio/util/OgoglioProperties.java
spaces/trunk/src/com/ogoglio/util/PrepareDatabase.java
Removed Paths:
-------------
spaces/trunk/src/com/ogoglio/PrepareDatabase.java
spaces/trunk/src/com/ogoglio/persist/MigrateDB_TemplateTables.java
Added: spaces/trunk/docs/properties-example.txt
===================================================================
--- spaces/trunk/docs/properties-example.txt (rev 0)
+++ spaces/trunk/docs/properties-example.txt 2007-08-06 17:34:13 UTC (rev 235)
@@ -0,0 +1,78 @@
+#
+# This is an example of an ogoglio developer's properties file.
+# If a file in this format isn't in $HOME/.ogoglio-properties your tests
+# will fail. There are no defaults, you must edit these values to be
+# correct for your setup or the system may fail.
+
+#
+# TOMCAT
+#
+# pointer to your tomcat 5.5 install
+tomcat_dir = /usr/share/tomcat5.5
+
+#
+# LOCALHOST
+#
+# addr (where your development sever should live) ... might need to change this to test that
+# the server can be accessed by clients outside
+localhost_addr = 127.0.0.1:8080
+
+#
+# DATABASE
+#
+# Select which database to use. Valid values are "mysql" and "hsqldb".
+# If you chose hsqldb you will be running with an "in-memory" single user database.
+# no matter which you chose, the options that don't apply can be left in this file without harm
+# use "hqsl" for the other DB
+database_choice = mysql
+
+#
+# Hibernate dialect
+#
+#hibernate dialect for mysql (you can probably leave this alone)
+database_mysql_hibernate_dialect = org.hibernate.dialect.MySQLDialect
+#hibernate dialect for hsqldb (you can probably leave this alone)
+database_mysql_hibernate_dialect = org.hibernate.dialect.HSQLDialect
+#
+# JDBC Drivers
+#
+database_hsql_driver = org.hsqldb.jdbcDriver
+database_mysql_driver = com.mysql.jdbc.Driver
+
+#
+# SERVER CONFIGURATION FOR DB
+#
+#if you are using mysql this is a pointer to the database the server uses
+#you will need to create this database via mysqladmin create <name> ("og" in this example)
+database_mysql_server_uri = jdbc:mysql://127.0.0.1/og?autoreconnect=true
+#username to access the server's database
+database_mysql_server_user = oguser
+#password to access the server's database
+database_mysql_server_pass = sssh
+
+#hsql settings (URI points to a file in the filesystem where stuff gets stored)
+database_hsql_server_uri = jdbc:hsqldb:/tmp/ogoglio-db
+#username to access the server's database
+database_hsql_server_user = sa
+#password to access the server's database
+database_hsql_server_pass =
+
+#
+# TEST CONFIGURATION FOR DB
+#
+#if you are using mysql this is a pointer to the database the server uses
+#you will need to create this database via mysqladmin create <name> ("ogtest" in this example)
+database_mysql_test_uri = jdbc:mysql://127.0.0.1/ogtest?autoreconnect=true
+#username to access the server's database
+database_mysql_test_user = oguser
+#password to access the server's database
+database_mysql_test_pass = sssh
+
+#hsql settings (note that the uri points to a file in the filesystem)
+database_hsql_test_uri = jdbc:hsqldb:/tmp/ogoglio-test-db
+#username to access the server's database
+database_hsql_test_user = sa
+#password to access the server's database
+database_hsql_test_pass =
+
+
Modified: spaces/trunk/docs/server.xml
===================================================================
--- spaces/trunk/docs/server.xml 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/docs/server.xml 2007-08-06 17:34:13 UTC (rev 235)
@@ -17,7 +17,8 @@
<Logger className="org.apache.catalina.logger.SystemOutLogger" verbosity="4" timestamp="true"/>
<!-- THIS DEFINES THE DATABASE USED BY THE OGOGLIO SERVLETS, SET THE HSQL PATH OR ANOTHER JDBC URL (e.g. MySQL) -->
- <Resource name="jdbc/space" scope="Shareable" type="javax.sql.DataSource" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" url="jdbc:hsqldb:/Users/trevor/Code/EclipseWorkspace/spaces/db/ogoglio" driverClassName="org.hsqldb.jdbcDriver" username="sa" password="" maxIdle="5" maxActive="50" />
+ <!-- <Resource name="jdbc/space" scope="Shareable" type="javax.sql.DataSource" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" url="jdbc:hsqldb:/tmp/ogogliodb" driverClassName="org.hsqldb.jdbcDriver" username="sa" password="" maxIdle="5" maxActive="50" /> -->
+ <Resource name="jdbc/space" scope="Shareable" type="javax.sql.DataSource" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" url="jdbc:mysql:/og" driverClassName="com.mysql.jdbc.Driver" username="oguser" password="sssh" maxIdle="5" maxActive="50" />
<!-- THE FOLLOWING VARIABLES ARE READ IN com.ogoglio.site.AbstractResourceServet.init -->
Deleted: spaces/trunk/src/com/ogoglio/PrepareDatabase.java
===================================================================
--- spaces/trunk/src/com/ogoglio/PrepareDatabase.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/PrepareDatabase.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -1,58 +0,0 @@
-package com.ogoglio;
-
-import java.net.URI;
-
-import org.hibernate.SessionFactory;
-import org.hibernate.cfg.Configuration;
-
-import com.ogoglio.media.MediaStore;
-import com.ogoglio.persist.HibernateBase;
-import com.ogoglio.persist.ServiceInitializationPersistTasks;
-
-public class PrepareDatabase extends HibernateBase {
-
- /*
- * This is the beginning of a utility program to allow you be sure that your database is ready to
- * be used by the space (web) service. This opens the database in the correct mode to get it to
- * drop all the existing tables, create them according to the Persist.hbm.xml document while dumping
- * to the terminal the SQL it is using, and then exiting cleanly.
- *
- * This is program is only used on development machines to initialize their local HSQL instance
- * into a fresh state. After this program has run successfully, you can fire up the web service,
- * and the test suite can AND SHOULD be run.
- */
- /**
- * @param args IGNORED
- */
- public static void main(String[] args) {
- if (args.length!=2) {
- System.out.println("Need to pass the username and password on the command line!");
- System.exit(1);
- }
- new PrepareDatabase().start(args[0], args[1]);
- }
- public void start(String user, String pass) {
- setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml",
- "create",
- "org.hibernate.dialect.MySQLDialect",
- "com.mysql.jdbc.Driver",
- "jdbc:mysql://127.0.0.1/og?autoReconnect=true",
- user, pass,
- "5");
- config.setProperty("hibernate.connection.shutdown","true");
- String host = "10.0.1.198"; //best choice: 127.0.0.1
- String siteInfo = "http://"+host+":8080/og"; //configured in server.xml
- SessionFactory sessionFactory = getSessionFactory();
- try {
- //new SchemaUpdate(configuration).execute(true,true);
- ServiceInitializationPersistTasks.initializeLocalSim(new URI(siteInfo), sessionFactory);
- ServiceInitializationPersistTasks.initializeLibraryAccount(sessionFactory,host);
- sessionFactory.close();
- System.out.println("Completed successfully. DB is now ready.");
- } catch (Exception e) {
- e.printStackTrace();
- System.err.println("Exception during attempt to init DB:\n"+e.getMessage());
- }
- }
-
-}
Modified: spaces/trunk/src/com/ogoglio/client/ClientTests.java
===================================================================
--- spaces/trunk/src/com/ogoglio/client/ClientTests.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/client/ClientTests.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -75,6 +75,7 @@
WebAPIDescriptor descriptor1 = null;
+
public void setUp() {
try {
serviceURI1 = new URI("http://127.0.0.1:8080/og/"); //best choice: 127.0.0.1 for tests
Modified: spaces/trunk/src/com/ogoglio/persist/AccountPersistTasks.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/AccountPersistTasks.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/persist/AccountPersistTasks.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -22,6 +22,7 @@
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_COOKIE = "com.ogoglio.persist.accountByCookie";
@@ -130,13 +131,24 @@
AccountRecord record = (AccountRecord)query.uniqueResult();
if(record != null) {
- return 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;
@@ -161,4 +173,16 @@
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/HibernateBase.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/HibernateBase.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/persist/HibernateBase.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -3,6 +3,8 @@
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
+import com.ogoglio.util.OgoglioProperties;
+
/**
* Allows the hibernate initialization code to be in one place. Serves a few different purposes, but
* in general allows connection the hibernate DB directly from a program or test.
@@ -10,46 +12,77 @@
*
*/
public class HibernateBase {
+ private static final String DB_USER = "OGOGLIO_DB_USER";
+
+ private static final String DB_NAME = "OGOGLIO_DB_NAME";
+
+ private static final String DB_PASS = "OGOGLIO_DB_PASSWORD";
+
+ private static final String DB_USE_MYSQL= "OGOGLIO_USE_MYSQL";
+
protected Configuration config = null;
+
protected SessionFactory sessionFactory = null;
- public void setupSessionFactory(String persistXMLConfig, String autoDDL, String dialect, String driver, String URL, String user, String pw, String poolSize) {
- config = new Configuration();
- config.addResource(persistXMLConfig);
- if (autoDDL!=null) {
- config.setProperty("hibernate.hbm2ddl.auto", autoDDL);
- }
- config.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
- config.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
- config.setProperty("hibernate.connection.url", "jdbc:mysql://127.0.0.1/og?autoReconnect=true");
- config.setProperty("hibernate.connection.username", "oguser");
- config.setProperty("hibernate.connection.password", "sssh");
- config.setProperty("hibernate.connection.pool_size", "5");
+ private void configErrorMessage() {
+ System.err.println("We have changed the way DB server configuration works now.");
+ System.err.println("You need to se these environment variables ");
+ System.err.println(DB_USER);
+ System.err.println(DB_NAME);
+ System.err.println(DB_PASS);
+ System.err.println(DB_USE_MYSQL);
+ System.err.println("to the right values for your local MySQL setup.");
+ System.exit(1);
+ }
+
+ public void setupSessionFactory(String persistXMLConfig, String autoDDL, String dialect, String driver, String URI,
+ String user, String pw, String poolSize) {
+
+ config = new Configuration();
+ config.addResource(persistXMLConfig);
- /*
- config.setProperty("hibernate.dialect", dialect);
- config.setProperty("hibernate.connection.driver_class", driver);
- config.setProperty("hibernate.connection.url", URL);
- config.setProperty("hibernate.connection.username", user);
- config.setProperty("hibernate.connection.password", pw);
- config.setProperty("hibernate.connection.pool_size", poolSize);
- config.setProperty("hibernate.connection.shutdown","true");
- */
- sessionFactory = config.buildSessionFactory();
- }
-
- public SessionFactory getSessionFactory() {
- return sessionFactory;
- }
-
-
- public void setupSessionFactoryForTest() {
- setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml",
- "create",
- "org.hibernate.dialect.HSQLDialect",
- "org.hsqldb.jdbcDriver",
- "jdbc:hsqldb:test/db",
- "sa", "",
- "1");
- }
+
+ if (autoDDL!=null) {
+ config.setProperty("hibernate.hbm2ddl.auto", "create");
+ }
+ 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);
+ //always want these
+ config.setProperty("hibernate.connection.shutdown","true");
+ config.setProperty("hibernate.connection.pool_size", poolSize);
+ sessionFactory = config.buildSessionFactory();
+
+ if (sessionFactory==null) {
+ System.err.println("You have no hope of running properly because sessionFactory was not setup correctly");
+ System.err.println("in com.ogoglio.persist.HibernateBase.java");
+ System.exit(1);
+ }
+
+ }
+
+ public SessionFactory getSessionFactory() {
+ return sessionFactory;
+ }
+
+ public void setupSessionFactoryForTest() {
+ String dialect, uri, user, pass, driver;
+
+ if (OgoglioProperties.getOgoglioProperty(OgoglioProperties.WHICH_DB).equals(OgoglioProperties.WHICH_MYSQL)) {
+ dialect = OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_DIALECT);
+ driver = OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_DRIVER);
+ uri = OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_TEST_URI);
+ user = OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_TEST_USER);
+ pass = OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_TEST_PASS);
+ } else {
+ dialect = OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_DIALECT);
+ driver = OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_DRIVER);
+ uri = OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_TEST_URI);
+ user = OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_TEST_USER);
+ pass = OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_TEST_PASS);
+ }
+ setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml",null,dialect,driver,uri,user,pass,"5");
+ }
}
Modified: spaces/trunk/src/com/ogoglio/persist/HibernateTests.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/HibernateTests.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/persist/HibernateTests.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -1,7 +1,6 @@
package com.ogoglio.persist;
import org.hibernate.SessionFactory;
-import org.hibernate.cfg.Configuration;
import com.agical.rmock.extension.junit.RMockTestCase;
@@ -11,12 +10,13 @@
protected SessionFactory sessionFactory=null;
public void setUp() {
if (sessionFactory==null) {
- base.setupSessionFactoryForTest();
- sessionFactory=base.getSessionFactory();
- }
+ base.setupSessionFactoryForTest();
+ sessionFactory=base.getSessionFactory();
+ }
}
public void tearDown() {
sessionFactory.close();
+ sessionFactory=null;
}
}
Deleted: spaces/trunk/src/com/ogoglio/persist/MigrateDB_TemplateTables.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/MigrateDB_TemplateTables.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/persist/MigrateDB_TemplateTables.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -1,287 +0,0 @@
-package com.ogoglio.persist;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import javax.print.attribute.SupportedValuesAttribute;
-
-import org.hibernate.SessionFactory;
-
-import com.ogoglio.media.MediaService;
-
-//This is a truly dodgy piece of code. It is intended to be used with care. At some points it
-//copies pointers (e.g. a template ID) in a record without any care to whether or not the thing
-//pointed to makes sense. Thus, it depends on the numbering of the auto-created IDs in the
-//new database being the same as in the old one. This is certainly true for hsqldb but with
-//other databases, YMMV.
-//
-public class MigrateDB_TemplateTables extends HibernateBase {
-
- public static void main(String[] argv) {
- new MigrateDB_TemplateTables().start(argv);
- }
-
- public static final long BODY_INIT_VAL = -3828;
-
- long defaultBodyID = BODY_INIT_VAL;
-
- SessionFactory oldFactory;
- SessionFactory newFactory;
-
- /* You need to be sure that this points the right file or web storage URL */
- String URL_OF_MEDIA_STORE = "file:///home/iansmith/transmutable/workspace/spaces/working/media";
-
- public void createConnectionToOldAndNewDB()
- {
- /*
- * This CREATES the CURRENT database of ogoglio.
- * Modify the driver, URL, and username/pw if you are using MySQL. The current database
- * should not exist at the time this program is run; it will be created by this program.
- * If you are using HSQLDB then this means deleting the db files. Modify the driver, URL,
- * and username/pw if you are using MySQL.
- */
- setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml", "create",
- "org.hibernate.dialect.HSQLDialect",
- "org.hsqldb.jdbcDriver",
- "jdbc:hsqldb:db/ogoglio", // <--- filename in your db directory, will end up in new format
- "sa", "",
- "1");
- newFactory = getSessionFactory();
-
- /*
- * This USES (doesn't destroy) the OLD database of ogoglio. Modify the driver, URL, and
- * username/pw if you are using MySQL.
- */
- setupSessionFactory("com/ogoglio/persist/Persist_NoTemplateTables.hbm.xml", null,
- "org.hibernate.dialect.HSQLDialect",
- "org.hsqldb.jdbcDriver",
- "jdbc:hsqldb:db/ogoglio-old",// <---- filename in your db directory of old format db
- "sa", "",
- "1");
- oldFactory = getSessionFactory();
-
- }
-
- public void start(String[] argv) {
- try {
-
- createConnectionToOldAndNewDB();
-
- copyAccounts();
- copyBodies();
- copySims();
- copySpaces();
- copySpaceMembers();
- patchTemplates();
- copyPossessions();
-
- newFactory.close();
- oldFactory.close();
- } catch (PersistException e) {
- e.printStackTrace();
- System.out.println("PersistException:"+e.getMessage());
- } catch (IOException e) {
- e.printStackTrace();
- System.out.println("IOException:"+e.getMessage());
- } catch (URISyntaxException e) {
- e.printStackTrace();
- System.out.println("URISyntaxException:"+e.getMessage());
- }
- }
-
- public void abort(String msg) {
- System.out.println(msg);
- System.exit(1);
- }
-
- public void copyPossessions() throws PersistException{
- PossessionRecord[] poss=PossessionPersistTasks.findAllPossessions(oldFactory);
- for (int i=0; i<poss.length;++i) {
- PossessionRecord curr=poss[i];
- PossessionRecord newPoss = PossessionPersistTasks.createPossession(curr.getOwnerUsername(), curr.getTemplateID(), newFactory);
- if (newPoss.getPossessionID()!=curr.getPossessionID()) {
- abort("Possession IDs have gotten out of order!");
- }
- newPoss.setSpaceID(curr.getSpaceID());
- newPoss.setThingID(curr.getThingID());
- PossessionPersistTasks.update(newPoss, newFactory);
- }
- }
- public void copySims() throws PersistException{
- SimRecord[] allOldSims=SimPersistTasks.findSims(oldFactory);
- for (int i=0; i<allOldSims.length;++i) {
- SimRecord curr=allOldSims[i];
- SimRecord newSim=SimPersistTasks.createSim(curr.getDisplayName(),
- curr.getSimURI(), curr.getEventPort(), curr.isActive(), newFactory);
- if (newSim.getSimID()!=curr.getSimID()) {
- abort("Sim IDs have gotten out of order!");
- }
- }
- }
- public void copySpaceMembers() throws PersistException{
- SpaceMemberRecord[] allOldSpaceMembers=SpaceMemberPersistTasks.findAllSpaceMembers(oldFactory);
- for (int i=0; i<allOldSpaceMembers.length;++i) {
- SpaceMemberRecord curr=allOldSpaceMembers[i];
- SpaceMemberRecord newSpaceMember = SpaceMemberPersistTasks.createSpaceMember(curr.getSpaceID(),
- curr.getMemberUsername(), curr.isBanned(), newFactory);
- if (newSpaceMember.getSpaceMemberID()!=curr.getSpaceMemberID()) {
- abort("SpaceMemberIDs have gotten out of order!");
- }
- newSpaceMember.setRole(curr.getRole());
- SpaceMemberPersistTasks.update(newSpaceMember, newFactory);
- }
- }
-
- public void copySpaces() throws PersistException{
- SpaceRecord[] allOldSpaces=SpacePersistTasks.findAllSpaces(oldFactory);
- for (int i=0; i<allOldSpaces.length;++i) {
- SpaceRecord curr=allOldSpaces[i];
- SpaceRecord newSpace = SpacePersistTasks.createSpace(curr.getDisplayName(),
- curr.getOwnerUsername(), newFactory);
- if (newSpace.getSpaceID()!=curr.getSpaceID()) {
- abort("SpaceIDs have gotten out of order!");
- }
- newSpace.setDisplaySea(curr.getDisplaySea());
- newSpace.setMaxGuests(curr.getMaxGuests());
- newSpace.setPublished(curr.isPublished());
- newSpace.setSeaLevel(curr.getSeaLevel());
- newSpace.setSimID(curr.getSimID());
- SpacePersistTasks.update(newSpace, newFactory);
- }
- }
-
- public void copyAccounts() throws PersistException
- {
- AccountRecord[] oldAccount = AccountPersistTasks.findAllAccounts(oldFactory);
- for (int i=0; i<oldAccount.length;++i) {
- AccountRecord curr=oldAccount[i];
- AccountRecord newAcct =
- AccountPersistTasks.createAccount(curr.getUsername(),curr.getAccountlevel(),curr.getEmail(), newFactory);
- newAcct.setPassword(curr.getPassword());
- AccountPersistTasks.update(newAcct, newFactory);
- //blow away the body because it is initialized to a default value and we are going
- //to copy it rather than use the default
- BodyRecord[] body = BodyPersistTasks.findBodyByUsername(newAcct.getUsername(), newFactory);
- if (body.length!=1) {
- System.err.println("Whoa! More than one body created by default! Or No body!");
- System.exit(1);
- }
- boolean delResult = BodyPersistTasks.delete(body[0], newFactory);
- if (delResult==false) {
- //System.err.println("Can't delete body for user "+newAcct.getUsername() + "(probably default)");
- }
- }
- }
-
- public long getDefaultBodyID() throws PersistException {
-
- if (defaultBodyID==BODY_INIT_VAL) {
- AccountRecord[] allAccts = AccountPersistTasks.findAllAccounts(newFactory);
- defaultBodyID=allAccts[0].getDefaultBodyID();
- }
- return defaultBodyID;
- }
-
- public void copyBodies() throws PersistException {
- BodyRecord[] oldBody = BodyPersistTasks.findAllBodies(oldFactory);
- for (int i=0; i<oldBody.length;++i) {
- BodyRecord curr=oldBody[i];
- //careful, may have been created by the creation of the account
- BodyRecord newBody = BodyPersistTasks.findBodyByID(curr.getBodyID(), newFactory);
- if (newBody==null) {
- newBody = BodyPersistTasks.createBody(curr.getDisplayName(),curr.getOwnerUsername(),newFactory);
- }
- if (newBody.getBodyID()!=curr.getBodyID()) {
- abort("BodyIDs have gotten out of order!");
- }
- newBody.setEyesIndex(curr.getEyesIndex());
- newBody.setFaceIndex(curr.getFaceIndex());
- newBody.setGirth(curr.getGirth());
- newBody.setHairIndex(curr.getHairIndex());
- newBody.setHeight(curr.getHeight());
- newBody.setMale(curr.getMale());
- newBody.setMouthIndex(curr.getMouthIndex());
- newBody.setNoseIndex(curr.getNoseIndex());
- BodyPersistTasks.update(newBody, newFactory);
- }
- }
-
- public void patchTemplates() throws PersistException, IOException, URISyntaxException{
- MediaService svc = new MediaService(new URI(URL_OF_MEDIA_STORE));
- String[] names=svc.getAllNames();
- int SIGNAL_NO_LOD_FOUND=-622;
- for (int i=0; i<names.length;++i) {
- String name=names[i];
- long templateID=-288;
- int lod = SIGNAL_NO_LOD_FOUND;
- TemplateRecord patched=null;
-
- if (name.startsWith(MediaService.TEMPLATE_GEOMETRY_PREFIX)){
- String shorter =name.substring(MediaService.TEMPLATE_GEOMETRY_PREFIX.length());
- String templateParsed = shorter.substring(0,shorter.indexOf('-'));
- String lodParsed = shorter.substring(shorter.indexOf('-')+1);
- try {
- templateID = Long.parseLong(templateParsed);
- } catch (NumberFormatException ex) {
- abort("Unable to understand the template ID in "+name);
- }
- try {
- lod = Integer.parseInt(lodParsed);
- if (lod!=0) {
- abort("We currently don't know how to handle any LOD except 0.");
- }
- } catch (NumberFormatException e) {
- //we have lod already in place
- }
- TemplateRecord curr = TemplatePersistTasks.findTemplateByTemplateID(templateID, oldFactory);
- if (curr==null) {
- continue;
- }
- patched = getTemplateByIDOrCreateIt(templateID, curr);
- TemplateSupportFileRecord rec;
- if (lod!=SIGNAL_NO_LOD_FOUND) {
- rec=TemplateSupportFilePersistTasks.createSupportFileForGeometry(lod,newFactory);
- } else {
- rec=TemplateSupportFilePersistTasks.createSupportFileForMaterial(lodParsed,newFactory);
- }
- patched.addTemplateSupportFileRecord(rec);
- TemplatePersistTasks.update(patched, newFactory);
- } else if (name.startsWith(MediaService.TEMPLATE_SCRIPT_PREFIX)) {
- if (!name.endsWith(MediaService.TEMPLATE_SCRIPT_SUFFIX)) {
- abort("Unable to handle that type of a script document:"+name);
- }
- String shorter = name.substring(MediaService.TEMPLATE_SCRIPT_PREFIX.length(),
- name.indexOf('.'));
- try {
- templateID = Long.parseLong(shorter);
- } catch (NumberFormatException e) {
- abort("Can't handle the template number on this script file:"+name);
- }
- TemplateRecord curr = TemplatePersistTasks.findTemplateByTemplateID(templateID, oldFactory);
- if (curr==null) {
- continue;
- }
- patched = getTemplateByIDOrCreateIt(templateID, curr);
- TemplateSupportFileRecord rec=TemplateSupportFilePersistTasks.createSupportFileForScript(newFactory);
- patched.addTemplateSupportFileRecord(rec);
- TemplatePersistTasks.update(patched, newFactory);
- } else if (name.startsWith(MediaService.SPACE_DOCUMENT_PREFIX)) {
- continue; //prevents trying to update!
- } else {
- System.out.println("WARNING: Ignoring media file:"+name);
- continue; //prevents trying to update!
- }
- }
- }
-
- private TemplateRecord getTemplateByIDOrCreateIt(long templateID, TemplateRecord curr) throws PersistException {
- TemplateRecord patched;
- patched=TemplatePersistTasks.findTemplateByTemplateID(templateID, newFactory);
- if (patched==null) {
- patched = TemplatePersistTasks.createTemplate(curr.getDisplayName(),
- curr.getOwnerUsername(), newFactory);
- }
- return patched;
- }
-}
Modified: spaces/trunk/src/com/ogoglio/persist/Persist.hbm.xml
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/Persist.hbm.xml 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/persist/Persist.hbm.xml 2007-08-06 17:34:13 UTC (rev 235)
@@ -76,7 +76,6 @@
<class name="com.ogoglio.persist.AccountRecord" table="AccountRecords">
<id name="username">
</id>
-
<property name="email" not-null="true" unique="true" />
<property name="accountlevel" not-null="true" />
<property name="password"/>
@@ -153,6 +152,10 @@
<![CDATA[ from com.ogoglio.persist.AccountRecord as account where account.username = :username ]]>
</query>
+ <query name="com.ogoglio.persist.accountByEmail">
+ <![CDATA[ from com.ogoglio.persist.AccountRecord as account where account.email = :email ]]>
+ </query>
+
<query name="com.ogoglio.persist.accountByCookie">
<![CDATA[ from com.ogoglio.persist.AccountRecord as account where account.cookie = :cookie ]]>
</query>
Modified: spaces/trunk/src/com/ogoglio/persist/PersistTests.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/PersistTests.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/persist/PersistTests.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -52,7 +52,7 @@
email2 = AccountRecord.cleanEmail("kv...@ex...");
level2 = "pro";
- simURI1 = new URI("http://127.0.0.1/sim");
+ simURI1 = new URI("http://127.0.0.1:8080/sim");
ownerUsername = "Mr. Goldwater";
} catch (Exception e) {
fail("Could not setup:" + e);
@@ -62,48 +62,49 @@
public void testRecords() {
try {
- AccountRecord accRec1 = AccountPersistTasks.createAccount(username1, level1, email1, sessionFactory);
-
- assertEquals(username1, accRec1.getUsername());
- assertEquals(email1, accRec1.getEmail());
- assertEquals(level1, accRec1.getAccountlevel());
-
+ String ONE_TWO="1234";
+
+ AccountRecord accRec1= AccountPersistTasks.findAccountByUsername(username1, sessionFactory);
+ if (accRec1!=null) {
+ System.out.println("Destroying leftover account test state:"+username1);
+ AccountPersistTasks.delete(accRec1,sessionFactory);
+ }
+ accRec1 = AccountPersistTasks.createAccount(username1, level1, email1, sessionFactory);
+ verifyAccountProps(accRec1,username1, email1, level1, null);
+
accRec1.setPassword("1234");
AccountPersistTasks.update(accRec1, sessionFactory);
AccountRecord accRec2 = AccountPersistTasks.findAccountByUsername(username1, sessionFactory);
assertNotNull(accRec2);
- assertEquals(username1, accRec2.getUsername());
- assertEquals(email1, accRec2.getEmail());
- assertEquals(level1, accRec2.getAccountlevel());
-
+ verifyAccountProps(accRec2, username1, email1, level1, ONE_TWO);
+
String templateName1 = "Plate of Raw Oysters";
TemplateRecord templateRec1 = TemplatePersistTasks.createTemplate(templateName1 , username1, sessionFactory);
- assertNotNull(templateRec1);
- assertEquals(templateName1, templateRec1.getDisplayName());
- assertEquals(username1, templateRec1.getOwnerUsername());
+ verifyTemplateProps(templateName1, templateRec1);
templateRec1 = TemplatePersistTasks.findTemplateByTemplateID(templateRec1.getTemplateID(), sessionFactory);
- assertNotNull(templateRec1);
- assertEquals(templateName1, templateRec1.getDisplayName());
- assertEquals(username1, templateRec1.getOwnerUsername());
-
- SimRecord simRecord1 = SimPersistTasks.createSim(displayName1, simURI1, 2048, true, sessionFactory);
- assertEquals(displayName1, simRecord1.getDisplayName());
- assertEquals(simURI1, simRecord1.getSimURI());
- assertFalse(-1 == simRecord1.getSimID());
- assertEquals(2048, simRecord1.getEventPort());
+ verifyTemplateProps(templateName1, templateRec1);
+ SimRecord simRecord1=SimPersistTasks.findSimsBySimURI(simURI1, sessionFactory);
+ if (simRecord1!=null) {
+ System.out.println("Destroying leftover sim record test state:"+
+ simRecord1.getDisplayName());
+ SimPersistTasks.delete(simRecord1,sessionFactory);
+ }
+ //ok to create sim now on that URI
+ simRecord1 = SimPersistTasks.createSim(displayName1, simURI1, 2048, true, sessionFactory);
+ verifySimProps(simRecord1,displayName1,simURI1,-1,2048);
+
String displayName2 = "moon unit";
simRecord1.setDisplayName(displayName2);
SimPersistTasks.update(simRecord1, sessionFactory);
assertEquals(displayName2, simRecord1.getDisplayName());
+ //better test is to load it from db
+ SimRecord simRecord2 = SimPersistTasks.findSimsBySimURI(simURI1, sessionFactory);
+ verifySimProps(simRecord2, displayName2, simURI1, -1, 2048);
- SimRecord simRecord2 = SimPersistTasks.findSimsBySimURI(simURI1, sessionFactory);
- assertNotNull(simRecord2);
- assertEquals(displayName2, simRecord2.getDisplayName());
- assertEquals(simURI1, simRecord2.getSimURI());
- assertFalse(-1 == simRecord2.getSimID());
+ //it's the same sim on the same URI so better have same id?
assertEquals(simRecord1.getSimID(), simRecord2.getSimID());
String spaceName1 = "Space 1";
@@ -119,7 +120,18 @@
assertEquals(spaceRecord1, spaceRecord2);
SimRecord assignedSimRecord = SpacePersistTasks.findOrAssignSim(spaceRecord2, sessionFactory);
+ assertNotNull(assignedSimRecord);
+ System.out.println("XXX ASSIGNED TO SIM:"+assignedSimRecord.getSimID()+","+assignedSimRecord.getSimURI()+" -->\n"+
+ "space was "+spaceRecord2.getSpaceID()+" now on "+spaceRecord2.getSimID()+","+spaceRecord2.getDisplayName());
+ /*
+ * IES: I spent a lot of time looking at this and could not see any way to test this given that
+ * IES: that assigned sim is random. Apparently, before we were depending on a random number
+ * IES: sequence doing something we expected.
+ assertEquals(simRecord1.getSimURI(), assignedSimRecord.getSimURI());
+ assertEquals(simRecord1.getDisplayName(), assignedSimRecord.getDisplayName());
+ assertEquals(simRecord1.getSimID(), assignedSimRecord.getSimID());
assertEquals(simRecord1, assignedSimRecord);
+ */
BodyRecord bodyRec1 = BodyPersistTasks.createBody(displayName1, "bogosity", sessionFactory);
assertNull("created body with bogus username", bodyRec1);
@@ -142,7 +154,8 @@
assertEquals(12, possRecord.getThingID());
PossessionRecord[] possRecs1 = PossessionPersistTasks.findPossessionsByOwnerUsername(username1, sessionFactory);
- assertNotNull(possRecs1);
+ assertNotNull(possRecs1);
+
assertEquals(username1, possRecs1[0].getOwnerUsername());
} catch (PersistException e) {
e.printStackTrace();
@@ -150,9 +163,39 @@
}
try {
+ // IES: testing that our weird semantics here work as expected...
assertNull(AccountPersistTasks.createAccount(username1, level1, email2, sessionFactory));
} catch (PersistException e) {
fail("Should have just returned null instead of failed: " + e);
}
}
+
+
+ private void verifySimProps(SimRecord rec, String name, URI uri, int not_id, int port) {
+ assertNotNull(rec);
+ assertEquals(name, rec.getDisplayName());
+ assertEquals(uri, rec.getSimURI());
+ assertFalse(not_id == rec.getSimID());
+ assertEquals(port, rec.getEventPort());
+ }
+
+
+ private void verifyTemplateProps(String templateName1, TemplateRecord templateRec1) {
+ assertNotNull(templateRec1);
+ assertEquals(templateName1, templateRec1.getDisplayName());
+ assertEquals(username1, templateRec1.getOwnerUsername());
+ }
+
+
+ private void verifyAccountProps(AccountRecord rec, String user, String mail, String level, String pwd) {
+ assertNotNull(rec);
+ assertEquals(user, rec.getUsername());
+ assertEquals(mail, rec.getEmail());
+ assertEquals(level, rec.getAccountlevel());
+ if (pwd==null) {
+ assertNull(rec.getPassword());
+ } else {
+ assertEquals(pwd,rec.getPassword());
+ }
+ }
}
\ No newline at end of file
Modified: spaces/trunk/src/com/ogoglio/persist/ServiceInitializationPersistTasks.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/ServiceInitializationPersistTasks.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/persist/ServiceInitializationPersistTasks.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -45,7 +45,6 @@
if (accountRec != null) {
return;
}
-
accountRec = AccountPersistTasks.createAccount(LIBRARY_USERNAME, "admin", "library@"+host, sessionFactory);
accountRec.setPassword(DEFAULT_LIBRARY_PASSWORD);
AccountPersistTasks.update(accountRec, sessionFactory);
Modified: spaces/trunk/src/com/ogoglio/persist/SimPersistTasks.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/SimPersistTasks.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/persist/SimPersistTasks.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -72,4 +72,16 @@
task.setSessionFactory(sessionFactory);
task.execute();
}
+
+
+ public static void delete(final SimRecord simRecord, SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session hibernateSession) {
+ hibernateSession.delete(simRecord);
+ return null;
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ task.execute();
+ }
}
Modified: spaces/trunk/src/com/ogoglio/persist/SpacePersistTasks.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/SpacePersistTasks.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/persist/SpacePersistTasks.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -145,7 +145,6 @@
if (sims.length == 0) { // no active sims!!!
return null;
}
-
//TODO pick a sim based on load, not at random
simRecord = (SimRecord) sims[Math.abs(RANDOM.nextInt() % sims.length)];
spaceRecord.setSimID(simRecord.getSimID());
Modified: spaces/trunk/src/com/ogoglio/site/AccountServlet.java
===================================================================
--- spaces/trunk/src/com/ogoglio/site/AccountServlet.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/site/AccountServlet.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -125,7 +125,6 @@
}
newAccountRec = AccountPersistTasks.createAccount(newAccountDoc.getUsername(), newAccountDoc.getAccountLevel(), newAccountDoc.getEmail(), getSessionFactory());
- System.out.println(new Date() + ": Admin " + authedAccount.getUsername() + " created new account " + newAccountRec.getUsername());
newAccountRec.setPassword(newAccountDoc.getPassword());
newAccountRec.setFirstName(newAccountDoc.getFirstName());
newAccountRec.setLastName(newAccountDoc.getLastName());
Modified: spaces/trunk/src/com/ogoglio/site/AuthServlet.java
===================================================================
--- spaces/trunk/src/com/ogoglio/site/AuthServlet.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/site/AuthServlet.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -84,7 +84,6 @@
if (accountRecord.getCookie() == null) {
accountRecord.setCookie(generateAuthCookie(false));
}
-
AccountPersistTasks.update(accountRecord, getSessionFactory());
return accountRecord;
@@ -160,7 +159,6 @@
newCookie.setMaxAge(Integer.MAX_VALUE - 1);
newCookie.setDomain(getSiteInfo().getHost());
response.addCookie(newCookie);
-
AuthDocument authDoc = new AuthDocument(authedAccountRecord.getUsername(), true);
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("text/xml");
Modified: spaces/trunk/src/com/ogoglio/templatesync/SyncToolSpec.java
===================================================================
--- spaces/trunk/src/com/ogoglio/templatesync/SyncToolSpec.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/templatesync/SyncToolSpec.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -389,7 +389,7 @@
mockSyncTool.upScript.delete(client, mockTempDoc, null, SyncTool.IS_SCRIPT);
modify().forward();
- client.updateTemplateScript(mockTempDoc.getOwnerUsername(), mockTempDoc.getTemplateID(), "");
+ client.updateTemplateScript(mockTempDoc.getOwnerUsername(), TID, "");
modify().args(is.ANYTHING, is.ANYTHING, is.ANYTHING);
//now hit it
@@ -546,8 +546,8 @@
modify().multiplicity(expect.atMost(2));
modify().returnValue(TID);
- client.getTemplateDocument(mockTempDoc.getOwnerUsername(), TID);
- modify().args(is.AS_RECORDED, is.AS_RECORDED);
+ client.getTemplateDocument("some authenticator object will be here", TID);
+ modify().args(is.ANYTHING,is.AS_RECORDED);
modify().multiplicity(expect.atMost(2));
modify().returnValue(mockTempDoc);
Modified: spaces/trunk/src/com/ogoglio/templatesync/SyncToolTest.java
===================================================================
--- spaces/trunk/src/com/ogoglio/templatesync/SyncToolTest.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/templatesync/SyncToolTest.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -59,11 +59,11 @@
}
public void testTwoCriticalDirs_unit() {
- String FART="/fart", BARF="/barf";
+ String YACK="/yack", BARF="/barf";
- List choices = tool.candidatesDirsFromCriticalDirs(FART,BARF);
+ List choices = tool.candidatesDirsFromCriticalDirs(YACK,BARF);
assertThat(choices.size(),is.eq(4));
- assertThat(choices.get(0),is.eq(FART+File.separatorChar+"templates")); //prefer no dot
+ assertThat(choices.get(0),is.eq(YACK+File.separatorChar+"templates")); //prefer no dot
assertThat(choices.get(3),is.eq(BARF+File.separatorChar+".templates"));
}
Modified: spaces/trunk/src/com/ogoglio/templatesync/TemplateServerSideTests.java
===================================================================
--- spaces/trunk/src/com/ogoglio/templatesync/TemplateServerSideTests.java 2007-08-04 00:19:57 UTC (rev 234)
+++ spaces/trunk/src/com/ogoglio/templatesync/TemplateServerSideTests.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -9,12 +9,11 @@
public class TemplateServerSideTests extends HibernateTests {
- public void setUp() {
- super.setUp();
- }
public void createPlausibleAccount(String user, String level, String email) throws PersistException{
AccountRecord accRec1 = AccountPersistTasks.createAccount(user, level, email, sessionFactory);
-
+ if (accRec1==null) {
+ accRec1=AccountPersistTasks.findAccountByUsername(user, sessionFactory);
+ }
// sanity
assertEquals(user, accRec1.getUsername());
assertEquals(email, accRec1.getEmail());
Added: spaces/trunk/src/com/ogoglio/util/OgoglioProperties.java
===================================================================
--- spaces/trunk/src/com/ogoglio/util/OgoglioProperties.java (rev 0)
+++ spaces/trunk/src/com/ogoglio/util/OgoglioProperties.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -0,0 +1,74 @@
+package com.ogoglio.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Properties;
+
+public class OgoglioProperties extends Properties {
+
+ public static final String PROPERTY_FILE_NAME = ".ogoglio-properties";
+ private static OgoglioProperties prop=null;
+
+ public static String WHICH_DB = "database_choice";
+ public static String WHICH_MYSQL = "mysql";
+ public static String WHICH_HSQL = "hsql";
+
+ // the reason these properties are duplicated is to make it easy to switch in the configuration
+ // file by changing only one line and leaving everything else in place
+ public static String MYSQL_DB_DIALECT = "database_mysql_hibernate_dialect";
+ public static String MYSQL_DB_DRIVER= "database_mysql_driver";
+
+ public static String MYSQL_DB_SERVER_URI = "database_mysql_server_uri";
+ public static String MYSQL_DB_SERVER_USER = "database_mysql_server_user";
+ public static String MYSQL_DB_SERVER_PASS = "database_mysql_server_pass";
+
+ public static String MYSQL_DB_TEST_URI = "database_mysql_test_uri";
+ public static String MYSQL_DB_TEST_USER = "database_mysql_test_user";
+ public static String MYSQL_DB_TEST_PASS = "database_mysql_test_pass";
+
+ public static String HSQL_DB_DIALECT = "database_hsql_hibernate_dialect";
+ public static String HSQL_DB_DRIVER= "database_hsql_driver";
+
+ public static String HSQL_DB_SERVER_URI = "database_hsql_server_uri";
+ public static String HSQL_DB_SERVER_USER = "database_hsql_server_user";
+ public static String HSQL_DB_SERVER_PASS = "database_hsql_server_pass";
+
+ public static String HSQL_DB_TEST_URI = "database_hsql_test_uri";
+ public static String HSQL_DB_TEST_USER = "database_hsql_test_user";
+ public static String HSQL_DB_TEST_PASS = "database_hsql_test_pass";
+
+ private OgoglioProperties() {
+
+ }
+
+ public static void validate() {
+ if (prop!=null) {
+ return;
+ }
+ //init
+ File f = new File(System.getProperty("user.home"),PROPERTY_FILE_NAME);
+ prop=new OgoglioProperties();
+ try {
+ prop.load(new FileInputStream(f));
+ } catch (FileNotFoundException e) {
+ System.err.println("Can't find ogoglio properties file ("+f.getPath()+"):"+e.getMessage());
+ System.exit(1);
+ } catch (IOException e) {
+ System.err.println("Error reading ogoglio properties file ("+f.getPath()+"):"+e.getMessage());
+ System.exit(1);
+ }
+ }
+
+ public static String getOgoglioProperty(String pname)
+ {
+ validate();
+ String result = prop.getProperty(pname,null);
+ if (result==null) {
+ System.out.println("Unable to locate property "+pname+" in your "+PROPERTY_FILE_NAME+" file! Aborting!");
+ System.exit(1);
+ }
+ return result;
+ }
+}
Copied: spaces/trunk/src/com/ogoglio/util/PrepareDatabase.java (from rev 234, spaces/trunk/src/com/ogoglio/PrepareDatabase.java)
===================================================================
--- spaces/trunk/src/com/ogoglio/util/PrepareDatabase.java (rev 0)
+++ spaces/trunk/src/com/ogoglio/util/PrepareDatabase.java 2007-08-06 17:34:13 UTC (rev 235)
@@ -0,0 +1,94 @@
+package com.ogoglio.util;
+
+import java.net.URI;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+
+import com.ogoglio.media.MediaStore;
+import com.ogoglio.persist.HibernateBase;
+import com.ogoglio.persist.ServiceInitializationPersistTasks;
+
+public class PrepareDatabase extends HibernateBase {
+
+ /*
+ * This is the beginning of a utility program to allow you be sure that your database is ready to
+ * be used by the space (web) service. This opens the database in the correct mode to get it to
+ * drop all the existing tables, create them according to the Persist.hbm.xml document while dumping
+ * to the terminal the SQL it is using, and then exiting cleanly.
+ *
+ * This is program is only used on development machines to initialize their local HSQL instance
+ * into a fresh state. After this program has run successfully, you can fire up the web service,
+ * and the test suite can AND SHOULD be run.
+ */
+ /**
+ * @param args IGNORED
+ */
+ public static void main(String[] args) {
+ if (args.length!=0) {
+ System.out.println("Dosen't take command line parameters, use the .ogoglio-properties file!");
+ System.exit(1);
+ }
+ PrepareDatabase db= new PrepareDatabase();
+ db.start(true);
+ db.start(false);
+ System.out.println("Completed successfully. DBs are now ready.");
+ }
+
+ public void setupSessionFactory(boolean isServer) {
+ if (isServer) {
+ if (OgoglioProperties.getOgoglioProperty(OgoglioProperties.WHICH_DB).equals(OgoglioProperties.WHICH_MYSQL)) {
+ setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml", "create",
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_DIALECT),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_DRIVER),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_SERVER_URI),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_SERVER_USER),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_SERVER_PASS),
+ "5");
+
+ } else {
+ setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml", "create",
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_DIALECT),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_DRIVER),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_SERVER_URI),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_SERVER_USER),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_SERVER_PASS),
+ "5");
+ }
+ } else {
+ if (OgoglioProperties.getOgoglioProperty(OgoglioProperties.WHICH_DB).equals(OgoglioProperties.WHICH_MYSQL)) {
+ setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml", "create",
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_DIALECT),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_DRIVER),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_TEST_URI),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_TEST_USER),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.MYSQL_DB_TEST_PASS),
+ "5");
+
+ } else {
+ setupSessionFactory("com/ogoglio/persist/Persist.hbm.xml", "create",
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_DIALECT),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_DRIVER),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_TEST_URI),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_TEST_USER),
+ OgoglioProperties.getOgoglioProperty(OgoglioProperties.HSQL_DB_TEST_PASS),
+ "5");
+ }
+ }
+ }
+ public void start(boolean isServer) {
+ setupSessionFactory(isServer);
+ String host = "127.0.0.1";
+ String siteInfo = "http://"+host+":8080/og"; //configured in server.xml
+ SessionFactory sessionFactory = getSessionFactory();
+ try {
+ ServiceInitializationPersistTasks.initializeLocalSim(new URI(siteInfo), sessionFactory);
+ ServiceInitializationPersistTasks.initializeLibraryAccount(sessionFactory,host);
+ sessionFactory.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.err.println("Exception during attempt to init DB:\n"+e.getMessage());
+ }
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|