Package org.fto.jthink.jdbc

Examples of org.fto.jthink.jdbc.SQLExecutor


 
  /**
   * 创建MssqlSQLExecutor的实例,以SQLExecutor类型返回
   */
  public SQLExecutor create() {
    SQLExecutor executor = new MssqlSQLExecutor(transaction, connId);
//    if(mker!=null){
//      executor.setResultMaker(mker);
//    }
    return executor;
  }
View Full Code Here


    logger.info("向数据库表中插入数据。");
    String connId = "SampleDataSource";
    //JDBCTransaction transaction = (JDBCTransaction)resManager.getResource(JDBCTransaction.class.getName());
    JDBCTransaction transaction = (JDBCTransaction)((TransactionFactory)resManager.getResource("SampleTransaction")).create();
    /* 返回SQLExecutor工厂,并创建SQLExecutor对象 */
    SQLExecutor sqlExecutor = transaction.getSQLExecutorFactory(connId).create();
    /* 返回SQLBuilder工厂,并创建SQLBuilder对象 */
    SQLBuilder sqlBuilder = transaction.getSQLBuilderFactory(connId).create("");

    try{
      /* 开始事务 */
      transaction.begin();
      //transaction.setAutoCommit(connId, true);
     
      System.out.println("transaction.getAutoCommit(connId):"+transaction.getAutoCommit(connId));
     
      //transaction.setTransactionLevel(connId, level);
     
//      SQL sql = sqlBuilder.constructSQLForInsert("Messages", messagesHM);
//      if(logger.isDebugEnabled()){
//        logger.debug("通过SQLBuilder构建的SQL: " + sql.getSQLString()+"     "+messagesHM);
//      }
      String[] sqls = new String[messagesMaps.length];
      for(int i=0;i<messagesMaps.length;i++){
        String sqlstr =
        "INSERT INTO Messages (Sender,Email,Subject,Contact,IP,SendTime,ID,Content) " +
        "VALUES ('"+messagesMaps[i].get("Sender")+
        "','"+messagesMaps[i].get("Email")+
        "','"+messagesMaps[i].get("Subject")+
        "','"+messagesMaps[i].get("Contact")+
        "','"+messagesMaps[i].get("IP")+
        "','"+DateTimeHelper.formatDateTimetoString(DateTimeHelper.getSystemDate())+
        "','"+(generateID(sqlExecutor).intValue()+i)+
        "','"+messagesMaps[i].get("Content")+"')";
        sqls[i]=sqlstr;
        if(logger.isDebugEnabled()){
          logger.debug("通过SQLBuilder构建的SQL: " + sqlstr+"     ");
        }
      }
      /* 执行SQ语句 */
      int[] rs = sqlExecutor.executeBatch(sqls);
      System.out.println(rs[0]+","+rs[1]);
      /* 提交事务 */
      transaction.commit();
    }catch(Exception e){
      /* 回退事务 */
 
View Full Code Here

   
    //JDBCTransaction transaction = (JDBCTransaction)resManager.getResource(JDBCTransaction.class.getName());
    JDBCTransaction transaction = (JDBCTransaction)((TransactionFactory)resManager.getResource("SampleTransaction")).create();
   
    /* 返回SQLExecutor工厂,并创建SQLExecutor对象 */
    SQLExecutor sqlExecutor = transaction.getSQLExecutorFactory("SampleDataSource").create();
    //sqlExecutor.setTimeout(60);
//    PreparedStatement ps = sqlExecutor.getConnection().prepareStatement("select 1");
//    logger.debug("timeout:"+ps.getQueryTimeout());
//    ps.close();
//    logger.debug("timeout:"+sqlExecutor.getTimeout());
    /* 返回SQLBuilder工厂,并创建SQLBuilder对象 */
    SQLBuilder sqlBuilder = transaction.getSQLBuilderFactory("SampleDataSource").create("");
   
    try{
      /* 开始事务 */
      transaction.begin();
     
      //logger.debug("getTransactionLevel():"+transaction.getTransactionLevel("SampleDataSource"));
     
      messagesHM.put("ID", generateID(sqlExecutor));
      messagesHM.put("SendTime", DateTimeHelper.formatDateTimetoString(DateTimeHelper.getSystemDate()));
     
      SQL sql = sqlBuilder.constructSQLForInsert("Messages", messagesHM);
      if(logger.isDebugEnabled()){
        logger.debug("通过SQLBuilder构建的SQL: " + sql.getSQLString()+"     "+messagesHM);
      }
      /* 执行SQ语句 */
      sqlExecutor.execute(sql);
     
      /* 提交事务 */
      transaction.commit();
    }catch(Exception e){
      /* 回退事务 */
 
View Full Code Here

    logger.info("修改数据。");
   
    //JDBCTransaction transaction = (JDBCTransaction)resManager.getResource(JDBCTransaction.class.getName());
    JDBCTransaction transaction = (JDBCTransaction)((TransactionFactory)resManager.getResource("SampleTransaction")).create();
    /* 返回SQLExecutor工厂,并创建SQLExecutor对象 */
    SQLExecutor sqlExecutor = transaction.getSQLExecutorFactory("SampleDataSource").create();
    /* 返回SQLBuilder工厂,并创建SQLBuilder对象 */
    SQLBuilder sqlBuilder = transaction.getSQLBuilderFactory("SampleDataSource").create("");
   
    try{
      /* 开始事务 */
      transaction.begin();

      Condition condi = new Condition();
      condi.add(new ConditionItem("ID","=",id));
     
      SQL sql = sqlBuilder.constructSQLForUpdate("Messages", messagesHM, condi);
      if(logger.isDebugEnabled()){
        logger.debug("通过SQLBuilder构建的SQL: " + sql.getSQLString()+"     "+messagesHM);
      }
      /* 执行SQ语句 */
      Object rs = sqlExecutor.execute(sql);
     
      System.out.println("update rows="+rs);
     
      /* 提交事务 */
      transaction.commit();
View Full Code Here

    logger.info("修改数据。");
   
    //JDBCTransaction transaction = (JDBCTransaction)resManager.getResource(JDBCTransaction.class.getName());
    JDBCTransaction transaction = (JDBCTransaction)((TransactionFactory)resManager.getResource("SampleTransaction")).create();
    /* 返回SQLExecutor工厂,并创建SQLExecutor对象 */
    SQLExecutor sqlExecutor = transaction.getSQLExecutorFactory("SampleDataSource").create();
    /* 返回SQLBuilder工厂,并创建SQLBuilder对象 */
    SQLBuilder sqlBuilder = transaction.getSQLBuilderFactory("SampleDataSource").create("");
   
    try{
      /* 开始事务 */
      transaction.begin();

      Condition condi = new Condition();
      condi.add(new ConditionItem("ID","=",id));
     
      SQL sql = sqlBuilder.constructSQLForDelete("Messages", condi);
      if(logger.isDebugEnabled()){
        logger.debug("通过SQLBuilder构建的SQL: " + sql.getSQLString()+"     ");
      }
      /* 执行SQ语句 */
      Object rs = sqlExecutor.execute(sql);
     
      System.out.println("delete rows="+rs);
     
      /* 提交事务 */
      transaction.commit();
View Full Code Here

    logger.info("统计数量。");
   
    //JDBCTransaction transaction = (JDBCTransaction)resManager.getResource(JDBCTransaction.class.getName());
    JDBCTransaction transaction = (JDBCTransaction)((TransactionFactory)resManager.getResource("SampleTransaction")).create();
    /* 返回SQLExecutor工厂,并创建SQLExecutor对象 */
    SQLExecutor sqlExecutor = transaction.getSQLExecutorFactory("SampleDataSource").create();
    //sqlExecutor.setPoolable(true);
    //sqlExecutor.setResultMaker(new MapResultMaker());
    SQLBuilder sqlBuilder = transaction.getSQLBuilderFactory("SampleDataSource").create("");
    try{
      /* 开始事务 */
      transaction.begin();
      /* 直接执行SQL查询语句 */
      return (List)sqlExecutor.execute(sqlBuilder.constructSQLForCount("messages", "*", "MsgCount", null));
     
    }finally{
      /* 关闭事务 */
      transaction.close();
    }
View Full Code Here

    logger.info("返回数据库表中所有的数据。");
   
    //JDBCTransaction transaction = (JDBCTransaction)resManager.getResource(JDBCTransaction.class.getName());
    JDBCTransaction transaction = (JDBCTransaction)((TransactionFactory)resManager.getResource("SampleTransaction")).create();
    /* 返回SQLExecutor工厂,并创建SQLExecutor对象 */
    SQLExecutor sqlExecutor = transaction.getSQLExecutorFactory("SampleDataSource").create();
    //sqlExecutor.setPoolable(true);
    //sqlExecutor.setResultMaker(new MapResultMaker());
   
    try{
      /* 开始事务 */
      transaction.begin();
      /* 直接执行SQL查询语句 */
      return (List)sqlExecutor.executeQuery("select * from messages");
     
    }finally{
      /* 关闭事务 */
      transaction.close();
    }
View Full Code Here

    logger.info("返回数据库表中与ID匹配的数据。");
   
    //JDBCTransaction transaction = (JDBCTransaction)resManager.getResource(JDBCTransaction.class.getName());
    JDBCTransaction transaction = (JDBCTransaction)((TransactionFactory)resManager.getResource("SampleTransaction")).create();
    /* 返回SQLExecutor工厂,并创建SQLExecutor对象 */
    SQLExecutor sqlExecutor = transaction.getSQLExecutorFactory("SampleDataSource").create();
   
    /* 返回SQLBuilder工厂,并创建SQLBuilder对象 */
    SQLBuilder sqlBuilder = transaction.getSQLBuilderFactory("SampleDataSource").create("");
   
    //sqlExecutor.setResultMaker(new MapResultMaker());
   
    try{
      /* 开始事务 */
      transaction.begin();
     
//      /* 构建查询条件 */
//      Condition condition = new Condition();
//      condition.add(new ConditionItem("Id","=",id));
     
      /* 通过SQLBuilder来构建SQL语句 */
      SQL sql = sqlBuilder.constructSQLForSelect("Messages",false,new Column[]{new Column("SUBJECT"),new Column("SENDER")},condition,null,null,3,2);
      //SQL sql = sqlBuilder.constructSQLForSelect("Messages",true,null,condition,null,null);
     
      logger.debug("通过SQLBuilder构建的SQL: " + sql.getSQLString());
     
      return (List)sqlExecutor.execute(sql);
     
    }finally{
      /* 关闭事务 */
      transaction.close();
    }
View Full Code Here

 
  /**
   * 创建并返回SQLExecutor类型的实例
   */
  public SQLExecutor create() {
    SQLExecutor executor = new SQLExecutor(transaction, connId);
//    if(mker!=null){
//      executor.setResultMaker(mker);
//    }
    return executor;
  }
View Full Code Here

 
  /**
   * 创建MysqlSQLExecutor的实例,以SQLExecutor类型返回
   */
  public SQLExecutor create() {
    SQLExecutor executor = new MysqlSQLExecutor(transaction, connId);
//    if(mker!=null){
//      executor.setResultMaker(mker);
//    }
    return executor;
  }
View Full Code Here

TOP

Related Classes of org.fto.jthink.jdbc.SQLExecutor

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.