Exemplo n.º 1
0
 private void setup() {
   StringBuffer buf = new StringBuffer(100);
   buf.append("SELECT ");
   StringBuffer whereBuf = new StringBuffer(100);
   whereBuf.append(" WHERE");
   List primaryKeyList = new ArrayList();
   for (int i = 0; i < table.getColumnSize(); ++i) {
     DataColumn column = table.getColumn(i);
     buf.append(column.getColumnName());
     buf.append(", ");
     if (column.isPrimaryKey()) {
       whereBuf.append(" ");
       whereBuf.append(column.getColumnName());
       whereBuf.append(" = ? AND");
       primaryKeyList.add(column.getColumnName());
     }
   }
   buf.setLength(buf.length() - 2);
   whereBuf.setLength(whereBuf.length() - 4);
   buf.append(" FROM ");
   buf.append(table.getTableName());
   buf.append(whereBuf);
   sql = buf.toString();
   primaryKeys = (String[]) primaryKeyList.toArray(new String[primaryKeyList.size()]);
 }
Exemplo n.º 2
0
 public DataTable read() {
   DataTable newTable = new DataTableImpl(table.getTableName());
   for (int i = 0; i < table.getColumnSize(); ++i) {
     DataColumn column = table.getColumn(i);
     newTable.addColumn(column.getColumnName(), column.getColumnType());
   }
   for (int i = 0; i < table.getRowSize(); ++i) {
     DataRow row = table.getRow(i);
     DataRow newRow = newTable.addRow();
     reload(row, newRow);
   }
   return newTable;
 }
Exemplo n.º 3
0
  /**
   * {@link SqlReloadTableReader}を作成します。
   *
   * @param dataSource データソース
   * @param table テーブル
   */
  public SqlReloadTableReader(DataSource dataSource, DataTable table) {

    this.dataSource = dataSource;
    this.table = table;
    Connection con = DataSourceUtil.getConnection(dataSource);
    try {
      DatabaseMetaData dbMetaData = ConnectionUtil.getMetaData(con);
      table.setupMetaData(dbMetaData);
    } finally {
      ConnectionUtil.close(con);
    }
    setup();
  }
 /** @throws Exception */
 public void testHandle2() throws Exception {
   String sql = "select dept_no, d_name from dept3 where dept_no = ?";
   DataTable table = new DataTableImpl("dept3");
   table.addColumn("dept_no").setPrimaryKey(true);
   table.addColumn("d_name");
   DataRow row = table.addRow();
   row.setValue("dept_no", new BigDecimal(20));
   row.setValue("d_name", "RESEARCH");
   DataTable newTable = new DataTableImpl("dept3");
   newTable.addColumn("dept_no").setPrimaryKey(true);
   newTable.addColumn("d_name");
   DataRow newRow = newTable.addRow();
   SelectHandler handler =
       new BasicSelectHandler(ds_, sql, new DataRowReloadResultSetHandler(newRow));
   handler.execute(new Object[] {new Integer(20)});
   System.out.println(newRow);
   assertEquals(row, newRow);
 }
 /** @throws Exception */
 public void testHandle() throws Exception {
   String sql = "select empno, ename from emp where empno = ?";
   DataTable table = new DataTableImpl("emp");
   table.addColumn("empno").setPrimaryKey(true);
   table.addColumn("ename");
   DataRow row = table.addRow();
   row.setValue("empno", new BigDecimal(7788));
   row.setValue("ename", "SCOTT");
   DataTable newTable = new DataTableImpl("emp");
   newTable.addColumn("empno").setPrimaryKey(true);
   newTable.addColumn("ename");
   DataRow newRow = newTable.addRow();
   SelectHandler handler =
       new BasicSelectHandler(ds_, sql, new DataRowReloadResultSetHandler(newRow));
   handler.execute(new Object[] {new Integer(7788)});
   System.out.println(newRow);
   assertEquals("2", row, newRow);
 }