Package de.mhus.lib.sql

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


   * @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

   * @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

   * @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

     
      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

      }
    }
  }
 
  private void query(IConfig config, LinkedList<CaoElement> list) throws Exception {
    DbConnection con = ((DbCaoConnection)getConnection()).getPool().getConnection();
    String staName = config.getExtracted("statement");
    DbStatement sta = null;
    if (staName != null) {
      sta = con.getStatement(staName);
    } else {
      sta = con.createStatement(config.getString("sql",null));
    }
   
    String tbl = config.getExtracted("table");
    DbMetadata m = ((DbApplication)getApplication()).getMetadata(tbl);
   
    DbResult res = sta.executeQuery(attributes);
    while (res.next()) {
      list.add(new DbData(this,m,res,config));
    }
    res.close();
    con.close();
  }
View Full Code Here

      }
     
    }
    private DbResult createResult() throws Exception {
      DbResult res = null;
      DbConnection con = ((DbCaoConnection)getConnection()).getPool().getConnection();
      DbStatement sth = con.createStatement(queryString);
      if (sth.execute(  ((DbApplication)getApplication()).getMapping() )) {
        res = sth.getResultSet();
      } else {
        res = new MutableResult();
        ((MutableResult)res).addColumnName("count");
View Full Code Here

TOP

Related Classes of de.mhus.lib.sql.DbConnection

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.