use of org.datanucleus.store.rdbms.SQLController in project datanucleus-rdbms by datanucleus.
the class SchemaTable method getAllClasses.
/**
* Accessor for the classes already supported by this Schema Table.
* @param conn Connection for this datastore.
* @return The HashSet of class names (StoreData)
* @throws SQLException Thrown when an error occurs in the process.
*/
public HashSet getAllClasses(ManagedConnection conn) throws SQLException {
HashSet schema_data = new HashSet();
if (storeMgr.getDdlWriter() != null && !tableExists((Connection) conn.getConnection())) {
// do not query non-existing schema table when DDL is only written to file
return schema_data;
}
SQLController sqlControl = storeMgr.getSQLController();
PreparedStatement ps = sqlControl.getStatementForQuery(conn, fetchAllStmt);
try {
ResultSet rs = sqlControl.executeStatementQuery(null, conn, fetchAllStmt, ps);
try {
while (rs.next()) {
StoreData data = new RDBMSStoreData(rs.getString(1), rs.getString(2), rs.getString(4).equals("1") ? true : false, rs.getString(3).equals("FCO") ? StoreData.Type.FCO : StoreData.Type.SCO, rs.getString(6));
schema_data.add(data);
}
} finally {
rs.close();
}
} finally {
sqlControl.closeStatement(conn, ps);
}
return schema_data;
}
use of org.datanucleus.store.rdbms.SQLController in project datanucleus-rdbms by datanucleus.
the class SchemaTable method addClass.
/**
* Method to insert a row in the SchemaTable. This is called when DataNucleus is
* now supporting a new class (and hence DB table).
* @param data Data for the class
* @param conn Connection to the datastore
* @throws SQLException Thrown when an error occurs inserting the schema.
*/
public void addClass(RDBMSStoreData data, ManagedConnection conn) throws SQLException {
if (storeMgr.getDdlWriter() != null) {
// No interest in actually adding the class to the table
return;
}
if (hasClass(data, conn)) {
// Data already exists, so remove the chance of a duplicate insert
return;
}
SQLController sqlControl = storeMgr.getSQLController();
PreparedStatement ps = sqlControl.getStatementForUpdate(conn, insertStmt, false);
try {
int jdbc_id = 1;
classMapping.setString(null, ps, MappingHelper.getMappingIndices(jdbc_id, classMapping), data.getName());
jdbc_id += classMapping.getNumberOfDatastoreMappings();
tableMapping.setString(null, ps, MappingHelper.getMappingIndices(jdbc_id, tableMapping), data.hasTable() ? data.getTableName() : "");
jdbc_id += tableMapping.getNumberOfDatastoreMappings();
typeMapping.setString(null, ps, MappingHelper.getMappingIndices(jdbc_id, typeMapping), data.isFCO() ? "FCO" : "SCO");
jdbc_id += typeMapping.getNumberOfDatastoreMappings();
ownerMapping.setString(null, ps, MappingHelper.getMappingIndices(jdbc_id, ownerMapping), data.isTableOwner() ? "1" : "0");
jdbc_id += ownerMapping.getNumberOfDatastoreMappings();
// TODO Sort out version
versionMapping.setString(null, ps, MappingHelper.getMappingIndices(jdbc_id, versionMapping), "DataNucleus");
jdbc_id += versionMapping.getNumberOfDatastoreMappings();
interfaceNameMapping.setString(null, ps, MappingHelper.getMappingIndices(jdbc_id, interfaceNameMapping), data.getInterfaceName());
jdbc_id += interfaceNameMapping.getNumberOfDatastoreMappings();
sqlControl.executeStatementUpdate(null, conn, insertStmt, ps, true);
// TODO : handle any warning messages
} finally {
sqlControl.closeStatement(conn, ps);
}
}
use of org.datanucleus.store.rdbms.SQLController in project datanucleus-rdbms by datanucleus.
the class SchemaTable method hasClass.
/**
* Method to verify the a class is already stored in the table.
* @param data Data for the class
* @param conn Connection to the datastore
* @return if the SchemaTable already has the class
* @throws SQLException Thrown when an error occurs inserting the schema.
*/
private boolean hasClass(StoreData data, ManagedConnection conn) throws SQLException {
if (!tableExists((Connection) conn.getConnection())) {
return false;
}
SQLController sqlControl = storeMgr.getSQLController();
PreparedStatement ps = sqlControl.getStatementForQuery(conn, fetchStmt);
try {
int jdbc_id = 1;
tableMapping.setString(null, ps, MappingHelper.getMappingIndices(jdbc_id, tableMapping), data.getName());
ResultSet rs = sqlControl.executeStatementQuery(null, conn, fetchStmt, ps);
try {
if (rs.next()) {
return true;
}
} finally {
rs.close();
}
} finally {
sqlControl.closeStatement(conn, ps);
}
return false;
}
Aggregations