PageRenderTime 16ms CodeModel.GetById 6ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://hdbc.googlecode.com/
Java | 51 lines | 43 code | 8 blank | 0 comment | 0 complexity | 03eadb083b131b714185b79a4850454d MD5 | raw file
 1package com.googlecode.hdbc.dbdiff.db;
 2
 3import java.sql.SQLException;
 4import javax.sql.DataSource;
 5
 6import com.googlecode.hdbc.dbdiff.model.ColumnDefinition;
 7import com.googlecode.hdbc.dbdiff.model.ScriptedObjects;
 8import com.googlecode.hdbc.dbdiff.model.TabularObjects;
 9import com.googlecode.hdbc.dbdiff.model.UserObjectDefinition;
10import com.googlecode.hdbc.dbdiff.model.UserObjects;
11
12public class Database implements IDatabase {
13    private final DataSource dataSource;
14    private final String databaseName;
15
16    public Database(final String dbName, final DataSource ds) {
17        databaseName = dbName;
18        dataSource = ds;
19    }
20
21    public final TabularObjects selectTabularObject(final String tableName) {
22        try {
23            QueryExecutionTemplate<ColumnDefinition> template = new QueryExecutionTemplate<ColumnDefinition>();
24            QueryTableColumns query = new QueryTableColumns(databaseName, tableName);
25            return (TabularObjects) template.executeQuery(query, dataSource);
26        } catch (SQLException e) {
27            throw new IllegalStateException(e);
28        }
29    }
30
31    public final UserObjects selectUserObjects() {
32        try {
33            QueryExecutionTemplate<UserObjectDefinition> template = new QueryExecutionTemplate<UserObjectDefinition>();
34            QueryUserObjects query = new QueryUserObjects(databaseName);
35            return (UserObjects) template.executeQuery(query, dataSource);
36        } catch (SQLException e) {
37            throw new IllegalStateException(e);
38        }
39    }
40
41    public final ScriptedObjects selectScriptedObject(final String scriptObjName) {
42        try {
43            QueryExecutionTemplate<String> template = new QueryExecutionTemplate<String>();
44            QueryScriptLines query = new QueryScriptLines(databaseName, scriptObjName);
45            return (ScriptedObjects) template.executeQuery(query, dataSource);
46        } catch (SQLException e) {
47            throw new IllegalStateException(e);
48        }
49    }
50
51}