Examples of ORMPersistenceManager


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

   
   
    /*
     * First, make sure an association exists
     */
    ORMPersistenceManager orm = parentConfig.getORMPersistenceManager();
   
    String associationSimpleName = associationName;
    if (associationName.contains(".")) {
      associationSimpleName = associationName.split("\\.")[1];
    }
    boolean isManyToOne = orm.isManyToOne(parentClass, associationSimpleName);
    boolean isOneToMany = orm.isOneToMany(parentClass, associationSimpleName) || orm.isManyToMany(parentClass, associationSimpleName);
    if (!isManyToOne && !isOneToMany) {
      throw new RuntimeException("Could not find association from "
          + parentConfig.getModelName() + " to "
          + associationName);
    }

    /*
     * If we've got a :n relationship, get the type of the collection elements
     */
    String entityClassName = associationName;
    if (isOneToMany || isManyToOne) {
      entityClassName = orm.getFieldEntityClass(parentClass, StringUtilities.uncapitalize(associationSimpleName)).getSimpleName();
    }
   
   
    /*
     * Set the association type
View Full Code Here

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

  public ModelInstance(ExtConfig extConfig, Object id) {
    this(extConfig, id, null, null);
  }

  private ModelInstance(ExtConfig extConfig, Object id, String key, Object value) {
    ORMPersistenceManager orm = extConfig.getORMPersistenceManager();
   
    Object entity;
    if (id != null) {
      entity = orm.getEntity(extConfig.getEntityClass(), id);
    } else {
      entity = orm.getEntity(extConfig.getEntityClass(), key, value);
    }
   
    ORMModelInstance ormModelInstance = orm.getModelInstance(extConfig, entity);
    this.data = ormModelInstance.getData();
  }
View Full Code Here

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

     * Get this model name
     */
    this.modelName = extConfig.getModelName();
   
   
    ORMPersistenceManager orm = AdaptrexServices.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

 
  public static ORMPersistenceManager getPersistenceManager(String factoryName) {
    if (factoryName == null) factoryName = getConfig().get(AdaptrexConfig.PERSISTENCE_ORM_DEFAULT);
    String key = factoryName != null ? factoryName : "_default";
   
    ORMPersistenceManager persistenceManager = persistenceManagers.get(key);
    if (persistenceManager == null) {
      synchronized(AdaptrexServices.class) {
        if (persistenceManagers.get(key) != null) {
          return persistenceManagers.get(key);
        }
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();
    EntityManagerFactory emf = em.getEntityManagerFactory();
    Cache emfCache = emf.getCache();
   
    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) {
            log.debug("Couldn't set " + field.getName());
            continue;
          }
        }

        /*
         * Check for 1:m or n:m
         */
        if (key.endsWith("Ids")) {
          key = StringUtilities.pluralize(key.substring(0, key.length() - 3));
          if (orm.isManyToOne(clazz, key) || orm.isManyToMany(clazz, key)) {
            Class<?> fieldType = null;
           
            try {
              evictAssociated(em, entity);
            } catch (Exception e) {
              log.info("Couldn't evict associated entity for " + entity.getClass().getName());
            }
           
            try {
              field = entity.getClass().getDeclaredField(key);
              fieldType = field.getType();
             
              List<Object> assocObjList = new ArrayList<Object>();

              Class<?> itemType = null;
              Type type = field.getGenericType();
              if (type instanceof ParameterizedType) {
                ParameterizedType pt = (ParameterizedType) type;
                itemType = (Class<?>) pt.getActualTypeArguments()[0];
              }
             
              @SuppressWarnings("unchecked")
              List<Object> listItemIds = (List<Object>) StringUtilities.fromJson((String) val, List.class);
              for (Object listItemId : listItemIds) {
                assocObjList.add(orm.getEntity(itemType, listItemId));
              }

              if (fieldType.getSimpleName().equals("Set")) {
                val = new HashSet<Object>(assocObjList);
              } else {
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
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.