Examples of AdaptrexEntityType


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

    List<String> entityIncludes = PersistenceTools.getIncludes(extConfig, nodePath);
    List<String> entityExcludes = PersistenceTools.getExcludes(extConfig, nodePath);
    List<String> entityJoins = PersistenceTools.getJoins(extConfig, nodePath);

    AdaptrexEntityType adaptrexEntity = apm.getAdaptrexEntity(entityClazz.getSimpleName());
    Map<String,AdaptrexFieldType> adaptrexFields = adaptrexEntity.getFields();
    Map<String,AdaptrexCollectionType> adaptrexCollections = adaptrexEntity.getCollections();
    Map<String,AdaptrexAssociationType> adaptrexAssociations = adaptrexEntity.getAssociations();
   
    /*
     * Add ID field
     */
    entityData.put(AdaptrexEntityType.ENTITY_ID_NAME, adaptrexEntity.getEntityIdFrom(entity));
   
    /*
     * Add data fields
     */
    for (String fieldName : adaptrexFields.keySet()) {
      if (doInclude(entityClazz, fieldName, entityIncludes, entityExcludes)) {
        AdaptrexFieldType adaptrexField = adaptrexFields.get(fieldName);
        Object fieldValue = adaptrexField.getValueFrom(entity);
        entityData.put(fieldName, ExtTypeFormatter.format(fieldValue));
      }
    }

    /*
     * Add collections
     */
    for (String fieldName : adaptrexCollections.keySet()) {
      AdaptrexCollectionType adaptrexCollection = adaptrexEntity.getCollection(fieldName);
      String assocIdsName = StringUtilities.singularize(fieldName) +
          StringUtils.capitalize(AdaptrexEntityType.COLLECTION_IDS_NAME);
      boolean includeAssoc = entityJoins.contains(StringUtilities.capitalize(fieldName));
      boolean includeAssocIds = doInclude(entityClazz, assocIdsName, entityIncludes, entityExcludes);
     
      if (!includeAssoc && !includeAssocIds) continue;
     
      Object fieldValue = adaptrexCollection.getCollectionFrom(entity);
     
      List<Object> associatedIds = new ArrayList<Object>();
      List<Map<String, Object>> associatedData = new ArrayList<Map<String, Object>>();
     
      List<Object> assocObjList = fieldValue == null
          ? new ArrayList<Object>()
          : new ArrayList<Object>((Collection<? extends Object>) fieldValue);       
     
      for (Object assocObj : assocObjList) {
        if (includeAssoc)
          associatedData.add(getObjectGraph(assocObj, fieldName, entity, entityName));
        if (includeAssocIds)
          associatedIds.add(adaptrexEntity.getEntityIdFrom(assocObj));
      }
      if (includeAssoc) entityData.put(fieldName, associatedData);
      if (includeAssocIds) entityData.put(assocIdsName, associatedIds)
    }
   
    /*
     * Add association
     */
    for (String fieldName : adaptrexAssociations.keySet()) {
      AdaptrexAssociationType adaptrexAssociation = adaptrexEntity.getAssociation(fieldName);
      String assocIdName = fieldName + StringUtils.capitalize(AdaptrexEntityType.ENTITY_ID_NAME);
      boolean includeAssoc = entityJoins.contains(StringUtilities.capitalize(fieldName));
      boolean includeAssocId = doInclude(entityClazz, assocIdName, entityIncludes, entityExcludes);
     
      if (!includeAssoc && !includeAssocId) continue;
     
      Object fieldValue = adaptrexAssociation.getAssociationFrom(entity);
     
      if (includeAssoc) {
        Map<String,Object> assoc = fieldValue == null
            ? null
            : getObjectGraph(fieldValue, fieldName, entity, entityName);
        entityData.put(fieldName, assoc);
      }
     
      if (includeAssocId) {
        Object assocId = fieldValue == null ? null : adaptrexEntity.getEntityIdFrom(fieldValue);
        entityData.put(assocIdName, assocId);
      }
    }
   
    return entityData;
View Full Code Here

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

    List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
   
    Class<?> clazz = extConfig.getEntityClass();
    CayennePersistenceManager cayenne = (CayennePersistenceManager) extConfig.getORMPersistenceManager();
    ObjectContext objectContext = cayenne.getReadOnlyObjectContext();
    AdaptrexEntityType adaptrexEntity = cayenne.getAdaptrexEntity(clazz.getSimpleName());
   
    /*
     * If we have a where clause, fall back to JPQL
     */
    if (this.getWhere() != null && !this.getWhere().isEmpty()) {
      return getWhereFallback(cayenne, objectContext, clazz, data);
    }
   
    try {
     
      /*
       * Create the expressions
       */
      Expression expression = null;
      for (Filter filter : this.getFilters()) {
        Object val = filter.getValue();
        if (val == null || String.valueOf(val).isEmpty()) continue;
       
        String key = filter.getProperty();
        String extFieldType = adaptrexEntity.getField(key).getFieldDefinition().getType();
       
        Expression newExpression = null;
       
        /*
         * String filter
View Full Code Here

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

    excludes = extConfig.getExcludes();
   
    entityClassIncludes = PersistenceTools.getIncludes(extConfig, extConfig.getModelName());
    entityClassExcludes = PersistenceTools.getExcludes(extConfig, extConfig.getModelName());
   
    AdaptrexEntityType adaptrexEntity = orm.getAdaptrexEntity(extConfig.getEntityClass().getSimpleName());
    Map<String,AdaptrexFieldType> adaptrexFields = adaptrexEntity.getFields();
    Map<String,AdaptrexCollectionType> adaptrexCollections = adaptrexEntity.getCollections();
    Map<String,AdaptrexAssociationType> adaptrexAssociations = adaptrexEntity.getAssociations();

    for (String key : adaptrexFields.keySet()) {
      if (doInclude(key))
        this.fields.add(adaptrexFields.get(key).getFieldDefinition());
    }
View Full Code Here

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

    String associationSimpleName = StringUtilities.capitalize(associationName);
   
    Class<?> parentClass = parentConfig.getEntityClass();
   
    AdaptrexPersistenceManager orm = parentConfig.getORMPersistenceManager();
    AdaptrexEntityType adaptrexEntity = orm.getAdaptrexEntity(parentClass.getSimpleName());
   
    AdaptrexAssociationType adaptrexAssociation = adaptrexEntity.getAssociation(associationName);
    if (adaptrexAssociation != null) {
      this.type = BELONGS_TO;
      this.modelName = parentConfig.getModelName() + associationSimpleName;
      this.entityClassName = adaptrexAssociation.getAssociationType().getSimpleName();
     
      this.name = StringUtilities.uncapitalize(associationName);
      this.associationKey = this.name;
      this.foreignKey = this.name + StringUtils.capitalize(AdaptrexEntityType.ENTITY_ID_NAME);
     
      this.getterName = "get" + associationSimpleName;
      this.setterName = "set" + associationSimpleName;
    }
   
    AdaptrexCollectionType adaptrexCollection = adaptrexEntity.getCollection(associationName);
    if (adaptrexCollection != null) {
      this.type = HAS_MANY;
      this.modelName = parentConfig.getModelName() + Inflector.getInstance().singularize(associationSimpleName);
      this.entityClassName = adaptrexCollection.getItemType().getSimpleName();
      this.associationKey = StringUtilities.uncapitalize(associationName);
View Full Code Here

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

    List<String> entityIncludes = PersistenceTools.getIncludes(extConfig, nodePath);
    List<String> entityExcludes = PersistenceTools.getExcludes(extConfig, nodePath);
    List<String> entityJoins = PersistenceTools.getJoins(extConfig, nodePath);

    AdaptrexEntityType adaptrexEntity = apm.getAdaptrexEntity(entityClazzName);
    Map<String,AdaptrexFieldType> adaptrexFields = adaptrexEntity.getFields();
    Map<String,AdaptrexCollectionType> adaptrexCollections = adaptrexEntity.getCollections();
    Map<String,AdaptrexAssociationType> adaptrexAssociations = adaptrexEntity.getAssociations();
   
    /*
     * Add ID field
     */
    entityData.put(AdaptrexEntityType.ENTITY_ID_NAME, adaptrexEntity.getEntityIdFrom(entity));
   
    /*
     * Add data fields
     */
    for (String fieldName : adaptrexFields.keySet()) {
      if (doInclude(entityClazz, fieldName, entityIncludes, entityExcludes)) {
        AdaptrexFieldType adaptrexField = adaptrexFields.get(fieldName);
        Object fieldValue = adaptrexField.getValueFrom(entity);
        entityData.put(fieldName, ExtTypeFormatter.format(fieldValue));
      }
    }

    /*
     * Add collections
     */
    for (String fieldName : adaptrexCollections.keySet()) {
      AdaptrexCollectionType adaptrexCollection = adaptrexEntity.getCollection(fieldName);
      String assocIdsName = StringUtilities.singularize(fieldName) +
          StringUtils.capitalize(AdaptrexEntityType.COLLECTION_IDS_NAME);
      boolean includeAssoc = entityJoins.contains(StringUtilities.capitalize(fieldName));
      boolean includeAssocIds = doInclude(entityClazz, assocIdsName, entityIncludes, entityExcludes);
     
      if (!includeAssoc && !includeAssocIds) continue;
     
      Object fieldValue = adaptrexCollection.getCollectionFrom(entity);
     
      List<Object> associatedIds = new ArrayList<Object>();
      List<Map<String, Object>> associatedData = new ArrayList<Map<String, Object>>();
     
      List<Object> assocObjList = fieldValue == null
          ? new ArrayList<Object>()
          : new ArrayList<Object>((Collection<? extends Object>) fieldValue);       
     
      for (Object assocObj : assocObjList) {
        if (includeAssoc)
          associatedData.add(getObjectGraph(assocObj, fieldName, entity, entityName));
        if (includeAssocIds)
          associatedIds.add(adaptrexEntity.getEntityIdFrom(assocObj));
      }
      if (includeAssoc) entityData.put(fieldName, associatedData);
      if (includeAssocIds) entityData.put(assocIdsName, associatedIds)
    }
   
    /*
     * Add association
     */
    for (String fieldName : adaptrexAssociations.keySet()) {
      AdaptrexAssociationType adaptrexAssociation = adaptrexEntity.getAssociation(fieldName);
      String assocIdName = fieldName + StringUtils.capitalize(AdaptrexEntityType.ENTITY_ID_NAME);
      boolean includeAssoc = entityJoins.contains(StringUtilities.capitalize(fieldName));
      boolean includeAssocId = doInclude(entityClazz, assocIdName, entityIncludes, entityExcludes);
     
      if (!includeAssoc && !includeAssocId) continue;
     
      Object fieldValue = adaptrexAssociation.getAssociationFrom(entity);
     
      if (includeAssoc) {
        Map<String,Object> assoc = fieldValue == null
            ? null
            : getObjectGraph(fieldValue, fieldName, entity, entityName);
        entityData.put(fieldName, assoc);
      }
     
      if (includeAssocId) {
        Object assocId = fieldValue == null ? null : adaptrexEntity.getEntityIdFrom(fieldValue);
        entityData.put(assocIdName, assocId);
      }
    }
   
    return entityData;
View Full Code Here

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

    List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
   
    Class<?> clazz = extConfig.getEntityClass();
    JPAPersistenceManager jpa = (JPAPersistenceManager) extConfig.getORMPersistenceManager();
    EntityManager em = jpa.getEntityManager();
    AdaptrexEntityType adaptrexEntity = jpa.getAdaptrexEntity(clazz.getSimpleName());
   
    /*
     * If we have a where clause, fall back to JPQL
     */
    if (this.getWhere() != null && !this.getWhere().isEmpty()) {
      return getWhereFallback(jpa, em, clazz, data);
    }
   
   
    try {
      /*
       * Get the criteria builder
       */
      CriteriaBuilder builder = em.getCriteriaBuilder();

      /*
       * Create the CriteriaQuery and it's Root
       */
      CriteriaQuery<?> query = builder.createQuery(clazz);
      Root<?> root = query.from(clazz);
     
      /*
       * Create the list of predicates to hold our individual filters
       */
      List<Predicate> predicates = new ArrayList<Predicate>();
      for (Filter filter : this.getFilters()) {
       
        /*
         * Get the value of the filter
         */
        Object val = filter.getValue();
        if (val == null || String.valueOf(val).isEmpty()) continue;

        /*
         * Get the property to filter
         */
        String key = filter.getProperty();
        String propertyName = key;
        String extFieldType = null;
        Path<String> currentNode = (Path<String>) root;
        if (key.contains(".")) {
          propertyName = StringUtils.substringAfterLast(key, ".");
          key = StringUtils.substringBeforeLast(key, ".");
         
          String[] propParts = StringUtils.split(key, ".");
          for (String propPart : propParts) {
            currentNode = currentNode.get(propPart);
          }
         
          extFieldType = jpa.getAdaptrexEntity(currentNode.getJavaType().getSimpleName())
              .getField(propertyName).getFieldDefinition().getType();
        } else {
          extFieldType = adaptrexEntity.getField(propertyName).getFieldDefinition().getType();
        }
       
       
        /*
         * Get an expression representing the entity property we're filtering
View Full Code Here

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

  @Override
  public ModelInstance createModelInstance(ExtConfig extConfig, Map<String, Object> data) {
    Object id = null;
    EntityManager em = getEntityManager();
    try {
      AdaptrexEntityType adaptrexEntity = getAdaptrexEntity(extConfig.getClassName());
      Class<?> clazz = extConfig.getEntityClass();
      Object entity = clazz.newInstance();
      this.updateEntity(em, clazz, entity, data, true);
      id = adaptrexEntity.getEntityIdFrom(entity);
    } catch (Exception e) {
      throw new RuntimeException(e);
    } finally {
      closeEM(em);
    }
View Full Code Here

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

  private ModelInstance updateModelInstance(
      ExtConfig extConfig, Object id, String key, Object value, Map<String, Object> data) throws Exception {
    EntityManager em = getEntityManager();
    try {
      AdaptrexEntityType adaptrexEntity = getAdaptrexEntity(extConfig.getClassName());
      Class<?> clazz = extConfig.getEntityClass();
      Object entity = id != null ? this.getEntity(em, clazz, id) : this.getEntity(em, clazz, key, value);
      this.updateEntity(em, clazz, entity, data, false);
      id = id != null ? id : adaptrexEntity.getEntityIdFrom(entity);
    } catch (Exception e) {
      throw new Exception(e);
    } finally {
      closeEM(em);
    }
View Full Code Here

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

    return list;
  }
 

  private void updateEntity(EntityManager em, Class<?> clazz, Object entity, Map<String,Object> data, boolean isNew) throws Exception {
    AdaptrexEntityType adaptrexEntity = getAdaptrexEntity(clazz.getSimpleName());
   
    EntityTransaction tx = em.getTransaction();
    tx.begin();

    try {
      for (String fieldName : data.keySet()) {
        if (fieldName.equals(AdaptrexEntityType.ENTITY_ID_NAME)) continue;
       
        Object newValue = data.get(fieldName);
       
        AdaptrexFieldType adaptrexField = adaptrexEntity.getField(fieldName);
        if (adaptrexField != null) {
          adaptrexField.setValueFor(entity, ExtTypeFormatter.parse(newValue, adaptrexField.getFieldType()));
          continue;
        }
       
        JPAAssociationType adaptrexAssociation = (JPAAssociationType) adaptrexEntity.getAssociationByIdField(fieldName);
        if (adaptrexAssociation != null) {
          adaptrexAssociation.setById(em, entity, newValue);
          continue;
        }
       
        JPACollectionType adaptrexCollection = (JPACollectionType) adaptrexEntity.getCollectionByIdsField(fieldName);
        if (adaptrexCollection != null) {
          adaptrexCollection.setByIds(em, entity, newValue);
        }
      }
     
View Full Code Here

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

    String associationSimpleName = StringUtilities.capitalize(associationName);
   
    Class<?> parentClass = parentConfig.getEntityClass();
   
    AdaptrexPersistenceManager orm = parentConfig.getORMPersistenceManager();
    AdaptrexEntityType adaptrexEntity = orm.getAdaptrexEntity(parentClass.getSimpleName());
   
    AdaptrexAssociationType adaptrexAssociation = adaptrexEntity.getAssociation(associationName);
    if (adaptrexAssociation != null) {
      this.type = BELONGS_TO;
      this.modelName = parentConfig.getModelName() + associationSimpleName;
      this.entityClassName = adaptrexAssociation.getAssociationType().getSimpleName();
     
      this.name = StringUtilities.uncapitalize(associationName);
      this.associationKey = this.name;
      this.foreignKey = this.name + AdaptrexEntityType.ENTITY_ID_NAME;
     
      this.getterName = "get" + associationSimpleName;
      this.setterName = "set" + associationSimpleName;
    }
   
    AdaptrexCollectionType adaptrexCollection = adaptrexEntity.getCollection(associationName);
    if (adaptrexCollection != null) {
      this.type = HAS_MANY;
      this.modelName = parentConfig.getModelName() + Inflector.getInstance().singularize(associationSimpleName);
      this.entityClassName = adaptrexCollection.getItemType().getSimpleName();
      this.associationKey = StringUtilities.uncapitalize(associationName);
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.