Exemplo n.º 1
0
  private void createTables(boolean dropTables) {
    for (Enumeration e = EOModelGroup.defaultGroup().models().objectEnumerator();
        e.hasMoreElements(); ) {
      final EOModel eomodel = (EOModel) e.nextElement();
      EODatabaseContext dbc = EOUtilities.databaseContextForModelNamed(ec, eomodel.name());
      dbc.lock();
      try {
        EOAdaptorChannel channel = dbc.availableChannel().adaptorChannel();
        if (eomodel.adaptorName().contains("JDBC")) {
          EOSynchronizationFactory syncFactory =
              (EOSynchronizationFactory)
                  channel.adaptorContext().adaptor().synchronizationFactory();
          ERXSQLHelper helper = ERXSQLHelper.newSQLHelper(channel);
          NSDictionary options = helper.defaultOptionDictionary(true, dropTables);

          // Primary key support creation throws an unwanted exception
          // if
          // EO_PK_TABLE already
          // exists (e.g. in case of MySQL), so we add pk support in a
          // stand-alone step
          options = optionsWithPrimaryKeySupportDisabled(options);
          createPrimaryKeySupportForModel(eomodel, channel, syncFactory);

          String sqlScript =
              syncFactory.schemaCreationScriptForEntities(eomodel.entities(), options);
          log.info("Creating tables: {}", eomodel.name());
          ERXJDBCUtilities.executeUpdateScript(channel, sqlScript, true);
        }
      } catch (SQLException ex) {
        log.error("Can't update", ex);
      } finally {
        dbc.unlock();
      }
    }
  }
Exemplo n.º 2
0
 private void createPrimaryKeySupportForModel(
     EOModel eomodel, EOAdaptorChannel channel, EOSynchronizationFactory syncFactory) {
   try {
     // AK: the (Object) cast is needed, because in 5.4 new NSArray(obj)
     // != new NSArray(array).
     NSArray pkSupportExpressions =
         syncFactory.primaryKeySupportStatementsForEntityGroups(
             new NSArray((Object) eomodel.entities()));
     Enumeration enumeration = pkSupportExpressions.objectEnumerator();
     while (enumeration.hasMoreElements()) {
       EOSQLExpression expression = (EOSQLExpression) enumeration.nextElement();
       channel.evaluateExpression(expression);
     }
   } catch (Exception e) {
   }
 }