Examples of ORMPersistenceManager


Examples of com.adaptrex.core.persistence.api.ORMPersistenceManager

     * Get this model name
     */
    this.modelName = extConfig.getModelName();
   
   
    ORMPersistenceManager orm = AdaptrexRegistry.getPersistenceManager(extConfig.getFactoryName());
   
    /*
     * Get the ORM's part of the model definition
     */
    ORMModelDefinition ormModelDefinition = orm.getModelDefinition(extConfig);

    /*
     * Get info from the orm
     */
    this.fields = ormModelDefinition.getFields();
    this.idProperty = ormModelDefinition.getIdProperty();
   
    /*
     * Add this model's associations
     */
    for (String associationName : extConfig.getAssociations()) {
      if (isRoot && associationName.contains(".")) continue;
      if (!isRoot && !associationName.contains(".")) continue;

      String associationSimpleName = associationName;
      if (associationName.contains(".")) {
        if (!associationName.startsWith(extConfig.getModelName() + ".")) {
          continue;
        } else {
          associationSimpleName = associationName.split("\\.")[1];
        }
      }
     
      if (orm.isAssociated(clazz, associationSimpleName)) {
        Association association = new Association(extConfig, associationName);
        this.associations.add(association);
       
        /*
         * Add return association to associated model
View Full Code Here

Examples of com.adaptrex.core.persistence.api.ORMPersistenceManager

  private List<FieldDefinition>   fields = new ArrayList<FieldDefinition>();
  private String           idProperty;
 
  public JPAModelDefinition(ExtConfig config) {
    boolean isRoot = config.getParentConfig() == null;
    ORMPersistenceManager orm = config.getORMPersistenceManager();
   
    List<String> includes = config.getIncludes();
    List<String> excludes = config.getExcludes();
   
    List<String> entityClassIncludes = new ArrayList<String>();
    List<String> entityClassExcludes = new ArrayList<String>()
   
   
    /*
     * Determine list of included/excluded fields for this model
     */
    if (isRoot) {
      /*
       * Loop each include/exclude/join config and determine if they
       * are set for the root entity.
       */
      for (String incl : includes) {
        if (!incl.contains(".")) entityClassIncludes.add(incl);
      }
   
      for (String excl : excludes) {
        if (!excl.contains(".")) entityClassExcludes.add(excl);
      }
     
    } else {
     
      /*
       * Loop each include/exclude/join config and determine if they are set for
       * the current entity at this position in the tree.  If the full path to a
       * specific field on this entity is set, we want to include it in the entity
       * specific config.  We only need the field portion when testing against
       * the current entity so that gets split out before adding to the list
       */
      for (String incl : includes) {
        if (incl.contains(config.getModelName() + ".")) {
          entityClassIncludes.add(incl.split("\\.")[1]);
        }
      }
   
      for (String excl : excludes) {
        if (excl.contains(config.getModelName() + ".")) {
          entityClassExcludes.add(excl.split("\\.")[1]);
        }
      }
    }
   
   
    /*
     * Get the class for this model
     */
    Class<?> clazz = config.getEntityClass();
   
    /*
     * Create and add the fields for this model
     */
    for (java.lang.reflect.Field field : clazz.getDeclaredFields()) {

      /*
       * Static fields don't get returned
       */
      if (Modifier.isStatic(field.getModifiers())) {
        continue;
      }


      /*
       * Get the field name
       */
      String fieldName = field.getName();
     
      /*
       * Identify id field
       */
      if (orm.isIdField(clazz, fieldName)) {
        this.fields.add(new FieldDefinition(field, config));
        this.idProperty = fieldName;
        continue;
      }
     
     
      /*
       * Create the field names for association id fields
       */
      String extFieldName = field.getName();
      if (orm.isOneToMany(clazz, fieldName) || orm.isManyToMany(clazz, fieldName)) {
        extFieldName = Inflector.getInstance().singularize(fieldName) + "Ids";
      } else if (orm.isManyToOne(clazz, fieldName)) {
        extFieldName = fieldName + "Id";
      }
     
     
      /*
       * Is this field included or excluded?
       */
      if (isRoot) {
        if (includes.size() > 0
            && (!includes.contains("*") && !includes.contains(extFieldName))) {
          continue;
        }
        if (excludes.contains("*") || excludes.contains(extFieldName)) {
          continue;
        }

      } else {
        if (includes.size() > 0) {
          if (entityClassIncludes.isEmpty()
              || (!entityClassIncludes.contains("*") && !entityClassIncludes.contains(extFieldName))) {
            continue;
          }
        }

        if (excludes.size() > 0) {
          if (entityClassExcludes.contains("*") || entityClassExcludes.contains(extFieldName)) {
            continue;
          }
        }
      }
     
     
      /*
       * If we have a one to many association, add a field to hold an array
       * of ID's for that association
       */
      if (orm.isOneToMany(clazz, fieldName) || orm.isManyToMany(clazz, fieldName) || orm.isManyToOne(clazz, fieldName)) {
        this.fields.add(new FieldDefinition(extFieldName, "auto"));
      } else {
        this.fields.add(new FieldDefinition(field, config));
      }
    }
View Full Code Here

Examples of com.adaptrex.core.persistence.api.ORMPersistenceManager

 
  private static String[]  dateFormatStrings = {"yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd", "HH:mm:ss"};
  @Override
  public ORMModelInstance update(Map<String, Object> data) {
    ORMPersistenceManager orm = AdaptrexServices.getPersistenceManager(this.extConfig.getFactoryName());
    EntityManager em = (EntityManager) orm.getSession();
    EntityTransaction tx = em.getTransaction();
    try {
      tx.begin();
      for (String key : data.keySet()) {
        if (key.equals("id")) {
          continue;
        }
        Object val = data.get(key);

        /*
         * Get our class
         */
        Class<?> clazz = this.entity.getClass();
       
        /*
         * Get info about the field we're updating
         */
        Field field = null;
        try {
          field = clazz.getDeclaredField(key);
        } catch (Exception e) {
        }
       
       
        /*
         * If we don't have a field with the current name, check for a
         * foreign entity
         */
        if (key.endsWith("Id")
            && orm.isManyToOne(clazz,
                key.substring(0, key.length() - 2))) {
          key = key.substring(0, key.length() - 2);
          try {
            field = entity.getClass().getDeclaredField(key);
            if (field != null && val != null) {
              val = orm.getEntity(field.getType(), val);
            }
          } catch (Exception e) {
            continue;
          }
        }
View Full Code Here

Examples of com.adaptrex.core.persistence.api.ORMPersistenceManager

  }

  @Override
  public ORMModelInstance delete() {

    ORMPersistenceManager orm = AdaptrexServices.getPersistenceManager(this.extConfig.getFactoryName());
    EntityManager em = (EntityManager) orm.getSession();
    EntityTransaction tx = em.getTransaction();
    try {
      tx.begin();
     
      try {
View Full Code Here

Examples of com.adaptrex.core.persistence.api.ORMPersistenceManager

 
  private static String[]  dateFormatStrings = {"yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd", "HH:mm:ss"};
  @Override
  public ORMModelInstance update(Map<String, Object> data) {
    ORMPersistenceManager orm = AdaptrexServices.getPersistenceManager(this.extConfig.getFactoryName());
    EntityManager em = (EntityManager) orm.getSession();
    try {
      em.getTransaction().begin();
      for (String key : data.keySet()) {
        if (key.equals("id")) {
          continue;
        }
        Object val = data.get(key);

        /*
         * Get our class
         */
        Class<?> clazz = this.entity.getClass();
       
        /*
         * Get info about the field we're updating
         */
        Field field = null;
        try {
          field = clazz.getDeclaredField(key);
        } catch (Exception e) {
        }
       
        /*
         * If we don't have a field with the current name, check for a
         * foreign entity
         */
        if (key.endsWith("Id")
            && orm.isManyToOne(clazz,
                key.substring(0, key.length() - 2))) {
          key = key.substring(0, key.length() - 2);
          try {
            field = entity.getClass().getDeclaredField(key);
            if (field != null && val != null) {
              val = orm.getEntity(field.getType(), val);
            }
          } catch (Exception e) {
            continue;
          }
        }
View Full Code Here

Examples of com.adaptrex.core.persistence.api.ORMPersistenceManager

  }

  @Override
  public ORMModelInstance delete() {

    ORMPersistenceManager orm = AdaptrexServices.getPersistenceManager(this.extConfig.getFactoryName());
    EntityManager em = (EntityManager) orm.getSession();
    try {
      em.getTransaction().begin();
     
      try {
        evictAssociated(em, entity);
View Full Code Here

Examples of com.adaptrex.core.persistence.api.ORMPersistenceManager

      if (params.containsKey("associations")) {
        extConfig.setAssociations(params.get("associations").get(0));
      }     
    }
   
    ORMPersistenceManager orm = AdaptrexServices.getPersistenceManager(factoryName);
    this.modelInstance = orm.createModelinstance(extConfig, data);
  }
View Full Code Here

Examples of com.adaptrex.core.persistence.api.ORMPersistenceManager

    this.modelInstance = orm.createModelinstance(extConfig, data);
  }
 
  public RestModel(String className, Object id, UriInfo uriInfo, String factoryName) {
    ExtConfig extConfig = new ExtConfig(className, factoryName);
    ORMPersistenceManager orm = AdaptrexServices.getPersistenceManager(factoryName);
    entity = orm.getEntity(extConfig.getEntityClass(), id);
   
    /*
     * Process parameters
     */
    if (uriInfo != null) {
      MultivaluedMap<String,String> params = uriInfo.getQueryParameters();
      /*
       * Add include/exclude/associations to the config
       */
      if (params.containsKey("include")) {
        extConfig.setIncludes(params.get("include").get(0));
      }
      if (params.containsKey("exclude")) {
        extConfig.setExcludes(params.get("exclude").get(0));
      }
      if (params.containsKey("associations")) {
        extConfig.setAssociations(params.get("associations").get(0));
      }     
    }
   
    this.modelInstance = orm.getModelInstance(extConfig, entity);
  }
View Full Code Here

Examples of com.adaptrex.core.persistence.api.ORMPersistenceManager

  private List<FieldDefinition>   fields = new ArrayList<FieldDefinition>();
  private String           idProperty;
 
  public JPAModelDefinition(ExtConfig config) {
    boolean isRoot = config.getParentConfig() == null;
    ORMPersistenceManager orm = config.getORMPersistenceManager();
   
    List<String> includes = config.getIncludes();
    List<String> excludes = config.getExcludes();
   
    List<String> entityClassIncludes = new ArrayList<String>();
    List<String> entityClassExcludes = new ArrayList<String>()
   
   
    /*
     * Determine list of included/excluded fields for this model
     */
    if (isRoot) {
      /*
       * Loop each include/exclude/join config and determine if they
       * are set for the root entity.
       */
      for (String incl : includes) {
        if (!incl.contains(".")) entityClassIncludes.add(incl);
      }
   
      for (String excl : excludes) {
        if (!excl.contains(".")) entityClassExcludes.add(excl);
      }
     
    } else {
     
      /*
       * Loop each include/exclude/join config and determine if they are set for
       * the current entity at this position in the tree.  If the full path to a
       * specific field on this entity is set, we want to include it in the entity
       * specific config.  We only need the field portion when testing against
       * the current entity so that gets split out before adding to the list
       */
      for (String incl : includes) {
        if (incl.contains(config.getModelName() + ".")) {
          entityClassIncludes.add(incl.split("\\.")[1]);
        }
      }
   
      for (String excl : excludes) {
        if (excl.contains(config.getModelName() + ".")) {
          entityClassExcludes.add(excl.split("\\.")[1]);
        }
      }
    }
   
   
    /*
     * Get the class for this model
     */
    Class<?> clazz = config.getEntityClass();
   
    /*
     * Create and add the fields for this model
     */
    for (java.lang.reflect.Field field : clazz.getDeclaredFields()) {

      /*
       * Static fields don't get returned
       */
      if (Modifier.isStatic(field.getModifiers())) {
        continue;
      }


      /*
       * Get the field name
       */
      String fieldName = field.getName();
     
      /*
       * Identify id field
       */
      if (orm.isIdField(clazz, fieldName)) {
        this.fields.add(new FieldDefinition(field, config));
        this.idProperty = fieldName;
        continue;
      }
     
     
      /*
       * Create the field names for association id fields
       */
      String extFieldName = field.getName();
      if (orm.isOneToMany(clazz, fieldName) || orm.isManyToMany(clazz, fieldName)) {
        extFieldName = Inflector.getInstance().singularize(fieldName) + "Ids";
      } else if (orm.isManyToOne(clazz, fieldName)) {
        extFieldName = fieldName + "Id";
      }
     
     
      /*
       * Is this field included or excluded?
       */
      if (isRoot) {
        if (includes.size() > 0
            && (!includes.contains("*") && !includes.contains(extFieldName))) {
          continue;
        }
        if (excludes.contains("*") || excludes.contains(extFieldName)) {
          continue;
        }

      } else {
        if (includes.size() > 0) {
          if (entityClassIncludes.isEmpty()
              || (!entityClassIncludes.contains("*") && !entityClassIncludes.contains(extFieldName))) {
            continue;
          }
        }

        if (excludes.size() > 0) {
          if (entityClassExcludes.contains("*") || entityClassExcludes.contains(extFieldName)) {
            continue;
          }
        }
      }
     
     
      /*
       * If we have a one to many association, add a field to hold an array
       * of ID's for that association
       */
      if (orm.isOneToMany(clazz, fieldName) || orm.isManyToMany(clazz, fieldName) || orm.isManyToOne(clazz, fieldName)) {
        this.fields.add(new FieldDefinition(extFieldName, "auto"));
      } else {
        this.fields.add(new FieldDefinition(field, config));
      }
    }
View Full Code Here

Examples of com.adaptrex.core.persistence.api.ORMPersistenceManager

 
  private static String[]  dateFormatStrings = {"yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd", "HH:mm:ss"};
  @Override
  public ORMModelInstance update(Map<String, Object> data) {
    ORMPersistenceManager orm = AdaptrexServices.getPersistenceManager(this.extConfig.getFactoryName());
    EntityManager em = (EntityManager) orm.getSession();
    try {
      em.getTransaction().begin();
      for (String key : data.keySet()) {
        if (key.equals("id")) {
          continue;
        }
        Object val = data.get(key);

        /*
         * Get our class
         */
        Class<?> clazz = this.entity.getClass();
       
        /*
         * Get info about the field we're updating
         */
        Field field = null;
        try {
          field = clazz.getDeclaredField(key);
        } catch (Exception e) {
        }
       
        /*
         * If we don't have a field with the current name, check for a
         * foreign entity
         */
        if (key.endsWith("Id")
            && orm.isManyToOne(clazz,
                key.substring(0, key.length() - 2))) {
          key = key.substring(0, key.length() - 2);
          try {
            field = entity.getClass().getDeclaredField(key);
            if (field != null && val != null) {
              val = orm.getEntity(field.getType(), val);
            }
          } catch (Exception e) {
            continue;
          }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.