diff --git a/uk/ac/sanger/artemis/chado/ChadoTransactionManager.java b/uk/ac/sanger/artemis/chado/ChadoTransactionManager.java index 2e2582de675201d6027559f1c92bcc3c03b01977..70a08e2bcc6297c403064c053d64d2723d897d52 100644 --- a/uk/ac/sanger/artemis/chado/ChadoTransactionManager.java +++ b/uk/ac/sanger/artemis/chado/ChadoTransactionManager.java @@ -557,8 +557,9 @@ public class ChadoTransactionManager **/ public void commit(DatabaseDocument dbDoc) { - dbDoc.commit(sql); - sql = new Vector(); + int retVal = dbDoc.commit(sql); + if(retVal == 0) + sql = new Vector(); } } diff --git a/uk/ac/sanger/artemis/chado/IBatisDAO.java b/uk/ac/sanger/artemis/chado/IBatisDAO.java index 9df0b7a3a8b3978a2025c08be08601ab60728710..e313e049cbe0cbff9d0b02d8abe39782d3d6caaa 100644 --- a/uk/ac/sanger/artemis/chado/IBatisDAO.java +++ b/uk/ac/sanger/artemis/chado/IBatisDAO.java @@ -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()); diff --git a/uk/ac/sanger/artemis/chado/JdbcDAO.java b/uk/ac/sanger/artemis/chado/JdbcDAO.java index 151d89880cb5fb76352b83fdae5dc88664c8e7b3..8ad1db6c72ac153bc6ff2033d7c65f9a1aa901a8 100644 --- a/uk/ac/sanger/artemis/chado/JdbcDAO.java +++ b/uk/ac/sanger/artemis/chado/JdbcDAO.java @@ -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,14 +697,14 @@ 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>. + * 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> * @return number of rows deleted @@ -721,7 +716,8 @@ public class JdbcDAO { String sql = "DELETE FROM "+schema+".feature WHERE uniquename='"+ tsn.getUniqueName()+"'"; - + appendToLogFile(sql, sqlLog); + Statement st = conn.createStatement(); return st.executeUpdate(sql); } @@ -745,6 +741,12 @@ public class JdbcDAO Statement st = conn.createStatement(); 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 diff --git a/uk/ac/sanger/artemis/util/DatabaseDocument.java b/uk/ac/sanger/artemis/util/DatabaseDocument.java index 45886b76390b0829852f98d4d67ac046ebcc88bc..f1de62bfced081f5326ab065bcdf93c70cf21151 100644 --- a/uk/ac/sanger/artemis/util/DatabaseDocument.java +++ b/uk/ac/sanger/artemis/util/DatabaseDocument.java @@ -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 } /** - * - * Lookup a cvterm name from the collection of cvterms. - * + * 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[])