/** @param args */ public static void main(String[] args) throws Exception { BasicConfigurator.configure(); Logger.getLogger("org.eclipse.emf.teneo").setLevel(Level.INFO); Logger.getLogger("org.hibernate").setLevel(Level.WARN); DatabaseSetupData setupData = new DatabaseSetupData(); if (args != null && args.length > 0) { setupData.setSchemaFileName(args[0]); if (args.length > 1) { setupData.setDatabaseName(args[1]); } } if (!DatabaseSetupUtil.testServerConnection(setupData)) { throw new RuntimeException("Unable to connect to running server"); } if (DatabaseSetupUtil.checkDatabaseExists(setupData)) { throw new RuntimeException("Database: '" + setupData.getDatabaseName() + "' exists!"); } // documentation DatabaseSetupUtil.generateSchemaFile(setupData); DatabaseSetupUtil.generateHibernateMapping(setupData); // create live database DatabaseSetupUtil.createDatabase(setupData); // create seed data and initial dairy record DatabaseSetupUtil setupUtil = new DatabaseSetupUtil(setupData); setupUtil.intializeDairyDatabase("registration #", "licensee name"); }
private static Configuration generateTeneoHibernateConfig(DatabaseSetupData data) { // for teneo, we need to intialize the datastore in order ot properly // init the configuration. So we set an invalid db so init will fail, // but then we can use the config to generate schema... HbDataStore tempDataStore = HbHelper.INSTANCE.createRegisterDataStore("fakedatastore"); String savedDbName = data.getDatabaseName(); data.setDatabaseName("generateschema" + data.hashCode()); String savedUserName = data.getUserName(); data.setUserName(data.hashCode() + "generateschema"); try { tempDataStore.setProperties(data.getOptions()); tempDataStore.setEPackages(EPACKAGES); tempDataStore.initialize(); } catch (Throwable t) { System.out.println("Caught expected error: " + t.getMessage()); } data.setUserName(savedUserName); data.setDatabaseName(savedDbName); Configuration configuration = tempDataStore.getHibernateConfiguration(); return configuration; }