mysqlDs.setUser( user );
mysqlDs.setPassword( passwd );
ds = mysqlDs;
}
Platform platform = PlatformFactory.createNewPlatformInstance( ds );
/*
* Do not use delimiters for the database object names in SQL statements.
* This is to avoid case sensitivity problems with SQL92 compliant
* databases like Derby - non-delimited identifiers are interpreted as case
* insensitive.
*
* I am not sure if this is the correct way to solve the issue, however,
* I am not willing to make a big change of schema definitions either.
*/
platform.getPlatformInfo().setDelimiterToken( "" );
platform.setUsername( user );
platform.setPassword( passwd );
platform.createTables( dbModel, true, true );
// Insert the seed data to database
DataToDatabaseSink sink = new DataToDatabaseSink( platform, dbModel );
DataReader reader = new DataReader();
reader.setModel( dbModel );
reader.setSink( sink );
InputStream seedDataStream = this.getClass().getClassLoader().getResourceAsStream( "photovault_seed_data.xml" );
try {
reader.parse( seedDataStream );
} catch (SAXException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
if ( seedDataResource != null ) {
seedDataStream = this.getClass().getClassLoader().getResourceAsStream( seedDataResource );
try {
reader.parse( seedDataStream );
} catch (SAXException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
// Create the database
// TODO: Since the seed has only 48 significant bits this id is not really an
// 128-bit random number!!!
Random rnd = new Random();
String idStr = "";
StringBuffer idBuf = new StringBuffer();
for ( int n=0; n < 4; n++ ) {
int r = rnd.nextInt();
idBuf.append( Integer.toHexString( r ) );
}
idStr = idBuf.toString();
DynaBean dbInfo = dbModel.createDynaBeanFor( "database_info", false );
dbInfo.set( "database_id", idStr );
dbInfo.set( "schema_version", new Integer( CURRENT_SCHEMA_VERSION ) );
dbInfo.set( "create_time", new Timestamp( System.currentTimeMillis() ) );
platform.insert( dbModel, dbInfo );
}