use of cbit.sql.StarField 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.StarField 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.StarField 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