1 22 23 package org.xquark.extractor.sybase; 24 25 import java.lang.reflect.InvocationTargetException ; 26 import java.lang.reflect.Method ; 27 import java.sql.*; 28 import java.sql.Connection ; 29 import java.sql.PreparedStatement ; 30 import java.sql.SQLException ; 31 32 import org.xquark.extractor.metadata.QNameEncoder; 33 import org.xquark.jdbc.typing.DBMSInfo; 34 35 36 public final class Loader extends org.xquark.extractor.metadata.Loader { 37 38 private static final String RCSRevision = "$Revision: 1.6 $"; 39 private static final String RCSName = "$Name: $"; 40 41 public Loader(Connection connection, DBMSInfo dbmsInfo, QNameEncoder encoder) 42 throws SQLException { 43 super(connection, dbmsInfo, encoder); 44 } 45 46 protected String getDefaultSchema() throws SQLException { 47 Statement statement = null; 48 ResultSet rs = null; 49 try { 50 statement = _connection.createStatement(); 51 rs = statement.executeQuery("select user"); 52 rs.next(); 53 return rs.getString(1); 54 } finally { 55 if (rs != null) rs.close(); 56 if (statement != null) statement.close(); 57 } 58 } 59 60 protected String createQuery(String catalogName, String schemaName, String origTableName){ 61 StringBuffer retVal = new StringBuffer (); 62 63 retVal.append("SELECT * FROM "); 64 if (null != catalogName && 0 < catalogName.trim().length()) { 65 retVal.append(catalogName.trim()); 66 retVal.append('.'); 67 } 68 if (null != schemaName && 0 < schemaName.trim().length()) { 69 retVal.append(schemaName.trim()); 70 retVal.append('.'); 71 } 72 if (null != origTableName && 0 < origTableName.trim().length()) { 73 retVal.append(origTableName.trim()); 74 } 75 retVal.append(" WHERE 0=1"); 76 return retVal.toString(); 77 } 78 79 protected PreparedStatement createPreparedStatement(Connection jdbcConnection,String command) throws SQLException { 80 try { 81 Class [] argTypes = { String .class, Boolean.TYPE }; 82 Method method = jdbcConnection.getClass().getMethod("prepareStatement", argTypes); 83 Object [] args = { command, Boolean.TRUE }; 84 return (PreparedStatement )method.invoke(jdbcConnection, args); 85 } catch (InvocationTargetException ex) { 86 throw (SQLException )ex.getTargetException(); 87 } catch (IllegalAccessException ex) { 88 throw new SQLException ("Could not create prepared statement"); 89 } catch (NoSuchMethodException ex) { 90 throw new SQLException ("Could not create prepared statement"); 91 } 92 } 93 94 } 95 | Popular Tags |