use of org.vcell.util.document.Version in project vcell by virtualcell.
the class DbDriver method groupRemoveUser.
/**
* This method was created in VisualAge.
* @return cbit.sql.Versionable
* @param user cbit.vcell.server.User
* @param versionable cbit.sql.Versionable
*/
public static void groupRemoveUser(Connection con, KeyFactory keyFactory, User owner, VersionableType vType, KeyValue vKey, String userRemoveFromGroupString, boolean isHiddenFromOwner, DatabaseSyntax dbSyntax) throws SQLException, ObjectNotFoundException, DataAccessException {
User userRemoveFromGroup = getUserFromUserid(con, userRemoveFromGroupString);
if (userRemoveFromGroup == null) {
throw new IllegalArgumentException("User name " + userRemoveFromGroupString + " not found");
}
//
if ((con == null) || (vType == null) || (owner == null) || (vKey == null) || (userRemoveFromGroup == null)) {
throw new IllegalArgumentException("Improper parameters for groupRemoveUser userRemoveFromGroupString=" + (userRemoveFromGroupString == null ? "NULL" : userRemoveFromGroupString));
}
//
Version currentVersion = permissionInit(con, vType, vKey, owner);
// If userRemoveFromGroup is not in group it is an error, or if not a "real" group
boolean bExists = false;
if (currentVersion.getGroupAccess() instanceof GroupAccessSome) {
bExists = (((GroupAccessSome) currentVersion.getGroupAccess()).isNormalMember(userRemoveFromGroup) && !isHiddenFromOwner) || (((GroupAccessSome) currentVersion.getGroupAccess()).isHiddenMember(userRemoveFromGroup) && isHiddenFromOwner);
}
if (!bExists) {
throw new DataAccessException(userRemoveFromGroup + " not a member of group");
}
if (lg.isTraceEnabled())
lg.trace("DbDriver.groupAccessRemoveUser(user=" + owner + ", type =" + vType + ", key=" + vKey + ")");
GroupAccessSome currentGroup = (GroupAccessSome) currentVersion.getGroupAccess();
VersionTable vTable = VersionTable.getVersionTable(vType);
//
// calculate hash after removing user (null if last user in group)
//
BigDecimal newHash = null;
int count = (currentGroup.getNormalGroupMembers() != null ? currentGroup.getNormalGroupMembers().length : 0) + (currentGroup.getHiddenGroupMembers() != null ? currentGroup.getHiddenGroupMembers().length : 0);
if (count > 1) {
// See if group already exists without member and get it's ID
newHash = currentGroup.calculateHashWithoutMember(userRemoveFromGroup, isHiddenFromOwner);
}
//
BigDecimal updatedGroupID = null;
String sql = null;
//
if (newHash != null) {
sql = "SELECT groupid FROM " + GroupTable.table.getTableName() + " WHERE groupMemberHash = " + newHash.toString();
java.sql.Statement stmt = con.createStatement();
try {
java.sql.ResultSet rset = stmt.executeQuery(sql);
if (rset.next()) {
// Group already exists,Re-Use
updatedGroupID = rset.getBigDecimal(GroupTable.table.groupid.toString());
}
} finally {
stmt.close();
}
} else {
//
// user was last user in group, new group is the Private Group (AccessNone), groupID is predefined.
//
updatedGroupID = GroupAccess.GROUPACCESS_NONE;
}
//
if (updatedGroupID == null) {
updatedGroupID = getNewGroupID(con, keyFactory);
//
// Re-Add Normal users not removed
//
User[] normalUsers = currentGroup.getNormalGroupMembers();
for (int i = 0; normalUsers != null && i < normalUsers.length; i += 1) {
if (!(normalUsers[i].compareEqual(userRemoveFromGroup)) || isHiddenFromOwner) {
String userRef = normalUsers[i].getID().toString();
sql = "INSERT INTO " + GroupTable.table.getTableName() + " VALUES ( " + keyFactory.getNewKey(con).toString() + "," + updatedGroupID + "," + userRef + "," + (false ? "1" : "0") + "," + newHash + " )";
updateCleanSQL(con, sql);
}
}
//
// Re-Add Hidden users not removed
//
User[] hiddenUsers = currentGroup.getHiddenGroupMembers();
for (int i = 0; hiddenUsers != null && i < hiddenUsers.length; i += 1) {
if (!(hiddenUsers[i].compareEqual(userRemoveFromGroup)) || !isHiddenFromOwner) {
String userRef = hiddenUsers[i].getID().toString();
sql = "INSERT INTO " + GroupTable.table.getTableName() + " VALUES ( " + keyFactory.getNewKey(con).toString() + "," + updatedGroupID + "," + userRef + "," + (true ? "1" : "0") + "," + newHash + " )";
updateCleanSQL(con, sql);
}
}
}
//
String set = vTable.privacy.getQualifiedColName() + " = " + updatedGroupID;
String cond = vTable.id.getQualifiedColName() + " = " + vKey;
// " AND " + vTable.ownerRef.getQualifiedColName() + " = " + owner.getID();
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("Remove User " + userRemoveFromGroup + " Permission to access failed, " + vType.getTypeName() + "(" + vKey + ") record not found");
} else {
throw new DataAccessException("Remove User " + userRemoveFromGroup + " Permission to access failed " + vType.getTypeName() + "(" + vKey + ")");
}
}
}
use of org.vcell.util.document.Version in project vcell by virtualcell.
the class DbDriver method getVersionFromKeyValue.
/**
* This method was created in VisualAge.
* @return cbit.sql.Version
* @param keyValue cbit.sql.KeyValue
* @param vType cbit.sql.VersionableType
*/
private static Version getVersionFromKeyValue(Connection con, VersionableType vType, KeyValue keyValue) throws SQLException, DataAccessException {
Version version = null;
//
// Get a version from this keyValue
//
String sql = null;
VersionTable versionTable = VersionTable.getVersionTable(vType);
UserTable userTable = UserTable.table;
sql = "SELECT " + versionTable.getTableName() + "." + versionTable.id + "," + versionTable.getTableName() + "." + versionTable.name + "," + versionTable.getTableName() + "." + versionTable.ownerRef + "," + versionTable.getTableName() + "." + versionTable.privacy + "," + versionTable.getTableName() + "." + versionTable.versionBranchPointRef + "," + versionTable.getTableName() + "." + versionTable.versionDate + "," + versionTable.getTableName() + "." + versionTable.versionFlag + "," + versionTable.getTableName() + "." + versionTable.versionAnnot + "," + versionTable.getTableName() + "." + versionTable.versionBranchID + "," + userTable.getTableName() + "." + userTable.userid + " FROM " + versionTable.getTableName() + "," + userTable.getTableName() + " WHERE " + versionTable.getTableName() + "." + versionTable.id + " = " + keyValue + " AND " + versionTable.getTableName() + "." + versionTable.ownerRef + " = " + userTable.getTableName() + "." + userTable.id;
java.sql.Statement stmt = con.createStatement();
try {
java.sql.ResultSet rset = stmt.executeQuery(sql);
if (rset.next()) {
BigDecimal groupid = rset.getBigDecimal(VersionTable.privacy_ColumnName);
version = VersionTable.getVersion(rset, getGroupAccessFromGroupID(con, groupid));
} else {
throw new ObjectNotFoundException("Failed to find " + vType.getTypeName() + " (Key=" + keyValue + ")");
}
} catch (ObjectNotFoundException e) {
lg.error("objectNotFound: " + e.getMessage(), e);
throw e;
} catch (Exception e) {
lg.error("failed to get version: " + e.getMessage(), e);
throw new DataAccessException("Failed to find " + vType.getTypeName() + " (Key=" + keyValue + "). \nError: " + e.getMessage());
} finally {
stmt.close();
}
return version;
}
use of org.vcell.util.document.Version in project vcell by virtualcell.
the class DbDriver method findAllChildren.
/**
* This method was created in VisualAge.
* @return java.util.Hashtable
*/
private static void findAllChildren(java.sql.Connection con, VersionableTypeVersion vtv, VersionableFamily refs) throws DataAccessException, SQLException {
// Get VersionableTypes(tables) which possibly are children of argument vType
Vector<VersionRef> possibleRefs = VersionTable.getChildVersionableTypes(vtv.getVType());
Enumeration<VersionRef> enum1 = possibleRefs.elements();
UserTable userTable = UserTable.table;
while (enum1.hasMoreElements()) {
VersionRef vr = enum1.nextElement();
// BEGIN check VersionableType for children of versionKey
String sql = null;
VersionTable table = VersionTable.getVersionTable(vr.getVType());
VersionTable vtvTable = VersionTable.getVersionTable(vtv.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() + "," + vtvTable.getTableName() + " WHERE " + vr.getRefField().getQualifiedColName() + " = " + table.id.getQualifiedColName() + " AND " + vtvTable.id.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() + " = " + table.id.getQualifiedColName() + " AND " + vr.getLinkField().getQualifiedColName() + " = " + vtv.getVersion().getVersionKey() + " AND " + table.ownerRef.getQualifiedColName() + " = " + userTable.id.getQualifiedColName();
}
java.sql.Statement stmt = con.createStatement();
Vector<VersionableTypeVersion> allChildrenVTV = 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 childVTV = new VersionableTypeVersion(vr.getVType(), version);
allChildrenVTV.addElement(childVTV);
} catch (Throwable e) {
throw new DataAccessException(e.getMessage());
}
}
} finally {
stmt.close();
}
//
for (int c = 0; c < allChildrenVTV.size(); c += 1) {
VersionableTypeVersion childVTV = allChildrenVTV.elementAt(c);
//
// Add VersionableRelationship to children of refs
//
refs.addChildRelationship(new VersionableRelationship(vtv, childVTV));
//
// Check referencingVTV for children to it(Recursion)
//
findAllChildren(con, childVTV, refs);
}
}
}
use of org.vcell.util.document.Version in project vcell by virtualcell.
the class DictionaryDbDriver method getDatabaseSpecies.
/**
* Insert the method's description here.
* Creation date: (2/15/2003 10:12:24 PM)
* @return cbit.vcell.dictionary.DBSpecies[]
* @param con java.sql.Connection
* @param user cbit.vcell.server.User
* @param bOnlyUser boolean
*/
public DBFormalSpecies[] getDatabaseSpecies(Connection con, User user, String likeString, boolean isBound, FormalSpeciesType speciesType, int restrictSearch, int rowLimit, boolean bOnlyUser) throws SQLException {
if (speciesType != null && speciesType.equals(FormalSpeciesType.speciesMatchSearch)) {
FormalSpeciesType.MatchSearchFormalSpeciesType matchSearchFormalSpeciesType = (FormalSpeciesType.MatchSearchFormalSpeciesType) speciesType;
if (matchSearchFormalSpeciesType.getMatchCriterias() == null || matchSearchFormalSpeciesType.getMatchCriterias().length == 0) {
return null;
}
ArrayList<VCDocumentInfo> matchedVCDocumentInfos = new ArrayList<VCDocumentInfo>();
Statement stmt = null;
// OR condition
// String sql =
// "SELECT UNIQUE " +BioModelTable.table.id.getQualifiedColName() +
// " FROM " + BioModelTable.table.getTableName() + "," + SpeciesContextModelTable.table.getTableName() +
// " WHERE " + BioModelTable.table.modelRef.getQualifiedColName() + " = "+ SpeciesContextModelTable.table.modelRef.getQualifiedColName() +
// " AND (";
// for (int i = 0; i < matchSearchFormalSpeciesType.getMatchCriterias().length; i++) {
// sql+=
// (i>0?" OR ":"") +
// " LOWER("+SpeciesContextModelTable.table.name.getQualifiedColName()+") LIKE " + "'" + matchSearchFormalSpeciesType.getMatchCriterias()[i] + "'" + " ESCAPE '"+BeanUtils.SQL_ESCAPE_CHARACTER+"'";
// }
// sql+=")";
// AND condition
String sql = "";
for (int i = 0; i < matchSearchFormalSpeciesType.getMatchCriterias().length; i++) {
sql += (i > 0 ? " INTERSECT " : "") + "SELECT UNIQUE " + BioModelTable.table.id.getQualifiedColName() + " FROM " + BioModelTable.table.getTableName() + "," + SpeciesContextModelTable.table.getTableName() + " WHERE " + BioModelTable.table.modelRef.getQualifiedColName() + " = " + SpeciesContextModelTable.table.modelRef.getQualifiedColName() + " AND " + " LOWER(" + SpeciesContextModelTable.table.name.getQualifiedColName() + ") LIKE " + "'" + matchSearchFormalSpeciesType.getMatchCriterias()[i] + "'" + " ESCAPE '" + BeanUtils.SQL_ESCAPE_CHARACTER + "'";
}
try {
stmt = con.createStatement();
ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
BigDecimal versionKey = rset.getBigDecimal(1);
Version version = new Version(new KeyValue(versionKey), null, null, null, null, null, null, null, null);
matchedVCDocumentInfos.add(new BioModelInfo(version, null, (BioModelChildSummary) null, null));
}
} finally {
if (stmt != null) {
stmt.close();
}
}
if (matchedVCDocumentInfos.size() == 0) {
return null;
}
return new DBFormalSpecies[] { new MatchedVCDocumentsFromSearch(matchedVCDocumentInfos) };
}
if (!speciesType.bValidProperties(restrictSearch)) {
throw new IllegalArgumentException("Improper properties in restrictSearch");
}
if (bOnlyUser && isBound == false) {
throw new IllegalArgumentException("user not null expects isBound = true");
}
if (!((rowLimit == -1) || (rowLimit > 0))) {
throw new IllegalArgumentException("rowLimit must be -1(Unlimited) or greater than 0");
}
if ((((restrictSearch & FormalSpeciesType.COMPOUND_ID) != 0) && (restrictSearch != FormalSpeciesType.COMPOUND_ID)) || (((restrictSearch & FormalSpeciesType.ENZYME_ID) != 0) && (restrictSearch != FormalSpeciesType.ENZYME_ID)) || (((restrictSearch & FormalSpeciesType.PROTEIN_ID) != 0) && (restrictSearch != FormalSpeciesType.PROTEIN_ID))) {
throw new RuntimeException("Incompatible search properties together");
}
likeString = likeString.toUpperCase();
// Columns always needed
String columns = (speciesType.equals(FormalSpeciesType.compound) ? CompoundTable.table.getTableName() + ".*" + "," + CompoundAliasTable.table.name.getQualifiedColName() + "," + CompoundAliasTable.table.preferred.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.enzyme) ? EnzymeTable.table.getTableName() + ".*" + "," + EnzymeAliasTable.table.name.getQualifiedColName() + "," + EnzymeAliasTable.table.preferred.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.protein) ? ProteinTable.table.getTableName() + ".*" + "," + ProteinAliasTable.table.name.getQualifiedColName() + "," + ProteinAliasTable.table.preferred.getQualifiedColName() : "");
// Columns if Bound (aliased because id in other tables)
String dbSpeciesTable_id_alias = "dbspecies_id";
if (isBound) {
columns = columns + "," + DBSpeciesTable.table.id.getQualifiedColName() + " " + dbSpeciesTable_id_alias;
}
// Tables always needed
String tables = (speciesType.equals(FormalSpeciesType.compound) ? CompoundTable.table.getTableName() + "," + CompoundAliasTable.table.getTableName() : "") + (speciesType.equals(FormalSpeciesType.enzyme) ? EnzymeTable.table.getTableName() + "," + EnzymeAliasTable.table.getTableName() : "") + (speciesType.equals(FormalSpeciesType.protein) ? ProteinTable.table.getTableName() + "," + ProteinAliasTable.table.getTableName() : "");
// Tables if Bound
if (isBound) {
tables = tables + "," + DBSpeciesTable.table.getTableName();
if (bOnlyUser) {
tables = tables + "," + SpeciesContextModelTable.table.getTableName() + "," + SpeciesTable.table.getTableName() + "," + ModelTable.table.getTableName();
}
}
String condition = "";
// Conditions always needed
condition = condition + (speciesType.equals(FormalSpeciesType.compound) ? CompoundTable.table.id.getQualifiedColName() + "=" + CompoundAliasTable.table.compoundRef.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.enzyme) ? EnzymeTable.table.id.getQualifiedColName() + "=" + EnzymeAliasTable.table.enzymeRef.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.protein) ? ProteinTable.table.id.getQualifiedColName() + "=" + ProteinAliasTable.table.proteinRef.getQualifiedColName() : "");
java.util.Vector<String> likeConditions = new java.util.Vector<String>();
if (speciesType.equals(FormalSpeciesType.compound)) {
if ((restrictSearch & FormalSpeciesType.COMPOUND_ID) != 0) {
likeConditions.add(" UPPER(" + CompoundTable.table.id.getQualifiedColName() + ") = " + likeString);
}
if ((restrictSearch & FormalSpeciesType.COMPOUND_ALIAS) != 0) {
likeConditions.add(" UPPER(" + CompoundAliasTable.table.name.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
if ((restrictSearch & FormalSpeciesType.COMPOUND_KEGGID) != 0) {
likeConditions.add(" UPPER(" + CompoundTable.table.keggID.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
if ((restrictSearch & FormalSpeciesType.COMPOUND_CASID) != 0) {
likeConditions.add(" UPPER(" + CompoundTable.table.casID.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
if ((restrictSearch & FormalSpeciesType.COMPOUND_FORMULA) != 0) {
likeConditions.add(" UPPER(" + CompoundTable.table.formula.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
} else if (speciesType.equals(FormalSpeciesType.enzyme)) {
if ((restrictSearch & FormalSpeciesType.ENZYME_ID) != 0) {
likeConditions.add(" UPPER(" + EnzymeTable.table.id.getQualifiedColName() + ") = " + likeString);
}
if ((restrictSearch & FormalSpeciesType.ENZYME_ALIAS) != 0) {
likeConditions.add(" UPPER(" + EnzymeAliasTable.table.name.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
if ((restrictSearch & FormalSpeciesType.ENZYME_SYSNAME) != 0) {
likeConditions.add(" UPPER(" + EnzymeTable.table.sysname.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
if ((restrictSearch & FormalSpeciesType.ENZYME_ECNUMBER) != 0) {
likeConditions.add(" UPPER(" + EnzymeTable.table.ecNumber.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
// if((restrictSearch & FormalSpeciesType.ENZYME_ECNUMBER) != 0){likeConditions.add(" UPPER("+EnzymeTable.table.ecNumber.getQualifiedColName() + ") LIKE " + "'EC "+likeString+"'");}
if ((restrictSearch & FormalSpeciesType.ENZYME_REACTION) != 0) {
likeConditions.add(" UPPER(" + EnzymeTable.table.reaction.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
if ((restrictSearch & FormalSpeciesType.ENZYME_CASID) != 0) {
likeConditions.add(" UPPER(" + EnzymeTable.table.casID.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
} else if (speciesType.equals(FormalSpeciesType.protein)) {
if ((restrictSearch & FormalSpeciesType.PROTEIN_ID) != 0) {
likeConditions.add(" UPPER(" + ProteinTable.table.id.getQualifiedColName() + ") = " + likeString);
}
if ((restrictSearch & FormalSpeciesType.PROTEIN_ALIAS) != 0) {
likeConditions.add(" UPPER(" + ProteinAliasTable.table.name.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
if ((restrictSearch & FormalSpeciesType.PROTEIN_ACCESSION) != 0) {
likeConditions.add(" UPPER(" + ProteinTable.table.accessionNumber.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
if ((restrictSearch & FormalSpeciesType.PROTEIN_SWISSPROTID) != 0) {
likeConditions.add(" UPPER(" + ProteinTable.table.swissProtEntryName.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
if ((restrictSearch & FormalSpeciesType.PROTEIN_ORGANISM) != 0) {
likeConditions.add(" UPPER(" + ProteinTable.table.organism.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
if ((restrictSearch & FormalSpeciesType.PROTEIN_KEYWORD) != 0) {
likeConditions.add(" UPPER(" + ProteinTable.table.keywords.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
if ((restrictSearch & FormalSpeciesType.PROTEIN_DESCR) != 0) {
likeConditions.add(" UPPER(" + ProteinTable.table.description.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
}
} else {
throw new RuntimeException(speciesType.getName() + " Unsupported");
}
if (likeConditions.size() > 0) {
condition = condition + " AND ( ";
for (int i = 0; i < likeConditions.size(); i += 1) {
String newCondition = (String) likeConditions.get(i);
if (i != 0) {
condition = condition + " OR ";
}
condition = condition + newCondition;
}
condition = condition + ")";
}
if (isBound) {
condition = condition + " AND " + (speciesType.equals(FormalSpeciesType.compound) ? CompoundTable.table.id.getQualifiedColName() + "=" + DBSpeciesTable.table.compoundRef.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.enzyme) ? EnzymeTable.table.id.getQualifiedColName() + "=" + DBSpeciesTable.table.enzymeRef.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.protein) ? ProteinTable.table.id.getQualifiedColName() + "=" + DBSpeciesTable.table.proteinRef.getQualifiedColName() : "");
if (bOnlyUser) {
condition = condition + " AND " + SpeciesContextModelTable.table.speciesRef.getQualifiedColName() + " = " + SpeciesTable.table.id.getQualifiedColName() + " AND " + SpeciesTable.table.dbSpeciesRef.getQualifiedColName() + " = " + DBSpeciesTable.table.id.getQualifiedColName() + " AND " + SpeciesContextModelTable.table.modelRef.getQualifiedColName() + " = " + ModelTable.table.id.getQualifiedColName() + " AND " + ModelTable.table.ownerRef.getQualifiedColName() + " = " + user.getID();
}
}
// ORDER BY 'id' must not be changed, used to collect multiple aliasnames into same info object
String orderBy = (speciesType.equals(FormalSpeciesType.compound) ? CompoundTable.table.id.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.enzyme) ? EnzymeTable.table.id.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.protein) ? ProteinTable.table.id.getQualifiedColName() : "");
String sql = "SELECT " + columns + " FROM " + tables + " WHERE " + condition + " ORDER BY " + orderBy;
DBFormalSpecies[] databaseSpecies = null;
Statement stmt = con.createStatement();
if (rowLimit > 0) {
stmt.setMaxRows(rowLimit);
}
try {
ResultSet rset = stmt.executeQuery(sql);
if (speciesType.equals(FormalSpeciesType.compound)) {
databaseSpecies = CompoundTable.table.getCompounds(rset, isBound);
} else if (speciesType.equals(FormalSpeciesType.enzyme)) {
databaseSpecies = EnzymeTable.table.getEnzymes(rset, isBound);
} else if (speciesType.equals(FormalSpeciesType.protein)) {
databaseSpecies = ProteinTable.table.getProteins(rset, isBound);
} else {
throw new RuntimeException("FormalSpeciesType=" + speciesType.getName() + " Unsupported");
}
} finally {
// Release resources include resultset
stmt.close();
}
//
return databaseSpecies;
}
use of org.vcell.util.document.Version in project vcell by virtualcell.
the class GeomDbDriver 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, QueryHashtable dbc, Connection con, User user, Geometry geometry, KeyValue updatedImageKey, boolean bVersion) throws DataAccessException, SQLException, RecordChangedException {
Version newVersion = null;
try {
newVersion = updateVersionableInit(hash, con, user, geometry, bVersion);
insertGeometry(hash, dbc, con, user, geometry, updatedImageKey, newVersion, bVersion);
} catch (ImageException e) {
lg.error(e.getMessage(), e);
throw new DataAccessException("ImageException: " + e.getMessage());
}
return newVersion.getVersionKey();
}
Aggregations