EbeanServer setConfig() { // programmatically build a EbeanServer instance // specify the configuration... ServerConfig config = new ServerConfig(); config.setName("mysql"); // Define DataSource parameters DataSourceConfig postgresDb = new DataSourceConfig(); postgresDb.setDriver("com.mysql.jdbc.Driver"); postgresDb.setUsername("root"); postgresDb.setPassword(""); postgresDb.setUrl("jdbc:mysql://127.0.0.1:3306/perbekalan_farmasi"); // specify a JNDI DataSource // config.setDataSourceJndiName("someJndiDataSourceName"); // set DDL options... // config.setDdlGenerate(true); // config.setDdlRun(true); config.setDdlGenerate(false); config.setDdlRun(false); config.setDefaultServer(false); config.setRegister(false); // automatically determine the DatabasePlatform // using the jdbc driver config.setDatabasePlatform(new MySqlPlatform()); config.setDataSourceConfig(postgresDb); // specify the entity classes (and listeners etc) // ... if these are not specified Ebean will search // ... the classpath looking for entity classes. // config.addClass(Order.class); config.addClass(DeletedGoods.class); config.addClass(Goods.class); config.addClass(GoodsConsumption.class); config.addClass(GoodsReception.class); config.addClass(Insurance.class); config.addClass(Invoice.class); config.addClass(InvoiceItem.class); config.addClass(PurchaseOrder.class); config.addClass(PurchaseOrderItem.class); config.addClass(ReqPlanning.class); config.addClass(Role.class); config.addClass(Setting.class); config.addClass(Supplier.class); config.addClass(SupplierGoods.class); config.addClass(User.class); config.addClass(Manufacturer.class); // ... // specify jars to search for entity beans // config.addJar("someJarThatContainsEntityBeans.jar"); // create the EbeanServer instance EbeanServer server = EbeanServerFactory.create(config); return server; }
private EbeanServer initializeDatabase(boolean dropAndCreateDatabase, String dbName) { ServerConfig config = new ServerConfig(); config.setName(dbName); DataSourceConfig hdDB = new DataSourceConfig(); hdDB.setDriver("org.h2.Driver"); hdDB.setUsername("test"); hdDB.setPassword("test"); hdDB.setUrl("jdbc:h2:mem:tests;DB_CLOSE_DELAY=-1"); hdDB.setHeartbeatSql("select 1 "); config.setDataSourceConfig(hdDB); config.setDefaultServer(false); config.setRegister(false); if (dropAndCreateDatabase) { config.setDdlGenerate(true); config.setDdlRun(true); // config.setDebugSql(true); } config.addClass(Viite.class); config.addClass(Attribuutti.class); return EbeanServerFactory.create(config); }
private void tryLoadOldSensors() { java.io.File f = null; for (File fi : this.getDataFolder().listFiles()) { if (fi.getName().toLowerCase().contains("minecartmaniarebornsigncommands.db")) { f = fi; break; } } if (f == null) { return; } Logger.debug("Found old sensor DB. Attempting load..."); com.avaje.ebean.config.DataSourceConfig dsc = new com.avaje.ebean.config.DataSourceConfig(); dsc.setUsername("temp"); dsc.setPassword("temp"); dsc.setDriver("org.sqlite.JDBC"); dsc.setIsolationLevel(8); dsc.setUrl("jdbc:sqlite:plugins/minecartmania/minecartmaniarebornsigncommands.db"); ServerConfig config = new ServerConfig(); config.setDataSourceConfig(dsc); config.setName("Old DB"); config.addClass(com.afforess.minecartmaniasigncommands.sensor.SensorDataTable.class); config.addJar("MinecartMania.jar"); SensorManager.database = com.avaje.ebean.EbeanServerFactory.create(config); SensorManager.loadsensors(); if (SensorManager.getCount() > 0) { Logger.severe("Found sensors in old db, moving..."); // loaded old sensors for (Sensor s : SensorManager.getSensorList().values()) { SensorManager.saveSensor(s); } Logger.severe("Complete. Removing old db."); } SensorManager.database = this.getDatabase(); f.delete(); }
private void prepareDatabase( String driver, String url, String username, String password, String isolation) { // Setup the data source DataSourceConfig ds = new DataSourceConfig(); ds.setDriver(driver); ds.setUrl(replaceDatabaseString(url)); ds.setUsername(username); ds.setPassword(password); ds.setIsolationLevel(TransactionIsolation.getLevel(isolation)); // Setup the server configuration ServerConfig sc = new ServerConfig(); sc.setDefaultServer(false); sc.setRegister(false); sc.setName(ds.getUrl().replaceAll("[^a-zA-Z0-9]", "")); // Get all persistent classes List<Class<?>> classes = getDatabaseClasses(); // Do a sanity check first if (classes.size() == 0) { // Exception: There is no use in continuing to load this database throw new RuntimeException("Database has been enabled, but no classes are registered to it"); } // Register them with the EbeanServer sc.setClasses(classes); // Check if the SQLite JDBC supplied with Bukkit is being used if (ds.getDriver().equalsIgnoreCase("org.sqlite.JDBC")) { // Remember the database is a SQLite-database usingSQLite = true; // Modify the platform, as SQLite has no AUTO_INCREMENT field sc.setDatabasePlatform(new SQLitePlatform()); sc.getDatabasePlatform().getDbDdlSyntax().setIdentity(""); } prepareDatabaseAdditionalConfig(ds, sc); // Finally the data source sc.setDataSourceConfig(ds); // Store the ServerConfig serverConfig = sc; }
/** * Populates a given {@link com.avaje.ebean.config.ServerConfig} with values attributes to this * server * * @param dbConfig ServerConfig to populate */ public void configureDbConfig(com.avaje.ebean.config.ServerConfig dbConfig) { com.avaje.ebean.config.DataSourceConfig ds = new com.avaje.ebean.config.DataSourceConfig(); ds.setDriver(config.getString("database.driver", "org.sqlite.JDBC")); ds.setUrl(config.getString("database.url", "jdbc:sqlite:{DIR}{NAME}.db")); ds.setUsername(config.getString("database.username", "glow")); ds.setPassword(config.getString("database.password", "stone")); ds.setIsolationLevel( com.avaje.ebeaninternal.server.lib.sql.TransactionIsolation.getLevel( config.getString("database.isolation", "SERIALIZABLE"))); if (ds.getDriver().contains("sqlite")) { dbConfig.setDatabasePlatform(new com.avaje.ebean.config.dbplatform.SQLitePlatform()); dbConfig.getDatabasePlatform().getDbDdlSyntax().setIdentity(""); } dbConfig.setDataSourceConfig(ds); }
@Override public void configureDbConfig(com.avaje.ebean.config.ServerConfig dbConfig) { com.avaje.ebean.config.DataSourceConfig ds = new com.avaje.ebean.config.DataSourceConfig(); ds.setDriver(config.getString(ServerConfig.Key.DB_DRIVER)); ds.setUrl(config.getString(ServerConfig.Key.DB_URL)); ds.setUsername(config.getString(ServerConfig.Key.DB_USERNAME)); ds.setPassword(config.getString(ServerConfig.Key.DB_PASSWORD)); ds.setIsolationLevel( com.avaje.ebeaninternal.server.lib.sql.TransactionIsolation.getLevel( config.getString(ServerConfig.Key.DB_ISOLATION))); if (ds.getDriver().contains("sqlite")) { dbConfig.setDatabasePlatform(new com.avaje.ebean.config.dbplatform.SQLitePlatform()); dbConfig.getDatabasePlatform().getDbDdlSyntax().setIdentity(""); } dbConfig.setDataSourceConfig(ds); }
@Override public void configureDbConfig(ServerConfig config) { DataSourceConfig ds = new DataSourceConfig(); ds.setDriver(configuration.getString("database.driver")); ds.setUrl(configuration.getString("database.url")); ds.setUsername(configuration.getString("database.username")); ds.setPassword(configuration.getString("database.password")); ds.setIsolationLevel( TransactionIsolation.getLevel(configuration.getString("database.isolation"))); if (ds.getDriver().contains("sqlite")) { config.setDatabasePlatform(new SQLitePlatform()); config.getDatabasePlatform().getDbDdlSyntax().setIdentity(""); } else if (ds.getDriver().contains("mysql")) { theLogger.warning("MySQL is presently unsupported for CraftForge"); } config.setDataSourceConfig(ds); }