예제 #1
0
 /**
  * A helper method for creating an implicit transaction is it is required.
  *
  * <p>A transaction may have been passed in or active in the thread local. If not then create one
  * implicitly to handle the request.
  */
 public void createImplicitTransIfRequired(boolean readOnlyTransaction) {
   if (transaction == null) {
     transaction = ebeanServer.getCurrentServerTransaction();
     if (transaction == null || !transaction.isActive()) {
       // create an implicit transaction to execute this query
       transaction = ebeanServer.createServerTransaction(false, -1);
       createdTransaction = true;
     }
   }
 }
  public DLoadContext(
      SpiEbeanServer ebeanServer,
      BeanDescriptor<?> rootDescriptor,
      Boolean readOnly,
      boolean excludeBeanCache,
      ObjectGraphNode parentNode,
      boolean useAutofetchManager) {

    this.ebeanServer = ebeanServer;
    this.hardRefs = GlobalProperties.getBoolean("ebean.hardrefs", false);
    this.defaultBatchSize = ebeanServer.getLazyLoadBatchSize();
    this.rootDescriptor = rootDescriptor;
    this.rootBeanContext =
        new DLoadBeanContext(
            this, rootDescriptor, null, defaultBatchSize, null, createBeanLoadList());
    this.readOnly = readOnly;
    this.excludeBeanCache = excludeBeanCache;
    this.useAutofetchManager = useAutofetchManager;

    if (parentNode != null) {
      this.origin = parentNode.getOriginQueryPoint();
      this.relativePath = parentNode.getPath();
    } else {
      this.origin = null;
      this.relativePath = null;
    }
  }
예제 #3
0
  protected void executeDerivedRelationships() {
    List<DerivedRelationshipData> derivedRelationships = persistRequest.getDerivedRelationships();
    if (derivedRelationships != null) {

      SpiEbeanServer ebeanServer = (SpiEbeanServer) persistRequest.getEbeanServer();

      for (int i = 0; i < derivedRelationships.size(); i++) {
        DerivedRelationshipData derivedRelationshipData = derivedRelationships.get(i);

        BeanDescriptor<?> beanDescriptor =
            ebeanServer.getBeanDescriptor(derivedRelationshipData.getBean().getClass());

        BeanProperty prop =
            beanDescriptor.getBeanProperty(derivedRelationshipData.getLogicalName());
        EntityBean entityBean = (EntityBean) derivedRelationshipData.getBean();
        entityBean._ebean_getIntercept().markPropertyAsChanged(prop.getPropertyIndex());

        ebeanServer.update(entityBean, transaction);
      }
    }
  }
  /** Load the query tuning information from it's data store. */
  @Override
  public void startup() {

    if (queryTuning) {
      loadTuningFile();
      if (isRuntimeTuningUpdates()) {
        // periodically gather and update query tuning
        server
            .getBackgroundExecutor()
            .executePeriodically(new ProfilingUpdate(), profilingUpdateFrequency, TimeUnit.SECONDS);
      }
    }
  }
  public DefaultAutoTuneService(SpiEbeanServer server, ServerConfig serverConfig) {

    AutoTuneConfig config = serverConfig.getAutoTuneConfig();

    this.server = server;
    this.queryTuning = config.isQueryTuning();
    this.profiling = config.isProfiling();
    this.tuningFile = config.getQueryTuningFile();
    this.profilingFile = config.getProfilingFile();
    this.profilingUpdateFrequency = config.getProfilingUpdateFrequency();
    this.serverName = server.getName();
    this.profileManager = new ProfileManager(config, server);
    this.queryTuner = new BaseQueryTuner(config, server, profileManager);
    this.skipGarbageCollectionOnShutdown = config.isSkipGarbageCollectionOnShutdown();
    this.skipProfileReportingOnShutdown = config.isSkipProfileReportingOnShutdown();
    this.defaultGarbageCollectionWait = (long) config.getGarbageCollectionWait();
  }
  /** Execute the DDL if required. */
  private void executeDDL(SpiEbeanServer server, boolean online) {

    server.getDdlGenerator().execute(online);
  }
예제 #7
0
  private void installDatabase(boolean rebuild) {
    // Check if the database already (partially) exists
    boolean databaseExists = false;

    List<Class<?>> classes = getDatabaseClasses();
    for (int i = 0; i < classes.size(); i++) {
      try {
        // Do a simple query which only throws an exception if the table does not exist
        ebeanServer.find(classes.get(i)).findRowCount();

        // Query passed without throwing an exception, a database therefore already exists
        databaseExists = true;
        break;
      } catch (Exception ex) {
        // Do nothing
      }
    }

    // Check if the database has to be created or rebuilt
    if (!rebuild && databaseExists) {
      return;
    }

    // Create a DDL generator
    SpiEbeanServer serv = (SpiEbeanServer) ebeanServer;
    DdlGenerator gen = serv.getDdlGenerator();

    // Fire "before drop" event
    try {
      beforeDropDatabase();
    } catch (Exception ex) {
      // If the database exists, dropping has to be canceled to prevent data-loss
      if (databaseExists) {
        throw new RuntimeException("An unexpected exception occured", ex);
      }
    }

    // Generate a DropDDL-script
    gen.runScript(true, gen.generateDropDdl());

    // If SQLite is being used, the database has to reloaded to release all resources
    if (usingSQLite) {
      loadDatabase();
    }

    // Generate a CreateDDL-script
    if (usingSQLite) {
      // If SQLite is being used, the CreateDLL-script has to be validated and potentially fixed to
      // be valid
      gen.runScript(false, validateCreateDDLSqlite(gen.generateCreateDdl()));
    } else {
      gen.runScript(false, gen.generateCreateDdl());
    }

    // Fire "after create" event
    try {
      afterCreateDatabase();
    } catch (Exception ex) {
      throw new RuntimeException("An unexpected exception occured", ex);
    }
  }
예제 #8
0
  private DdlHandler handler() {

    return server.getDatabasePlatform().createDdlHandler();
  }
예제 #9
0
  protected void removeDDL() {
    SpiEbeanServer serv = (SpiEbeanServer) getDatabase();
    DdlGenerator gen = serv.getDdlGenerator();

    gen.runScript(true, gen.generateDropDdl());
  }
예제 #10
0
  protected void installDDL() {
    SpiEbeanServer serv = (SpiEbeanServer) getDatabase();
    DdlGenerator gen = serv.getDdlGenerator();

    gen.runScript(false, gen.generateCreateDdl());
  }
예제 #11
0
 public BeanRequest(SpiEbeanServer ebeanServer, SpiTransaction t) {
   this.ebeanServer = ebeanServer;
   this.serverName = ebeanServer.getName();
   this.transaction = t;
 }