|
From: <tre...@us...> - 2007-09-18 16:03:28
|
Revision: 417
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=417&view=rev
Author: trevorolio
Date: 2007-09-18 09:03:23 -0700 (Tue, 18 Sep 2007)
Log Message:
-----------
Added the ability to choose a male or female avatar.
Both avatar models still need work.
Consolidated the two UIConstants classes into one.
Modified Paths:
--------------
maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/MigrationSupport.java
Modified: maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/MigrationSupport.java
===================================================================
--- maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/MigrationSupport.java 2007-09-18 16:03:11 UTC (rev 416)
+++ maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/MigrationSupport.java 2007-09-18 16:03:23 UTC (rev 417)
@@ -12,25 +12,26 @@
import com.ogoglio.appdev.persist.PersistException;
import com.ogoglio.util.Log;
import com.ogoglio.util.PropStorage;
-import com.ogoglio.viewer.render.UIConstants;
+import com.ogoglio.util.UIConstants;
-
-
public abstract class MigrationSupport {
//check on migration okayness
public static final String MIGRATION_KEY = "ogoglio/okToMigrateDB";
- public static final boolean DDL_MODE_UPDATE=true;
- public static final boolean DDL_MODE_CREATE=false;
-
+ public static final boolean DDL_MODE_UPDATE = true;
+
+ public static final boolean DDL_MODE_CREATE = false;
+
public MigrationSupport() {
}
-
+
public abstract int getVersionNumber();
+
public abstract Migration[] getMigrationList();
+
public abstract String getResourcePath();
-
+
public boolean verifyVersion(ServletConfig servletConf, Context ctx) {
try {
SessionFactory sessionFactory = getCurrentConfiguration().buildSessionFactory();
@@ -38,8 +39,7 @@
if (version != getVersionNumber()) {
Log.error("DB Version Mismatch! Expected (" + getVersionNumber() + ") but got " + version + "!");
sessionFactory.close();
- return tryUpgrade(servletConf, ctx, version, getVersionNumber(),
- DDL_MODE_UPDATE, true, null);
+ return tryUpgrade(servletConf, ctx, version, getVersionNumber(), DDL_MODE_UPDATE, true, null);
}
sessionFactory.close();
return true; // we are at the expected version
@@ -68,12 +68,12 @@
return false;
}
}
-
+
public boolean initVersionAndUpgrade(ServletConfig conf, Context ctx) {
- if (!initVersionOnly(true,null)) {
- return false;
- }
- return tryUpgrade(conf, ctx, 0, getVersionNumber(), DDL_MODE_UPDATE, true,null);
+ if (!initVersionOnly(true, null)) {
+ return false;
+ }
+ return tryUpgrade(conf, ctx, 0, getVersionNumber(), DDL_MODE_UPDATE, true, null);
}
public Configuration getCurrentConfiguration() {
@@ -88,9 +88,9 @@
if (useJNDI) {
configuration.setProperty("hibernate.connection.datasource", "java:comp/env/jdbc/space");
} else {
- configuration.addProperties(ps.getAllProps(PropStorage.TEST_CONFIG_PROPS));
+ configuration.addProperties(ps.getAllProps(PropStorage.TEST_CONFIG_PROPS));
}
- configuration.addInputStream(UIConstants.getResource(getResourcePath()+"/migration-" + num + ".xml"));
+ configuration.addInputStream(UIConstants.getResource(getResourcePath() + "/migration-" + num + ".xml"));
return configuration.configure();
}
@@ -103,43 +103,41 @@
}
}
- public boolean tryUpgrade(ServletConfig servletConfig, Context ctx, int db_is,
- int db_wants_to_be, boolean isUpdate, boolean useJNDI, PropStorage propStore) {
+ public boolean tryUpgrade(ServletConfig servletConfig, Context ctx, int db_is, int db_wants_to_be, boolean isUpdate, boolean useJNDI, PropStorage propStore) {
if (getMigrationList().length != getVersionNumber()) {
Log.error("Internal error! Migration list length should be " + getVersionNumber() + " but is " + getMigrationList().length + "!");
return false;
}
boolean canMigrate = false;
-
+
//check the flags
try {
- String migrate;
- if (useJNDI) {
- migrate = (String) ctx.lookup(MIGRATION_KEY);
- } else {
- migrate= propStore.getKeyFromSet(PropStorage.TEST_CONFIG_PROPS, "ogoglio.okToMigrateDB");
- }
- if ("true".equals(migrate)) {
- canMigrate = true;
- }
+ String migrate;
+ if (useJNDI) {
+ migrate = (String) ctx.lookup(MIGRATION_KEY);
+ } else {
+ migrate = propStore.getKeyFromSet(PropStorage.TEST_CONFIG_PROPS, "ogoglio.okToMigrateDB");
+ }
+ if ("true".equals(migrate)) {
+ canMigrate = true;
+ }
} catch (NamingException e) {
- Log.error("Naming exception trying to access " + MIGRATION_KEY + " from naming context!");
- canMigrate=false;
+ Log.error("Naming exception trying to access " + MIGRATION_KEY + " from naming context!");
+ canMigrate = false;
}
if (!canMigrate) {
Log.error("Cannot migrate data! Property ogoglio.okToMigrateDB is false or non-existent!");
return false;
}
- String hbm_auto_flag="update";
+ String hbm_auto_flag = "update";
if (!isUpdate) {
- hbm_auto_flag="create";
+ hbm_auto_flag = "create";
}
-
for (int i = db_is; i < db_wants_to_be; ++i) {
Migration current = getMigrationList()[i];
- Log.info("DB: Attempting migration from " + i + " to " + (i + 1) + " with auto HBM:"+hbm_auto_flag);
+ Log.info("DB: Attempting migration from " + i + " to " + (i + 1) + " with auto HBM:" + hbm_auto_flag);
//try to get hibernate to do the work
Configuration config = createConfigurationForHibernate(i + 1, hbm_auto_flag, useJNDI, propStore);
@@ -153,65 +151,65 @@
setVersionNumberOfDbViaQuery(factory, i + 1, expectedRecords);
try {
- if (!current.patch(factory, servletConfig, ctx, i, i + 1)) {
- factory.close();
- return false;
- }
+ if (!current.patch(factory, servletConfig, ctx, i, i + 1)) {
+ factory.close();
+ return false;
+ }
} catch (PersistException e) {
- Log.error("Whoa! Patch failed at revision!"+(i+1)+" on class "+current.getClass().getName());
- Log.error("Whoa! Persistance layer problem was:"+e.getMessage());
+ Log.error("Whoa! Patch failed at revision!" + (i + 1) + " on class " + current.getClass().getName());
+ Log.error("Whoa! Persistance layer problem was:" + e.getMessage());
}
-
+
try {
- if (!isUpdate) {
- //we need to go ahead and create the data
- if (!current.populate(factory, i, i+1)) {
- Log.error("Whoa! Populate failed at revision!"+(i+1)+" on class "+current.getClass().getName());
- factory.close();
- return false;
- }
- }
+ if (!isUpdate) {
+ //we need to go ahead and create the data
+ if (!current.populate(factory, i, i + 1)) {
+ Log.error("Whoa! Populate failed at revision!" + (i + 1) + " on class " + current.getClass().getName());
+ factory.close();
+ return false;
+ }
+ }
} catch (PersistException e) {
- Log.error("Whoa! Populate failed at revision!"+(i+1)+" on class "+current.getClass().getName());
- Log.error("Whoa! Persistance layer problem was:"+e.getMessage());
+ Log.error("Whoa! Populate failed at revision!" + (i + 1) + " on class " + current.getClass().getName());
+ Log.error("Whoa! Persistance layer problem was:" + e.getMessage());
}
-
+
factory.close();
}
return true;
}
- public boolean destroyAllData() {
- PropStorage ps =new PropStorage();
- if (ps.loadPropertySet(PropStorage.TEST_CONFIG_PROPS)==false) {
- return false;
- }
+ public boolean destroyAllData() {
+ PropStorage ps = new PropStorage();
+ if (ps.loadPropertySet(PropStorage.TEST_CONFIG_PROPS) == false) {
+ return false;
+ }
- if (initVersionOnly(false, ps)==false) {
- return false;
- }
+ if (initVersionOnly(false, ps) == false) {
+ return false;
+ }
- if (tryUpgrade(null, null, 0, getVersionNumber(), DDL_MODE_CREATE, false, ps)==false) {
- Log.error("Aborted destroying data after failure to upgrade");
- return false;
- }
- ps.loadPropertySet(PropStorage.BASIC_PROPS);
- String dir = ps.getKeyFromSet(PropStorage.BASIC_PROPS, "ogoglio.mediaDirectory");
- if (dir==null) {
- Log.error("Can't find a property ogoglio.mediaDirectory to cleanse media store");
- return false;
- }
- File store = new File(dir);
- if ((!store.exists()) || (!store.canWrite())) {
- Log.error("Media directory doesn't exist or can't be changed:"+dir);
- return false;
- }
- File[] children= store.listFiles();
- for (int i=0; i<children.length;++i) {
- if (children[i].delete()!=true) {
- Log.error("Failed to delete media file:"+children[i].getAbsolutePath());
- }
- }
- return true;
- }
+ if (tryUpgrade(null, null, 0, getVersionNumber(), DDL_MODE_CREATE, false, ps) == false) {
+ Log.error("Aborted destroying data after failure to upgrade");
+ return false;
+ }
+ ps.loadPropertySet(PropStorage.BASIC_PROPS);
+ String dir = ps.getKeyFromSet(PropStorage.BASIC_PROPS, "ogoglio.mediaDirectory");
+ if (dir == null) {
+ Log.error("Can't find a property ogoglio.mediaDirectory to cleanse media store");
+ return false;
+ }
+ File store = new File(dir);
+ if ((!store.exists()) || (!store.canWrite())) {
+ Log.error("Media directory doesn't exist or can't be changed:" + dir);
+ return false;
+ }
+ File[] children = store.listFiles();
+ for (int i = 0; i < children.length; ++i) {
+ if (children[i].delete() != true) {
+ Log.error("Failed to delete media file:" + children[i].getAbsolutePath());
+ }
+ }
+ return true;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|