Package com.adaptrex.core.ext

Examples of com.adaptrex.core.ext.ModelInstance


    try {
      ObjectContext objectContext = getObjectContext();
      Class<?> clazz = extConfig.getEntityClass();
      Object entity = objectContext.newObject(clazz);
      this.updateEntity(objectContext, clazz, entity, data);
      return new ModelInstance(extConfig, entity);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here


    Class<?> clazz = extConfig.getEntityClass();
    Object entity = id != null
        ? this.getEntity(objectContext, clazz, id)
        : this.getEntity(objectContext, clazz, key, value);
    this.updateEntity(objectContext, clazz, entity, data);
    return new ModelInstance(extConfig, entity);
  }
View Full Code Here

    ObjectContext objectContext = getObjectContext();
    Class<?> clazz = extConfig.getEntityClass();
    Object entity = id != null
        ? this.getEntity(objectContext, clazz, id)
        : this.getEntity(objectContext, clazz, key, value);
    ModelInstance model = new ModelInstance(extConfig, entity);
    objectContext.deleteObjects(entity);
    objectContext.commitChanges();
    return model;
  }
View Full Code Here

     * we also return an online instance
     * TODO: We should add the ability to load this via rest to enable associations
     */
    String modelInstanceString = "";
    if (this.entityId != null || entityKey != null) {
      ModelInstance modelInstance = this.entityId != null
          ? apm.getModelInstance(this.extConfig, this.entityId)
          : apm.getModelInstance(this.extConfig, this.entityKey, this.entityValue);
         
//      ModelInstance modelInstance = this.entityId != null
//          ? new ModelInstance(extConfig, this.entityId)
//          : new ModelInstance(extConfig, this.entityKey, this.entityValue);
         
      modelInstanceString = "Ext.ns('" + namespace + ".instance');" + "\n" +
          namespace + ".instance." + this.extConfig.getModelName() + "=Ext.create('" +
          fullModelName + "', " +
          StringUtilities.json(modelInstance.getData(), this.request.getServletContext()) + ");\n";
    }
   
   
    StringBuffer javascript = new StringBuffer();
    if (!configComponent.isWritten()) {
View Full Code Here

       */
      TypedQuery<?> typedQuery = em.createQuery(query);
      if (this.getLimit() != null) typedQuery.setMaxResults(this.getLimit());
      if (this.getStart() != null) typedQuery.setFirstResult(this.getStart());
      for (Object entity : typedQuery.getResultList()) {
        data.add(new ModelInstance(extConfig, entity).getData());
      }

     
      /*
       * Create a CriteriaQuery used to get the total count of records in the resultset
View Full Code Here

    }   
   
    if (this.getLimit() != null) query.setMaxResults(this.getLimit());
    if (this.getStart() != null) query.setFirstResult(this.getStart().intValue());
    for (Object entity : query.getResultList()) {
      data.add(new ModelInstance(extConfig, entity).getData());
    }
   
    /*
     * Get the initial list before applying limits
     */
 
View Full Code Here

  @Override
  public ModelInstance getModelInstance(ExtConfig extConfig, Object id) {
    EntityManager em = getEntityManager();
    try {
      Object entity = this.getEntity(em, extConfig.getEntityClass(), id);
      return new ModelInstance(extConfig, entity);
    } catch (Exception e) {} finally {
      closeEM(em);
    }
    return null;
  }
View Full Code Here

  @Override
  public ModelInstance getModelInstance(ExtConfig extConfig, String key, Object value) {
    EntityManager em = getEntityManager();
    try {
      Object entity = this.getEntity(em, extConfig.getEntityClass(), key, value);
      return new ModelInstance(extConfig, entity);
    } catch (Exception e) {} finally {
      closeEM(em);
    }
    return null;
  }
View Full Code Here

    EntityTransaction tx = em.getTransaction();
    try {
      tx.begin();
      Class<?> clazz = extConfig.getEntityClass();
      Object entity = id != null ? this.getEntity(em, clazz, id) : this.getEntity(em, clazz, key, value);
      ModelInstance model = new ModelInstance(extConfig, entity);
      this.evictAssociated(em, entity);
      em.remove(em.merge(entity));
      tx.commit();
      return model;
    } catch (Exception e) {
View Full Code Here

   
    /*
     * We need to do some formatting on the response
     */
    Map<String,Object> response = new HashMap<String,Object>();
    ModelInstance modelInstance = model.getModelInstance();
    if (modelInstance.getData().isEmpty()) {
      response.put("success", false);
      response.put("message", "Record Not Found");
    } else {
      response.put("data", modelInstance.getData());
      response.put("id", modelInstance.getData().get("id"));
      response.put("success", true);
    }
   
    try {
      String json = StringUtilities.json(response);
View Full Code Here

TOP

Related Classes of com.adaptrex.core.ext.ModelInstance

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.