Exemplo n.º 1
0
 /**
  * 根据解析结果设置数据源与真实表名称
  *
  * @param sqlStruct
  * @param sqlInfo
  * @throws SQLException
  */
 private void parsePartition(SQLStruct sqlStruct, SQLInfo sqlInfo) throws SQLException {
   DALCustomInfo dalCustomInfo = DALCurrentStatus.getCustomInfo();
   DALFactory dalFactory = DALFactory.getDefault();
   ParsedTableInfo parsedTableInfo = new ParsedTableInfo();
   boolean hasParser = true;
   if (sqlStruct.isCanParse()) {
     if (dalCustomInfo == null) {
       ConnectionStatus connectionStatus = new ConnectionStatus();
       connectionStatus.setAutoCommit(this.dalConnection.getAutoCommit());
       connectionStatus.setReadOnly(this.dalConnection.isReadOnly());
       PartitionParser parser;
       PartitionTableInfo partitionTableInfo = null;
       for (String table : sqlStruct.getTableNames()) {
         parser = dalFactory.getPartitionParserFactory().getParser(table);
         if (parser == null) {
           hasParser = false;
         } else {
           // 存在解析器时,进行解析
           partitionTableInfo = parser.parse(table, sqlInfo, connectionStatus);
           if (partitionTableInfo == null) {
             throw new DALRunTimeException(
                 "partitionTableInfo return from "
                     + parser.getClass().getName()
                     + " can not be null : "
                     + table);
           }
           parsedTableInfo.setRealTable(table, partitionTableInfo.getRealTable());
         }
       }
       // 如果不需要解析路由,就设置默认数据源
       if (partitionTableInfo == null) {
         //					DALCurrentStatus.setDefaultDsKey();
       }
       // 设置解析后的数据源
       else {
         DALCurrentStatus.setDsKey(partitionTableInfo.getDsName());
       }
     }
     // 通过代码指定数据源与表名称,进行设定
     else {
       for (String table : sqlStruct.getTableNames()) {
         parsedTableInfo.setRealTable(table, dalCustomInfo.getRealTable(table));
       }
       DALCurrentStatus.setDsKey(dalCustomInfo.getDsKey());
     }
     // 在有进行解析的条件下,获得解析后指定表的sql语句
     if (hasParser) {
       this.sql = dalFactory.getSqlAnalyzer().outPutSQL(sql, sqlStruct, sqlInfo, parsedTableInfo);
     }
   } else {
     // 当不需要进行解析时,什么也不做,直接使用上一次使用的解析结果
   }
 }
Exemplo n.º 2
0
 private void initRealPreparedStatement() throws SQLException {
   Connection con = null;
   try {
     con = this.dalConnection.getCurrentConnection();
   } catch (DALRunTimeException e) {
     throw new DALRunTimeException(e.getMessage() + " for sql: " + this.sql);
   }
   switch (this.createMethodByCon) {
     case CREATE_METHOD_BY_CON_S:
       ps = con.prepareStatement(sql);
       break;
     case CREATE_METHOD_BY_CON_S_I:
       ps = con.prepareStatement(sql, autoGeneratedKeys);
       break;
     case CREATE_METHOD_BY_CON_S_$I:
       ps = con.prepareStatement(sql, columnIndexes);
       break;
     case CREATE_METHOD_BY_CON_S_$S:
       ps = con.prepareStatement(sql, columnNames);
       break;
     case CREATE_METHOD_BY_CON_S_I_I:
       ps = con.prepareStatement(sql, resultSetType, resultSetConcurrency);
       break;
     case CREATE_METHOD_BY_CON_S_I_I_I:
       ps = con.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
       break;
   }
   if (ps == null) {
     throw new DALRunTimeException(
         "can not create PreparedStatement for dsKey " + DALCurrentStatus.getDsKey());
   }
 }