/* * DataSource.java * * Created on January 23, 2001, 4:44 PM */ package uk.ac.leeds.ccg.sfsql; import java.sql.*; import uk.ac.leeds.ccg.simplefeature.*; /** * * @author jamesm * @version */ public class DataSource extends Object { String url; private final static boolean DEBUG=true; Connection con; GeometryMetadata gm[]; GeometryTable gt; /** Creates new DataSource */ public DataSource(Connection con)throws SQLException{ SpatialReferenceSystemTable srst = new SpatialReferenceSystemTable(con); GeometryMetadataTable gmt = new GeometryMetadataTable(con); gm = gmt.getMetadata(); gt = new GeometryTable(con,gm[0]); } public DataSource(String url) { if(DEBUG)System.out.println("---->uk.ac.leeds.ccg.sfsql.DataSource constructed. Will identify itself as DaS->"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(java.lang.ClassNotFoundException e) { System.err.print("DaS->ClassNotFoundException: "); System.err.println("DaS->"+e.getMessage()); } try{ con = DriverManager.getConnection(url, "", ""); if(DEBUG)System.out.println("DaS->SpatialReferenceTable"); SpatialReferenceSystemTable srst = new SpatialReferenceSystemTable(con); GeometryMetadataTable gmt = new GeometryMetadataTable(con); gm = gmt.getMetadata(); gt = new GeometryTable(con,gm[0]); /*for(int i=0;i<50;i++){ System.out.println("Fetching "+i); gt.getGeometry(i); }*/ } catch(SQLException e){ System.err.println("DaS->"+e); e.printStackTrace(); } } public Geometry getGeometry(int id) throws SQLException { return gt.getGeometry(id); } public int getGeometryType(){ return gm[0].getGeometryType(); } public int[] getIds() throws SQLException { return gm[0].getIds(); } }