|
From: <ian...@us...> - 2007-07-01 18:46:55
|
Revision: 207
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=207&view=rev
Author: iansmith
Date: 2007-07-01 11:46:57 -0700 (Sun, 01 Jul 2007)
Log Message:
-----------
Minor changes.
1) Added PrepareDatabase in com.ogoglio to have a way to create the database without needed to flip switches in configuration files. This may be in the wrong package; I just put it near the test suite because I use it to prepare for running tests.
2) Added a workaround to get around the differences between Linux's JDK and Apple's. This is really gross, but necessary to get ogoglio to compile. It's marked with XXX in WebAPIClient.
3) Removed some dead code and parameters as I encountered them. It's all in the tree.
Modified Paths:
--------------
spaces/trunk/src/com/ogoglio/client/WebAPIClient.java
spaces/trunk/src/com/ogoglio/persist/ServiceInitializationPersistTasks.java
spaces/trunk/src/com/ogoglio/site/AccountServlet.java
Added Paths:
-----------
spaces/trunk/src/com/ogoglio/PrepareDatabase.java
Added: spaces/trunk/src/com/ogoglio/PrepareDatabase.java
===================================================================
--- spaces/trunk/src/com/ogoglio/PrepareDatabase.java (rev 0)
+++ spaces/trunk/src/com/ogoglio/PrepareDatabase.java 2007-07-01 18:46:57 UTC (rev 207)
@@ -0,0 +1,48 @@
+package com.ogoglio;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.tool.hbm2ddl.SchemaUpdate;
+
+import com.ogoglio.persist.ServiceInitializationPersistTasks;
+
+public class PrepareDatabase {
+
+ /*
+ * 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) {
+ Configuration configuration = new Configuration();
+ configuration.addResource("com/ogoglio/persist/Persist.hbm.xml");
+ configuration.setProperty("hibernate.hbm2ddl.auto", "create");
+ configuration.setProperty("hibernate.show_sql", "true");
+ configuration.setProperty("hibernate.connection.driver_class","org.hsqldb.jdbcDriver");
+ configuration.setProperty("hibernate.connection.url","jdbc:hsqldb:db/ogoglio");
+ configuration.setProperty("hibernate.connection.username","sa");
+ configuration.setProperty("hibernate.connection.password","");
+ configuration.setProperty("hibernate.connection.pool_size","1");
+ configuration.setProperty("hibernate.dialect","org.hibernate.dialect.HSQLDialect");
+ configuration.setProperty("hibernate.connection.shutdown","true");
+ SessionFactory sessionFactory = configuration.buildSessionFactory();
+ try {
+ //new SchemaUpdate(configuration).execute(true,true);
+ ServiceInitializationPersistTasks.initializeLibraryAccount(sessionFactory);
+ 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/WebAPIClient.java
===================================================================
--- spaces/trunk/src/com/ogoglio/client/WebAPIClient.java 2007-07-01 02:45:30 UTC (rev 206)
+++ spaces/trunk/src/com/ogoglio/client/WebAPIClient.java 2007-07-01 18:46:57 UTC (rev 207)
@@ -22,6 +22,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.zip.GZIPInputStream;
@@ -571,7 +572,19 @@
if (connection.getResponseCode() != 200) {
return -1;
}
- String lengthHeader = (String)connection.getRequestProperties().get("Content-Length");
+ // XXX get("Content-Length") on linux (1.5.0_07) returns a List so this hideous workaround
+ // XXX seems to be required
+ String lengthHeader=null;
+ Object makeLinuxHappy=(connection.getRequestProperties().get("Content-Length"));
+ if (makeLinuxHappy instanceof String) {
+ lengthHeader = (String)makeLinuxHappy;
+ } else if (makeLinuxHappy instanceof List) {
+ lengthHeader = (String) ((List)makeLinuxHappy).get(0);
+ } else {
+ // we don't understand this type at all
+ System.err.println("Unable to understand the type returned by Linux workaround in WebAPIClient!");
+ return -1;
+ }
if(lengthHeader == null) {
return -1;
}
Modified: spaces/trunk/src/com/ogoglio/persist/ServiceInitializationPersistTasks.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/ServiceInitializationPersistTasks.java 2007-07-01 02:45:30 UTC (rev 206)
+++ spaces/trunk/src/com/ogoglio/persist/ServiceInitializationPersistTasks.java 2007-07-01 18:46:57 UTC (rev 207)
@@ -13,16 +13,12 @@
limitations under the License. */
package com.ogoglio.persist;
-import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.net.URI;
import org.hibernate.SessionFactory;
import com.ogoglio.client.WebAPIClient;
-import com.ogoglio.media.MediaService;
-import com.ogoglio.util.StreamUtils;
public class ServiceInitializationPersistTasks {
@@ -36,10 +32,6 @@
public static final String DEFAULT_DOOR_DISPLAY_NAME = "Default Door";
- private static final String TEST_CUBE_DISPLAY_NAME = "Test Cube";
-
- private static final String TEST_CYLINDER_DISPLAY_NAME = "Test Cylinder";
-
public static void initializeLocalSim(URI serviceURI, SessionFactory sessionFactory) throws PersistException {
SimRecord[] simRecords = SimPersistTasks.findSims(sessionFactory);
if (simRecords.length != 0) {
@@ -48,11 +40,7 @@
SimPersistTasks.createSim(LOCAL_SIM_DISPLAY_NAME, WebAPIClient.appendToURI(serviceURI, "sim/"), SimRecord.DEFAULT_EVENT_PORT, true, sessionFactory);
}
- private static InputStream getResourceStream(String name) {
- return ServiceInitializationPersistTasks.class.getClassLoader().getResourceAsStream(name);
- }
-
- public static void initializeLibraryAccount(MediaService mediaService, SessionFactory sessionFactory) throws PersistException, IOException {
+ public static void initializeLibraryAccount(SessionFactory sessionFactory) throws PersistException, IOException {
AccountRecord accountRec = AccountPersistTasks.findAccountByUsername(LIBRARY_USERNAME, sessionFactory);
if (accountRec != null) {
return;
@@ -62,36 +50,5 @@
accountRec.setPassword(DEFAULT_LIBRARY_PASSWORD);
AccountPersistTasks.update(accountRec, sessionFactory);
- /*
- TemplateRecord defaultLandTemplate = TemplatePersistTasks.createTemplate(DEFAULT_LAND_DISPLAY_NAME, accountRec.getUsername(), sessionFactory);
- mediaService.write("templateGeometry-1-0", getResourceStream("com/ogoglio/persist/resources/defaultLand.obj"), -1);
- mediaService.write("templateGeometry-1-defaultLand.mtl", getResourceStream("com/ogoglio/persist/resources/defaultLand.mtl"), -1);
- mediaService.write("templateGeometry-1-Grid.gif", getResourceStream("com/ogoglio/persist/resources/Grid.gif"), -1);
-
- TemplateRecord defaultDoorTemplate = TemplatePersistTasks.createTemplate(DEFAULT_DOOR_DISPLAY_NAME, accountRec.getUsername(), sessionFactory);
- mediaService.write("templateGeometry-2-0", getResourceStream("com/ogoglio/persist/resources/door.obj"), -1);
- mediaService.write("templateGeometry-2-door.mtl", getResourceStream("com/ogoglio/persist/resources/door.mtl"), -1);
-
- TemplateRecord testCubeTemplate = TemplatePersistTasks.createTemplate(TEST_CUBE_DISPLAY_NAME, accountRec.getUsername(), sessionFactory);
- mediaService.write("templateGeometry-3-0", getResourceStream("com/ogoglio/persist/resources/TestCube.obj"), -1);
- mediaService.write("templateGeometry-3-TestCube.mtl", getResourceStream("com/ogoglio/persist/resources/TestCube.mtl"), -1);
- mediaService.write("templateGeometry-3-TestCube.gif", getResourceStream("com/ogoglio/persist/resources/TestCube.gif"), -1);
- mediaService.write("templateScript-3.js", getResourceStream("com/ogoglio/persist/resources/TestCube.js"), -1);
-
- TemplateRecord testCylinderTemplate = TemplatePersistTasks.createTemplate(TEST_CYLINDER_DISPLAY_NAME, accountRec.getUsername(), sessionFactory);
- mediaService.write("templateGeometry-4-0", getResourceStream("com/ogoglio/persist/resources/TestCylinder.obj"), -1);
- */
}
-
- private static AccountRecord createUser(String username, String accountlevel, String email, String password, String cookie, SessionFactory sessionFactory) throws PersistException {
- AccountRecord accountRec = AccountPersistTasks.findAccountByUsername(username, sessionFactory);
- if (accountRec != null) {
- return accountRec;
- }
- accountRec = AccountPersistTasks.createAccount(username, accountlevel, email, sessionFactory);
- accountRec.setPassword(password);
- accountRec.setCookie(cookie);
- AccountPersistTasks.update(accountRec, sessionFactory);
- return accountRec;
- }
}
Modified: spaces/trunk/src/com/ogoglio/site/AccountServlet.java
===================================================================
--- spaces/trunk/src/com/ogoglio/site/AccountServlet.java 2007-07-01 02:45:30 UTC (rev 206)
+++ spaces/trunk/src/com/ogoglio/site/AccountServlet.java 2007-07-01 18:46:57 UTC (rev 207)
@@ -80,7 +80,7 @@
super.init(config);
try {
ServiceInitializationPersistTasks.initializeLocalSim(new URI(getSiteInfo().getBaseUrl()), getSessionFactory());
- ServiceInitializationPersistTasks.initializeLibraryAccount(getMediaService(), getSessionFactory());
+ ServiceInitializationPersistTasks.initializeLibraryAccount(getSessionFactory());
} catch (PersistException e) {
e.printStackTrace();
throw new ServletException("Could not initialize service: " + e);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|