Search in sources :

Example 31 with Version

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);
}
Also used : User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) VersionableType(org.vcell.util.document.VersionableType) GroupAccessNone(org.vcell.util.document.GroupAccessNone) BigDecimal(java.math.BigDecimal) VersionFlag(org.vcell.util.document.VersionFlag) Version(org.vcell.util.document.Version) VersionableTypeVersion(org.vcell.util.document.VersionableTypeVersion) GroupAccess(org.vcell.util.document.GroupAccess) DataAccessException(org.vcell.util.DataAccessException)

Example 32 with Version

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 + ")");
        }
    }
}
Also used : VersionInfo(org.vcell.util.document.VersionInfo) Version(org.vcell.util.document.Version) VersionableTypeVersion(org.vcell.util.document.VersionableTypeVersion) BigDecimal(java.math.BigDecimal) DataAccessException(org.vcell.util.DataAccessException)

Example 33 with Version

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);
        }
    }
}
Also used : VersionableTypeVersion(org.vcell.util.document.VersionableTypeVersion) BigDecimal(java.math.BigDecimal) Version(org.vcell.util.document.Version) VersionableTypeVersion(org.vcell.util.document.VersionableTypeVersion) ResultSet(java.sql.ResultSet) Statement(java.sql.Statement) VersionableRelationship(org.vcell.util.document.VersionableRelationship) Vector(java.util.Vector) DataAccessException(org.vcell.util.DataAccessException)

Example 34 with Version

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;
}
Also used : Geometry(cbit.vcell.geometry.Geometry) BigDecimal(java.math.BigDecimal) KeyValue(org.vcell.util.document.KeyValue) Version(org.vcell.util.document.Version) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) MathDescription(cbit.vcell.math.MathDescription) Model(cbit.vcell.model.Model) SimulationContext(cbit.vcell.mapping.SimulationContext) BigDecimal(java.math.BigDecimal)

Example 35 with Version

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();
}
Also used : Version(org.vcell.util.document.Version) DependencyException(org.vcell.util.DependencyException) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

Version (org.vcell.util.document.Version)74 VCellSoftwareVersion (org.vcell.util.document.VCellSoftwareVersion)27 DataAccessException (org.vcell.util.DataAccessException)24 KeyValue (org.vcell.util.document.KeyValue)22 BigDecimal (java.math.BigDecimal)17 Geometry (cbit.vcell.geometry.Geometry)13 SimulationVersion (org.vcell.util.document.SimulationVersion)12 PropertyVetoException (java.beans.PropertyVetoException)10 User (org.vcell.util.document.User)10 VersionableTypeVersion (org.vcell.util.document.VersionableTypeVersion)10 Element (org.jdom.Element)9 MathDescription (cbit.vcell.math.MathDescription)8 RedistributionVersion (cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion)8 SimulationContext (cbit.vcell.mapping.SimulationContext)7 ResultSet (java.sql.ResultSet)7 Statement (java.sql.Statement)7 ImageException (cbit.image.ImageException)6 Simulation (cbit.vcell.solver.Simulation)6 VersionFlag (org.vcell.util.document.VersionFlag)6 Model (cbit.vcell.model.Model)5