use of org.vcell.util.document.Version in project vcell by virtualcell.
the class DbDriver method insertVersionableInit.
/**
* This method was created in VisualAge.
* @return cbit.sql.KeyValue
* @param versionable cbit.sql.Versionable
* @param pRef cbit.sql.KeyValue
* @param bCommit boolean
*/
protected Version insertVersionableInit(InsertHashtable hash, Connection con, User user, Versionable versionable, String name, String annot, boolean bVersion) throws SQLException, DataAccessException {
if (hash.getDatabaseKey(versionable) != null) {
throw new DataAccessException(versionable + " already inserted in this transaction");
}
VersionableType vType = VersionTable.versionableTypeFromVersionable(versionable);
if (vType.getIsTopLevel() && isNameUsed(con, vType, user, name)) {
throw new DataAccessException("'" + user.getName() + "' already has a " + vType.getTypeName() + " with name '" + name + "'");
}
User owner = user;
// AccessInfo accessInfo = new AccessInfo(AccessInfo.PRIVATE_CODE);
GroupAccess accessInfo = new GroupAccessNone();
KeyValue versionKey = keyFactory.getNewKey(con);
java.util.Date date = getNewDate(con);
// if(versionable.getVersion().getVersionKey() != null){
// throw new DataAccessException("GeomDbDriver:insertVersionable, VersionKey must be null to insert");
// }
String versionName = name;
// Check for Archive and Publish not needed in insert because versionflag is always forced to Current
VersionFlag versionFlag = null;
// if(bVersion){
// versionFlag = VersionFlag.Archived;
// }else{
versionFlag = VersionFlag.Current;
// }
KeyValue PRefKey = null;
java.math.BigDecimal branchID = getNewBranchID(con);
//
// Insert Software Version
//
insertSoftwareVersion(con, versionKey);
//
return new Version(versionKey, versionName, owner, accessInfo, PRefKey, branchID, date, versionFlag, annot);
}
use of org.vcell.util.document.Version in project vcell by virtualcell.
the class DbDriver method groupSetPublic.
/**
* This method was created in VisualAge.
* @return cbit.sql.Versionable
* @param owner cbit.vcell.server.User
* @param versionable cbit.sql.Versionable
*/
public static void groupSetPublic(Connection con, User owner, VersionableType vType, KeyValue vKey, DatabaseSyntax dbSyntax) throws SQLException, ObjectNotFoundException, DataAccessException {
if ((con == null) || (vType == null) || (owner == null) || (vKey == null)) {
throw new IllegalArgumentException("Improper parameters for groupAccessSetPublic");
}
//
Version currentVersion = permissionInit(con, vType, vKey, owner);
if (lg.isTraceEnabled())
lg.trace("DbDriver.groupSetPublic(owner=" + owner + ", type =" + vType + ", key=" + vKey + ")");
BigDecimal updatedGroupID = GroupAccess.GROUPACCESS_ALL;
VersionTable vTable = VersionTable.getVersionTable(vType);
String set = vTable.privacy.getQualifiedColName() + " = " + updatedGroupID;
String cond = vTable.id.getQualifiedColName() + " = " + vKey;
// " AND " + vTable.ownerRef.getQualifiedColName() + " = " + owner.getID();
String sql = DatabasePolicySQL.enforceOwnershipUpdate(owner, vTable, set, cond);
// System.out.println(sql);
int numRowsProcessed = updateCleanSQL(con, sql);
if (numRowsProcessed != 1) {
//
// check if update failed, or just already updated
//
Vector<VersionInfo> versionInfoList = getVersionableInfos(con, owner, vType, false, vKey, true, dbSyntax);
if (versionInfoList.size() == 0) {
throw new DataAccessException("groupSetPublic failed " + vType.getTypeName() + "(" + vKey + ") record not found");
} else {
throw new DataAccessException("groupSetPublic failed " + vType.getTypeName() + "(" + vKey + ")");
}
}
}
use of org.vcell.util.document.Version in project vcell by virtualcell.
the class DbDriver method findAllReferences.
/**
* This method was created in VisualAge.
* @return java.util.Hashtable
*/
private static void findAllReferences(java.sql.Connection con, VersionableTypeVersion vtv, VersionableFamily refs) throws DataAccessException, SQLException {
// Get VersionableTypes(tables) which possibly have references to argument vType
Vector<VersionRef> possibleRefs = VersionTable.getReferencingVersionableTypes(vtv.getVType());
Enumeration<VersionRef> enum1 = possibleRefs.elements();
UserTable userTable = UserTable.table;
while (enum1.hasMoreElements()) {
VersionRef vr = enum1.nextElement();
// BEGIN check VersionableType for references to versionKey
String sql = null;
VersionTable table = VersionTable.getVersionTable(vr.getVType());
if (vr.getLinkField() == null) {
//
// direct link between versionable types
//
sql = "SELECT " + table.id.getQualifiedColName() + "," + table.name.getQualifiedColName() + "," + table.ownerRef.getQualifiedColName() + "," + table.privacy.getQualifiedColName() + "," + table.versionBranchPointRef.getQualifiedColName() + "," + table.versionDate.getQualifiedColName() + "," + table.versionFlag.getQualifiedColName() + "," + table.versionAnnot.getQualifiedColName() + "," + table.versionBranchID.getQualifiedColName() + "," + userTable.userid.getQualifiedColName() + " FROM " + table.getTableName() + "," + userTable.getTableName() + " WHERE " + vr.getRefField().getQualifiedColName() + " = " + vtv.getVersion().getVersionKey() + " AND " + table.ownerRef.getQualifiedColName() + " = " + userTable.getTableName() + "." + userTable.id;
} else {
//
// indirect link between versionable types (Link Table ... e.g. BioModelSimulationLinkTable)
//
sql = "SELECT " + table.id.getQualifiedColName() + "," + table.name.getQualifiedColName() + "," + table.ownerRef.getQualifiedColName() + "," + table.privacy.getQualifiedColName() + "," + table.versionBranchPointRef.getQualifiedColName() + "," + table.versionDate.getQualifiedColName() + "," + table.versionFlag.getQualifiedColName() + "," + table.versionAnnot.getQualifiedColName() + "," + table.versionBranchID.getQualifiedColName() + "," + userTable.userid.getQualifiedColName() + " FROM " + table.getTableName() + "," + userTable.getTableName() + "," + vr.getLinkField().getTableName() + " WHERE " + vr.getRefField().getQualifiedColName() + " = " + vtv.getVersion().getVersionKey() + " AND " + vr.getLinkField().getQualifiedColName() + " = " + table.id.getQualifiedColName() + " AND " + table.ownerRef.getQualifiedColName() + " = " + userTable.id.getQualifiedColName();
}
java.sql.Statement stmt = con.createStatement();
Vector<VersionableTypeVersion> allReferencingVTV = new Vector<VersionableTypeVersion>();
try {
// Get KeyValues from statement and put into Vector, so we can close statement(good idea because we are recursive)
java.sql.ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
try {
BigDecimal groupid = rset.getBigDecimal(VersionTable.privacy_ColumnName);
Version version = VersionTable.getVersion(rset, getGroupAccessFromGroupID(con, groupid));
VersionableTypeVersion referencingVTV = new VersionableTypeVersion(vr.getVType(), version);
allReferencingVTV.addElement(referencingVTV);
} catch (Throwable e) {
throw new DataAccessException(e.getMessage());
}
}
} finally {
stmt.close();
}
//
for (int c = 0; c < allReferencingVTV.size(); c += 1) {
VersionableTypeVersion referencingVTV = allReferencingVTV.elementAt(c);
//
// Add VersionableRelationship to dependants of refs
//
refs.addDependantRelationship(new VersionableRelationship(referencingVTV, vtv));
//
// Check referencingVTV for references to it(Recursion)
//
findAllReferences(con, referencingVTV, refs);
}
}
}
use of org.vcell.util.document.Version in project vcell by virtualcell.
the class SimContextTable method getSimContext.
/**
* This method was created in VisualAge.
* @return cbit.vcell.mapping.SimulationContext
* @param rset java.sql.ResultSet
* @param log cbit.vcell.server.SessionLog
* @deprecated shouldn't do recursive query
*/
public SimulationContext getSimContext(QueryHashtable dbc, Connection con, User user, ResultSet rset, GeomDbDriver geomDB, ModelDbDriver modelDB, MathDescriptionDbDriver mathDB) throws SQLException, DataAccessException, java.beans.PropertyVetoException {
java.math.BigDecimal groupid = rset.getBigDecimal(VersionTable.privacy_ColumnName);
Version version = getVersion(rset, DbDriver.getGroupAccessFromGroupID(con, groupid));
KeyValue geomKey = new KeyValue(rset.getBigDecimal(SimContextTable.table.geometryRef.toString()));
Geometry geom = (Geometry) geomDB.getVersionable(dbc, con, user, VersionableType.Geometry, geomKey, false);
KeyValue modelKey = new KeyValue(rset.getBigDecimal(SimContextTable.table.modelRef.toString()));
Model model = (Model) modelDB.getVersionable(dbc, con, user, VersionableType.Model, modelKey);
//
// read characteristic size (may be null)
//
Double characteristicSize = null;
BigDecimal size = rset.getBigDecimal(charSize.toString());
if (!rset.wasNull() && size != null) {
characteristicSize = new Double(size.doubleValue());
}
//
// get mathKey (may be null)
//
MathDescription mathDesc = null;
BigDecimal mathKeyValue = rset.getBigDecimal(SimContextTable.table.mathRef.toString());
if (!rset.wasNull()) {
KeyValue mathKey = new KeyValue(mathKeyValue);
mathDesc = (MathDescription) mathDB.getVersionable(dbc, con, user, VersionableType.MathDescription, mathKey);
}
boolean bStochastic = mathDesc.isNonSpatialStoch() || mathDesc.isSpatialStoch() || mathDesc.isSpatialHybrid();
boolean bRuleBased = mathDesc.isRuleBased();
SimulationContext simContext = new SimulationContext(model, geom, mathDesc, version, bStochastic, bRuleBased);
if (characteristicSize != null) {
simContext.setCharacteristicSize(characteristicSize);
}
return simContext;
}
use of org.vcell.util.document.Version in project vcell by virtualcell.
the class SimulationContextDbDriver method updateVersionable.
/**
* This method was created in VisualAge.
* @return cbit.image.VCImage
* @param user cbit.vcell.server.User
* @param image cbit.image.VCImage
*/
public KeyValue updateVersionable(InsertHashtable hash, Connection con, User user, SimulationContext simContext, KeyValue updatedMathDescKey, Model updatedModel, KeyValue updatedGeometryKey, boolean bVersion) throws DataAccessException, SQLException, RecordChangedException {
Version newVersion = null;
try {
newVersion = updateVersionableInit(hash, con, user, simContext, bVersion);
insertSimulationContext(hash, con, user, simContext, updatedMathDescKey, updatedModel, updatedGeometryKey, newVersion, bVersion);
} catch (DependencyException e) {
lg.error(e.getMessage(), e);
throw new DataAccessException("MathException: " + e.getMessage());
}
return newVersion.getVersionKey();
}
Aggregations