MCPcopy Create free account
hub / github.com/dbfit/dbfit / DbTable

Class DbTable

dbfit-java/core/src/main/java/dbfit/api/DbTable.java:14–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12import static dbfit.util.Direction.OUTPUT;
13
14public class DbTable implements DbObject {
15
16 private DBEnvironment dbEnvironment;
17 private String tableOrViewName;
18 private Map<String, DbParameterAccessor> columns;
19
20 public DbTable(DBEnvironment dbEnvironment, String tableName)
21 throws SQLException {
22 this.dbEnvironment = dbEnvironment;
23 this.tableOrViewName = tableName;
24 columns = dbEnvironment.getAllColumns(tableName);
25 if (columns.isEmpty()) {
26 throw new SQLException("Cannot retrieve list of columns for "
27 + tableName + " - check spelling and access rights");
28 }
29 }
30
31 public StatementExecution buildPreparedStatement(
32 DbParameterAccessor[] accessors) throws SQLException {
33 StatementExecution statement = dbEnvironment.createStatementExecution(dbEnvironment
34 .buildInsertPreparedStatement(tableOrViewName, accessors));
35
36 for (int i = 0; i < accessors.length; i++) {
37 accessors[i].bindTo(statement, i + 1);
38 }
39 return statement;
40 }
41
42 public DbParameterAccessor getDbParameterAccessor(String columnName,
43 Direction expectedDirection) {
44 String normalisedName = NameNormaliser.normaliseName(columnName);
45 DbParameterAccessor accessor = columns.get(normalisedName);
46 if (null == accessor) {
47 throw new RuntimeException(
48 "No such database column or parameter: '" + normalisedName + "'");
49 }
50
51 if (accessor.hasDirection(INPUT)
52 && expectedDirection == OUTPUT) {
53 accessor = dbEnvironment
54 .createAutogeneratedPrimaryKeyAccessor(accessor);
55 }
56 return accessor;
57 }
58
59}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected