Skip to content
Snippets Groups Projects
Commit 7b0faf56 authored by tjc's avatar tjc
Browse files

more docs and checks

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@4273 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent d3e79ef3
No related branches found
No related tags found
No related merge requests found
......@@ -557,7 +557,8 @@ public class ChadoTransactionManager
**/
public void commit(DatabaseDocument dbDoc)
{
dbDoc.commit(sql);
int retVal = dbDoc.commit(sql);
if(retVal == 0)
sql = new Vector();
}
}
......
......@@ -42,12 +42,10 @@ import javax.swing.JPasswordField;
public class IBatisDAO implements ChadoDAO
{
/**
*
* Define a iBatis data access object. This uses <code>DbSqlConfig</code>
* to read the configuration in. The system property <quote>chado</quote>
* can be used to define the database location <i>e.g.</i>
* -Dchado=host:port/database?user
*
*/
public IBatisDAO(final JPasswordField pfield)
{
......@@ -372,7 +370,6 @@ public class IBatisDAO implements ChadoDAO
/**
*
* Delete a feature from the database defined by the <code>ChadoTransaction</code>.
* @param schema schema/organism name or null
* @param tsn the <code>ChadoTransaction</code>
......@@ -404,6 +401,11 @@ public class IBatisDAO implements ChadoDAO
Dbxref dbxref = tsn.getFeatureDbxref();
SqlMapClient sqlMap = DbSqlConfig.getSqlMapInstance();
Integer db_id = (Integer)sqlMap.queryForObject("getDbId", dbxref);
if(db_id == null)
throw new SQLException("No database called "+
dbxref.getName()+" found (for "+
tsn.getUniqueName()+
") check the spelling!");
dbxref.setDb_id(db_id.intValue());
......
......@@ -636,19 +636,15 @@ public class JdbcDAO
//
// get the organism_id
Statement st = conn.createStatement();
String str_sql = "SELECT organism_id from " + schema +
String sql = "SELECT organism_id from " + schema +
".feature where feature_id = '" + srcfeature_id + "'";
System.out.println(str_sql);
appendToLogFile(str_sql, sqlLog);
ResultSet rs = st.executeQuery(str_sql);
appendToLogFile(sql, sqlLog);
ResultSet rs = st.executeQuery(sql);
rs.next();
final int organism_id = rs.getInt("organism_id");
//
// insert feature into feature table
ChadoFeature chadoFeature = tsn.getChadoFeature();
// insert new feature into feature table
StringBuffer sql_buff = new StringBuffer();
......@@ -666,21 +662,20 @@ public class JdbcDAO
sql_buff.append(Long.toString(chadoFeature.getType_id()));
sql_buff.append(" )");
System.out.println(new String(sql_buff));
sql = new String(sql_buff);
appendToLogFile(sql, sqlLog);
st = conn.createStatement();
int rowCount = st.executeUpdate(new String(sql_buff));
int rowCount = st.executeUpdate(sql);
//
// get the current feature_id sequence value
String sql = "SELECT currval('"+schema+".feature_feature_id_seq')";
System.out.println(sql);
sql = "SELECT currval('"+schema+".feature_feature_id_seq')";
appendToLogFile(sql, sqlLog);
rs = st.executeQuery(sql);
rs.next();
final int feature_id = rs.getInt("currval");
// System.out.println("SELECT currval('"+schema+".featureprop_featureprop_id_seq')");
//
// insert feature location into featureloc
sql_buff = new StringBuffer();
......@@ -702,13 +697,13 @@ public class JdbcDAO
sql_buff.append(chadoFeature.getPhase());
sql_buff.append(" )");
System.out.println(new String(sql_buff));
sql = new String(sql_buff);
appendToLogFile(sql, sqlLog);
st = conn.createStatement();
rowCount = st.executeUpdate(new String(sql_buff));
rowCount = st.executeUpdate(sql);
}
/**
*
* Delete a feature from the database defined by the <code>ChadoTransaction</code>.
* @param schema schema/organism name or null
* @param tsn the <code>ChadoTransaction</code>
......@@ -721,6 +716,7 @@ public class JdbcDAO
{
String sql = "DELETE FROM "+schema+".feature WHERE uniquename='"+
tsn.getUniqueName()+"'";
appendToLogFile(sql, sqlLog);
Statement st = conn.createStatement();
return st.executeUpdate(sql);
......@@ -746,6 +742,12 @@ public class JdbcDAO
ResultSet rs = st.executeQuery(sql);
boolean exists = rs.next();
if(!exists)
throw new SQLException("No database called "+
dbxref.getName()+
" found (for "+uniquename+
") check the spelling!");
final int db_id = rs.getInt("db_id");
// find if accession exists already
String sqlDbxrefId = "SELECT dbxref_id FROM dbxref WHERE accession='"+
......
......@@ -346,9 +346,12 @@ public class DatabaseDocument extends Document
}
/**
*
* Create an array of GFF-like lines
*
* Create an array of GFF lines.
* @param dao the data access object
* @param parentFeatureID the parent identifier for the features to
* extract
* @return the <code>ByteBuffer</code> array of GFF lines
* @throws java.sql.SQLException
*/
private ByteBuffer[] getGff(ChadoDAO dao, String parentFeatureID)
throws java.sql.SQLException
......@@ -433,9 +436,6 @@ public class DatabaseDocument extends Document
this_buff.append("timelastmodified=" + timelastmodified + ";");
// String value = "";
// if(feat.getValue() != null)
// value = GFFStreamFeature.encode(feat.getValue());
// attributes
Hashtable qualifiers = feat.getQualifiers();
......@@ -481,6 +481,11 @@ public class DatabaseDocument extends Document
}
/**
* Look up the cvterm_id for a controlled vocabulary name.
* @param name
* @return
*/
public static Long getCvtermID(String name)
{
Enumeration enum_cvterm = cvterm.keys();
......@@ -495,9 +500,9 @@ public class DatabaseDocument extends Document
}
/**
*
* Look up a cvterm name from the collection of cvterms.
*
* @param id a cvterm_id
* @return the cvterm name
*/
private String getCvtermName(long id)
{
......@@ -521,9 +526,9 @@ public class DatabaseDocument extends Document
}
/**
*
* Look up cvterms names and id and return in a hashtable.
*
* @param dao the data access object
* @return the cvterm <code>Hashtable</code>
*/
private Hashtable getCvterm(ChadoDAO dao)
{
......@@ -549,6 +554,13 @@ public class DatabaseDocument extends Document
return cvterm;
}
/**
* Get the sequence for a feature.
* @param dao the data access object
* @param buff the buffer to add the sequence to
* @return the resulting buffer
* @throws java.sql.SQLException
*/
private ByteBuffer getSequence(ChadoDAO dao, ByteBuffer buff)
throws java.sql.SQLException
{
......@@ -572,12 +584,10 @@ public class DatabaseDocument extends Document
}
/**
*
* Create a hashtable of the available entries with residues.
* @return a <code>Hashtable</code> of the <code>String</code>
* representation (schema-type-feature_name) and the
* corresponding feature_id
*
*/
public Hashtable getDatabaseEntries()
{
......@@ -629,9 +639,10 @@ public class DatabaseDocument extends Document
/**
*
* Make a connetion with the jdbc
* jdbc:postgresql://localhost:13001/chadoCVS?user=es2
* jdbc:postgresql://host:port/database?user
*
*/
/**
public Connection getConnection() throws java.sql.SQLException,
java.net.ConnectException
{
......@@ -645,12 +656,11 @@ public class DatabaseDocument extends Document
location.substring(index + 6),
new String(pfield.getPassword()));
}
*/
/**
*
* Get the data access object (DAO).
* @return data access object
*
*/
private ChadoDAO getDAO()
throws java.net.ConnectException, SQLException
......@@ -695,14 +705,20 @@ public class DatabaseDocument extends Document
return file_output_stream;
}
public void commit(Vector sql)
/**
* Commit the <code>ChadoTransaction</code> SQL back to the
* database.
* @param sql the collection of <code>ChadoTransaction</code> objects
* @return
*/
public int commit(Vector sql)
{
int i = 0;
try
{
ChadoDAO dao = getDAO();
for(int i = 0; i < sql.size(); i++)
for(i = 0; i < sql.size(); i++)
{
ChadoTransaction tsn = (ChadoTransaction) sql.get(i);
......@@ -730,9 +746,9 @@ public class DatabaseDocument extends Document
}
catch (java.sql.SQLException sqlExp)
{
JOptionPane.showMessageDialog(null, "Problems Writing",
"Problems Writing to Database "+
JOptionPane.showMessageDialog(null, "Problems Writing...\n" +
sqlExp.getMessage(),
"Problems Writing to Database ",
JOptionPane.ERROR_MESSAGE);
sqlExp.printStackTrace();
}
......@@ -744,7 +760,7 @@ public class DatabaseDocument extends Document
JOptionPane.ERROR_MESSAGE);
conn_ex.printStackTrace();
}
return i;
}
public static void main(String args[])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment