Examples of DbConnection


Examples of org.jugile.util.DBConnection

    if (sql == null) sql = "where " + q2.toSql();
    sql = "select " + bo._getSelectFlds() +" from " + bo.table() + " " + sql;

    List<E> res = new ArrayList<E>();
    DBPool db = DBPool.getPool();
    DBConnection c = db.getConnection();
    try {
      c.prepare(sql);
      for (List<Object> row : c.select()) {
        long id = (Integer)row.get(0);
        E o = (E)bo.createOld(bo.getClass(), id);
        o._setState(null,bo.bi(),row);
        res.add(o);
      }
    } catch (Exception e) {
      log.error("dbread failed",e);
      try { c.rollback(); } catch (Exception e2) { fail(e2);}
    } finally {
      try { c.free(); } catch (Exception e) {}
    }
    return res;
  }
View Full Code Here

Examples of org.jugile.util.DBConnection

    }     
  }

  public static List<Msg> getMessages(String node, int max) {
    DBPool pool = DBPool.getPool();
    DBConnection c = pool.getConnection();
    List<Msg> msgs = new ArrayList<Msg>();
    try {
      String sql ="";
      sql += "select msg_id, nodeid, status, ts from dbmq_queue_t ";
      sql += "where nodeid=? AND status=? ORDER BY ts LIMIT ?";
      c.prepare(sql);
      c.param(node);
      c.param(NEW);
      c.param(max);
      List<Long> ids = new ArrayList<Long>();
      for (List row : c.select()) {
        long msg_id = (Integer)row.get(0);
        ids.add(msg_id);
      }
      if (ids.size() == 0) return msgs;
     
      // get messages
      sql = "select msg, nodeid, id_f, ts from dbmq_messages_t ";
      sql += "where id_f IN ("+qmarks(ids.size())+")";
      c.prepare(sql);
      for (Long id : ids) { c.param(id); }
      for (List<Object> row : c.select()) {
        String msg = (String)row.get(0);
        String nodeid = (String)row.get(1);
        long id = (Integer)row.get(2);
        Time ts = new Time((java.util.Date)row.get(3));
        Msg m = new Msg(msg);
        m.id = id;
        m.ts = ts;
        m.nodeid = nodeid;
        msgs.add(m);
      }
      c.rollback();
     
      // mark all status in progress     
      sql = "update dbmq_queue_t set status=? ";
      sql += "where nodeid=? AND status=? AND msg_id IN ("+qmarks(ids.size())+")";
      c.prepare(sql);
      c.param(INPROGRESS);
      c.param(node);
      c.param(NEW);
      for (Long id : ids) { c.param(id); }
      int count = c.execute();
      if (count != ids.size()) fail("inconsistent status write: " + count + "/"+ ids.size());
      c.commit();
      log.debug("read messages from :" + node + " size: " + count);
      return msgs;
    } catch (java.sql.SQLNonTransientConnectionException se) {
      log.info("connection error in read. retrying in 30 sec: " + node);
      // sleep 30 sec and retry
      try {
        Thread.sleep(30000);
      } catch (InterruptedException ie) {
        fail(ie);
      }
      log.info("retrying read now: " + node);
      return getMessages(node,max);
    } catch (Exception e) {
      try {
        c.rollback();
      } catch (Exception e2) {
        fail(e2);
      }
      fail(e);
    } finally {
      try {
        c.free();
      } catch (Exception e3) {
        //fail(e3);
      }
    }
    return msgs;
View Full Code Here

Examples of org.jugile.util.DBConnection

    return msgs;
  }
 
  public static int flush(String name) {
    DBPool pool = DBPool.getPool();
    DBConnection c = pool.getConnection();
    try {
      String sql = "delete from dbmq_queue_t where nodeid=?";
      c.prepare(sql);
      c.param(name);
      int res = c.execute();
      c.commit();
      return res;
    } catch (java.sql.SQLNonTransientConnectionException se) {
      fail("connection error in flush: " + name);
    } catch (Exception e) {
      try { c.rollback()} catch (Exception e2) { fail(e2);}
      fail(e);
    } finally {
      try { c.free(); } catch (Exception e3) { }
    }
    return 0;
  }
View Full Code Here

Examples of org.jugile.util.DBConnection

    return 0;
  }

  public static int flushNotNew(String name) {
    DBPool pool = DBPool.getPool();
    DBConnection c = pool.getConnection();
    try {
      String sql = "delete from dbmq_queue_t where nodeid=? and status!=0";
      c.prepare(sql);
      c.param(name);
      int res = c.execute();
      c.commit();
      return res;
    } catch (java.sql.SQLNonTransientConnectionException se) {
      fail("connection error in flush: " + name);
    } catch (Exception e) {
      try { c.rollback()} catch (Exception e2) { fail(e2);}
      fail(e);
    } finally {
      try { c.free(); } catch (Exception e3) { }
    }
    return 0;
  }
View Full Code Here

Examples of org.jugile.util.DBConnection

public class DBTest extends JugileTestCase {

  public static void clearDatabase() throws Exception {
    DBPool db = DBPool.getPool();
    DBConnection c = db.getConnection();
    c.updateN("delete from person_t");
    c.updateN("delete from family_t");
    c.updateN("delete from map_person_2friend_family");
    c.updateN("delete from dbmq_queue_t");
    c.updateN("delete from dbmq_messages_t");
    c.updateN("update idpool set nextid=100 where obj=\"global\"");
    HiLo.setNextid(1);
    c.commit()
  }
View Full Code Here

Examples of org.milowski.db.DBConnection

   }
  
   public void delete()
      throws SQLException
   {
      DBConnection connection = db.getConnection();
      try {
         connection.deleteById(AuthDB.DELETE_ROLE_PERMISSIONS_BY_PERMISSION, id);
         connection.deleteById(AuthDB.DELETE_PERMISSION, id);
         db.realmGroupCaches.clear();
         db.roleCache.clear();
         db.permissionCache.remove(id);
      } finally {
         db.release(connection);
View Full Code Here

Examples of org.milowski.db.DBConnection

   public void delete()
      throws SQLException
   {
      final DBCache<UUID,Group> groupCache = db.realmGroupCaches.get(this);
      final DBCache<UUID,RealmUser> userCache = db.realmUserCaches.get(this);
      DBConnection connection = db.getConnection();
      try {
         connection.query(AuthDB.GROUP_BY_REALM,new DBQueryHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
            }
            public void onResults(ResultSet set)
               throws SQLException
            {
               while (set.next()) {
                  Group group = groupCache.get(set.getInt(1));
                  group.delete();
               }
            }
         });
         connection.query(AuthDB.REALM_USER_BY_REALM,new DBQueryHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
            }
            public void onResults(ResultSet set)
               throws SQLException
            {
               while (set.next()) {
                  RealmUser user = userCache.get(set.getInt(1));
                  user.delete();
               }
            }
         });
         connection.deleteById(AuthDB.DELETE_AUTHENTICATED_BY_REALM, id);
         connection.deleteById(AuthDB.DELETE_REALM, id);
         db.realmCache.remove(id);
         db.realmUserCaches.remove(this);
         db.realmGroupCaches.remove(this);
      } finally {
         db.release(connection);
View Full Code Here

Examples of org.mule.module.db.internal.domain.connection.DbConnection

    }

    @Override
    public MuleEvent process(MuleEvent muleEvent) throws MuleException
    {
        DbConnection connection = null;

        DbConfig dbConfig = dbConfigResolver.resolve(muleEvent);

        try
        {
View Full Code Here

Examples of org.openbel.framework.core.df.DBConnection

     * @return a test {@link KamInfo}
     * @throws SQLException Thrown if a SQL error occurred accessing the KAM
     * catalog
     */
    public static KamInfo createKamInfo() throws SQLException {
        DBConnection dbc =
                new DBConnection(mockConn, DatabaseType.DERBY, "", "", "");
        KAMCatalogDao kcdao = new KAMCatalogDao(dbc, "foo", "bar");
        return kcdao.getKamInfoByName("test");
    }
View Full Code Here

Examples of org.palo.viewapi.DbConnection

  }
 
  protected void initDbConnection(ServletContext globalContext) {
    // HERE WE CREATE GLOBAL CONNECTIONs AND/OR GLOBAL CONNECTION POOLS
    try {
      DbConnection sqlConnection = (DbConnection) globalContext
          .getAttribute(SQL_CONNECTION);
      if (sqlConnection == null && ServiceProvider.getDbConnection() == null) {
        dbConnection = createConnection();
        ServiceProvider.initialize(dbConnection, true);
        initialised = true;
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.