use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class AdminDBTopLevel method insertUserInfo.
/**
* This method was created in VisualAge.
* @return cbit.sql.UserInfo
* @param newUserInfo cbit.sql.UserInfo
*/
KeyValue insertUserInfo(UserInfo newUserInfo, boolean bEnableRetry) throws SQLException, UseridIDExistsException {
Object lock = new Object();
Connection con = conFactory.getConnection(lock);
try {
if (userDB.getUserFromUserid(con, newUserInfo.userid) != null) {
throw new UseridIDExistsException("Insert new user failed: username '" + newUserInfo.userid + "' already exists");
}
KeyValue key = userDB.insertUserInfo(con, conFactory.getKeyFactory(), newUserInfo);
con.commit();
return key;
} catch (Throwable e) {
lg.error("failure in insertUserInfo()", e);
if (e instanceof UseridIDExistsException) {
throw (UseridIDExistsException) e;
}
try {
con.rollback();
} catch (Throwable rbe) {
lg.error("exception during rollback, bEnableRetry = " + bEnableRetry, rbe);
}
if (bEnableRetry && isBadConnection(con)) {
conFactory.failed(con, lock);
return insertUserInfo(newUserInfo, false);
} else {
handle_SQLException(e);
// never gets here;
return null;
}
} finally {
conFactory.release(con, lock);
}
}
use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class GeomDbDriver method getImageRefKeyFromGeometry.
/**
* getModel method comment.
*/
private KeyValue getImageRefKeyFromGeometry(Connection con, KeyValue geomKey) throws SQLException, DataAccessException, ObjectNotFoundException {
if (geomKey == null) {
throw new IllegalArgumentException("Improper parameters for getImageRefKeyFromGeometry");
}
// log.print("GeomDbDriver.getImageRefKeyFromGeometry(id="+geomKey+")");
String sql;
sql = " SELECT " + geomTable.imageRef + " FROM " + geomTable.getTableName() + " WHERE " + geomTable.id + " = " + geomKey;
// System.out.println(sql);
// Connection con = conFact.getConnection();
Statement stmt = con.createStatement();
try {
ResultSet rset = stmt.executeQuery(sql);
if (rset.next()) {
java.math.BigDecimal iR = rset.getBigDecimal(geomTable.imageRef.toString());
if (rset.wasNull()) {
return null;
}
return new KeyValue(iR);
} else {
throw new ObjectNotFoundException("getSizeKeyFromGeometry for Image id=" + geomKey + " not found");
}
} finally {
// Release resources include resultset
stmt.close();
}
}
use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class GeomDbDriver method insertFilamentsSQL.
/**
* This method was created in VisualAge.
* @param vcimage cbit.image.VCImage
* @param userid java.lang.String
* @exception java.rmi.RemoteException The exception description.
*/
private void insertFilamentsSQL(Connection con, Geometry geom, KeyValue geomKey) throws SQLException, DataAccessException {
String sql;
Filament[] filaments = geom.getGeometrySpec().getFilamentGroup().getFilaments();
for (int i = 0; i < filaments.length; i++) {
// Iterate through Filaments
KeyValue newFilamentKey = keyFactory.getNewKey(con);
//
// Insert Filament
//
Filament currentFilament = filaments[i];
sql = "INSERT INTO " + filamentTable.getTableName() + " " + filamentTable.getSQLColumnList() + " VALUES " + filamentTable.getSQLValueList(newFilamentKey, currentFilament.getName(), geomKey);
updateCleanSQL(con, sql);
//
// Insert all Curves for this filament
//
Curve[] curves = currentFilament.getCurves();
for (int j = 0; j < curves.length; j += 1) {
KeyValue newCurveKey = keyFactory.getNewKey(con);
sql = "INSERT INTO " + curveTable.getTableName() + " " + curveTable.getSQLColumnList() + " VALUES " + curveTable.getSQLValueList(newCurveKey, newFilamentKey, dbSyntax);
//
switch(dbSyntax) {
case ORACLE:
{
updateCleanSQL(con, sql);
updateCleanLOB(con, curveTable.id.toString(), newCurveKey, curveTable.tableName, curveTable.curveData, CurveTable.encodeCurve(curves[j]), dbSyntax);
break;
}
case POSTGRES:
{
updatePreparedCleanSQL(con, sql, CurveTable.encodeCurve(curves[j]));
break;
}
default:
{
throw new RuntimeException("unexpected DatabaseSyntax " + dbSyntax);
}
}
}
}
}
use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class GeomDbDriver method getExtentRefKeyFromImage.
/**
* getModel method comment.
*/
private KeyValue getExtentRefKeyFromImage(Connection con, KeyValue imageKey) throws SQLException, DataAccessException, ObjectNotFoundException {
if (imageKey == null) {
throw new IllegalArgumentException("Improper parameters for getSizeKeyFromImage");
}
// log.print("GeomDbDriver.getSizeRefKeyFromImage(id="+imageKey+")");
String sql;
sql = " SELECT " + imageTable.extentRef + " FROM " + imageTable.getTableName() + " WHERE " + imageTable.id + " = " + imageKey;
// System.out.println(sql);
// Connection con = conFact.getConnection();
Statement stmt = con.createStatement();
try {
ResultSet rset = stmt.executeQuery(sql);
if (rset.next()) {
return new KeyValue(rset.getBigDecimal(imageTable.extentRef.toString()));
} else {
throw new ObjectNotFoundException("getSizeKeyFromImage for Image id=" + imageKey + " not found");
}
} finally {
// Release resources include resultset
stmt.close();
}
}
use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class GeomDbDriver method deleteGeometrySQL.
/**
* only the owner can delete a Geometry
*/
private void deleteGeometrySQL(Connection con, User user, KeyValue geomKey) throws SQLException, DataAccessException, DependencyException {
failOnExternalRefs(con, MathDescTable.table.geometryRef, VersionTable.getVersionTable(VersionableType.MathDescription), geomKey, GeometryTable.table);
failOnExternalRefs(con, SimContextTable.table.geometryRef, VersionTable.getVersionTable(VersionableType.SimulationContext), geomKey, GeometryTable.table);
String sql;
KeyValue imageRefKey = getImageRefKeyFromGeometry(con, geomKey);
KeyValue extentKey = getExtentRefKeyFromGeometry(con, geomKey);
// Delete Geometry, all APPROPRIATE children go ON DELETE CASCADE
sql = DatabasePolicySQL.enforceOwnershipDelete(user, geomTable, GeometryTable.table.id + " = " + geomKey);
// System.out.println(sql);
updateCleanSQL(con, sql);
// Don't have to check if other Geometries are using because Geometries never share sizetable
if (imageRefKey == null) {
sql = "DELETE FROM " + extentTable.getTableName() + " WHERE " + extentTable.id + " = " + extentKey;
// System.out.println(sql);
updateCleanSQL(con, sql);
}
}
Aggregations