Examples of DbConnection


Examples of de.mhus.lib.sql.DbConnection

   * @throws MException
   */
  public <T> DbCollection<T> executeQuery(DbConnection con, T clazz, String registryName, String query, Map<String,Object> attributes) throws MException {
    Map<String, Object> map = null;
   
    DbConnection myCon = null;
    if (con == null) {
      try {
        myCon = pool.getConnection();
      } catch (Throwable t) {
        throw new MException(con,query,attributes,t);
View Full Code Here

Examples of de.mhus.lib.sql.DbConnection

   * @return
   * @throws MException
   */
  public Object getObject(DbConnection con, String registryName, Object ... keys) throws MException {
   
    DbConnection myCon = null;
    if (con == null) {
      try {
        myCon = pool.getConnection();
        con = myCon;
      } catch (Throwable t) {
        throw new MException(t);
      }
    }
   
    Table c = cIndex.get(registryName);
    if (c == null)
      throw new MException("class definition not found in schema",registryName);
   
    try {
      Object out = c.getObject(con,keys);
     
      if (myCon != null) {
        try {
          myCon.commit();
        } catch (Throwable t) {
          throw new MException(t);
        }
        myCon.close();
      }
     
      return out;
    } catch (Throwable t) {
      throw new MException(registryName,t);
View Full Code Here

Examples of de.mhus.lib.sql.DbConnection

   * @param object The object to fill
   * @throws MException
   */
  public void reloadObject(DbConnection con, String registryName, Object object) throws MException {

    DbConnection myCon = null;
    if (con == null) {
      try {
        myCon = pool.getConnection();
        con = myCon;
      } catch (Throwable t) {
        throw new MException(t);
      }
    }
   
    if (registryName == null) {
      Class<?> clazz = schema.findClassForObject(object,this);
      if (clazz == null)
        throw new MException("class definition not found for object",object.getClass().getCanonicalName(),registryName);
      registryName = clazz.getCanonicalName();
    }

    Table c = cIndex.get(registryName);
    if (c == null)
      throw new MException("class definition not found in schema",registryName);

    LinkedList<Object> keys = new LinkedList<Object>();
    try {
      for (Field f : c.getPrimaryKeys()) {
        keys.add(f.getFromTarget(object));
      }
     
      if (c.fillObject(con,object,keys.toArray()) == null)
        throw new MException("object not found");
     
      schema.doPostLoad(c,object,con,this);
     
    } catch (Throwable t) {
      throw new MException(registryName,t);
    }
   
    if (myCon != null) {
      try {
        myCon.commit();
      } catch (Throwable t) {
        throw new MException(t);
      }
      myCon.close();
    }
  }
View Full Code Here

Examples of de.mhus.lib.sql.DbConnection

   * @return
   * @throws MException
   */
  public boolean objectChanged(DbConnection con, String registryName, Object object) throws MException {

    DbConnection myCon = null;
    if (con == null) {
      try {
        myCon = pool.getConnection();
        con = myCon;
      } catch (Throwable t) {
        throw new MException(t);
      }
    }
   
    if (registryName == null) {
      Class<?> clazz = schema.findClassForObject(object,this);
      if (clazz == null)
        throw new MException("class definition not found for object",object.getClass().getCanonicalName(),registryName);
      registryName = clazz.getCanonicalName();
    }

    Table c = cIndex.get(registryName);
    if (c == null)
      throw new MException("class definition not found in schema",registryName);

    boolean ret = false;
    LinkedList<Object> keys = new LinkedList<Object>();
    try {
      for (Field f : c.getPrimaryKeys()) {
        keys.add(f.getFromTarget(object));
      }
     
      ret = c.objectChanged(con,object,keys.toArray());
     
      // schema.doPostLoad(c,object,con,this);
     
    } catch (Throwable t) {
      throw new MException(registryName,t);
    }
   
    if (myCon != null) {
      try {
        myCon.commit();
      } catch (Throwable t) {
        throw new MException(t);
      }
      myCon.close();
    }
   
    return ret;
  }
View Full Code Here

Examples of de.mhus.lib.sql.DbConnection

   * @param keys The primary keys
   * @throws MException
   */
  public void fillObject(DbConnection con, String registryName, Object object, Object ... keys) throws MException {

    DbConnection myCon = null;
    if (con == null) {
      try {
        myCon = pool.getConnection();
        con = myCon;
      } catch (Throwable t) {
        throw new MException(t);
      }
    }
   
    if (registryName == null) {
      Class<?> clazz = schema.findClassForObject(object,this);
      if (clazz == null)
        throw new MException("class definition not found for object",object.getClass().getCanonicalName(),registryName);
      registryName = clazz.getCanonicalName();
    }

    Table c = cIndex.get(registryName);
    if (c == null)
      throw new MException("class definition not found in schema",registryName);
   
    try {
      c.fillObject(con,object,keys);
     
      schema.doPostLoad(c,object,con,this);
     
    } catch (Throwable t) {
      throw new MException(registryName,t);
    }
   
    if (myCon != null) {
      try {
        myCon.commit();
      } catch (Throwable t) {
        throw new MException(t);
      }
      myCon.close();
    }
   
  }
View Full Code Here

Examples of de.mhus.lib.sql.DbConnection

   * @param object The object to create.
   * @throws MException
   */
  public void createObject(DbConnection con, String registryName, Object object) throws MException {
   
    DbConnection myCon = null;
    if (con == null) {
      try {
        myCon = pool.getConnection();
        con = myCon;
      } catch (Throwable t) {
        throw new MException(t);
      }
    }
   
    if (registryName == null) {
      Class<?> clazz = schema.findClassForObject(object,this);
      if (clazz == null)
        throw new MException("class definition not found for object",object.getClass().getCanonicalName(),registryName);
      registryName = clazz.getCanonicalName();
    }
    Table c = cIndex.get(registryName);
    if (c == null)
      throw new MException("class definition not found in schema",registryName);
   
    try {
      // prepare object
      c.prepareCreate(object);
      schema.doPreCreate(c,object,con,this);
     
      //save object
   
      c.createObject(con,object);
     
      schema.doPostLoad(c,object,con,this);

    } catch (Throwable t) {
      throw new MException(registryName,t);
    }
   
    if (myCon != null) {
      try {
        myCon.commit();
      } catch (Throwable t) {
        throw new MException(t);
      }
      myCon.close();
    }
  }
View Full Code Here

Examples of de.mhus.lib.sql.DbConnection

   * @param object The object to save
   * @throws MException
   */
  public void saveObject(DbConnection con, String registryName, Object object) throws MException {
   
    DbConnection myCon = null;
    if (con == null) {
      try {
        myCon = pool.getConnection();
        con = myCon;
      } catch (Throwable t) {
        throw new MException(t);
      }
    }
   
    if (registryName==null) {
      Class<?> clazz = schema.findClassForObject(object,this);
      if (clazz == null)
        throw new MException("class definition not found for object",object.getClass().getCanonicalName());
      registryName = clazz.getCanonicalName();
    }
    Table c = cIndex.get(registryName);
    if (c == null)
      throw new MException("class definition not found in schema",registryName);
   
    try {
      // prepare object
      schema.doPreSave(c,object,con,this);
     
      //save object
      c.saveObject(con,object);
    } catch (Throwable t) {
      throw new MException(registryName,t);
    }
   
    if (myCon != null) {
      try {
        myCon.commit();
      } catch (Throwable t) {
        throw new MException(t);
      }
      myCon.close();
    }
  }
View Full Code Here

Examples of de.mhus.lib.sql.DbConnection

   * @param object The object to remove from database
   * @throws MException
   */
  public void removeObject(DbConnection con, String registryName, Object object) throws MException {

    DbConnection myCon = null;
    if (con == null) {
      try {
        myCon = pool.getConnection();
        con = myCon;
      } catch (Throwable t) {
        throw new MException(t);
      }
    }
   
    if (registryName == null) {
      Class<?> clazz = schema.findClassForObject(object,this);
      if (clazz == null)
        throw new MException("class definition not found for object",object.getClass().getCanonicalName());
      registryName = clazz.getCanonicalName();
    }
    Table c = cIndex.get(registryName);
    if (c == null)
      throw new MException("class definition not found in schema",registryName);
   
    try {
      // prepare object
      schema.doPreRemove(c,object,con,this);
     
      //save object
      c.removeObject(con,object);
     
      schema.doPostRemove(c,object,con,this);

    } catch (Throwable t) {
      throw new MException(registryName,t);
    }
   
    if (myCon != null) {
      try {
        myCon.commit();
      } catch (Throwable t) {
        throw new MException(t);
      }
      myCon.close();
    }
   
  }
View Full Code Here

Examples of de.mhus.lib.sql.DbConnection

   * @throws Exception
   */
  protected void initDatabase() throws Exception {
       
    Class<?>[] types = schema.getObjectTypes();
    DbConnection con = pool.getConnection();
    cIndex.clear();
    nameMapping = new HashMap<String, Object>();
    nameMappingRO = Collections.unmodifiableMap(nameMapping);
      caoBundle = new MetadataBundle(NoneDriver.getInstance());

    // schema info
    if (schema.hasPersistentInfo()) {
      addClass(schema.getSchemaName(),schema.getClass().getCanonicalName(),Property.class,con);
      schemaPersistence = new DbProperties(this, schema.getClass().getCanonicalName());
    }
   
    // classes
    for (Class<?> clazz : types) {
      addClass(null,clazz.getCanonicalName(),clazz,con);
    }
    con.commit();
   
    // fill name mapping
    for (Table c : cIndex.values()) {
      c.fillNameMapping(nameMapping);
    }
View Full Code Here

Examples of de.mhus.lib.sql.DbConnection

     
      System.out.println("----------------------");
     
      // test a native sql execute - remove all persons
     
      DbConnection con = manager.getPool().getConnection();
      con.createStatement("DELETE FROM $db.Person$", null ).execute(manager.getNameMapping());
      con.commit();
     
      System.out.println("----------------------");
      col = manager.executeQuery(new Person(), "select * from $db.Person$"null);
      count = 0;
      for (Person pp : col) {
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.