Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EOModel


      _postMigrations = postMigrations;
    }

    @Override
    protected int doPerform(EOAdaptorChannel channel) {
      EOModel model = _modelVersion.model();
      boolean locked;
      do {
        locked = _migrationLock.tryLock(channel, model, _lockOwnerName);
        if (!locked) {
          try {
            Thread.sleep(5 * 1000);
          }
          catch (InterruptedException e) {
            // do nothing
          }
        }
        // MS: Do we put a timeout here? It could take a very long time
        // ...
      }
      while (!locked);

      if (locked) {
        try {
          int currentVersion = _migrationLock.versionNumber(channel, model);
          int nextVersion = _modelVersion.version();
          if (currentVersion < nextVersion) {
            if (ERXMigrator.log.isInfoEnabled()) {
              ERXMigrator.log.info("Upgrading " + model.name() + " to version " + nextVersion + " with migration '" + _migration + "'");
            }
            _migration.upgrade(_editingContext, channel, model);
            _migrationLock.setVersionNumber(channel, model, nextVersion);
            _editingContext.saveChanges();
            channel.adaptorContext().commitTransaction();
            channel.adaptorContext().beginTransaction();
            if (ERXMigrator.log.isInfoEnabled()) {
              ERXMigrator.log.info(model.name() + " is now version " + nextVersion);
            }
            if (_migration instanceof IERXPostMigration) {
              _postMigrations.put((IERXPostMigration) _migration, _modelVersion);
            }
          }
          else {
            ERXMigrator.log.debug("Already upgraded " + model.name() + " to " + nextVersion + ", skipping");
          }
        }
        catch (Throwable t) {
          throw new ERXMigrationFailedException("Migration failed.", t);
        }
View Full Code Here


    public ERXDatabaseConsole(WOContext context) {
        super(context);
    }

    public WOComponent executeQuery() {
        EOModel m = EOModelGroup.defaultGroup().models().objectAtIndex(0);
        con = ERXJDBCConnectionBroker.connectionBrokerForModel(m).getConnection();
        try {
            con.setAutoCommit(false);
            Statement s = con.createStatement();
            ResultSet rs = s.executeQuery(sql);
View Full Code Here

        }
        return context().page();
    }
   
    public WOComponent executeUpdate() {
        EOModel m = EOModelGroup.defaultGroup().models().objectAtIndex(0);
        con = ERXJDBCConnectionBroker.connectionBrokerForModel(m).getConnection();
        try {
            Statement s = con.createStatement();
            int r = s.executeUpdate(sql);
            response = "result: "+r;
View Full Code Here

        constraintName = _NSStringUtilities.concat(tableName, "_", relationship.name(), "_FK");
      }
      String sourceKeyList = sourceColumns.componentsJoinedByString(", ");
      String destinationKeyList = destinationColumns.componentsJoinedByString(", ");

      EOModel sourceModel = entity.model();
      EOModel destModel = relationship.destinationEntity().model();
      if (sourceModel != destModel && !sourceModel.connectionDictionary().equals(destModel.connectionDictionary())) {
        throw new IllegalArgumentException("prepareConstraintStatementForRelationship unable to create a constraint for " + relationship.name() + " because the source and destination entities reside in different databases");
      }
      else {
        setStatement("ALTER TABLE " + entity.externalName() + " ADD CONSTRAINT " + constraintName + " FOREIGN KEY (" + sourceKeyList + ") REFERENCES " + relationship.destinationEntity().externalName() + " (" + destinationKeyList + ") DEFERRABLE INITIALLY DEFERRED");
      }
View Full Code Here

   *
   * @return a <code>String</code> containing SQL statements to create
   *         tables
   */
  public String createSchemaSQLForEntitiesInModelWithNameAndOptions(NSArray<EOEntity> entities, String modelName, NSDictionary optionsCreate) {
    EOModel m = ERXEOAccessUtilities.modelGroup(null).modelNamed(modelName);
    return createSchemaSQLForEntitiesInModelAndOptions(entities, m, optionsCreate);
  }
View Full Code Here

   *            the name of the EOModel
   * @return a <code>String</code> containing SQL statements to create
   *         tables
   */
  public String createSchemaSQLForEntitiesInModelWithName(NSArray<EOEntity> entities, String modelName) {
    EOModel model = ERXEOAccessUtilities.modelGroup(null).modelNamed(modelName);
    return createSchemaSQLForEntitiesInModel(entities, model);
  }
View Full Code Here

   *
   * @return the EOSQLExpression which the EOFetchSpecification would use
   */
  public EOSQLExpression sqlExpressionForFetchSpecification(EOEditingContext ec, EOFetchSpecification spec, long start, long end, NSArray<EOAttribute> attributes) {
    EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, spec.entityName());
    EOModel model = entity.model();
    EODatabaseContext dbc = EOUtilities.databaseContextForModelNamed(ec, model.name());
    EOAdaptor adaptor = dbc.adaptorContext().adaptor();
    EOSQLExpressionFactory sqlFactory = adaptor.expressionFactory();
    spec = (EOFetchSpecification) spec.clone();

    EOQualifier qualifier = spec.qualifier();
View Full Code Here

   * @return the number of rows
   */
  public int rowCountForFetchSpecification(EOEditingContext ec, EOFetchSpecification spec) {
    int rowCount = -1;
    EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, spec.entityName());
    EOModel model = entity.model();
    NSArray result = null;
    String sql;
    if (spec.hints() == null || spec.hints().isEmpty() || spec.hints().valueForKey(EODatabaseContext.CustomQueryExpressionHintKey) == null) {
      // no hints
      if (spec.fetchLimit() > 0 || spec.sortOrderings() != null) {
        boolean usesDistinct = spec.usesDistinct();
        spec = new EOFetchSpecification(spec.entityName(), spec.qualifier(), null);
        spec.setUsesDistinct(usesDistinct);
      }

      EOSQLExpression sqlExpression = sqlExpressionForFetchSpecification(ec, spec, 0, -1);
      String statement = sqlExpression.statement();
      String listString = sqlExpression.listString();

      String countExpression;
      if (spec.usesDistinct()) {
        countExpression = sqlForCountDistinct(entity);
      } else {
        countExpression = "count(*) ";
      }
      statement = statement.replace(listString, countExpression);
      sqlExpression.setStatement(statement);
      sql = statement;
      result = ERXEOAccessUtilities.rawRowsForSQLExpression(ec, model.name(), sqlExpression);
    }
    else {
      // we have hints
      Object hint = spec.hints().valueForKey(EODatabaseContext.CustomQueryExpressionHintKey);
      sql = ERXSQLHelper.newSQLHelper(model).customQueryExpressionHintAsString(hint);
      // MS: This looks super sketchy ...
      if (sql.endsWith(";")) {
        sql = sql.substring(0, sql.length() - 1);
      }
      sql = "select count(*) from " + sqlForSubquery(sql, "result_count_temp_table");
      result = EOUtilities.rawRowsForSQL(ec, model.name(), sql, null);
    }

    if (result.count() > 0) {
      NSDictionary dict = (NSDictionary) result.objectAtIndex(0);
      NSArray values = dict.allValues();
View Full Code Here

   * EOAttributes in it.
   * 
   * @return a shell of an EOEntity for this table
   */
  public EOEntity _blankEntity() {
    EOModel newModel = _database._blankModel();
    EOEntity newEntity = new EOEntity();
    newEntity.setExternalName(_name);
    newEntity.setName("ERXMigrationTable_" + _name);
    newModel.addEntity(newEntity);
    return newEntity;
  }
View Full Code Here

      if (!channel.isOpen()) {
        channel.openChannel();
        wasOpen = false;
      }
      try {
        EOModel dbUpdaterModel = dbUpdaterModelWithModel(model, adaptor);
        NSMutableDictionary<String, Object> row = new NSMutableDictionary<String, Object>();
        row.setObjectForKey(Integer.valueOf(1), "updateLock");
        row.setObjectForKey(lockOwnerName, "lockOwner");
        EOEntity dbUpdaterEntity = dbUpdaterModel.entityNamed(migrationTableName(adaptor));
        try {
          count = channel.updateValuesInRowsDescribedByQualifier(row, EOQualifier.qualifierWithQualifierFormat("modelName = '" + model.name() + "' and (updateLock = 0 or lockOwner = '" + lockOwnerName + "')", null), dbUpdaterEntity);
        }
        finally {
          channel.cancelFetch();
View Full Code Here

TOP

Related Classes of com.webobjects.eoaccess.EOModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.