use of cbit.sql.Table in project vcell by virtualcell.
the class GeomDbDriver method getVCImage.
/**
* getModel method comment.
*/
private VCImage getVCImage(QueryHashtable dbc, Connection con, User user, KeyValue imageKey, boolean bCheckPermission) throws SQLException, DataAccessException, ObjectNotFoundException {
// log.print("GeomDbDriver.getImage(user="+user+", id="+imageKey+")");
String sql;
Field[] f = { new StarField(imageTable), userTable.userid, imageDataTable.data, new StarField(extentTable) };
Table[] t = { imageTable, userTable, imageDataTable, extentTable };
String condition = imageTable.id.getQualifiedColName() + " = " + imageKey + " AND " + imageTable.ownerRef.getQualifiedColName() + " = " + userTable.id.getQualifiedColName() + " AND " + imageTable.id.getQualifiedColName() + " = " + imageDataTable.imageRef.getQualifiedColName() + " AND " + imageTable.extentRef.getQualifiedColName() + " = " + extentTable.id.getQualifiedColName();
sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax, bCheckPermission);
// System.out.println(sql);
// Connection con = conFact.getConnection();
VCImage vcImage = null;
Statement stmt = con.createStatement();
try {
ResultSet rset = stmt.executeQuery(sql);
if (rset.next()) {
vcImage = imageTable.getImage(rset, con, imageDataTable, dbSyntax);
getImageRegionsForVCImage(dbc, con, vcImage);
} else {
throw new ObjectNotFoundException("Image id=" + imageKey + " not found for user '" + user + "'");
}
} finally {
// Release resources include resultset
stmt.close();
}
return vcImage;
}
use of cbit.sql.Table in project vcell by virtualcell.
the class SimulationContextDbDriver method getSimulationContextSQL.
/**
* getModel method comment.
*/
private SimulationContext getSimulationContextSQL(QueryHashtable dbc, Connection con, User user, KeyValue simContextKey) throws /*, ReactStepDbDriver reactStepDB*/
SQLException, DataAccessException, IllegalMappingException, PropertyVetoException {
SimulationContext simContext = null;
String sql;
Field[] f = { new cbit.sql.StarField(simContextTable), userTable.userid };
Table[] t = { simContextTable, userTable };
String condition = simContextTable.id.getQualifiedColName() + " = " + simContextKey + " AND " + simContextTable.ownerRef.getQualifiedColName() + " = " + userTable.id.getQualifiedColName();
sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax);
// System.out.println(sql);
Statement stmt = con.createStatement();
try {
ResultSet rset = stmt.executeQuery(sql);
if (rset.next()) {
simContext = simContextTable.getSimContext(dbc, con, user, rset, geomDB, modelDB, mathDescDB);
} else {
throw new ObjectNotFoundException("SimulationContext id=" + simContextKey + " not found for user '" + user + "'");
}
} finally {
stmt.close();
}
DataSymbolTable.table.populateDataSymbols(con, simContextKey, simContext.getDataContext(), user, simContext.getModel().getUnitSystem());
ArrayList<AnnotatedFunction> outputFunctionList = ApplicationMathTable.table.getOutputFunctionsSimcontext(con, simContextKey, dbSyntax);
if (outputFunctionList != null) {
OutputFunctionContext outputFnContext = simContext.getOutputFunctionContext();
outputFnContext.setOutputFunctions(outputFunctionList);
}
SimContextTable.table.readAppComponents(con, simContext, dbSyntax);
assignStimuliSQL(con, simContextKey, simContext);
assignStructureMappingsSQL(dbc, con, simContextKey, simContext);
assignSpeciesContextSpecsSQL(con, simContextKey, simContext);
assignReactionSpecsSQL(con, simContextKey, simContext);
for (GeometryClass gc : simContext.getGeometry().getGeometryClasses()) {
try {
StructureSizeSolver.updateUnitStructureSizes(simContext, gc);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
simContext.getGeometryContext().enforceHierarchicalBoundaryConditions(simContext.getModel().getStructureTopology());
simContext.getModel().refreshDependencies();
assignAnalysisTasksSQL(con, simContextKey, simContext);
// really needed to calculate MembraneMapping parameters that are not stored (inside/outside flux correction factors).
simContext.refreshDependencies();
return simContext;
}
use of cbit.sql.Table in project vcell by virtualcell.
the class BioModelDbDriver method getBioModelMetaDatas.
/**
* getModel method comment.
*/
BioModelMetaData[] getBioModelMetaDatas(Connection con, User user, boolean bAll, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException, ObjectNotFoundException {
if (user == null) {
throw new IllegalArgumentException("Improper parameters for getBioModelMetaDatas");
}
if (lg.isTraceEnabled())
lg.trace("BioModelDbDriver.getBioModelMetaDatas(user=" + user + ", bAll=" + bAll + ")");
//
// to construct a BioModelMetaData as an immutable object, lets collect all keys first
// (even before authentication). If the user doesn't authenticate, then throw away the
// child keys (from link tables).
//
//
// get BioModelMetaData object for bioModelKey
//
String sql;
Field[] f = { new cbit.sql.StarField(bioModelTable), userTable.userid };
Table[] t = { bioModelTable, userTable };
String condition = userTable.id.getQualifiedColName() + " = " + bioModelTable.ownerRef.getQualifiedColName();
if (!bAll) {
condition += " AND " + userTable.id.getQualifiedColName() + " = " + user.getID();
}
sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax);
//
StringBuffer newSQL = new StringBuffer(sql);
newSQL.insert(7, Table.SQL_GLOBAL_HINT);
sql = newSQL.toString();
//
Statement stmt = con.createStatement();
Vector<BioModelMetaData> bioModelMetaDataList = new Vector<BioModelMetaData>();
try {
ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
BioModelMetaData bioModelMetaData = bioModelTable.getBioModelMetaData(rset, this, con, dbSyntax);
bioModelMetaDataList.addElement(bioModelMetaData);
}
} finally {
// Release resources include resultset
stmt.close();
}
BioModelMetaData[] bioModelMetaDataArray = new BioModelMetaData[bioModelMetaDataList.size()];
bioModelMetaDataList.copyInto(bioModelMetaDataArray);
return bioModelMetaDataArray;
}
use of cbit.sql.Table in project vcell by virtualcell.
the class BioModelDbDriver method getBioModelMetaData.
/**
* getModel method comment.
*/
private BioModelMetaData getBioModelMetaData(Connection con, User user, KeyValue bioModelKey, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException, ObjectNotFoundException {
if (user == null || bioModelKey == null) {
throw new IllegalArgumentException("Improper parameters for getBioModelMetaData");
}
// if (lg.isTraceEnabled()) lg.trace("BioModelDbDriver.getBioModelMetaData(user=" + user + ", id=" + bioModelKey + ")");
//
// to construct a BioModelMetaData as an immutable object, lets collect all keys first
// (even before authentication). If the user doesn't authenticate, then throw away the
// child keys (from link tables).
//
//
// get Simulation Keys for bioModelKey
//
KeyValue[] simKeys = getSimulationEntriesFromBioModel(con, bioModelKey);
//
// get SimulationContext Keys for bioModelKey
//
KeyValue[] simContextKeys = getSimContextEntriesFromBioModel(con, bioModelKey);
//
// get BioModelMetaData object for bioModelKey
//
String sql;
VCMetaDataTable vcMetadataTable = VCMetaDataTable.table;
Field[] f = { new StarField(bioModelTable), userTable.userid, new StarField(vcMetadataTable) };
Table[] t = { bioModelTable, userTable, vcMetadataTable };
switch(dbSyntax) {
case ORACLE:
{
String condition = bioModelTable.id.getQualifiedColName() + " = " + bioModelKey + " AND " + userTable.id.getQualifiedColName() + " = " + bioModelTable.ownerRef.getQualifiedColName() + " AND " + vcMetadataTable.bioModelRef.getQualifiedColName() + "(+) = " + bioModelTable.id.getQualifiedColName();
sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, null, condition, null, dbSyntax, true);
break;
}
case POSTGRES:
{
String condition = bioModelTable.id.getQualifiedColName() + " = " + bioModelKey + " AND " + userTable.id.getQualifiedColName() + " = " + bioModelTable.ownerRef.getQualifiedColName() + " ";
// " AND "+ VCMetaDataTable.table.bioModelRef.getQualifiedColName() + "(+) = " + bioModelTable.id.getQualifiedColName();
OuterJoin outerJoin = new OuterJoin(vcMetadataTable, bioModelTable, JoinOp.RIGHT_OUTER_JOIN, vcMetadataTable.bioModelRef, bioModelTable.id);
sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, outerJoin, condition, null, dbSyntax, true);
break;
}
default:
{
throw new RuntimeException("unexpected DatabaseSyntax " + dbSyntax);
}
}
Statement stmt = con.createStatement();
BioModelMetaData bioModelMetaData = null;
try {
ResultSet rset = stmt.executeQuery(sql);
if (rset.next()) {
bioModelMetaData = bioModelTable.getBioModelMetaData(rset, con, simContextKeys, simKeys, dbSyntax);
} else {
throw new ObjectNotFoundException("BioModel id=" + bioModelKey + " not found for user '" + user + "'");
}
} finally {
// Release resources include resultset
stmt.close();
}
return bioModelMetaData;
}
use of cbit.sql.Table in project vcell by virtualcell.
the class GeomDbDriver method getGeometry.
/**
* getModel method comment.
*/
private Geometry getGeometry(QueryHashtable dbc, Connection con, User user, KeyValue geomKey, boolean bCheckPermission) throws SQLException, DataAccessException, ObjectNotFoundException {
if (user == null || geomKey == null) {
throw new IllegalArgumentException("Improper parameters for getGeometry");
}
// log.print("GeomDbDriver.getGeometry(user="+user+", id="+geomKey+")");
String sql;
Field[] f = { new StarField(geomTable), userTable.userid, extentTable.extentX, extentTable.extentY, extentTable.extentZ };
Table[] t = { geomTable, userTable, extentTable };
String condition = geomTable.id.getQualifiedColName() + " = " + geomKey + " AND " + userTable.id.getQualifiedColName() + " = " + geomTable.ownerRef.getQualifiedColName() + " AND " + extentTable.id.getQualifiedColName() + " = " + geomTable.extentRef.getQualifiedColName();
sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax, bCheckPermission);
// System.out.println(sql);
Geometry geom = null;
// Connection con = conFact.getConnection();
Statement stmt = con.createStatement();
try {
ResultSet rset = stmt.executeQuery(sql);
if (rset.next()) {
// This geometry privacy flag gives this user permission to access
geom = getGeometry(dbc, con, user, rset);
} else {
// see if at least 1 geometry parents (Mathmodels and/or BioModels) are shared with this user
if (bCheckPermission) {
rset.close();
String parentSQL = GeometryTable.getParentsPermissionSQL(geomKey, user);
rset = stmt.executeQuery(parentSQL);
if (rset.next()) {
// At least 1 parent of the geometry exists that's shared to this user so give them the geometry
rset.close();
// Get the geometry without checking the geometry permission
sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax, false);
rset = stmt.executeQuery(sql);
if (rset.next()) {
geom = getGeometry(dbc, con, user, rset);
}
}
}
if (geom == null) {
throw new ObjectNotFoundException("Geometry id=" + geomKey + " not found for user '" + user + "'");
}
}
} finally {
// Release resources include resultset
stmt.close();
}
return geom;
}
Aggregations