use of org.verdictdb.connection.DbmsConnection in project traindb by traindb-project.
the class TrainDBQueryEngine method loadSynopsisIntoTable.
private void loadSynopsisIntoTable(DbmsConnection dbmsConn, String synopsisName, MModelInstance mModelInstance, String synopsisFile) throws Exception {
Connection origConn = null;
if (dbmsConn instanceof CachedDbmsConnection) {
loadSynopsisIntoTable(((CachedDbmsConnection) dbmsConn).getOriginalConnection(), synopsisName, mModelInstance, synopsisFile);
return;
} else if (dbmsConn instanceof JdbcConnection) {
origConn = ((JdbcConnection) dbmsConn).getConnection();
} else {
throw new TrainDBException("cannot load synopsis data into table");
}
StringBuilder sb = new StringBuilder();
sb.append("INSERT INTO ");
sb.append(mModelInstance.getSchemaName());
sb.append(".");
sb.append(synopsisName);
sb.append(" VALUES (");
for (String columnName : mModelInstance.getColumnNames()) {
sb.append("?,");
}
sb.deleteCharAt(sb.lastIndexOf(","));
sb.append(")");
CSVReader csvReader = new CSVReaderBuilder(new FileReader(synopsisFile)).withSkipLines(1).build();
String sql = sb.toString();
PreparedStatement pstmt = origConn.prepareStatement(sql);
int collen = mModelInstance.getColumnNames().size();
String[] row;
try {
while ((row = csvReader.readNext()) != null) {
for (int i = 1; i <= collen; i++) {
pstmt.setObject(i, row[i - 1]);
}
pstmt.addBatch();
}
pstmt.executeBatch();
} catch (Exception e) {
throw e;
} finally {
if (pstmt != null) {
pstmt.close();
}
}
}
use of org.verdictdb.connection.DbmsConnection in project traindb by traindb-project.
the class TrainDBConnection method getDatabaseMetaData.
private java.sql.DatabaseMetaData getDatabaseMetaData() throws SQLException {
DbmsConnection conn = vc.getConnection();
java.sql.DatabaseMetaData metaData = getDatabaseMetaDataFromConnection(conn);
if (metaData == null) {
throw new SQLException("Unexpected underlying connection: " + conn);
} else {
return metaData;
}
}
Aggregations