[MOBY-guts] biomoby commit

Eddie Kawas kawas at pub.open-bio.org
Tue Mar 14 16:23:06 UTC 2006


kawas
Tue Mar 14 11:23:06 EST 2006
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/definitions/types
In directory pub.open-bio.org:/tmp/cvs-serv25768/org/biomoby/registry/definitions/types

Modified Files:
	JServicesSqlImpl.java JNamespacesSqlImpl.java 
Log Message:
new method to retrieve full service type information, like lsid, contact_email, authority, etc for use (in the RDF) by registry clients

moby-live/Java/src/main/org/biomoby/registry/definitions/types JServicesSqlImpl.java,1.1,1.2 JNamespacesSqlImpl.java,1.2,1.3
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/definitions/types/JServicesSqlImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/definitions/types/JServicesSqlImpl.java	2005/08/29 20:19:20	1.1
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/definitions/types/JServicesSqlImpl.java	2006/03/14 16:23:06	1.2
@@ -16,115 +16,175 @@
 import org.biomoby.shared.MobyException;
 
 /**
- * @author Eddie Kawas
- * mySQL implementation of JServicesI
- * <p>email me at edward.kawas at gmail.com
+ * @author Eddie Kawas mySQL implementation of JServicesI
+ *         <p>
+ *         email me at edward.kawas at gmail.com
  */
-public final class JServicesSqlImpl implements JServiceI{
-    private static final String sql = "SELECT ot1.service_type, rt.relationship_type, ot2.service_type, ot1.description "
-            + "FROM service as ot1, service_term2term as rt, service as ot2 "
-            + "WHERE ot1.service_id = rt.service1_id and ot2.service_id = rt.service2_id order by ot1.service_type";
-
-    private Connection connection = null;
-
-    private final String newline = System.getProperty("line.separator");
-
-    /**
-     * 
-     * @throws MobyException if database driver cannot be found or there is an database access error.
-     */
-    public JServicesSqlImpl() throws MobyException {
-        try {
-            // Load the JDBC driver
-            String driverName = "com.mysql.jdbc.Driver";
-            Class.forName(driverName);
-            // get certain properties from mobycentral.config
-            Map map = MobyCentralConfig.getMobyService();
-            // Create a connection to the database
-            String serverName = map.get("url") + ":" + map.get("port");//localhost:3306"; //TODO - make this a property
-            String mydatabase = (String) map.get("dbname");//"mobyobject";
-            String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
-            String username = (String) map.get("username");//"moby_external";
-            String password = (String) map.get("password");//"";
-
-                     /*   String serverName = "mobycentral.icapture.ubc.ca:3306";
-             String mydatabase = "mobyservice";
-             String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
-             String username = "moby_external";
-             String password = "";*/
-            this.connection = DriverManager.getConnection(url, username,
-                    password);
-        } catch (ClassNotFoundException e) {
-            throw new MobyException(
-                    "Could not find database driver. Please ensure that you have the right libraries present");
-        } catch (SQLException e) {
-            e.printStackTrace();
-            throw new MobyException("Database access error.");
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see org.biomoby.registry.definitions.types.JServiceI#getServices()
-     */
-    public final String getServices() {
-        StringBuffer sb = new StringBuffer();
-        /*ensure connection is not null*/
-        if (connection == null)
-            return "";
-
-        ResultSet rs = null;
-        try {
-            Statement stmt = connection.createStatement();
-            rs = stmt.executeQuery(sql);
-        } catch (SQLException ex) {
-            // TODO - throw exception - Error in sql
-            return ex.getMessage();
-        }
-        try {
-            while (rs.next()) {
-                // Get the data from the row using the column index
-                sb.append(rs.getString(1) + "\t" + rs.getString(2) + "\t"
-                        + rs.getString(3) + "\t" + rs.getString(4) + newline);
-            }
-        } catch (SQLException e) {
-            // TODO - throw exception - Database access error
-            return e.getMessage();
-        }
-        return sb.toString();
-    }
-
-    /* (non-Javadoc)
-     * @see org.biomoby.registry.definitions.types.JServiceI#getServicesAsArray()
-     */
-    public String[][] getServicesAsArray() {
-        ArrayList sb = new ArrayList();
-        /*ensure connection is not null*/
-        if (connection == null)
-            return null;
-
-        ResultSet rs = null;
-        try {
-            Statement stmt = connection.createStatement();
-            rs = stmt.executeQuery(sql);
-        } catch (SQLException ex) {
-            // TODO - throw exception - Error in sql
-            return null;
-        }
-        try {
-            while (rs.next()) {
-                // Get the data from the row using the column index
-                sb.add(new String[] {rs.getString(1) , rs.getString(2), rs.getString(3), rs.getString(4)});
-            }
-        } catch (SQLException e) {
-            // TODO - throw exception - Database access error
-            return null;
-        }
-        String[][] array = new String[sb.size()][];
-        sb.toArray( array );
-        return array;
-    }
-    
-    public static void main(String[] args) throws MobyException {
-        System.out.println(new JServicesSqlImpl().getServicesAsArray());
-    }
+public final class JServicesSqlImpl implements JServiceI {
+	private static final String sql = "SELECT ot1.service_type, rt.relationship_type, ot2.service_type, ot1.description "
+			+ "FROM service as ot1, service_term2term as rt, service as ot2 "
+			+ "WHERE ot1.service_id = rt.service1_id and ot2.service_id = rt.service2_id order by ot1.service_type";
+
+	private static final String sql_all = "SELECT ot1.service_type, rt.relationship_type, ot2.service_type, ot1.description, ot1.service_lsid, ot1.authority, ot1.contact_email "
+			+ "FROM service as ot1, service_term2term as rt, service as ot2 "
+			+ "WHERE ot1.service_id = rt.service1_id and ot2.service_id = rt.service2_id order by ot1.service_type";
+
+	private Connection connection = null;
+
+	private final String newline = System.getProperty("line.separator");
+
+	/**
+	 * 
+	 * @throws MobyException
+	 *             if database driver cannot be found or there is an database
+	 *             access error.
+	 */
+	public JServicesSqlImpl() throws MobyException {
+		try {
+			// Load the JDBC driver
+			String driverName = "com.mysql.jdbc.Driver";
+			Class.forName(driverName);
+			// get certain properties from mobycentral.config
+			Map map = MobyCentralConfig.getMobyService();
+			// Create a connection to the database
+			String serverName = map.get("url") + ":" + map.get("port");// localhost:3306";
+																		// //TODO
+																		// -
+																		// make
+																		// this
+																		// a
+																		// property
+			String mydatabase = (String) map.get("dbname");// "mobyobject";
+			String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
+			String username = (String) map.get("username");// "moby_external";
+			String password = (String) map.get("password");// "";
+
+			/*
+			 * String serverName = "mobycentral.icapture.ubc.ca:3306"; String
+			 * mydatabase = "mobyservice"; String url = "jdbc:mysql://" +
+			 * serverName + "/" + mydatabase; String username = "moby_external";
+			 * String password = "";
+			 */
+			this.connection = DriverManager.getConnection(url, username, password);
+		} catch (ClassNotFoundException e) {
+			throw new MobyException(
+					"Could not find database driver. Please ensure that you have the right libraries present");
+		} catch (SQLException e) {
+			e.printStackTrace();
+			throw new MobyException("Database access error.");
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.biomoby.registry.definitions.types.JServiceI#getServices()
+	 */
+	public final String getServices() {
+		StringBuffer sb = new StringBuffer();
+		/* ensure connection is not null */
+		if (connection == null)
+			return "";
+
+		ResultSet rs = null;
+		try {
+			Statement stmt = connection.createStatement();
+			rs = stmt.executeQuery(sql);
+		} catch (SQLException ex) {
+			// TODO - throw exception - Error in sql
+			return ex.getMessage();
+		}
+		try {
+			while (rs.next()) {
+				// Get the data from the row using the column index
+				sb.append(rs.getString(1) + "\t" + rs.getString(2) + "\t" + rs.getString(3) + "\t"
+						+ rs.getString(4) + newline);
+			}
+		} catch (SQLException e) {
+			// TODO - throw exception - Database access error
+			return e.getMessage();
+		}
+		return sb.toString();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.biomoby.registry.definitions.types.JServiceI#getServicesAsArray()
+	 */
+	public String[][] getServicesAsArray() {
+		ArrayList sb = new ArrayList();
+		/* ensure connection is not null */
+		if (connection == null)
+			return null;
+
+		ResultSet rs = null;
+		try {
+			Statement stmt = connection.createStatement();
+			rs = stmt.executeQuery(sql);
+		} catch (SQLException ex) {
+			// TODO - throw exception - Error in sql
+			return null;
+		}
+		try {
+			while (rs.next()) {
+				// Get the data from the row using the column index
+				sb.add(new String[] { rs.getString(1), rs.getString(2), rs.getString(3),
+						rs.getString(4) });
+			}
+		} catch (SQLException e) {
+			// TODO - throw exception - Database access error
+			return null;
+		}
+		String[][] array = new String[sb.size()][];
+		sb.toArray(array);
+		return array;
+	}
+
+	/**
+	 * Get all the data in the db regrading service types.
+	 * @return an array of String[] objects. The String[] consists of
+	 *         {service_type, relationship_type, to_service_type, description, service_lsid, authority,
+	 *         contact_email}. <em>Note that relationship_type is the relationship that service_type has
+	 *         with to_service_type.</em>
+	 */
+	public String[][] getFullServicesAsArray() {
+		ArrayList sb = new ArrayList();
+		/* ensure connection is not null */
+		if (connection == null)
+			return null;
+
+		ResultSet rs = null;
+		try {
+			Statement stmt = connection.createStatement();
+			rs = stmt.executeQuery(sql_all);
+		} catch (SQLException ex) {
+			// TODO - throw exception - Error in sql
+			return null;
+		}
+		try {
+			while (rs.next()) {
+				// Get the data from the row using the column index
+				sb.add(new String[] { rs.getString(1), rs.getString(2), rs.getString(3),
+						rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7) });
+			}
+		} catch (SQLException e) {
+			// TODO - throw exception - Database access error
+			return null;
+		}
+		String[][] array = new String[sb.size()][];
+		sb.toArray(array);
+		return array;
+	}
+
+	public static void main(String[] args) throws MobyException {
+		String[][] services = new JServicesSqlImpl().getFullServicesAsArray();
+		for (int i = 0; i < services.length; i++) {
+			String[] service = services[i];
+			for (int j = 0; j < service.length; j++) {
+				System.out.print(service[j] + " ");
+			}
+			System.out.println();
+		}
+	}
 }

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/definitions/types/JNamespacesSqlImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/definitions/types/JNamespacesSqlImpl.java	2006/03/14 16:11:43	1.2
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/definitions/types/JNamespacesSqlImpl.java	2006/03/14 16:23:06	1.3
@@ -16,149 +16,165 @@
 import org.biomoby.shared.MobyException;
 
 /**
- * @author Eddie Kawas
- * mySQL implementation of JNamespaceI.
- * <p>email me at edward.kawas at gmail.com
+ * @author Eddie Kawas mySQL implementation of JNamespaceI.
+ *         <p>
+ *         email me at edward.kawas at gmail.com
  */
-public final class JNamespacesSqlImpl implements JNamespaceI{
-    private static final String sql = "SELECT namespace_type, description FROM namespace ORDER BY namespace_type asc";
-    
-    private static final String sql_all = "SELECT namespace_type, description, namespace_lsid, authority, contact_email FROM namespace ORDER BY namespace_type asc";
-
-    private final String newline = System.getProperty("line.separator");
-
-    private Connection connection = null;
-
-    /**
-     * 
-     * @throws MobyException if database driver cannot be found or there is an database access error.
-     */
-    public JNamespacesSqlImpl() throws MobyException {
-        try {
-            // Load the JDBC driver
-            String driverName = "com.mysql.jdbc.Driver";
-            Class.forName(driverName);
-            // get certain properties from mobycentral.config
-            Map map = MobyCentralConfig.getMobyNamespace();
-            // Create a connection to the database
-            String serverName = map.get("url") + ":" + map.get("port");//localhost:3306"; //TODO - make this a property
-            String mydatabase = (String) map.get("dbname");//"mobyobject";
-            String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
-            String username = (String) map.get("username");//"moby_external";
-            String password = (String) map.get("password");//"";
-
-                 /*       String serverName = "mobycentral.icapture.ubc.ca:3306";
-             String mydatabase = "mobynamespace";
-             String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
-             String username = "moby_external";
-             String password = "";*/
-            this.connection = DriverManager.getConnection(url, username,
-                    password);
-        } catch (ClassNotFoundException e) {
-            throw new MobyException(
-                    "Could not find database driver. Please ensure that you have the right libraries present");
-        } catch (SQLException e) {
-            e.printStackTrace();
-            throw new MobyException("Database access error.");
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see org.biomoby.registry.definitions.types.JNamespaceI#getNamespaces()
-     */
-    public final String getNamespaces() {
-        /*ensure that the connection isnt null*/
-        if (connection == null)
-            return "";
-
-        StringBuffer sb = new StringBuffer();
-        ResultSet rs = null;
-        try {
-            Statement stmt = connection.createStatement();
-            rs = stmt.executeQuery(sql);
-        } catch (SQLException ex) {
-            // TODO - throw exception - Error in sql
-            return ex.getMessage();
-        }
-        try {
-            while (rs.next()) {
-                // Get the data from the row using the column index
-                sb.append(rs.getString(1) + "\t" + rs.getString(2) + newline);
-            }
-        } catch (SQLException e) {
-            // TODO - throw exception - Database access error
-            return e.getMessage();
-        }
-        return sb.toString();
-    }
-
-    /* (non-Javadoc)
-     * @see org.biomoby.registry.definitions.types.JNamespaceI#getNamespacesAsArray()
-     */
-    public String[][] getNamespacesAsArray() {
-        /*ensure that the connection isnt null*/
-        if (connection == null)
-            return null;
-
-        ArrayList sb = new ArrayList();
-        ResultSet rs = null;
-        try {
-            Statement stmt = connection.createStatement();
-            rs = stmt.executeQuery(sql);
-        } catch (SQLException ex) {
-            return null;
-        }
-        try {
-            while (rs.next()) {
-                // Get the data from the row using the column index
-                sb.add(new String[]{ rs.getString(1), rs.getString(2)});
-            }
-        } catch (SQLException e) {
-            return null;
-        }
-        String[][] array = new String[sb.size()][];
-        sb.toArray(array);
-        return array;
-    }
-    
-    /**
-     * Get all the data in the db regrading namespaces.
-     * @return 
-     */
-    public String[][] getFullNamespacesAsArray() {
-        /*ensure that the connection isnt null*/
-        if (connection == null)
-            return null;
-
-        ArrayList sb = new ArrayList();
-        ResultSet rs = null;
-        try {
-            Statement stmt = connection.createStatement();
-            rs = stmt.executeQuery(sql_all);
-        } catch (SQLException ex) {
-            return null;
-        }
-        try {
-            while (rs.next()) {
-                // Get the data from the row using the column index
-                sb.add(new String[]{ rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5)});
-            }
-        } catch (SQLException e) {
-            return null;
-        }
-        String[][] array = new String[sb.size()][];
-        sb.toArray(array);
-        return array;
-    }
-    
-    public static void main(String[] args) throws MobyException {
-    	String[][] namespaces =new JNamespacesSqlImpl().getFullNamespacesAsArray();
-    	for (int i = 0; i < namespaces.length; i++) {
-    		String[] namespace = namespaces[i];
-    		for (int j = 0; j < namespace.length; j++) {
-    			System.out.print(namespace[j] + " ");
+public final class JNamespacesSqlImpl implements JNamespaceI {
+	private static final String sql = "SELECT namespace_type, description FROM namespace ORDER BY namespace_type asc";
+
+	private static final String sql_all = "SELECT namespace_type, description, namespace_lsid, authority, contact_email FROM namespace ORDER BY namespace_type asc";
+
+	private final String newline = System.getProperty("line.separator");
+
+	private Connection connection = null;
+
+	/**
+	 * 
+	 * @throws MobyException
+	 *             if database driver cannot be found or there is an database
+	 *             access error.
+	 */
+	public JNamespacesSqlImpl() throws MobyException {
+		try {
+			// Load the JDBC driver
+			String driverName = "com.mysql.jdbc.Driver";
+			Class.forName(driverName);
+			// get certain properties from mobycentral.config
+			Map map = MobyCentralConfig.getMobyNamespace();
+			// Create a connection to the database
+			String serverName = map.get("url") + ":" + map.get("port");// localhost:3306";
+																		// //TODO
+																		// -
+																		// make
+																		// this
+																		// a
+																		// property
+			String mydatabase = (String) map.get("dbname");// "mobyobject";
+			String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
+			String username = (String) map.get("username");// "moby_external";
+			String password = (String) map.get("password");// "";
+
+			/*
+			 * String serverName = "mobycentral.icapture.ubc.ca:3306"; String
+			 * mydatabase = "mobynamespace"; String url = "jdbc:mysql://" +
+			 * serverName + "/" + mydatabase; String username = "moby_external";
+			 * String password = "";
+			 */
+			this.connection = DriverManager.getConnection(url, username, password);
+		} catch (ClassNotFoundException e) {
+			throw new MobyException(
+					"Could not find database driver. Please ensure that you have the right libraries present");
+		} catch (SQLException e) {
+			e.printStackTrace();
+			throw new MobyException("Database access error.");
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.biomoby.registry.definitions.types.JNamespaceI#getNamespaces()
+	 */
+	public final String getNamespaces() {
+		/* ensure that the connection isnt null */
+		if (connection == null)
+			return "";
+
+		StringBuffer sb = new StringBuffer();
+		ResultSet rs = null;
+		try {
+			Statement stmt = connection.createStatement();
+			rs = stmt.executeQuery(sql);
+		} catch (SQLException ex) {
+			// TODO - throw exception - Error in sql
+			return ex.getMessage();
+		}
+		try {
+			while (rs.next()) {
+				// Get the data from the row using the column index
+				sb.append(rs.getString(1) + "\t" + rs.getString(2) + newline);
+			}
+		} catch (SQLException e) {
+			// TODO - throw exception - Database access error
+			return e.getMessage();
+		}
+		return sb.toString();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.biomoby.registry.definitions.types.JNamespaceI#getNamespacesAsArray()
+	 */
+	public String[][] getNamespacesAsArray() {
+		/* ensure that the connection isnt null */
+		if (connection == null)
+			return null;
+
+		ArrayList sb = new ArrayList();
+		ResultSet rs = null;
+		try {
+			Statement stmt = connection.createStatement();
+			rs = stmt.executeQuery(sql);
+		} catch (SQLException ex) {
+			return null;
+		}
+		try {
+			while (rs.next()) {
+				// Get the data from the row using the column index
+				sb.add(new String[] { rs.getString(1), rs.getString(2) });
+			}
+		} catch (SQLException e) {
+			return null;
+		}
+		String[][] array = new String[sb.size()][];
+		sb.toArray(array);
+		return array;
+	}
+
+	/**
+	 * Get all the data in the db regrading namespaces.
+	 * 
+	 * @return an array of String[] objects. The String[] consists of
+	 *         {namespace_type, description, namespace_lsid, authority,
+	 *         contact_email}.
+	 */
+	public String[][] getFullNamespacesAsArray() {
+		/* ensure that the connection isnt null */
+		if (connection == null)
+			return null;
+
+		ArrayList sb = new ArrayList();
+		ResultSet rs = null;
+		try {
+			Statement stmt = connection.createStatement();
+			rs = stmt.executeQuery(sql_all);
+		} catch (SQLException ex) {
+			return null;
+		}
+		try {
+			while (rs.next()) {
+				// Get the data from the row using the column index
+				sb.add(new String[] { rs.getString(1), rs.getString(2), rs.getString(3),
+						rs.getString(4), rs.getString(5) });
+			}
+		} catch (SQLException e) {
+			return null;
+		}
+		String[][] array = new String[sb.size()][];
+		sb.toArray(array);
+		return array;
+	}
+
+	public static void main(String[] args) throws MobyException {
+		String[][] namespaces = new JNamespacesSqlImpl().getFullNamespacesAsArray();
+		for (int i = 0; i < namespaces.length; i++) {
+			String[] namespace = namespaces[i];
+			for (int j = 0; j < namespace.length; j++) {
+				System.out.print(namespace[j] + " ");
 			}
-    		System.out.println();
-    	}
-    }
+			System.out.println();
+		}
+	}
 }




More information about the MOBY-guts mailing list