PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/db-diff/src/main/java/com/googlecode/hdbc/dbdiff/db/QueryTableColumns.java

http://hdbc.googlecode.com/
Java | 46 lines | 38 code | 8 blank | 0 comment | 1 complexity | 1467d2a17cbf884e06ab329c5418fdb1 MD5 | raw file
 1package com.googlecode.hdbc.dbdiff.db;
 2
 3import java.math.BigDecimal;
 4import java.sql.PreparedStatement;
 5import java.sql.ResultSet;
 6import java.sql.SQLException;
 7
 8import com.googlecode.hdbc.dbdiff.model.ColumnDefinition;
 9import com.googlecode.hdbc.dbdiff.model.TabularObjects;
10
11public class QueryTableColumns implements IQueryDefinition<ColumnDefinition> {
12    private final String tableName;
13    private final TabularObjects result;
14    private static final String SQL = "SELECT column_name, data_type, data_length, data_precision, data_scale, nullable " +
15        "FROM user_tab_columns " +
16        "WHERE table_name = ? ";
17
18    public QueryTableColumns(final String owningDb, final String table) {
19        tableName = table;
20        result = new TabularObjects(owningDb);
21    }
22
23    public final String getParameterizedSQL() {
24        return SQL;
25    }
26
27    public final void processStatement(final PreparedStatement stmt) throws SQLException {
28        stmt.setString(Parameter.ONE.index(), tableName);
29        ResultSet rs = stmt.executeQuery();
30        while (rs.next()) {
31            String columnName = rs.getString("column_name");
32            String dataType = rs.getString("data_type");
33            int dataLength = rs.getInt("data_length");
34            BigDecimal dataPrecision = rs.getBigDecimal("data_precision");
35            BigDecimal dataScale = rs.getBigDecimal("data_scale");
36            String nullable = rs.getString("nullable");
37            result.add(new ColumnDefinition(columnName, dataType, dataLength,
38                    dataPrecision, dataScale, nullable));
39        }
40    }
41
42    public final TabularObjects result() {
43        return result;
44    }
45
46}