Package com.adaptrex.core.persistence

Examples of com.adaptrex.core.persistence.AdaptrexSession


  }
    }

    private Model(String entityName, Integer id, ExtConfig extConfig) {
  try {
      AdaptrexSession session = new AdaptrexSession();
      entity = session.getEntity(entityName, id);
      session.close();

      config = new Config();
      config.setClazz(entity.getClass());
      if (extConfig != null) {
    this.config.applyExtConfig(extConfig);
View Full Code Here


      log.warn("Error", e);
  }
    }

    private Model(String entityName, ModelData modelData, Integer id, ExtConfig extConfig) {
  AdaptrexSession session = new AdaptrexSession();

  try {
      Class<?> clazz = null;
      if (id == null) {
    clazz = persistence.getEntityClass(entityName);
    entity = clazz.newInstance();
      } else {
    entity = session.getEntity(entityName, id);
    clazz = entity.getClass();
      }

      entity = updateEntity(entity, modelData);
View Full Code Here

    /*
     * Delete an existing model
     */
    public static Model delete(String entityName, Integer id) {
  AdaptrexSession session = new AdaptrexSession();
  Model m = new Model(session.deleteEntity(entityName, id), null);
  session.close();
  return m;
    }
View Full Code Here

    if (key.endsWith("Id") && persistence.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) {
          AdaptrexSession session = new AdaptrexSession();
          val = session.getEntity(field.getType(), (Integer) val);
      }
        } catch (Exception e) {
      log.warn("Error", e);
      continue;
        }
    }


    if (field == null) {
        log.debug("Unable to serialize " + key);
        continue;
    }

    String typeName = field.getType().getSimpleName().toLowerCase();

    /*
     * Handle Date Fields
     */
    if (typeName.equals("date")) {
        try {
      val = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH).parse((String) val);
        } catch (Exception e) {
      continue;
        }
    }


    try {
        Method getter = clazz.getMethod("set" + StringUtilities.capitalize(key), field.getType());
        getter.invoke(entity, val);
    } catch (Exception e) {
        log.warn("Error updating field:  Couldn't invoke set" + StringUtilities.capitalize(key));
    }

      }
  } catch (Exception e) {
      log.warn("Error", e);
  }

  AdaptrexSession session = new AdaptrexSession();
  Object e = session.saveEntity(entity);
  session.close();
  return e;
    }
View Full Code Here

 
  public List<Map<String,Object>> getData() {
    /*
     * Get List of entities
     */
    AdaptrexSession session = new AdaptrexSession();
    List<Object> entityList = session.getEntityList(this);
   
    /*
     * Convert entities into ModelInstance objects
     */
    List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
    for (Object entity : entityList) {
      ModelInstance modelInstance = new ModelInstance(this.config, entity);
      data.add(modelInstance.getData());
    }
   
    session.close();
    return data;
  }
View Full Code Here

    }

    public static Store read(String entityName, RestOptions restOptions, String factoryName) {
  AdaptrexPersistence persistence =
    Adaptrex.getAdaptrex().getPersistenceManager().getPersistence(factoryName);
  AdaptrexSession session = new AdaptrexSession(persistence);
  Class<?> clazz = persistence.getEntityClass(entityName);
  DataConfig config = new DataConfig(clazz, persistence);
  config.applyRestOptions(restOptions);

  return new Store(session, config);
View Full Code Here


  /*
   * Create the model
   */
  AdaptrexSession session = new AdaptrexSession(persistence);
  Model model = new Model(session, config);

 
  /*
   * Set the model name
View Full Code Here


      /*
       * Create the store
       */
      AdaptrexSession session = new AdaptrexSession(persistence);
      Store store = new Store(session, config);


      /*
       * Set the model name
View Full Code Here

  public Model(AdaptrexSession adaptrexSession, DataConfig config) {
    this(adaptrexSession, config, null);
  }

  public Model(AdaptrexSession adaptrexSeession, DataConfig config, Integer id) {
    this.adaptrexSession = new AdaptrexSession(config.getAdaptrexPersistence());
    this.config = config;

    if (id != null) {
      this.entity = config.getAdaptrexPersistence().getEntity(adaptrexSession, config.getClazz(), id);
    } else {
View Full Code Here

    return read(entityName, id, restOptions, null);
  }

  public static Model read(String entityName, Integer id, RestOptions restOptions, String factoryName) {
    AdaptrexPersistence persistence = Adaptrex.getAdaptrex().getPersistenceManager().getPersistence(factoryName);
    AdaptrexSession session = new AdaptrexSession(persistence);
    Class<?> clazz = persistence.getEntityClass(entityName);
    DataConfig config = new DataConfig(clazz, persistence);
    if (restOptions != null) {
      config.applyRestOptions(restOptions);
    }
View Full Code Here

TOP

Related Classes of com.adaptrex.core.persistence.AdaptrexSession

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.