Search in sources :

Example 46 with StructureMapping

use of cbit.vcell.mapping.StructureMapping in project vcell by virtualcell.

the class SimulationContextDbDriver method assignStructureMappingsSQL.

/**
 * This method was created in VisualAge.
 * @param simContext cbit.vcell.mapping.SimulationContext
 */
private void assignStructureMappingsSQL(QueryHashtable dbc, Connection con, KeyValue simContextKey, SimulationContext simContext) throws SQLException, DataAccessException {
    String sql;
    sql = " SELECT " + "*" + " FROM " + structureMappingTable.getTableName() + " WHERE " + structureMappingTable.simContextRef + " = " + simContextKey;
    Statement stmt = con.createStatement();
    try {
        // log.print(sql);
        ResultSet rset = stmt.executeQuery(sql);
        while (rset.next()) {
            BigDecimal subvolumeRefBigDecimal = rset.getBigDecimal(structureMappingTable.subVolumeRef.toString());
            KeyValue subVolumeRef = (subvolumeRefBigDecimal == null ? null : new KeyValue(subvolumeRefBigDecimal));
            BigDecimal surfaceClassRefBigDecimal = rset.getBigDecimal(structureMappingTable.surfaceClassRef.toString());
            KeyValue surfaceClassRef = (surfaceClassRefBigDecimal == null ? null : new KeyValue(surfaceClassRefBigDecimal));
            KeyValue structureRef = new KeyValue(rset.getBigDecimal(structureMappingTable.structRef.toString()));
            // 
            // lookup structure and subVolume from SimulationContext by their keys
            // 
            // DBCache will not always give same instance consistently (usually this is
            // fixed up later in the ReferenceResolver at the Client).
            // 
            Structure theStructure = null;
            Structure[] structureArray = simContext.getModel().getStructures();
            for (int i = 0; i < structureArray.length; i++) {
                Structure structure = structureArray[i];
                if (structure.getKey().compareEqual(structureRef)) {
                    theStructure = structure;
                    break;
                }
            }
            if (theStructure == null) {
                throw new DataAccessException("Can't match structure and subvolume");
            }
            GeometryClass theGeometryClass = null;
            KeyValue geometryClassKey = (subVolumeRef == null ? surfaceClassRef : subVolumeRef);
            if (geometryClassKey != null) {
                GeometryClass[] geometryClasses = simContext.getGeometry().getGeometryClasses();
                for (int i = 0; i < geometryClasses.length; i++) {
                    if (geometryClasses[i].getKey().compareEqual(geometryClassKey)) {
                        theGeometryClass = geometryClasses[i];
                        break;
                    }
                }
                if (theGeometryClass == null) {
                    throw new DataAccessException("Can't find Geometryclass");
                }
            }
            Expression sizeExpression = null;
            String sizeExpressionS = rset.getString(StructureMappingTable.table.sizeExp.getUnqualifiedColName());
            if (!rset.wasNull() && sizeExpressionS != null && sizeExpressionS.length() > 0) {
                try {
                    sizeExpressionS = TokenMangler.getSQLRestoredString(sizeExpressionS);
                    sizeExpression = new Expression(sizeExpressionS);
                } catch (ExpressionException e) {
                    e.printStackTrace();
                    throw new DataAccessException("SimulationContextDbDriver.assignStructureMappingSQL : Couldn't parse non-null size expression for Structure " + theStructure.getName());
                }
            }
            StructureMapping sm = simContext.getGeometryContext().getStructureMapping(theStructure);
            try {
                sm.getSizeParameter().setExpression(sizeExpression);
            } catch (Exception e1) {
                throw new DataAccessException("SimulationContextDbDriver.assignStructureMappingSQL : Couldn't set size expression '" + sizeExpressionS + "'for Structure " + theStructure.getName());
            }
            try {
                sm.setGeometryClass(theGeometryClass);
            } catch (PropertyVetoException e) {
                lg.error(e.getMessage(), e);
                throw new DataAccessException(e.getMessage());
            }
            if (sm instanceof FeatureMapping) {
                FeatureMapping fm = (FeatureMapping) sm;
                String boundaryTypeXmString = rset.getString(structureMappingTable.boundaryTypeXm.toString());
                if (!rset.wasNull()) {
                    fm.setBoundaryConditionTypeXm(new BoundaryConditionType(boundaryTypeXmString));
                }
                String boundaryTypeXpString = rset.getString(structureMappingTable.boundaryTypeXp.toString());
                if (!rset.wasNull()) {
                    fm.setBoundaryConditionTypeXp(new BoundaryConditionType(boundaryTypeXpString));
                }
                String boundaryTypeYmString = rset.getString(structureMappingTable.boundaryTypeYm.toString());
                if (!rset.wasNull()) {
                    fm.setBoundaryConditionTypeYm(new BoundaryConditionType(boundaryTypeYmString));
                }
                String boundaryTypeYpString = rset.getString(structureMappingTable.boundaryTypeYp.toString());
                if (!rset.wasNull()) {
                    fm.setBoundaryConditionTypeYp(new BoundaryConditionType(boundaryTypeYpString));
                }
                String boundaryTypeZmString = rset.getString(structureMappingTable.boundaryTypeZm.toString());
                if (!rset.wasNull()) {
                    fm.setBoundaryConditionTypeZm(new BoundaryConditionType(boundaryTypeZmString));
                }
                String boundaryTypeZpString = rset.getString(structureMappingTable.boundaryTypeZp.toString());
                if (!rset.wasNull()) {
                    fm.setBoundaryConditionTypeZp(new BoundaryConditionType(boundaryTypeZpString));
                }
                String volPerUnitArea = rset.getString(structureMappingTable.volPerUnitAreaExp.toString());
                if (!rset.wasNull()) {
                    try {
                        fm.getVolumePerUnitAreaParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(volPerUnitArea)));
                    } catch (ExpressionException e) {
                        e.printStackTrace(System.out);
                        throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
                    }
                }
                String volPerUnitVol = rset.getString(structureMappingTable.volPerUnitVolExp.toString());
                if (!rset.wasNull()) {
                    try {
                        fm.getVolumePerUnitVolumeParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(volPerUnitVol)));
                    } catch (ExpressionException e) {
                        e.printStackTrace(System.out);
                        throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
                    }
                }
            } else if (sm instanceof MembraneMapping) {
                MembraneMapping mm = (MembraneMapping) sm;
                String surfToVolString = rset.getString(structureMappingTable.surfToVolExp.toString());
                if (!rset.wasNull()) {
                    try {
                        mm.getSurfaceToVolumeParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(surfToVolString)));
                    } catch (ExpressionException e) {
                        e.printStackTrace(System.out);
                        throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
                    }
                }
                String volFractString = rset.getString(structureMappingTable.volFractExp.toString());
                if (!rset.wasNull()) {
                    try {
                        mm.getVolumeFractionParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(volFractString)));
                    } catch (ExpressionException e) {
                        e.printStackTrace(System.out);
                        throw new DataAccessException("parse error in volFract expression: " + e.getMessage());
                    }
                }
                boolean bCalculateVoltage = rset.getBoolean(structureMappingTable.bCalculateVoltage.toString());
                if (!rset.wasNull()) {
                    mm.setCalculateVoltage(bCalculateVoltage);
                }
                java.math.BigDecimal specificCapacitance = rset.getBigDecimal(structureMappingTable.specificCap.toString());
                if (!rset.wasNull()) {
                    try {
                        mm.getSpecificCapacitanceParameter().setExpression(new Expression(specificCapacitance.doubleValue()));
                    } catch (ExpressionBindingException e) {
                        e.printStackTrace(System.out);
                        throw new DataAccessException("error setting membrane specific capacitance: " + e.getMessage());
                    }
                }
                String initialVoltageString = rset.getString(structureMappingTable.initialVoltage.toString());
                if (!rset.wasNull()) {
                    try {
                        mm.getInitialVoltageParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(initialVoltageString)));
                    } catch (ExpressionException e) {
                        e.printStackTrace(System.out);
                        throw new DataAccessException("database parse error in initial membrane voltage: " + e.getMessage());
                    }
                }
                String areaPerUnitArea = rset.getString(structureMappingTable.areaPerUnitAreaExp.toString());
                if (!rset.wasNull()) {
                    try {
                        mm.getAreaPerUnitAreaParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(areaPerUnitArea)));
                    } catch (ExpressionException e) {
                        e.printStackTrace(System.out);
                        throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
                    }
                }
                String areaPerUnitVol = rset.getString(structureMappingTable.areaPerUnitVolExp.toString());
                if (!rset.wasNull()) {
                    try {
                        mm.getAreaPerUnitVolumeParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(areaPerUnitVol)));
                    } catch (ExpressionException e) {
                        e.printStackTrace(System.out);
                        throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
                    }
                }
            } else {
                throw new DataAccessException("unknown structureMapping type");
            }
        // System.out.println("Structure Key = " + theStructure + " - " + "SubVolume Key " + theSubVolume.getKey());
        }
    } finally {
        stmt.close();
    }
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) MembraneMapping(cbit.vcell.mapping.MembraneMapping) KeyValue(org.vcell.util.document.KeyValue) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) BoundaryConditionType(cbit.vcell.math.BoundaryConditionType) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) StructureMapping(cbit.vcell.mapping.StructureMapping) BigDecimal(java.math.BigDecimal) ExpressionException(cbit.vcell.parser.ExpressionException) PropertyVetoException(java.beans.PropertyVetoException) DependencyException(org.vcell.util.DependencyException) RecordChangedException(cbit.sql.RecordChangedException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) SQLException(java.sql.SQLException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) PropertyVetoException(java.beans.PropertyVetoException) FeatureMapping(cbit.vcell.mapping.FeatureMapping) Expression(cbit.vcell.parser.Expression) ResultSet(java.sql.ResultSet) Structure(cbit.vcell.model.Structure) DataAccessException(org.vcell.util.DataAccessException)

Example 47 with StructureMapping

use of cbit.vcell.mapping.StructureMapping in project vcell by virtualcell.

the class SimulationContextDbDriver method insertStructureMappingsSQL.

/**
 * This method was created in VisualAge.
 */
private void insertStructureMappingsSQL(InsertHashtable hash, Connection con, KeyValue simContextKey, SimulationContext simContext) throws SQLException, DataAccessException {
    String sql;
    StructureMapping[] structureMappings = simContext.getGeometryContext().getStructureMappings();
    for (int i = 0; i < structureMappings.length; i++) {
        StructureMapping structureMapping = structureMappings[i];
        // 
        // check for incomplete StructureMappings, this allows partially mapped SimContext to be saved without Exceptions.
        // it's ok to have missing StructureMappings in the database, assignStructureMappingsSQL() is tolerant of this.
        // 
        // 
        KeyValue newStuctureMappingKey = keyFactory.getNewKey(con);
        // 
        sql = "INSERT INTO " + structureMappingTable.getTableName() + " " + structureMappingTable.getSQLColumnList() + " VALUES " + structureMappingTable.getSQLValueList(hash, newStuctureMappingKey, simContextKey, structureMapping);
        // System.out.println(sql);
        updateCleanSQL(con, sql);
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) StructureMapping(cbit.vcell.mapping.StructureMapping)

Aggregations

StructureMapping (cbit.vcell.mapping.StructureMapping)47 Expression (cbit.vcell.parser.Expression)23 Structure (cbit.vcell.model.Structure)21 ExpressionException (cbit.vcell.parser.ExpressionException)18 MembraneMapping (cbit.vcell.mapping.MembraneMapping)17 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)17 SimulationContext (cbit.vcell.mapping.SimulationContext)15 SpeciesContext (cbit.vcell.model.SpeciesContext)14 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)14 Model (cbit.vcell.model.Model)13 FeatureMapping (cbit.vcell.mapping.FeatureMapping)12 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)12 ReactionStep (cbit.vcell.model.ReactionStep)12 BioModel (cbit.vcell.biomodel.BioModel)11 Membrane (cbit.vcell.model.Membrane)11 GeometryContext (cbit.vcell.mapping.GeometryContext)10 Feature (cbit.vcell.model.Feature)10 ModelParameter (cbit.vcell.model.Model.ModelParameter)10 MappingException (cbit.vcell.mapping.MappingException)9 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)9