public InternalConfiguration(
      XmlConfig xmlConfig,
      ClusterManager clusterManager,
      ServerCacheManager cacheManager,
      SpiBackgroundExecutor backgroundExecutor,
      ServerConfig serverConfig,
      BootupClasses bootupClasses,
      PstmtBatch pstmtBatch) {

    this.xmlConfig = xmlConfig;
    this.pstmtBatch = pstmtBatch;
    this.clusterManager = clusterManager;
    this.backgroundExecutor = backgroundExecutor;
    this.cacheManager = cacheManager;
    this.serverConfig = serverConfig;
    this.bootupClasses = bootupClasses;
    this.expressionFactory = new DefaultExpressionFactory();

    this.typeManager = new DefaultTypeManager(serverConfig, bootupClasses);
    this.binder = new Binder(typeManager);

    this.resourceManager = ResourceManagerFactory.createResourceManager(serverConfig);
    this.deployOrmXml = new DeployOrmXml(resourceManager.getResourceSource());
    this.deployInherit = new DeployInherit(bootupClasses);

    this.deployCreateProperties = new DeployCreateProperties(typeManager);
    this.deployUtil = new DeployUtil(typeManager, serverConfig);

    this.beanDescriptorManager = new BeanDescriptorManager(this);
    beanDescriptorManager.deploy();

    this.debugLazyLoad = new DebugLazyLoad(serverConfig.isDebugLazyLoad());

    this.transactionManager =
        new TransactionManager(
            clusterManager,
            backgroundExecutor,
            serverConfig,
            beanDescriptorManager,
            this.getBootupClasses());

    this.cQueryEngine =
        new CQueryEngine(serverConfig.getDatabasePlatform(), binder, backgroundExecutor);

    ExternalTransactionManager externalTransactionManager =
        serverConfig.getExternalTransactionManager();
    if (externalTransactionManager == null && serverConfig.isUseJtaTransactionManager()) {
      externalTransactionManager = new JtaTransactionManager();
    }
    if (externalTransactionManager != null) {
      externalTransactionManager.setTransactionManager(transactionManager);
      this.transactionScopeManager =
          new ExternalTransactionScopeManager(transactionManager, externalTransactionManager);
      logger.info("Using Transaction Manager [" + externalTransactionManager.getClass() + "]");
    } else {
      this.transactionScopeManager = new DefaultTransactionScopeManager(transactionManager);
    }
  }
  /** Set the DatabasePlatform if it has not already been set. */
  private void setDatabasePlatform(ServerConfig config) {

    DatabasePlatform dbPlatform = config.getDatabasePlatform();
    if (dbPlatform == null) {

      DatabasePlatformFactory factory = new DatabasePlatformFactory();

      DatabasePlatform db = factory.create(config);
      config.setDatabasePlatform(db);
      logger.info("DatabasePlatform name:" + config.getName() + " platform:" + db.getName());
    }
  }
Ejemplo n.º 3
0
  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;
  }
Ejemplo n.º 4
0
  /**
   * 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);
  }
Ejemplo n.º 5
0
  @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);
  }
Ejemplo n.º 6
0
  @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);
  }
  /** Create the implementation from the configuration. */
  public SpiEbeanServer createServer(ServerConfig serverConfig) {

    synchronized (this) {
      setNamingConvention(serverConfig);

      BootupClasses bootupClasses = getBootupClasses(serverConfig);

      setDataSource(serverConfig);
      // check the autoCommit and Transaction Isolation
      boolean online = checkDataSource(serverConfig);

      // determine database platform (Oracle etc)
      setDatabasePlatform(serverConfig);
      if (serverConfig.getDbEncrypt() != null) {
        // use a configured DbEncrypt rather than the platform default
        serverConfig.getDatabasePlatform().setDbEncrypt(serverConfig.getDbEncrypt());
      }

      DatabasePlatform dbPlatform = serverConfig.getDatabasePlatform();

      PstmtBatch pstmtBatch = null;

      if (dbPlatform.getName().startsWith("oracle")) {
        PstmtDelegate pstmtDelegate = serverConfig.getPstmtDelegate();
        if (pstmtDelegate == null) {
          // try to provide the
          pstmtDelegate = getOraclePstmtDelegate(serverConfig.getDataSource());
        }
        if (pstmtDelegate != null) {
          // We can support JDBC batching with Oracle
          // via OraclePreparedStatement
          pstmtBatch = new OraclePstmtBatch(pstmtDelegate);
        }
        if (pstmtBatch == null) {
          // We can not support JDBC batching with Oracle
          logger.warning("Can not support JDBC batching with Oracle without a PstmtDelegate");
          serverConfig.setPersistBatching(false);
        }
      }

      // inform the NamingConvention of the associated DatabasePlaform
      serverConfig.getNamingConvention().setDatabasePlatform(serverConfig.getDatabasePlatform());

      ServerCacheManager cacheManager = getCacheManager(serverConfig);

      int uniqueServerId = serverId.incrementAndGet();
      SpiBackgroundExecutor bgExecutor = createBackgroundExecutor(serverConfig, uniqueServerId);

      InternalConfiguration c =
          new InternalConfiguration(
              xmlConfig,
              clusterManager,
              cacheManager,
              bgExecutor,
              serverConfig,
              bootupClasses,
              pstmtBatch);

      DefaultServer server = new DefaultServer(c, cacheManager);

      cacheManager.init(server);

      MBeanServer mbeanServer;
      ArrayList<?> list = MBeanServerFactory.findMBeanServer(null);
      if (list.size() == 0) {
        // probably not running in a server
        mbeanServer = MBeanServerFactory.createMBeanServer();
      } else {
        // use the first MBeanServer
        mbeanServer = (MBeanServer) list.get(0);
      }

      server.registerMBeans(mbeanServer, uniqueServerId);

      // generate and run DDL if required
      executeDDL(server, online);

      // initialise prior to registering with clusterManager
      server.initialise();

      if (online) {
        if (clusterManager.isClustering()) {
          // register the server once it has been created
          clusterManager.registerServer(server);
        }

        // warm the cache in 30 seconds
        int delaySecs = GlobalProperties.getInt("ebean.cacheWarmingDelay", 30);
        long sleepMillis = 1000 * delaySecs;

        if (sleepMillis > 0) {
          Timer t = new Timer("EbeanCacheWarmer", true);
          t.schedule(new CacheWarmer(server), sleepMillis);
        }
      }

      // start any services after registering with clusterManager
      server.start();
      return server;
    }
  }
 public DatabasePlatform getDatabasePlatform() {
   return serverConfig.getDatabasePlatform();
 }