use of org.vcell.util.document.VersionableFamily in project vcell by virtualcell.
the class DependencyTest method main.
/**
* Starts the application.
* @param args an array of command-line arguments
*/
public static void main(java.lang.String[] args) {
if (args.length != 2) {
throw new RuntimeException("Usage: DependencyTest VersionableType.toString() keyValue.toString()");
}
java.sql.Connection con = null;
try {
String versionableTypeS = args[0];
String keyValueS = args[1];
// new cbit.sql.KeyValue("1368");
org.vcell.util.document.KeyValue rootKey = new org.vcell.util.document.KeyValue(keyValueS);
// cbit.sql.VersionableType.VCImage;
org.vcell.util.document.VersionableType rootType = null;
if (VersionableType.VCImage.toString().equals(versionableTypeS)) {
rootType = VersionableType.VCImage;
} else if (VersionableType.Geometry.toString().equals(versionableTypeS)) {
rootType = VersionableType.Geometry;
} else if (VersionableType.Model.toString().equals(versionableTypeS)) {
rootType = VersionableType.Model;
} else if (VersionableType.MathDescription.toString().equals(versionableTypeS)) {
rootType = VersionableType.MathDescription;
} else if (VersionableType.SimulationContext.toString().equals(versionableTypeS)) {
rootType = VersionableType.SimulationContext;
} else {
throw new RuntimeException("Improper argument for VersionableType " + versionableTypeS);
}
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@nrcamdb.uchc.edu:1521:orc0";
con = java.sql.DriverManager.getConnection(url, "nrcamdbdev", "bogus");
System.out.println("Search for References to " + rootType.toString() + " id=" + rootKey.toString());
VersionableFamily vf = cbit.vcell.modeldb.DbDriver.getAllReferences(con, rootType, rootKey);
VersionableRelationship[] dependants = vf.getDependantRelationships();
for (int c = 0; c < dependants.length; c += 1) {
VersionableRelationship verrel = dependants[c];
VersionableTypeVersion from = verrel.from();
VersionableTypeVersion to = verrel.to();
System.out.println(from.getVType() + " " + from.getVersion().getVersionKey() + " ==> " + to.getVType() + " " + to.getVersion().getVersionKey());
}
System.out.println("------------------Top Down List-------------------");
VersionableTypeVersion[] topDown = vf.getDependantsTopDown();
byte[] spaces = { 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
for (int c = 0; c < topDown.length; c += 1) {
System.out.print(topDown[c].getVType());
System.out.write(spaces, 0, 30 - topDown[c].getVType().toString().length());
System.out.print(topDown[c].getVersion().getName());
System.out.write(spaces, 0, 40 - topDown[c].getVersion().getName().length());
System.out.println(topDown[c].getVersion().getVersionKey());
}
} catch (Throwable e) {
e.printStackTrace(System.out);
} finally {
try {
if (con != null) {
con.close();
}
} catch (java.sql.SQLException e) {
}
}
}
use of org.vcell.util.document.VersionableFamily in project vcell by virtualcell.
the class DBTopLevel method findReferences.
/**
* Insert the method's description here.
* Creation date: (11/6/2005 10:16:41 AM)
* @return cbit.vcell.modeldb.ReferenceQueryResult
* @param user cbit.vcell.server.User
* @param rqs cbit.vcell.modeldb.ReferenceQuerySpec
*/
ReferenceQueryResult findReferences(User user, ReferenceQuerySpec rqs2, boolean bEnableRetry) throws DataAccessException, java.sql.SQLException {
Object lock = new Object();
Connection con = conFactory.getConnection(lock);
try {
// Use MathDescription for search if ExternalData
VersionableType rqsVType = null;
KeyValue[] vTypeKeys = null;
if (rqs2.isVersionableType()) {
rqsVType = rqs2.getVersionableType();
vTypeKeys = new KeyValue[] { rqs2.getKeyValue() };
} else if (rqs2.isExternalDataIdentiferType()) {
DbDriver.cleanupDeletedReferences(con, user, rqs2.getExternalDataIdentifier(), false);
con.commit();
rqsVType = VersionableType.MathDescription;
vTypeKeys = getMathDescKeysForExternalData(rqs2.getKeyValue(), user, true);
if (vTypeKeys == null || vTypeKeys.length == 0) {
return null;
}
}
if (rqsVType == null) {
throw new DataAccessException("findAllReferences error: Couldn't determine Query type");
}
VersionableFamily finalVersionalbeFamily = null;
for (int k = 0; k < vTypeKeys.length; k += 1) {
// Find references
VersionableFamily vf = getAllReferences(user, vTypeKeys[k], rqsVType, true);
// Check permission
if (vf.bDependants()) {
VersionableTypeVersion[] vtvArr = vf.getUniqueDependants();
for (int i = 0; i < vtvArr.length; i += 1) {
if (vtvArr[i].getVType().equals(VersionableType.BioModelMetaData)) {
Vector<VersionInfo> checkedVInfos = getVersionableInfos(user, vtvArr[i].getVersion().getVersionKey(), VersionableType.BioModelMetaData, false, true, true);
if (checkedVInfos == null || checkedVInfos.size() == 0) {
throw new DataAccessException("References Not Accessible");
}
} else if (vtvArr[i].getVType().equals(VersionableType.MathModelMetaData)) {
Vector<VersionInfo> checkedVInfos = getVersionableInfos(user, vtvArr[i].getVersion().getVersionKey(), VersionableType.MathModelMetaData, false, true, true);
if (checkedVInfos == null || checkedVInfos.size() == 0) {
throw new DataAccessException("References Not Accessible");
}
}
}
}
if (finalVersionalbeFamily == null) {
finalVersionalbeFamily = vf;
} else {
VersionableRelationship[] versRelArr = vf.getDependantRelationships();
for (int r = 0; r < versRelArr.length; r += 1) {
finalVersionalbeFamily.addDependantRelationship(versRelArr[r]);
}
}
}
return new ReferenceQueryResult(finalVersionalbeFamily);
} catch (Throwable e) {
lg.error(e.getMessage(), e);
if (bEnableRetry && isBadConnection(con)) {
conFactory.failed(con, lock);
return findReferences(user, rqs2, false);
} else {
handle_DataAccessException_SQLException(e);
// never gets here;
return null;
}
} finally {
conFactory.release(con, lock);
}
}
use of org.vcell.util.document.VersionableFamily in project vcell by virtualcell.
the class DbDriver method getAllReferences.
/**
* This method was created in VisualAge.
* @return java.util.Hashtable
*/
public static VersionableFamily getAllReferences(java.sql.Connection con, VersionableType vType, KeyValue keyValue) throws DataAccessException, SQLException {
VersionableTypeVersion vtv = new VersionableTypeVersion(vType, getVersionFromKeyValue(con, vType, keyValue));
VersionableFamily refs = new VersionableFamily(vtv);
findAllReferences(con, refs.getTarget(), refs);
findAllChildren(con, refs.getTarget(), refs);
return refs;
}
Aggregations