use of cbit.vcell.model.DBFormalSpecies in project vcell by virtualcell.
the class SpeciesQueryPanel method createDBSpecies.
/**
* Comment
*/
private void createDBSpecies(javax.swing.event.ListSelectionEvent listSelectionEvent) {
if (bIgnoreSelection) {
return;
}
if (getDocumentManager() != null) {
if (!listSelectionEvent.getValueIsAdjusting()) {
if (!((javax.swing.ListSelectionModel) listSelectionEvent.getSource()).isSelectionEmpty()) {
try {
javax.swing.JList selectionJList = null;
if (getCompoundJList().getSelectionModel() == listSelectionEvent.getSource()) {
selectionJList = getCompoundJList();
} else if (getEnzymeJList().getSelectionModel() == listSelectionEvent.getSource()) {
selectionJList = getEnzymeJList();
} else if (getProteinJList().getSelectionModel() == listSelectionEvent.getSource()) {
selectionJList = getProteinJList();
} else {
throw new RuntimeException("Unknown ListSelectionModel");
}
int[] selection = new int[1];
selection[0] = selectionJList.getSelectedIndex();
DBFormalSpecies[] dbFormalSpecies = jlistData.get(selectionJList);
String query = jlistQuery.get(selectionJList);
ButtonModel scope = jlistScope.get(selectionJList);
boolean bBound = (scope != getDictionaryJRadioButton().getModel());
boolean bOnlyUser = (scope == getMyModelJRadioButton().getModel());
DictionaryQueryResults dqr = null;
if (bBound) {
if (getDocumentManager().getUser() == null) {
throw new RuntimeException("Query results for 'My Model' can't be bound to null user");
}
org.vcell.util.document.User user = (bOnlyUser ? getDocumentManager().getUser() : null);
dqr = new DictionaryQueryResults(query, user, (DBSpecies[]) dbFormalSpecies, selection);
} else {
dqr = new DictionaryQueryResults(query, dbFormalSpecies, selection);
}
setDictionaryQueryResults(dqr);
// Clear other selections
bIgnoreSelection = true;
if (getCompoundJList() != selectionJList) {
getCompoundJList().clearSelection();
}
if (getEnzymeJList() != selectionJList) {
getEnzymeJList().clearSelection();
}
if (getProteinJList() != selectionJList) {
getProteinJList().clearSelection();
}
bIgnoreSelection = false;
} catch (Exception e) {
e.printStackTrace();
PopupGenerator.showErrorDialog(this, "Error:\n" + e.getMessage(), e);
}
} else {
setDictionaryQueryResults(null);
}
}
}
}
use of cbit.vcell.model.DBFormalSpecies in project vcell by virtualcell.
the class DBReactionWizardPanel method showSpeciesBrowser.
/**
* Comment
*/
private DBFormalSpecies showSpeciesBrowser() {
SpeciesQueryDialog sqd = new SpeciesQueryDialog((java.awt.Frame) null, true);
sqd.setSearchableTypes(SpeciesQueryPanel.SEARCHABLE_ENZYME | SpeciesQueryPanel.SEARCHABLE_COMPOUND | (getSearchUserJRadioButton().isSelected() ? SpeciesQueryPanel.SEARCHABLE_PROTEIN : 0x00L));
// boolean isDictSearch = getJTabbedPane1().getTitleAt(getJTabbedPane1().getSelectedIndex()).equals("Dictionary");
// if(getSearchDictionaryJRadioButton().isSelected()){
// if(getAnyJRadioButton().isSelected()){
// sqd.setSearchableTypes(SpeciesQueryPanel.SEARCHABLE_ENZYME | SpeciesQueryPanel.SEARCHABLE_COMPOUND);
// }else{
// sqd.setSearchableTypes((getCatalystJRadioButton().isSelected()?SpeciesQueryPanel.SEARCHABLE_ENZYME:SpeciesQueryPanel.SEARCHABLE_COMPOUND));
// }
// }
sqd.setDocumentManager(getDocumentManager());
sqd.setSize(550, 500);
BeanUtils.centerOnScreen(sqd);
DialogUtils.showModalJDialogOnTop(sqd, this);
// sqd.setVisible(true);
DBFormalSpecies dbfs = null;
DictionaryQueryResults dqr = sqd.getDictionaryQueryResults();
if (dqr != null && dqr.getSelection() != null) {
dbfs = dqr.getDBFormalSpecies()[dqr.getSelection()[0]];
}
if (dbfs != null) {
setCurrentDBFormalSpecies(dbfs);
}
return dbfs;
}
use of cbit.vcell.model.DBFormalSpecies in project vcell by virtualcell.
the class EnzymeTable method getEnzymes.
/**
* returns a enzyme object from the ResultSet
* @return cbit.vcell.dictionary.enzyme
* @param rset java.sql.ResultSet
*/
public DBFormalSpecies[] getEnzymes(java.sql.ResultSet rset, boolean createBound) throws java.sql.SQLException {
Vector enzymes = new Vector();
Vector aliasNames = new Vector();
String currentAliasName = null;
String currentECNumber = null;
String currentSysname = null;
String currentReaction = null;
String currentPreferred = null;
String currentCasID = null;
org.vcell.util.document.KeyValue currentEnzymeID = null;
org.vcell.util.document.KeyValue currentDBSpeciesID = null;
while (rset.next() || rset.isAfterLast()) {
KeyValue enzymeID = null;
if (!rset.isAfterLast()) {
enzymeID = new KeyValue(rset.getBigDecimal(EnzymeTable.table.id.toString()));
}
if (!rset.isFirst() && (!currentEnzymeID.equals(enzymeID))) {
if (currentEnzymeID != null) {
if (aliasNames.size() > 0) {
String[] aliasNamesArr = new String[aliasNames.size()];
aliasNames.copyInto(aliasNamesArr);
EnzymeInfo enzymeInfo = new EnzymeInfo(currentECNumber, aliasNamesArr, currentReaction, currentSysname, currentCasID);
FormalEnzyme formalEnzyme = new FormalEnzyme(currentEnzymeID, enzymeInfo);
Object enzyme = formalEnzyme;
if (createBound) {
BoundEnzyme boundEnzyme = new BoundEnzyme(currentDBSpeciesID, formalEnzyme);
enzyme = boundEnzyme;
}
enzymes.add(enzyme);
}
}
aliasNames.clear();
if (rset.isAfterLast()) {
break;
}
}
if (aliasNames.size() == 0) {
currentEnzymeID = enzymeID;
currentECNumber = rset.getString(EnzymeTable.table.ecNumber.toString());
currentSysname = rset.getString(EnzymeTable.table.sysname.toString());
currentSysname = (currentSysname != null ? org.vcell.util.TokenMangler.getSQLRestoredString(currentSysname) : null);
currentReaction = rset.getString(EnzymeTable.table.reaction.toString());
currentReaction = (currentReaction != null ? org.vcell.util.TokenMangler.getSQLRestoredString(currentReaction) : null);
currentCasID = rset.getString(EnzymeTable.table.casID.toString());
currentCasID = (currentCasID != null ? org.vcell.util.TokenMangler.getSQLRestoredString(currentCasID) : null);
if (createBound) {
currentDBSpeciesID = new KeyValue(rset.getBigDecimal("dbspecies_id"));
}
}
currentPreferred = rset.getString(EnzymeAliasTable.table.preferred.toString());
currentAliasName = org.vcell.util.TokenMangler.getSQLRestoredString(rset.getString(EnzymeAliasTable.table.name.toString()));
if (currentPreferred.compareToIgnoreCase("T") == 0) {
aliasNames.add(0, currentAliasName);
} else {
aliasNames.add(currentAliasName);
}
}
DBFormalSpecies[] enzymesArr = null;
if (enzymes.size() > 0) {
if (createBound) {
BoundEnzyme[] boundEnzymesArr = null;
boundEnzymesArr = new BoundEnzyme[enzymes.size()];
enzymes.copyInto(boundEnzymesArr);
enzymesArr = boundEnzymesArr;
} else {
FormalEnzyme[] formalEnzymesArr = null;
formalEnzymesArr = new FormalEnzyme[enzymes.size()];
enzymes.copyInto(formalEnzymesArr);
enzymesArr = formalEnzymesArr;
}
}
return enzymesArr;
}
use of cbit.vcell.model.DBFormalSpecies in project vcell by virtualcell.
the class EnzymeReactionTable method getSQLReactionQuery.
/**
* Insert the method's description here.
* Creation date: (4/18/2003 10:29:26 AM)
*/
public String getSQLReactionQuery(cbit.vcell.model.ReactionQuerySpec rqs) {
DBFormalSpecies reactantsCompoundRef = rqs.getReactantBoundSpecies();
DBFormalSpecies enzymeRef = rqs.getCatalystBoundSpecies();
DBFormalSpecies productsCompoundRef = rqs.getProductBoundSpecies();
String reactantWildCard = rqs.getReactantLikeString();
String enzymeWildCard = rqs.getCatalystLikeString();
String productWildCard = rqs.getProductLikeString();
String repWildCard = rqs.getAnyReactionParticipantLikeString();
DBFormalSpecies typeWildCardDBFS = rqs.getAnyReactionParticipantBoundSpecies();
String typeWildCard = (typeWildCardDBFS != null ? typeWildCardDBFS.getDBFormalSpeciesKey().toString() : null);
//
if ((repWildCard != null || typeWildCard != null) && ((reactantWildCard != null) || (enzymeWildCard != null) || (productWildCard != null) || (reactantsCompoundRef != null) || (enzymeRef != null) || (productsCompoundRef != null))) {
throw new IllegalArgumentException("Illegal arguments to getSQLReactionQuery");
}
String nameConditionWild = null;
String nameConditionR = null;
String nameConditionP = null;
String nameConditionE = null;
String typeConditionWild = null;
String typeConditionR = null;
String typeConditionP = null;
String typeConditionE = null;
String rpNameCondition = " SELECT DISTINCT " + EnzymeReactionTable.table.reactionId.getQualifiedColName() + " FROM " + EnzymeReactionTable.table.getTableName() + "," + CompoundTable.table.getTableName() + "," + CompoundAliasTable.table.getTableName() + " WHERE " + EnzymeReactionTable.table.compoundRef.getQualifiedColName() + "=" + CompoundTable.table.id.getQualifiedColName() + " AND " + CompoundAliasTable.table.compoundRef.getQualifiedColName() + "=" + CompoundTable.table.id.getQualifiedColName() + " AND " + CompoundAliasTable.table.preferred.getQualifiedColName() + "=" + "'T'";
//
if (repWildCard == null) {
if (reactantWildCard != null) {
nameConditionR = rpNameCondition + " AND " + "LOWER(" + CompoundAliasTable.table.name.getQualifiedColName() + ") LIKE LOWER('" + reactantWildCard + "')" + " AND " + EnzymeReactionTable.table.type.getQualifiedColName() + "=" + "'" + REACANT_TYPE_REACTANT + "'";
} else if (productWildCard != null) {
nameConditionP = rpNameCondition + " AND " + "LOWER(" + CompoundAliasTable.table.name.getQualifiedColName() + ") LIKE LOWER('" + productWildCard + "')" + " AND " + EnzymeReactionTable.table.type.getQualifiedColName() + "=" + "'" + REACANT_TYPE_PRODUCT + "'";
}
}
//
if (typeWildCard == null) {
if (reactantsCompoundRef != null) {
typeConditionR = createRPTypeSearchCondition(REACANT_TYPE_REACTANT, new String[] { reactantsCompoundRef.getDBFormalSpeciesKey().toString() });
} else if (productsCompoundRef != null) {
typeConditionP = createRPTypeSearchCondition(REACANT_TYPE_PRODUCT, new String[] { productsCompoundRef.getDBFormalSpeciesKey().toString() });
}
}
//
if (repWildCard != null || enzymeWildCard != null) {
nameConditionE = " SELECT DISTINCT " + EnzymeReactionTable.table.reactionId.getQualifiedColName() + " FROM " + EnzymeReactionTable.table.getTableName() + "," + EnzymeTable.table.getTableName() + "," + EnzymeAliasTable.table.getTableName() + " WHERE " + EnzymeReactionTable.table.enzymeRef.getQualifiedColName() + " IS NOT NULL" + " AND " + EnzymeReactionTable.table.enzymeRef.getQualifiedColName() + "=" + EnzymeTable.table.id.getQualifiedColName() + " AND " + EnzymeAliasTable.table.enzymeRef.getQualifiedColName() + "=" + EnzymeTable.table.id.getQualifiedColName() + " AND " + EnzymeAliasTable.table.preferred.getQualifiedColName() + "=" + "'T'" + " AND " + "LOWER(" + EnzymeAliasTable.table.name.getQualifiedColName() + ") LIKE LOWER('" + (repWildCard != null ? repWildCard : enzymeWildCard) + "')";
}
if (enzymeRef != null || typeWildCard != null) {
typeConditionE = " SELECT DISTINCT " + EnzymeReactionTable.table.reactionId.getQualifiedColName() + " FROM " + EnzymeReactionTable.table.getTableName() + " WHERE " + EnzymeReactionTable.table.enzymeRef.getQualifiedColName() + " IS NOT NULL" + " AND " + EnzymeReactionTable.table.enzymeRef.getQualifiedColName() + "=" + (typeWildCard != null ? typeWildCard : enzymeRef.getDBFormalSpeciesKey().toString());
}
//
if (repWildCard != null) {
nameConditionWild = rpNameCondition + " AND " + "LOWER(" + CompoundAliasTable.table.name.getQualifiedColName() + ") LIKE LOWER('" + repWildCard + "')" + " UNION " + nameConditionE;
}
if (typeWildCard != null) {
typeConditionWild = "SELECT DISTINCT " + EnzymeReactionTable.table.reactionId.getQualifiedColName() + " FROM " + EnzymeReactionTable.table.getTableName() + " WHERE " + EnzymeReactionTable.table.compoundRef.getQualifiedColName() + "=" + typeWildCard + " OR " + EnzymeReactionTable.table.enzymeRef.getQualifiedColName() + "=" + typeWildCard;
}
//
String nameConditions = "";
nameConditions = nameConditions + (nameConditionWild != null ? nameConditionWild + " " : "");
nameConditions = nameConditions + (nameConditionR != null ? nameConditionR + " " : "");
nameConditions = nameConditions + (nameConditionP != null ? (nameConditions.length() > 0 ? " INTERSECT " : "") + nameConditionP + " " : "");
nameConditions = nameConditions + (nameConditionE != null && nameConditionWild == null ? (nameConditions.length() > 0 ? " INTERSECT " : "") + nameConditionE + " " : "");
String typeConditions = "";
typeConditions = typeConditions + (typeConditionWild != null ? typeConditionWild + " " : "");
typeConditions = typeConditions + (typeConditionR != null ? typeConditionR + " " : "");
typeConditions = typeConditions + (typeConditionP != null ? (typeConditions.length() > 0 ? " INTERSECT " : "") + typeConditionP + " " : "");
typeConditions = typeConditions + (typeConditionE != null && typeWildCard == null ? (typeConditions.length() > 0 ? " INTERSECT " : "") + typeConditionE + " " : "");
String conditions = null;
if (nameConditions.length() > 0 && typeConditions.length() > 0) {
conditions = "(" + nameConditions + ") UNION (" + typeConditions + ")";
} else if (nameConditions.length() > 0) {
conditions = nameConditions;
} else if (typeConditions.length() > 0) {
conditions = typeConditions;
}
//
String selectSQL_NotNull = "SELECT DISTINCT " + EnzymeReactionTable.table.reactionId.getQualifiedColName() + "," + EnzymeTable.table.ecNumber.getQualifiedColName() + " " + RXQ_ENZYMEFID_ALIAS + "," + EnzymeTable.table.id.getQualifiedColName() + " " + RXQ_ENZYMEID_ALIAS + "," + EnzymeAliasTable.table.name.getQualifiedColName() + " " + RXQ_ENZYMENAME_ALIAS + "," + EnzymeReactionTable.table.type.getQualifiedColName() + "," + EnzymeReactionTable.table.stoich.getQualifiedColName() + "," + CompoundTable.table.keggID.getQualifiedColName() + "," + CompoundTable.table.id.getQualifiedColName() + " " + RXQ_CMPNDID_ALIAS + "," + CompoundAliasTable.table.name.getQualifiedColName() + " " + RXQ_CMPDNDNAME_ALIAS;
String selectSQL_Null = "SELECT DISTINCT " + EnzymeReactionTable.table.reactionId.getQualifiedColName() + "," + EnzymeReactionTable.table.parsedECNumber.getQualifiedColName() + " " + RXQ_ENZYMEFID_ALIAS + "," + "TO_NUMBER(NULL)" + " " + RXQ_ENZYMEID_ALIAS + "," + "TO_CHAR(NULL)" + " " + RXQ_ENZYMENAME_ALIAS + "," + EnzymeReactionTable.table.type.getQualifiedColName() + "," + EnzymeReactionTable.table.stoich.getQualifiedColName() + "," + CompoundTable.table.keggID.getQualifiedColName() + "," + CompoundTable.table.id.getQualifiedColName() + " " + RXQ_CMPNDID_ALIAS + "," + CompoundAliasTable.table.name.getQualifiedColName() + " " + RXQ_CMPDNDNAME_ALIAS;
String fromSQL_NotNull = " FROM " + EnzymeReactionTable.table.getTableName() + "," + CompoundTable.table.getTableName() + "," + CompoundAliasTable.table.getTableName() + "," + EnzymeTable.table.getTableName() + "," + EnzymeAliasTable.table.getTableName();
String fromSQL_Null = " FROM " + EnzymeReactionTable.table.getTableName() + "," + CompoundTable.table.getTableName() + "," + CompoundAliasTable.table.getTableName();
String joinSQL_NotNull = EnzymeReactionTable.table.enzymeRef.getQualifiedColName() + " IS NOT NULL " + " AND " + EnzymeReactionTable.table.compoundRef.getQualifiedColName() + "=" + CompoundTable.table.id.getQualifiedColName() + " AND " + CompoundAliasTable.table.compoundRef.getQualifiedColName() + "=" + CompoundTable.table.id.getQualifiedColName() + " AND " + CompoundAliasTable.table.preferred.getQualifiedColName() + "=" + "'T'" + " AND " + EnzymeReactionTable.table.enzymeRef.getQualifiedColName() + "=" + EnzymeTable.table.id.getQualifiedColName() + " AND " + EnzymeAliasTable.table.enzymeRef.getQualifiedColName() + "=" + EnzymeTable.table.id.getQualifiedColName() + " AND " + EnzymeAliasTable.table.preferred.getQualifiedColName() + "=" + "'T'";
String joinSQL_Null = EnzymeReactionTable.table.enzymeRef.getQualifiedColName() + " IS NULL " + " AND " + EnzymeReactionTable.table.compoundRef.getQualifiedColName() + "=" + CompoundTable.table.id.getQualifiedColName() + " AND " + CompoundAliasTable.table.compoundRef.getQualifiedColName() + "=" + CompoundTable.table.id.getQualifiedColName() + " AND " + CompoundAliasTable.table.preferred.getQualifiedColName() + "=" + "'T'";
String orderBy = " ORDER BY " + EnzymeReactionTable.table.reactionId.getUnqualifiedColName() + "," + RXQ_ENZYMEFID_ALIAS + "," + EnzymeReactionTable.table.type.getUnqualifiedColName() + " DESC";
String sqlNonNull = selectSQL_NotNull + " " + fromSQL_NotNull + " WHERE " + EnzymeReactionTable.table.reactionId.getQualifiedColName() + " IN " + "(" + conditions + ")" + " AND " + joinSQL_NotNull;
String sqlNull = selectSQL_Null + " " + fromSQL_Null + " WHERE " + EnzymeReactionTable.table.reactionId.getQualifiedColName() + " IN " + "(" + conditions + ")" + " AND " + joinSQL_Null;
String sql = sqlNonNull + " UNION " + sqlNull + orderBy;
// System.out.println(sqlNonNull+"\n"+sqlNull+"\n"+sql);
return sql;
}
use of cbit.vcell.model.DBFormalSpecies 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;
}
Aggregations