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) + 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 + 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;

        String key = filter.getProperty();
        String extFieldType = adaptrexEntity.getField(key).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) {} 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

  }
 
 

  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
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.