Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EOModel


    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(0), "updateLock");
      row.setObjectForKey(NSKeyValueCoding.NullValue, "lockOwner");
      EOEntity dbUpdaterEntity = dbUpdaterModel.entityNamed(migrationTableName(adaptor));
      channel.adaptorContext().commitTransaction();
      try {
        channel.updateValuesInRowsDescribedByQualifier(row, new EOKeyValueQualifier("modelName", EOQualifier.QualifierOperatorEqual, model.name()), dbUpdaterEntity);
      }
      finally {
View Full Code Here


      channel.openChannel();
      wasOpen = false;
    }
    int version;
    try {
      EOModel dbUpdaterModel = dbUpdaterModelWithModel(model, adaptor);
      EOEntity dbUpdaterEntity = dbUpdaterModel.entityNamed(migrationTableName(adaptor));
      EOFetchSpecification fetchSpec = new EOFetchSpecification(migrationTableName(adaptor), new EOKeyValueQualifier("modelName", EOQualifier.QualifierOperatorEqual, model.name()), null);
      try {
        channel.selectAttributes(new NSArray<EOAttribute>(dbUpdaterEntity.attributeNamed("version")), fetchSpec, false, dbUpdaterEntity);
        NSDictionary nextRow = channel.fetchRow();
        if (nextRow == null) {
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(versionNumber), "version");
      EOEntity dbUpdaterEntity = dbUpdaterModel.entityNamed(migrationTableName(adaptor));
      int count;
      try {
        count = channel.updateValuesInRowsDescribedByQualifier(row, new EOKeyValueQualifier("modelName", EOQualifier.QualifierOperatorEqual, model.name()), dbUpdaterEntity);
      }
      finally {
View Full Code Here

    int initialVersion = ERXProperties.intForKeyWithDefault(modelName + ".InitialMigrationVersion", -1);
    return initialVersion;
  }

  protected EOModel dbUpdaterModelWithModel(EOModel model, JDBCAdaptor adaptor) {
    EOModel dbUpdaterModel;
    if (_lastUpdatedModel == model) {
      dbUpdaterModel = _dbUpdaterModelCache;
    }
    else {
      EOModelGroup modelGroup = model.modelGroup();
      EOEntity prototypeEntity = modelGroup.entityNamed(ERXModelGroup.prototypeEntityNameForModel(model));
      boolean isWonderPrototype = (prototypeEntity != null && prototypeEntity.model().name().equals("erprototypes"));

      dbUpdaterModel = new EOModel();
      dbUpdaterModel.setConnectionDictionary(model.connectionDictionary());
      dbUpdaterModel.setAdaptorName(model.adaptorName());

      EOEntity dbUpdaterEntity = new EOEntity();
      dbUpdaterEntity.setExternalName(migrationTableName(adaptor));
      dbUpdaterEntity.setName(migrationTableName(adaptor));
      dbUpdaterModel.addEntity(dbUpdaterEntity);

      EOAttribute modelNameAttribute = new EOAttribute();
      if (isWonderPrototype) {
        modelNameAttribute.setExternalType(prototypeEntity.attributeNamed("varchar100").externalType());
      }
View Full Code Here

    }
    return dbUpdaterModel;
  }

  protected String dbUpdaterCreateStatement(EOModel model, JDBCAdaptor adaptor) {
    EOModel dbUpdaterModel = dbUpdaterModelWithModel(model, adaptor);
    NSMutableDictionary<String, String> flags = new NSMutableDictionary<String, String>();
    flags.setObjectForKey("NO", EOSchemaGeneration.DropTablesKey);
    flags.setObjectForKey("NO", EOSchemaGeneration.DropPrimaryKeySupportKey);
    flags.setObjectForKey("YES", EOSchemaGeneration.CreateTablesKey);
    flags.setObjectForKey("NO", EOSchemaGeneration.CreatePrimaryKeySupportKey);
    flags.setObjectForKey("YES", EOSchemaGeneration.PrimaryKeyConstraintsKey);
    flags.setObjectForKey("NO", EOSchemaGeneration.ForeignKeyConstraintsKey);
    flags.setObjectForKey("NO", EOSchemaGeneration.CreateDatabaseKey);
    flags.setObjectForKey("NO", EOSchemaGeneration.DropDatabaseKey);
    String createTableScript = ERXSQLHelper.newSQLHelper(adaptor).createSchemaSQLForEntitiesWithOptions(new NSArray<EOEntity>(dbUpdaterModel.entityNamed(migrationTableName(adaptor))), adaptor, flags);
    return createTableScript;
  }
View Full Code Here

    return lastmod;
  }

  private void reloadModel(EOModel model) {
    log.echo("JRebel: reloading EOModel " + model.name() + " (" + model.hashCode() + ")");
    EOModel newModel = new EOModel(model.pathURL());
    EOModelGroup modelGroup = model.modelGroup();
    modelGroup.removeModel(model);
    modelGroup.addModel(newModel);
    for (Map.Entry<EOObjectStoreCoordinator, EOModelGroup> entry : oscCache.entrySet()) {
      if (modelGroup == entry.getValue()) {
View Full Code Here

  }

  public void modelAdded(NSNotification n) {
    if (modelCache.containsKey(n.object()))
      return;
    EOModel model = (EOModel) n.object();
    if (model.pathURL() != null) {
      modelCache.put(model, lastModified(model));
    }
  }
View Full Code Here

    return _modelStats.objectForKey(modelName);
  }

  public SEEntityStats entityStatsForEntityNamed(String entityName) {
    EOEntity entity = _modelGroup.entityNamed(entityName);
    EOModel model = entity.model();
    SEModelStats modelStats = modelStatsForModelNamed(model.name());
    SEEntityStats entityStats = modelStats.entityStatsForEntityNamed(entityName);
    return entityStats;
  }
View Full Code Here

                }
                // internal list empty; drop it and use modelgroup's.
                _modelList = new NSMutableArray(group.models());
            }
            _loadingComplete = true; // make sure we only do this once.
            EOModel currentModel = null;
            try {
                NSNotificationCenter.defaultCenter().addObserver(this,
                                                                 new NSSelector("transactionBeginning", ERXConstant.NotificationClassArray),
                                                                 EOAdaptorContext.AdaptorContextBeginTransactionNotification,
                                                                 null);
                log.debug("Beginning loading of shared EOs");
                NSMutableArray loadedModels = new NSMutableArray();
                for (Enumeration e = _modelList.objectEnumerator(); e.hasMoreElements();) {
                    currentModel = (EOModel)e.nextElement();
                    if (!loadedModels.containsObject(currentModel.name())) {
                        loadSharedObjectsForModel(currentModel);
                        loadedModels.addObject(currentModel.name());
                    }
                }
                NSNotificationCenter.defaultCenter().removeObserver(this, EOAdaptorContext.AdaptorContextBeginTransactionNotification, null);
                if (_didChangeDebugSetting) {
                    //_currentAdaptor.setDebugEnabled(true);
                    _didChangeDebugSetting = false;
                }
                if (_transCount != 0) {
                    // only print this if we loaded something; otherwise
                    // the request for the reg. obj. count with start sharing.
                    log.debug("Shared EO loading complete: " + _transCount + " transactions/ " +
                              EOSharedEditingContext.defaultSharedEditingContext().registeredObjects().count() + " objects.");
                } else {
                    log.debug("Shared EO loading complete: no objects loaded.");
                }
            } catch (Exception e) {
                log.error("Exception occurred with model: " + (currentModel != null ? currentModel.name() : "<null>" ) + "\n" + e + ERXUtilities.stackTrace());
                // no matter what happens, un-register for notifications.
                NSNotificationCenter.defaultCenter().removeObserver(this, EOAdaptorContext.AdaptorContextBeginTransactionNotification, null);
                if (_didChangeDebugSetting) {
                    //_currentAdaptor.setDebugEnabled(true);
                    _didChangeDebugSetting = false;
View Full Code Here

  public void initializePartialEntities(EOModelGroup modelGroup) {
    NSMutableDictionary<EOEntity, EOEntity> baseForPartial = new NSMutableDictionary<EOEntity, EOEntity>();

    Enumeration modelsEnum = modelGroup.models().objectEnumerator();
    while (modelsEnum.hasMoreElements()) {
      EOModel model = (EOModel) modelsEnum.nextElement();
      Enumeration entitiesEnum = model.entities().objectEnumerator();
      while (entitiesEnum.hasMoreElements()) {
        EOEntity partialExtensionEntity = (EOEntity) entitiesEnum.nextElement();
        NSDictionary userInfo = partialExtensionEntity.userInfo();
        NSDictionary entityModelerDictionary = (NSDictionary) userInfo.objectForKey("_EntityModeler");
        if (entityModelerDictionary != null) {
          String partialEntityName = (String) entityModelerDictionary.objectForKey("partialEntity");
          if (partialEntityName != null) {
            EOEntity partialEntity = modelGroup.entityNamed(partialEntityName);
            if (partialEntity == null) {
              throw new IllegalArgumentException("The entity '" + partialExtensionEntity.name() + "' claimed to be a partialEntity for the entity '" + partialEntityName + "', but there is no entity of that name.");
            }

            Enumeration partialAttributes = partialExtensionEntity.attributes().objectEnumerator();
            while (partialAttributes.hasMoreElements()) {
              EOAttribute partialAttribute = (EOAttribute) partialAttributes.nextElement();
              if (partialEntity.attributeNamed(partialAttribute.name()) == null) {
                NSMutableDictionary<String, Object> attributePropertyList = new NSMutableDictionary<String, Object>();
                partialAttribute.encodeIntoPropertyList(attributePropertyList);
                String factoryMethodArgumentType = (String) attributePropertyList.objectForKey("factoryMethodArgumentType");
                // OFFICIALLY THE DUMBEST DAMN THING I'VE EVER
                // SEEN
                if ("EOFactoryMethodArgumentIsString".equals(factoryMethodArgumentType)) {
                  attributePropertyList.setObjectForKey("EOFactoryMethodArgumentIsNSString", "factoryMethodArgumentType");
                }
                EOAttribute primaryAttribute = new EOAttribute(attributePropertyList, partialEntity);
                primaryAttribute.awakeWithPropertyList(attributePropertyList);
                partialEntity.addAttribute(primaryAttribute);
              }
              else {
                ERXModelGroup.log.debug("Skipping partial attribute " + partialExtensionEntity.name() + "." + partialAttribute.name() + " because " + partialEntity.name() + " already has an attribute of the same name.");
              }
            }

            Enumeration partialRelationships = partialExtensionEntity.relationships().objectEnumerator();
            while (partialRelationships.hasMoreElements()) {
              EORelationship partialRelationship = (EORelationship) partialRelationships.nextElement();
              if (partialEntity.relationshipNamed(partialRelationship.name()) == null) {
                NSMutableDictionary<String, Object> relationshipPropertyList = new NSMutableDictionary<String, Object>();
                partialRelationship.encodeIntoPropertyList(relationshipPropertyList);

                EORelationship primaryRelationship = new EORelationship(relationshipPropertyList, partialEntity);
                primaryRelationship.awakeWithPropertyList(relationshipPropertyList);
                partialEntity.addRelationship(primaryRelationship);
              }
              else {
                ERXModelGroup.log.debug("Skipping partial relationship " + partialExtensionEntity.name() + "." + partialRelationship.name() + " because " + partialEntity.name() + " already has a relationship of the same name.");
              }
            }

            NSMutableArray<Class<ERXPartial>> partialsForEntity = _partialsForEntity.objectForKey(partialEntity);
            if (partialsForEntity == null) {
              partialsForEntity = new NSMutableArray<Class<ERXPartial>>();
              _partialsForEntity.setObjectForKey(partialsForEntity, partialEntity);
            }
            Class<ERXPartial> partialClass = (Class<ERXPartial>) _NSUtilities.classWithName(partialExtensionEntity.className());
            ERXEntityClassDescription ecd = (ERXEntityClassDescription) partialEntity.classDescriptionForInstances();
            ecd._addPartialClass(partialClass);
            partialsForEntity.addObject(partialClass);
            baseForPartial.setObjectForKey(partialEntity, partialExtensionEntity);
          }
        }
      }
    }

    NSMutableSet<EOEntity> convertedEntities = new NSMutableSet<EOEntity>();
    modelsEnum = modelGroup.models().objectEnumerator();
    while (modelsEnum.hasMoreElements()) {
      EOModel model = (EOModel) modelsEnum.nextElement();
      Enumeration entitiesEnum = model.entities().objectEnumerator();
      while (entitiesEnum.hasMoreElements()) {
        EOEntity entity = (EOEntity) entitiesEnum.nextElement();
        convertEntityPartialReferences(entity, baseForPartial, convertedEntities);
      }
    }
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.