Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EOModel


      return copy;
    }

    protected void adjustLocalizedAttributes(EOModelGroup group) {
      for (Enumeration enumerator = group.models().objectEnumerator(); enumerator.hasMoreElements();) {
        EOModel model = (EOModel) enumerator.nextElement();
        for (Enumeration e1 = model.entities().objectEnumerator(); e1.hasMoreElements();) {
          EOEntity entity = (EOEntity) e1.nextElement();
          adjustLocalizedAttributes(entity);
        }
      }
    }
View Full Code Here


   * @param url URL to model
   * @return model object
   */
  @Override
  public EOModel addModelWithPathURL(URL url) {
    EOModel model = null;
    String customModelClass = null;
    if (patchModelsOnLoad) {
      if ((customModelClass = ERXProperties.stringForKey("er.extensions.ERXModelGroup.patchedModelClassName")) != null) {
        try {
          Class<? extends EOModel> modelClass = Class.forName(customModelClass).asSubclass(Model.class);
View Full Code Here

   *
   * @param n
   *            notification posted when a model is loaded. The object is the model.
   */
  public void modelAddedHandler(NSNotification n) {
    EOModel model = (EOModel) n.object();
    resetConnectionDictionaryInModel(model);
  }
View Full Code Here

    }

    NSDictionary jdbcInfoDictionary = null;
    if (jdbcInfo != null && jdbcInfo.length() > 0 && jdbcInfo.charAt(0) == '^') {
      String modelName = jdbcInfo.substring(1, jdbcInfo.length());
      EOModel modelForCopy = model.modelGroup().modelNamed(modelName);
      if (modelForCopy != null && modelForCopy != model) {
        jdbcInfoDictionary = (NSDictionary) modelForCopy.connectionDictionary().objectForKey("jdbc2Info");
      }
      else {
        log.warn("Unable to find model named \"" + modelName + "\"");
        jdbcInfo = null;
      }
    }

    String plugin = getProperty(aModelName + ".DBPlugin", "dbConnectPluginGLOBAL");

    // build the URL if we have a Postgresql plugin
    if ("Postgresql".equals(plugin) && ERXStringUtilities.stringIsNullOrEmpty(url) && !ERXStringUtilities.stringIsNullOrEmpty(serverName) && !ERXStringUtilities.stringIsNullOrEmpty(h)) {
      url = "jdbc:postgresql://" + h + "/" + serverName;
    }

    NSDictionary connectionDictionary = model.connectionDictionary();
    if (connectionDictionary == null) {
      connectionDictionary = new NSMutableDictionary();
      model.setConnectionDictionary(connectionDictionary);
    }

    NSMutableDictionary newConnectionDictionary = new NSMutableDictionary(connectionDictionary);
    if (adaptor != null) {
      model.setAdaptorName(adaptor);
    }
    if (url != null)
      newConnectionDictionary.setObjectForKey(url, "URL");
    if (userName != null)
      newConnectionDictionary.setObjectForKey(userName, "username");
    if (passwd != null)
      newConnectionDictionary.setObjectForKey(passwd, "password");
    if (driver != null)
      newConnectionDictionary.setObjectForKey(driver, "driver");
    if (jdbcInfoDictionary != null) {
      newConnectionDictionary.setObjectForKey(jdbcInfoDictionary, "jdbc2Info");
    }
    else if (jdbcInfo != null) {
      NSDictionary d = (NSDictionary) NSPropertyListSerialization.propertyListFromString(jdbcInfo);
      if (d != null)
        newConnectionDictionary.setObjectForKey(d, "jdbc2Info");
      else
        newConnectionDictionary.removeObjectForKey("jdbc2Info");
    }
    if (plugin != null) {
      newConnectionDictionary.setObjectForKey(plugin, "plugin");
    }

    // set the information for ERXJDBCConnectionBroker
    newConnectionDictionary.addEntriesFromDictionary(poolingDictionary);

    if (newConnectionDictionary.count() == 0) {
      ERXModelGroup.log.warn("The EOModel '" + model.name() + "' has an empty connection dictionary.");
    }
   
    String removeJdbc2Info = getProperty(aModelName + ".removeJdbc2Info", "dbRemoveJdbc2InfoGLOBAL", "true");
    if (ERXValueUtilities.booleanValue(removeJdbc2Info)) {
      newConnectionDictionary.removeObjectForKey("jdbc2Info");
    }

    // We want to clean up our connection dictionaries so all our models match.  When EOF
    // compares connection dictionaries, undefined plugin is not the same as plugin = ""
    // even though it semantically is the same.  So we are normalizing our connection
    // dictionaries here by removing blank keys that we know about.
    String pluginCheck = (String)newConnectionDictionary.objectForKey("plugin");
    if (pluginCheck != null && pluginCheck.length() == 0){
      newConnectionDictionary.removeObjectForKey("plugin");
    }
    String driverCheck = (String)newConnectionDictionary.objectForKey("driver");
    if (driverCheck != null && driverCheck.length() == 0){
      newConnectionDictionary.removeObjectForKey("driver");
    }

    model.setConnectionDictionary(newConnectionDictionary);

    // we want to be a bit more aggressive here
    String[] keysThatMatter = { "URL", "username" };
    Enumeration modelsEnum = model.modelGroup().models().objectEnumerator();
    while (modelsEnum.hasMoreElements()) {
      EOModel otherModel = (EOModel)modelsEnum.nextElement();
      if (otherModel != model) {
        NSDictionary otherConnectionDictionary = otherModel.connectionDictionary();
        if (otherConnectionDictionary != null && ObjectUtils.equals(newConnectionDictionary.objectForKey("adaptorName"), otherConnectionDictionary.objectForKey("adaptorName"))) {
          boolean valuesThatMatterMatch = true;
          for (int keyNum = 0; valuesThatMatterMatch && keyNum < keysThatMatter.length; keyNum ++) {
            String thisValue = (String)newConnectionDictionary.objectForKey(keysThatMatter[keyNum]);
            String otherValue = (String)otherConnectionDictionary.objectForKey(keysThatMatter[keyNum]);
            valuesThatMatterMatch = ERXStringUtilities.stringEqualsString(thisValue, otherValue);
          }
          if (valuesThatMatterMatch && !newConnectionDictionary.equals(otherConnectionDictionary)) {
            if (!isPrototypeModel(model) && !isPrototypeModel(otherModel)) {
              String message = "The connection dictionaries for " + model.name() + " and " + otherModel.name() + " have the same URL and username, but the connection dictionaries are not equal. Check your connection dictionaries carefully! This problem is often caused by jdbc2Info not matching between the two.  One fix for this is to set " + model.name() + ".removeJdbc2Info=true and " + otherModel.name() + ".removeJdbc2Info=true in your Properties file. (" + model.name() + "=" + newConnectionDictionary + "; and " + otherModel.name() + "=" + otherConnectionDictionary + ").";
              if (!raiseOnUnmatchingConnectionDictionaries) {
                // was intentionally switched off, so log only
                log.warn(message);
              }
              else {
                throw new IllegalArgumentException(message);
              }
            }
            log.info("The connection dictionaries for " + model.name() + " and " + otherModel.name() + " have the same URL and username, but at least one of them is a prototype model, so it shouldn't be a problem.");
          }
        }
      }
    }
  }
View Full Code Here

   * @property er.extensions.ERXModelGroup.[entityName].externalName change the table name for the given entityName
   * @property er.extensions.ERXModelGroup.[entityName].[attributeName].columnName change the column name for the given attribute
   */
  protected void modifyModelsFromProperties() {
    for (Enumeration modelsEnum = models().objectEnumerator(); modelsEnum.hasMoreElements();) {
      EOModel model = (EOModel) modelsEnum.nextElement();
      for (Enumeration entitiesEnum = model.entities().objectEnumerator(); entitiesEnum.hasMoreElements();) {
        EOEntity entity = (EOEntity) entitiesEnum.nextElement();
       
        String externalName = ERXProperties.stringForKey("er.extensions.ERXModelGroup." + entity.name() + ".externalName");
        if (externalName != null) {
          entity.setExternalName(externalName);
View Full Code Here

    else if (ERXModel.isUseExtendedPrototypesEnabled()) {
      log.warn("Using er.extensions.ERXModel.useExtendedPrototypes=true may be incompatible with er.extensions.ERXModelGroup.flattenPrototypes=true (its default value).");
    }
    String prototypesFixedKey = "_EOPrototypesFixed";
    for (Enumeration modelsEnum = models().objectEnumerator(); modelsEnum.hasMoreElements();) {
      EOModel model = (EOModel) modelsEnum.nextElement();
      if(_prototypeModelNames.containsObject(model.name())) {
        log.debug("Skipping prototype model " + model.name());
        continue;
      }
      NSDictionary userInfo = model.userInfo();
      Boolean prototypesFixedBoolean = (Boolean) userInfo.objectForKey(prototypesFixedKey);
      if (prototypesFixedBoolean == null || !prototypesFixedBoolean.booleanValue()) {
        boolean prototypesFixed = false;
        String prototypeEntityName = prototypeEntityNameForModel(model);
        if (prototypeEntityName == null) {
          prototypesFixed = true;
        }
        else {
          EOEntity prototypeEntity = entityNamed(prototypeEntityName);
          if (prototypeEntity == null) {
            log.info(model.name() + " references a prototype entity named " + prototypeEntityName + " which is not yet loaded.");
          }
          else {
            if (log.isDebugEnabled()) {
              log.debug("Flattening " + model.name() + " using the prototype " + prototypeEntity.name());
            }
            for (Enumeration entitiesEnum = model.entities().objectEnumerator(); entitiesEnum.hasMoreElements();) {
              EOEntity entity = (EOEntity) entitiesEnum.nextElement();
              for (Enumeration attributesEnum = entity.attributes().objectEnumerator(); attributesEnum.hasMoreElements();) {
                EOAttribute attribute = (EOAttribute) attributesEnum.nextElement();
                if (!attribute.isFlattened()) {
                  String prototypeAttributeName = attribute.prototypeName();
                  if (prototypeAttributeName == null) {
                    if (attribute.externalType() == null) {
                      log.warn(model.name() + "/" + entity.name() + "/" + attribute.name() + " does not have a prototype attribute name.  This can occur if the model cannot resolve ANY prototypes when loaded.  There must be a stub prototype for the model to load with that can then be replaced with the appropriate database-specific model.");
                    }
                  }
                  else {
                    EOAttribute prototypeAttribute = prototypeEntity.attributeNamed(prototypeAttributeName);
                    if (prototypeAttribute == null) {
                      log.warn(model.name() + "/" + entity.name() + "/" + attribute.name() + " references a prototype attribute named " + prototypeAttributeName + " that does not exist in " + prototypeEntity.name() + ".");
                    }
                    else if (attribute.prototype().entity() == prototypeEntity) {
                      if (log.isDebugEnabled()) {
                        log.debug("Skipping " + model.name() + "/" + entity.name() + "/" + attribute.name() + " because it is already prototyped by the correct entity.");
                      }
                    }
                    else {
                      flattenPrototypeAttribute(prototypeAttribute, attribute);
                      if (log.isDebugEnabled()) {
                        log.debug("Flattening " + model.name() + "/" + entity.name() + "/" + attribute.name() + " with the prototype attribute " + prototypeAttribute.entity().model().name() + "/" + prototypeAttribute.entity().name() + "/" + prototypeAttribute.name());
                      }
                    }
                  }
                }
                else {
                  log.debug("Skipping " + model.name() + "/" + entity.name() + "/" + attribute.name() + " because it's derived or flattened.");
                }
              }
            }
            prototypesFixed = true;
          }
        }
       
        NSMutableDictionary mutableUserInfo = userInfo.mutableClone();
        mutableUserInfo.setObjectForKey(Boolean.valueOf(prototypesFixed), prototypesFixedKey);
        model.setUserInfo(mutableUserInfo);
        dumpSchemaSQL(model);

      }
    }
  }
View Full Code Here

            //check the cache to see if this Valididty model has been loaded
            GSVModel model = (GSVModel)_modelCache.objectForKey(modelName);

            //if the model hasn't been cache, load then cache it
            if( model == null ){
                EOModel eomodel = eoentity.model();
                String eoModelPath = NSPathUtilities.stringByDeletingLastPathComponent(eomodel.path());
                eoModelPath = NSPathUtilities.stringByAppendingPathComponent(eoModelPath, eomodel.name());
                eoModelPath = NSPathUtilities.stringByAppendingPathExtension(eoModelPath, "eomodeld");
                String gsvModelPath = NSPathUtilities.stringByAppendingPathComponent(eoModelPath, GSVModel.MODEL_NAME);
                gsvModelPath = NSPathUtilities.stringByAppendingPathExtension(gsvModelPath, GSVModel.MODEL_EXTENSION);
                WOXMLDecoder decoder = WOXMLDecoder.decoder();
                decoder.setEncoding("UTF-8");
View Full Code Here

     *
     * @author David Avendasora
     */
    public static <T extends ERXCopyable<T>> T modelCopy(NSMutableDictionary<EOGlobalID, ERXCopyable<?>> copiedObjects, T source) {
      EOEntity entity = Utility.entity(source);
      EOModel model = entity.model();
      NSDictionary<String, Object> entityUserInfo = entity.userInfo();
      String entityName = entity.name();
      String modelName = model.name();

      if (!entityUserInfo.containsKey(ERXCopyable.ERXCOPYABLE_KEY)) {
        String message = "In order to use modelCopy the \"" + ERXCopyable.ERXCOPYABLE_KEY + "\" key must be set in the UserInfo dictionary of the \"" + entityName + "\" Entity in the " + modelName + " EOModel.";
        throw new IllegalStateException(message);
      }
View Full Code Here

      NSArray<String> copyTypes = (NSArray<String>) CopyType.copyTypesFor(property).valueForKey("type");
      String validCopyTypes = copyTypes.componentsJoinedByString(", ");
      String propertyName = property.name();
      EOEntity entity = property.entity();
      String entityName = entity.name();
      EOModel model = entity.model();
      String modelName = model.name();
      String exceptionMessage = "ERXCopyable's modelCopy requires the \"" + ERXCopyable.COPY_TYPE_KEY + "\" key must be set in the UserInfo dictionary of \"" + entityName + "." + propertyName + "\" " + propertyType + " in " + modelName + " AND it must be set to one of these values: {" + validCopyTypes + "}. \"" + copyType + "\" is not a valid value.";
      throw new IllegalStateException(exceptionMessage);
    }
View Full Code Here

    // quotes the identifier in the array
   
    String sourceKeyList = quoteArrayContents(sourceColumns).componentsJoinedByString(", ");
    String destinationKeyList = quoteArrayContents(destinationColumns).componentsJoinedByString(", ");
   
    EOModel sourceModel = entity.model();
    EOModel destModel = relationship.destinationEntity().model();
    if (sourceModel != destModel && !sourceModel.connectionDictionary().equals(destModel.connectionDictionary())) {
      throw new IllegalArgumentException(new StringBuilder().append("prepareConstraintStatementForRelationship unable to create a constraint for ").append(relationship.name()).append(" because the source and destination entities reside in different databases").toString());
    }
    setStatement(new StringBuilder()
        .append("ALTER TABLE ")
        .append(sqlStringForSchemaObjectName(entity.externalName()))
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.