From: David J. <d_j...@us...> - 2001-06-14 04:48:05
|
Update of /cvsroot/firebird/client-java/src/org/firebirdsql/jdbc In directory usw-pr-cvs1:/tmp/cvs-serv7418/org/firebirdsql/jdbc Modified Files: FBCallableStatement.java FBConnection.java FBDataSource.java FBPreparedStatement.java FBResultSet.java FBResultSetMetaData.java FBRowSet.java FBRowSetMetaData.java FBStatement.java Log Message: Checkin of partly working hybrid jca/jdbc driver. Datasource as ConnectionFactory for managed connection factory works, connections obtained are nearly jdbc connections: statement and prepared statement work, resultset works except for fancy fields like blobs, however transactions must be managed via connection.getLocalTransaction() similar to a javax.resource.cci.Connection. TestDBStandAloneConnectionManager shows how to set up and use the datasource. Index: FBCallableStatement.java =================================================================== RCS file: /cvsroot/firebird/client-java/src/org/firebirdsql/jdbc/FBCallableStatement.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -U3 -r1.1.1.1 -r1.2 --- FBCallableStatement.java 2001/05/09 14:28:23 1.1.1.1 +++ FBCallableStatement.java 2001/06/14 04:48:01 1.2 @@ -37,8 +37,10 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; +import org.firebirdsql.jca.FBManagedConnection; + /** * * @see <related> @@ -82,6 +84,10 @@ * @see ResultSet */ public class FBCallableStatement extends FBPreparedStatement implements CallableStatement { + + FBCallableStatement(FBConnection c, String sql) throws SQLException { + super(c, sql); + } /** * Registers the OUT parameter in ordinal position Index: FBConnection.java =================================================================== RCS file: /cvsroot/firebird/client-java/src/org/firebirdsql/jdbc/FBConnection.java,v retrieving revision 1.2 retrieving revision 1.3 diff -U3 -r1.2 -r1.3 --- FBConnection.java 2001/05/25 19:52:52 1.2 +++ FBConnection.java 2001/06/14 04:48:01 1.3 @@ -34,6 +34,9 @@ import java.sql.SQLWarning; import java.sql.Statement; +import javax.resource.cci.LocalTransaction; + +import org.firebirdsql.jca.FBLocalTransaction; import org.firebirdsql.jca.FBManagedConnection; //import javax.resource.cci.Connection;--can't import, two classes with same name. @@ -74,6 +77,8 @@ FBManagedConnection mc; + FBLocalTransaction localTransaction = null; + public FBConnection(FBManagedConnection mc) { this.mc = mc; } @@ -98,7 +103,7 @@ * @exception SQLException if a database access error occurs */ public Statement createStatement() throws SQLException { - return new FBStatement(mc); + return new FBStatement(this); } @@ -133,7 +138,7 @@ */ public PreparedStatement prepareStatement(String sql) throws SQLException { - return null; + return new FBPreparedStatement(this, sql); } @@ -261,7 +266,9 @@ * * @exception SQLException if a database access error occurs */ - public void close() throws SQLException { + public void close() { + mc.close(this); + mc = null; } @@ -271,8 +278,8 @@ * @return true if the connection is closed; false if it's still open * @exception SQLException if a database access error occurs */ - public boolean isClosed() throws SQLException { - throw new SQLException("Not yet implemented"); + public boolean isClosed() { + return mc == null; } @@ -540,6 +547,16 @@ * @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a> */ public void setTypeMap(java.util.Map map) throws SQLException { + } + + //------------------------------------------- + //Borrowed from javax.resource.cci.Connection + + public FBLocalTransaction getLocalTransaction() { + if (localTransaction == null) { + localTransaction = new FBLocalTransaction(mc, this); + } + return localTransaction; } } Index: FBDataSource.java =================================================================== RCS file: /cvsroot/firebird/client-java/src/org/firebirdsql/jdbc/FBDataSource.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -U3 -r1.1.1.1 -r1.2 --- FBDataSource.java 2001/05/09 14:26:50 1.1.1.1 +++ FBDataSource.java 2001/06/14 04:48:01 1.2 @@ -26,10 +26,19 @@ // imports -------------------------------------- +import org.firebirdsql.jca.FBConnectionRequestInfo; +import org.firebirdsql.jca.FBManagedConnectionFactory; + +import java.io.PrintWriter; import java.io.Serializable; import java.sql.Connection; import javax.sql.DataSource; import java.sql.SQLException; +import javax.naming.Reference; +import javax.resource.Referenceable; +import javax.resource.ResourceException; +import javax.resource.spi.ConnectionManager; +import javax.resource.spi.ManagedConnectionFactory; /** @@ -50,8 +59,33 @@ */ -public class FBDataSource implements DataSource { +public class FBDataSource implements DataSource, Serializable, Referenceable { + + transient private ConnectionManager cm; + + transient private FBManagedConnectionFactory mcf; + + transient private PrintWriter log; + + private Reference jndiReference; + + private int loginTimeout = 0; + + public FBDataSource(FBManagedConnectionFactory mcf, ConnectionManager cm) { + this.mcf = mcf; + this.cm = cm; + } + + public void setReference(Reference ref) { + this.jndiReference = ref; + } + + public Reference getReference() { + return jndiReference; + } + + /** * <p>Attempt to establish a database connection. * @@ -59,7 +93,12 @@ * @exception SQLException if a database-access error occurs. */ public Connection getConnection() throws SQLException { - throw new SQLException("Not yet implemented"); + try { + return (Connection)cm.allocateConnection(mcf, mcf.getDefaultConnectionRequestInfo()); + } + catch (ResourceException re) { + throw new SQLException("Problem getting connection: " + re); + } } @@ -73,7 +112,15 @@ * @exception SQLException if a database-access error occurs. */ public Connection getConnection(String username, String password) throws SQLException { - throw new SQLException("Not yet implemented"); + try { + FBConnectionRequestInfo subjectCri = new FBConnectionRequestInfo(mcf.getDefaultConnectionRequestInfo()); + subjectCri.setUser(username); + subjectCri.setPassword(password); + return (Connection)cm.allocateConnection(mcf, subjectCri); + } + catch (ResourceException re) { + throw new SQLException("Problem getting connection: " + re); + } } @@ -94,7 +141,7 @@ * @exception SQLException if a database-access error occurs. */ public java.io.PrintWriter getLogWriter() throws SQLException { - throw new SQLException("Not yet implemented"); + return log; } @@ -115,7 +162,7 @@ * @exception SQLException if a database-access error occurs. */ public void setLogWriter(java.io.PrintWriter out) throws SQLException { - throw new SQLException("Not yet implemented"); + log = out; } @@ -131,7 +178,7 @@ * @exception SQLException if a database access error occurs. */ public void setLoginTimeout(int seconds) throws SQLException { - throw new SQLException("Not yet implemented"); + loginTimeout = seconds; } @@ -147,7 +194,7 @@ * @exception SQLException if a database access error occurs. */ public int getLoginTimeout() throws SQLException { - throw new SQLException("Not yet implemented"); + return loginTimeout; } Index: FBPreparedStatement.java =================================================================== RCS file: /cvsroot/firebird/client-java/src/org/firebirdsql/jdbc/FBPreparedStatement.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -U3 -r1.1.1.1 -r1.2 --- FBPreparedStatement.java 2001/05/09 14:28:08 1.1.1.1 +++ FBPreparedStatement.java 2001/06/14 04:48:01 1.2 @@ -26,6 +26,11 @@ // imports -------------------------------------- + +import org.firebirdsql.gds.GDS; +import org.firebirdsql.gds.GDSException; +import org.firebirdsql.gds.XSQLVAR; +import org.firebirdsql.jca.FBManagedConnection; import java.math.BigDecimal; import java.util.Calendar; @@ -76,6 +81,20 @@ */ public class FBPreparedStatement extends FBStatement implements PreparedStatement { + + FBPreparedStatement(FBConnection c, String sql) throws SQLException { + super(c); + try { + if (fixedStmt == null) { + fixedStmt = mc.getAllocatedStatement(); + } + mc.prepareSQL(fixedStmt, sql, true); + } + catch (GDSException ge) { + throw new SQLException("GDS exception: " + ge.toString()); + } + + } /** * Executes the SQL query in this <code>PreparedStatement</code> object @@ -86,7 +105,10 @@ * @exception SQLException if a database access error occurs */ public ResultSet executeQuery() throws SQLException { - throw new SQLException("Not yet implemented"); + if (!execute()) { + throw new SQLException("No resultset for sql"); + } + return getResultSet(); } @@ -102,7 +124,10 @@ * @exception SQLException if a database access error occurs */ public int executeUpdate() throws SQLException { - throw new SQLException("Not yet implemented"); + if (execute()) { + throw new SQLException("update statement returned results!"); + } + return getUpdateCount(); } @@ -116,7 +141,8 @@ * @exception SQLException if a database access error occurs */ public void setNull(int parameterIndex, int sqlType) throws SQLException { - throw new SQLException("Not yet implemented"); + fixedStmt.getInSqlda().sqlvar[parameterIndex - 1].sqlind = -1; + fixedStmt.getInSqlda().sqlvar[parameterIndex - 1].sqldata = null; } @@ -130,7 +156,9 @@ * @exception SQLException if a database access error occurs */ public void setBoolean(int parameterIndex, boolean x) throws SQLException { - throw new SQLException("Not yet implemented"); + fixedStmt.getInSqlda().sqlvar[parameterIndex - 1].sqlind = 0; + //not quite + fixedStmt.getInSqlda().sqlvar[parameterIndex - 1].sqldata = new Boolean(x); } @@ -144,7 +172,8 @@ * @exception SQLException if a database access error occurs */ public void setByte(int parameterIndex, byte x) throws SQLException { - throw new SQLException("Not yet implemented"); + fixedStmt.getInSqlda().sqlvar[parameterIndex - 1].sqlind = 0; +//not quite fixedStmt.getInSqlda().sqlvar[parameterIndex - 1].sqldata = x; } @@ -158,7 +187,12 @@ * @exception SQLException if a database access error occurs */ public void setShort(int parameterIndex, short x) throws SQLException { - throw new SQLException("Not yet implemented"); + XSQLVAR sqlvar = fixedStmt.getInSqlda().sqlvar[parameterIndex - 1]; + if ((sqlvar.sqltype & ~1) != GDS.SQL_SHORT) { + throw new SQLException("Not a short, type: " + sqlvar.sqltype); + } + sqlvar.sqlind = 0; + sqlvar.sqldata = new Short(x); } @@ -172,7 +206,12 @@ * @exception SQLException if a database access error occurs */ public void setInt(int parameterIndex, int x) throws SQLException { - throw new SQLException("Not yet implemented"); + XSQLVAR sqlvar = fixedStmt.getInSqlda().sqlvar[parameterIndex - 1]; + if ((sqlvar.sqltype & ~1) != GDS.SQL_LONG) { + throw new SQLException("Not an int, type: " + sqlvar.sqltype); + } + sqlvar.sqlind = 0; + sqlvar.sqldata = new Integer(x); } @@ -186,7 +225,12 @@ * @exception SQLException if a database access error occurs */ public void setLong(int parameterIndex, long x) throws SQLException { - throw new SQLException("Not yet implemented"); + XSQLVAR sqlvar = fixedStmt.getInSqlda().sqlvar[parameterIndex - 1]; + if ((sqlvar.sqltype & ~1) != GDS.SQL_INT64) { + throw new SQLException("Not a long, type: " + sqlvar.sqltype); + } + sqlvar.sqlind = 0; + sqlvar.sqldata = new Long(x); } @@ -200,7 +244,12 @@ * @exception SQLException if a database access error occurs */ public void setFloat(int parameterIndex, float x) throws SQLException { - throw new SQLException("Not yet implemented"); + XSQLVAR sqlvar = fixedStmt.getInSqlda().sqlvar[parameterIndex - 1]; + if ((sqlvar.sqltype & ~1) != GDS.SQL_FLOAT) { + throw new SQLException("Not a float field, type: " + sqlvar.sqltype); + } + sqlvar.sqlind = 0; + sqlvar.sqldata = new Float(x); } @@ -214,7 +263,12 @@ * @exception SQLException if a database access error occurs */ public void setDouble(int parameterIndex, double x) throws SQLException { - throw new SQLException("Not yet implemented"); + XSQLVAR sqlvar = fixedStmt.getInSqlda().sqlvar[parameterIndex - 1]; + if ((sqlvar.sqltype & ~1) != GDS.SQL_DOUBLE) { + throw new SQLException("Not a double, type: " + sqlvar.sqltype); + } + sqlvar.sqlind = 0; + sqlvar.sqldata = new Double(x); } @@ -228,7 +282,13 @@ * @exception SQLException if a database access error occurs */ public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { - throw new SQLException("Not yet implemented"); + XSQLVAR sqlvar = fixedStmt.getInSqlda().sqlvar[parameterIndex - 1]; + if ((sqlvar.sqltype & ~1) != GDS.SQL_INT64) { + throw new SQLException("Not a BigDecimal, type: " + sqlvar.sqltype); + } + sqlvar.sqlind = 0; + //not quite + sqlvar.sqldata = x; } @@ -245,7 +305,12 @@ * @exception SQLException if a database access error occurs */ public void setString(int parameterIndex, String x) throws SQLException { - throw new SQLException("Not yet implemented"); + XSQLVAR sqlvar = fixedStmt.getInSqlda().sqlvar[parameterIndex - 1]; + if (((sqlvar.sqltype & ~1) != GDS.SQL_TEXT) && ((sqlvar.sqltype & ~1) != GDS.SQL_VARYING)){ + throw new SQLException("Not a String, type: " + sqlvar.sqltype); + } + sqlvar.sqlind = 0; + sqlvar.sqldata = x; } @@ -387,6 +452,9 @@ * @exception SQLException if a database access error occurs */ public void clearParameters() throws SQLException { + for (int i = 1; i <= fixedStmt.getInSqlda().sqln; i++) { + setNull(i, 0); + } } @@ -486,7 +554,14 @@ * @see Statement#execute */ public boolean execute() throws SQLException { - throw new SQLException("Not yet implemented"); + try { + closeResultSet(); + mc.executeStatement(fixedStmt); + return (fixedStmt.getOutSqlda().sqld > 0); + } + catch (GDSException ge) { + throw new SQLException("GDS exception: " + ge.toString()); + } } @@ -605,7 +680,7 @@ * 2.0 API</a> */ public ResultSetMetaData getMetaData() throws SQLException { - throw new SQLException("Not yet implemented"); + return new FBResultSetMetaData(fixedStmt); } @@ -709,6 +784,7 @@ * 2.0 API</a> */ public void setNull (int paramIndex, int sqlType, String typeName) throws SQLException { + setNull(paramIndex, sqlType); //all nulls are represented the same... a null reference } } Index: FBResultSet.java =================================================================== RCS file: /cvsroot/firebird/client-java/src/org/firebirdsql/jdbc/FBResultSet.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -U3 -r1.1.1.1 -r1.2 --- FBResultSet.java 2001/05/09 14:25:45 1.1.1.1 +++ FBResultSet.java 2001/06/14 04:48:01 1.2 @@ -39,7 +39,13 @@ import java.sql.SQLWarning; import java.sql.Statement; +import org.firebirdsql.gds.GDS; +import org.firebirdsql.gds.GDSException; +import org.firebirdsql.gds.isc_stmt_handle; +import org.firebirdsql.gds.XSQLVAR; +import org.firebirdsql.jca.FBManagedConnection; + /** * * @see <related> @@ -230,6 +236,25 @@ */ public class FBResultSet implements ResultSet { + + private FBManagedConnection mc; + + private FBStatement fbstatement; + + private isc_stmt_handle stmt; + + private Object[] row = null; + + private int rowNum = 0; + + FBResultSet(FBManagedConnection mc, FBStatement fbstatement, isc_stmt_handle stmt) { + this.mc = mc; + this.fbstatement = fbstatement; + this.stmt = stmt; + mc.registerStatement(fbstatement); + } + + /** * Moves the cursor down one row from its current position. @@ -248,7 +273,13 @@ * @exception SQLException if a database access error occurs */ public boolean next() throws SQLException { - throw new SQLException("Not yet implemented"); + try { + row = mc.fetch(stmt); + return (row != null); + } + catch (GDSException ge) { + throw new SQLException("fetch problem: " + ge.toString()); + } } @@ -269,7 +300,7 @@ * @exception SQLException if a database access error occurs */ public void close() throws SQLException { - throw new SQLException("Not yet implemented"); + fbstatement.closeResultSet(); } @@ -305,7 +336,11 @@ * @exception SQLException if a database access error occurs */ public String getString(int columnIndex) throws SQLException { - throw new SQLException("Not yet implemented"); + if (((getXsqlvar(columnIndex).sqltype & ~1) != GDS.SQL_TEXT) + &&((getXsqlvar(columnIndex).sqltype & ~1) != GDS.SQL_VARYING)) { + throw new SQLException("Wrong type for column " + columnIndex + "type should be" + getXsqlvar(columnIndex).sqltype); + } + return (String)row[columnIndex - 1]; } @@ -350,7 +385,13 @@ * @exception SQLException if a database access error occurs */ public short getShort(int columnIndex) throws SQLException { - throw new SQLException("Not yet implemented"); + if ((getXsqlvar(columnIndex).sqltype & ~1) != GDS.SQL_SHORT) { + throw new SQLException("Wrong type for column " + columnIndex + "type should be" + getXsqlvar(columnIndex).sqltype); + } + if (row[columnIndex - 1] == null) { + return 0; + } + return ((Short)row[columnIndex - 1]).shortValue(); } @@ -365,7 +406,13 @@ * @exception SQLException if a database access error occurs */ public int getInt(int columnIndex) throws SQLException { - throw new SQLException("Not yet implemented"); + if ((getXsqlvar(columnIndex).sqltype & ~1) != GDS.SQL_LONG) { + throw new SQLException("Wrong type for column " + columnIndex + "type should be" + getXsqlvar(columnIndex).sqltype); + } + if (row[columnIndex - 1] == null) { + return 0; + } + return ((Integer)row[columnIndex - 1]).intValue(); } @@ -380,7 +427,13 @@ * @exception SQLException if a database access error occurs */ public long getLong(int columnIndex) throws SQLException { - throw new SQLException("Not yet implemented"); + if ((getXsqlvar(columnIndex).sqltype & ~1) != GDS.SQL_INT64) { + throw new SQLException("Wrong type for column " + columnIndex + "type should be" + getXsqlvar(columnIndex).sqltype); + } + if (row[columnIndex - 1] == null) { + return 0; + } + return ((Long)row[columnIndex - 1]).longValue(); } @@ -395,7 +448,13 @@ * @exception SQLException if a database access error occurs */ public float getFloat(int columnIndex) throws SQLException { - throw new SQLException("Not yet implemented"); + if ((getXsqlvar(columnIndex).sqltype & ~1) != GDS.SQL_FLOAT) { + throw new SQLException("Wrong type for column " + columnIndex + "type should be" + getXsqlvar(columnIndex).sqltype); + } + if (row[columnIndex - 1] == null) { + return 0; + } + return ((Float)row[columnIndex - 1]).floatValue(); } @@ -410,14 +469,20 @@ * @exception SQLException if a database access error occurs */ public double getDouble(int columnIndex) throws SQLException { - throw new SQLException("Not yet implemented"); + if ((getXsqlvar(columnIndex).sqltype & ~1) != GDS.SQL_DOUBLE) { + throw new SQLException("Wrong type for column " + columnIndex + "type should be" + getXsqlvar(columnIndex).sqltype); + } + if (row[columnIndex - 1] == null) { + return 0; + } + return ((Double)row[columnIndex - 1]).doubleValue(); } /** * Gets the value of the designated column in the current row * of this <code>ResultSet</code> object as - * a <code>java.sql.BigDecimal</code> in the Java programming language. + * a <code>java.math.BigDecimal</code> in the Java programming language. * * @param columnIndex the first column is 1, the second is 2, ... * @param scale the number of digits to the right of the decimal point @@ -427,7 +492,14 @@ * @deprecated */ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { - throw new SQLException("Not yet implemented"); + if ((getXsqlvar(columnIndex).sqltype & ~1) != GDS.SQL_INT64) { + throw new SQLException("Wrong type for column " + columnIndex + "type should be" + getXsqlvar(columnIndex).sqltype); + } + if (row[columnIndex - 1] == null) { + return null; + } + //Is this the expected behavior???? Or do we move the decimal point? + return (BigDecimal.valueOf(((Long)row[columnIndex - 1]).longValue(), getXsqlvar(columnIndex).sqlscale)).setScale(scale); } @@ -594,7 +666,7 @@ * @exception SQLException if a database access error occurs */ public String getString(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getString(findColumn(columnName)); } @@ -609,7 +681,7 @@ * @exception SQLException if a database access error occurs */ public boolean getBoolean(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getBoolean(findColumn(columnName)); } @@ -624,7 +696,7 @@ * @exception SQLException if a database access error occurs */ public byte getByte(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getByte(findColumn(columnName)); } @@ -639,7 +711,7 @@ * @exception SQLException if a database access error occurs */ public short getShort(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getShort(findColumn(columnName)); } @@ -654,7 +726,7 @@ * @exception SQLException if a database access error occurs */ public int getInt(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getInt(findColumn(columnName)); } @@ -669,7 +741,7 @@ * @exception SQLException if a database access error occurs */ public long getLong(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getLong(findColumn(columnName)); } @@ -684,7 +756,7 @@ * @exception SQLException if a database access error occurs */ public float getFloat(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getFloat(findColumn(columnName)); } @@ -699,7 +771,7 @@ * @exception SQLException if a database access error occurs */ public double getDouble(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getDouble(findColumn(columnName)); } @@ -716,8 +788,8 @@ * @deprecated */ public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { - throw new SQLException("Not yet implemented"); - } + return getBigDecimal(findColumn(columnName), scale); + } /** @@ -732,7 +804,7 @@ * @exception SQLException if a database access error occurs */ public byte[] getBytes(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getBytes(findColumn(columnName)); } @@ -747,7 +819,7 @@ * @exception SQLException if a database access error occurs */ public java.sql.Date getDate(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getDate(findColumn(columnName)); } @@ -763,7 +835,7 @@ * @exception SQLException if a database access error occurs */ public java.sql.Time getTime(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getTime(findColumn(columnName)); } @@ -778,7 +850,7 @@ * @exception SQLException if a database access error occurs */ public java.sql.Timestamp getTimestamp(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getTimestamp(findColumn(columnName)); } @@ -805,7 +877,7 @@ * @exception SQLException if a database access error occurs */ public java.io.InputStream getAsciiStream(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getAsciiStream(findColumn(columnName)); } @@ -835,7 +907,7 @@ * @deprecated */ public java.io.InputStream getUnicodeStream(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getUnicodeStream(findColumn(columnName)); } @@ -861,7 +933,7 @@ * @exception SQLException if a database access error occurs */ public java.io.InputStream getBinaryStream(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getBinaryStream(findColumn(columnName)); } @@ -943,7 +1015,7 @@ * @exception SQLException if a database access error occurs */ public ResultSetMetaData getMetaData() throws SQLException { - throw new SQLException("Not yet implemented"); + return new FBResultSetMetaData(stmt); } @@ -973,7 +1045,10 @@ * @exception SQLException if a database access error occurs */ public Object getObject(int columnIndex) throws SQLException { - throw new SQLException("Not yet implemented"); + if (row == null) { + throw new SQLException("No row fetched"); + } + return row[columnIndex - 1]; } @@ -1003,7 +1078,7 @@ * @exception SQLException if a database access error occurs */ public Object getObject(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getObject(findColumn(columnName)); } @@ -1018,7 +1093,21 @@ * @exception SQLException if a database access error occurs */ public int findColumn(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + if (columnName == null || columnName.equals("")) { + throw new SQLException("zero length identifiers not allowed"); + } + XSQLVAR[] xsqlvars = stmt.getOutSqlda().sqlvar; + for (int i = 0; i< xsqlvars.length; i++) { + if (columnName.equals(xsqlvars[i].aliasname)) { + return ++i; + } + } + for (int i = 0; i< xsqlvars.length; i++) { + if (columnName.equals(xsqlvars[i].sqlname)) { + return ++i; + } + } + throw new SQLException("column name " + columnName + " not found in result set."); } @@ -1061,7 +1150,7 @@ * 2.0 API</a> */ public java.io.Reader getCharacterStream(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getCharacterStream(findColumn(columnName)); } @@ -1080,7 +1169,13 @@ * 2.0 API</a> */ public BigDecimal getBigDecimal(int columnIndex) throws SQLException { - throw new SQLException("Not yet implemented"); + if ((getXsqlvar(columnIndex).sqltype & ~1) != GDS.SQL_INT64) { + throw new SQLException("Wrong type for column " + columnIndex + "type should be" + getXsqlvar(columnIndex).sqltype); + } + if (row[columnIndex - 1] == null) { + return null; + } + return BigDecimal.valueOf(((Long)row[columnIndex - 1]).longValue(), getXsqlvar(columnIndex).sqlscale); } @@ -1100,7 +1195,7 @@ * */ public BigDecimal getBigDecimal(String columnName) throws SQLException { - throw new SQLException("Not yet implemented"); + return getBigDecimal(findColumn(columnName)); } @@ -2617,7 +2712,7 @@ * This method uses the specified <code>Map</code> object for * custom mapping if appropriate. * - * @param colName the name of the column from which to retrieve the value + * @param columnName the name of the column from which to retrieve the value * @param map a <code>java.util.Map</code> object that contains the mapping * from SQL type names to classes in the Java programming language * @return an <code>Object</code> representing the SQL value in the specified column @@ -2625,8 +2720,8 @@ * @see <a href="package-summary.html#2.0 API">What Is in the JDBC * 2.0 API</a> */ - public Object getObject(String colName, java.util.Map map) throws SQLException { - throw new SQLException("Not yet implemented"); + public Object getObject(String columnName, java.util.Map map) throws SQLException { + return getObject(findColumn(columnName), map); } @@ -2635,15 +2730,15 @@ * of this <code>ResultSet</code> object as a <code>Ref</code> object * in the Java programming language. * - * @param colName the column name + * @param columnName the column name * @return a <code>Ref</code> object representing the SQL <code>REF</code> value in * the specified column * @since 1.2 * @see <a href="package-summary.html#2.0 API">What Is in the JDBC * 2.0 API</a> */ - public Ref getRef(String colName) throws SQLException { - throw new SQLException("Not yet implemented"); + public Ref getRef(String columnName) throws SQLException { + return getRef(findColumn(columnName)); } @@ -2652,15 +2747,15 @@ * of this <code>ResultSet</code> object as a <code>Blob</code> object * in the Java programming language. * - * @param colName the name of the column from which to retrieve the value + * @param columnName the name of the column from which to retrieve the value * @return a <code>Blob</code> object representing the SQL <code>BLOB</code> value in * the specified column * @since 1.2 * @see <a href="package-summary.html#2.0 API">What Is in the JDBC * 2.0 API</a> */ - public Blob getBlob(String colName) throws SQLException { - throw new SQLException("Not yet implemented"); + public Blob getBlob(String columnName) throws SQLException { + return getBlob(findColumn(columnName)); } @@ -2669,15 +2764,15 @@ * of this <code>ResultSet</code> object as a <code>Clob</code> object * in the Java programming language. * - * @param colName the name of the column from which to retrieve the value + * @param columnName the name of the column from which to retrieve the value * @return a <code>Clob</code> object representing the SQL <code>CLOB</code> * value in the specified column * @since 1.2 * @see <a href="package-summary.html#2.0 API">What Is in the JDBC * 2.0 API</a> */ - public Clob getClob(String colName) throws SQLException { - throw new SQLException("Not yet implemented"); + public Clob getClob(String columnName) throws SQLException { + return getClob(findColumn(columnName)); } @@ -2686,15 +2781,15 @@ * of this <code>ResultSet</code> object as an <code>Array</code> object * in the Java programming language. * - * @param colName the name of the column from which to retrieve the value + * @param columnName the name of the column from which to retrieve the value * @return an <code>Array</code> object representing the SQL <code>ARRAY</code> value in * the specified column * @since 1.2 * @see <a href="package-summary.html#2.0 API">What Is in the JDBC * 2.0 API</a> */ - public Array getArray(String colName) throws SQLException { - throw new SQLException("Not yet implemented"); + public Array getArray(String columnName) throws SQLException { + return getArray(findColumn(columnName)); } @@ -2742,7 +2837,7 @@ * 2.0 API</a> */ public java.sql.Date getDate(String columnName, Calendar cal) throws SQLException { - throw new SQLException("Not yet implemented"); + return getDate(findColumn(columnName), cal); } @@ -2791,8 +2886,8 @@ * 2.0 API</a> */ public java.sql.Time getTime(String columnName, Calendar cal) throws SQLException { - throw new SQLException("Not yet implemented"); - } + return getTime(findColumn(columnName), cal); + } /** @@ -2839,8 +2934,20 @@ * 2.0 API</a> */ public java.sql.Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException { - throw new SQLException("Not yet implemented"); + return getTimestamp(findColumn(columnName), cal); + } + + //-------------------------------------------------------------------- + //package methods + + XSQLVAR getXsqlvar(int columnIndex) { + return stmt.getOutSqlda().sqlvar[columnIndex - 1]; + } + +/* int getColumnCount() { + return stmt.getOutSqlda().sqln; } +*/ } Index: FBResultSetMetaData.java =================================================================== RCS file: /cvsroot/firebird/client-java/src/org/firebirdsql/jdbc/FBResultSetMetaData.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -U3 -r1.1.1.1 -r1.2 --- FBResultSetMetaData.java 2001/05/09 14:24:47 1.1.1.1 +++ FBResultSetMetaData.java 2001/06/14 04:48:01 1.2 @@ -26,10 +26,20 @@ // imports -------------------------------------- +import org.firebirdsql.gds.GDS; +import org.firebirdsql.gds.isc_stmt_handle; +import org.firebirdsql.gds.XSQLDA; +import org.firebirdsql.gds.XSQLVAR; + +import java.math.BigDecimal; + import java.sql.ResultSetMetaData; +import java.sql.Blob; +import java.sql.Array; import java.sql.Connection; import java.sql.SQLException; +import java.sql.Types; /** * @@ -57,6 +67,12 @@ */ public class FBResultSetMetaData implements ResultSetMetaData { + + private isc_stmt_handle stmt; + + FBResultSetMetaData(isc_stmt_handle stmt) { + this.stmt = stmt; + } /** * Returns the number of columns in this <code>ResultSet</code> object. @@ -64,8 +80,8 @@ * @return the number of columns * @exception SQLException if a database access error occurs */ - public int getColumnCount() throws SQLException { - throw new SQLException("Not yet implemented"); + public int getColumnCount() { + return stmt.getOutSqlda().sqln;; } @@ -76,8 +92,8 @@ * @return <code>true</code> if so; <code>false</code> otherwise * @exception SQLException if a database access error occurs */ - public boolean isAutoIncrement(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + public boolean isAutoIncrement(int column) { + return false; } @@ -89,7 +105,7 @@ * @exception SQLException if a database access error occurs */ public boolean isCaseSensitive(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + return true; } @@ -101,7 +117,13 @@ * @exception SQLException if a database access error occurs */ public boolean isSearchable(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + if (((getXsqlvar(column).sqltype & ~1) == GDS.SQL_ARRAY) + || ((getXsqlvar(column).sqltype & ~1) == GDS.SQL_BLOB)) { + return false; + } + else { + return true; + } } @@ -113,7 +135,7 @@ * @exception SQLException if a database access error occurs */ public boolean isCurrency(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + return false; } @@ -126,7 +148,12 @@ * @exception SQLException if a database access error occurs */ public int isNullable(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + if ((getXsqlvar(column).sqltype & 1) == 1) { + return columnNullable; + } + else { + return columnNoNulls; + } } @@ -156,7 +183,17 @@ * @exception SQLException if a database access error occurs */ public boolean isSigned(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + switch (getXsqlvar(column).sqltype & ~1) { + case GDS.SQL_SHORT: + case GDS.SQL_LONG: + case GDS.SQL_FLOAT: + case GDS.SQL_DOUBLE: + case GDS.SQL_D_FLOAT: + case GDS.SQL_INT64: + return true; + default: + return false; + } } @@ -169,7 +206,44 @@ * @exception SQLException if a database access error occurs */ public int getColumnDisplaySize(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + //These are mostly wrong!! + switch (getXsqlvar(column).sqltype & ~1) { + case GDS.SQL_TEXT: + return getXsqlvar(column).sqllen; + case GDS.SQL_VARYING: + return getXsqlvar(column).sqllen; + case GDS.SQL_SHORT: + return getXsqlvar(column).sqllen; + case GDS.SQL_LONG: + return getXsqlvar(column).sqllen; + case GDS.SQL_FLOAT: + return getXsqlvar(column).sqllen; + case GDS.SQL_DOUBLE: + return getXsqlvar(column).sqllen; + case GDS.SQL_D_FLOAT: + return getXsqlvar(column).sqllen; + case GDS.SQL_TIMESTAMP: + return getXsqlvar(column).sqllen; + case GDS.SQL_BLOB: + return 0; + case GDS.SQL_ARRAY: + return 0; + case GDS.SQL_QUAD: + return getXsqlvar(column).sqllen; + case GDS.SQL_TYPE_TIME: + return getXsqlvar(column).sqllen; + case GDS.SQL_TYPE_DATE: + return 10; + case GDS.SQL_INT64: + if (getXsqlvar(column).sqlscale == 0) { + return getXsqlvar(column).sqllen; + } + else { + return getXsqlvar(column).sqllen; + } + default: + throw new SQLException("Unkown sql type"); + } } @@ -182,7 +256,7 @@ * @exception SQLException if a database access error occurs */ public String getColumnLabel(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + return (getXsqlvar(column).aliasname == null) ? getXsqlvar(column).sqlname: getXsqlvar(column).aliasname; } @@ -194,7 +268,7 @@ * @exception SQLException if a database access error occurs */ public String getColumnName(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + return getXsqlvar(column).sqlname; } @@ -206,7 +280,9 @@ * @exception SQLException if a database access error occurs */ public String getSchemaName(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + //not really implemented + throw new SQLException("Schemas aren't supported"); + //return getXsqlvar(column).ownname; } @@ -218,7 +294,8 @@ * @exception SQLException if a database access error occurs */ public int getPrecision(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + //presumable wrong!! + return getXsqlvar(column).sqllen; } @@ -230,7 +307,7 @@ * @exception SQLException if a database access error occurs */ public int getScale(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + return getXsqlvar(column).sqlscale; } @@ -242,7 +319,7 @@ * @exception SQLException if a database access error occurs */ public String getTableName(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + return getXsqlvar(column).relname; } @@ -254,7 +331,7 @@ * @exception SQLException if a database access error occurs */ public String getCatalogName(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + throw new SQLException("Catalogs not supported"); } @@ -267,7 +344,43 @@ * @see Types */ public int getColumnType(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + switch (getXsqlvar(column).sqltype & ~1) { + case GDS.SQL_TEXT: + return Types.CHAR; + case GDS.SQL_VARYING: + return Types.VARCHAR; + case GDS.SQL_SHORT: + return Types.SMALLINT; + case GDS.SQL_LONG: + return Types.BIGINT; + case GDS.SQL_FLOAT: + return Types.FLOAT; + case GDS.SQL_DOUBLE: + return Types.DOUBLE; + case GDS.SQL_D_FLOAT: + return Types.DOUBLE; + case GDS.SQL_TIMESTAMP: + return Types.TIMESTAMP; + case GDS.SQL_BLOB: + return Types.BLOB; + case GDS.SQL_ARRAY: + return Types.ARRAY; + case GDS.SQL_QUAD: + return Types.BIGINT; + case GDS.SQL_TYPE_TIME: + return Types.TIME; + case GDS.SQL_TYPE_DATE: + return Types.DATE; + case GDS.SQL_INT64: + if (getXsqlvar(column).sqlscale == 0) { + return Types.BIGINT; + } + else { + return Types.DECIMAL; + } + default: + throw new SQLException("Unkown sql type"); + } } @@ -280,7 +393,39 @@ * @exception SQLException if a database access error occurs */ public String getColumnTypeName(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + //Maybe these are supposed to be the sql keywords???? + switch (getXsqlvar(column).sqltype & ~1) { + case GDS.SQL_TEXT: + return "SQL_TEXT"; + case GDS.SQL_VARYING: + return "SQL_VARYING"; + case GDS.SQL_SHORT: + return "SQL_SHORT"; + case GDS.SQL_LONG: + return "SQL_LONG"; + case GDS.SQL_FLOAT: + return "SQL_FLOAT"; + case GDS.SQL_DOUBLE: + return "SQL_DOUBLE"; + case GDS.SQL_D_FLOAT: + return "SQL_D_FLOAT"; + case GDS.SQL_TIMESTAMP: + return "SQL_TIMESTAMP"; + case GDS.SQL_BLOB: + return "SQL_BLOB"; + case GDS.SQL_ARRAY: + return "SQL_ARRAY"; + case GDS.SQL_QUAD: + return "SQL_QUAD"; + case GDS.SQL_TYPE_TIME: + return "SQL_TYPE_TIME"; + case GDS.SQL_TYPE_DATE: + return "SQL_TYPE_DATE"; + case GDS.SQL_INT64: + return "SQL_INT64"; + default: + throw new SQLException("Unkown sql type"); + } } @@ -292,6 +437,7 @@ * @exception SQLException if a database access error occurs */ public boolean isReadOnly(int column) throws SQLException { + //Need to consider priveleges!! throw new SQLException("Not yet implemented"); } @@ -304,6 +450,7 @@ * @exception SQLException if a database access error occurs */ public boolean isWritable(int column) throws SQLException { + //Needs priveleges??? throw new SQLException("Not yet implemented"); } @@ -316,6 +463,7 @@ * @exception SQLException if a database access error occurs */ public boolean isDefinitelyWritable(int column) throws SQLException { + //Need to consider privileges!!! throw new SQLException("Not yet implemented"); } @@ -339,7 +487,51 @@ * 2.0 API</a> */ public String getColumnClassName(int column) throws SQLException { - throw new SQLException("Not yet implemented"); + switch (getXsqlvar(column).sqltype & ~1) { + case GDS.SQL_TEXT: + return String.class.getName(); + case GDS.SQL_VARYING: + return String.class.getName(); + case GDS.SQL_SHORT: + return Short.class.getName(); + case GDS.SQL_LONG: + return Long.class.getName(); + case GDS.SQL_FLOAT: + return Float.class.getName(); + case GDS.SQL_DOUBLE: + return Double.class.getName(); + case GDS.SQL_D_FLOAT: + return Double.class.getName(); + case GDS.SQL_TIMESTAMP: + return java.sql.Timestamp.class.getName(); + case GDS.SQL_BLOB: + return Blob.class.getName(); + case GDS.SQL_ARRAY: + return Array.class.getName(); + case GDS.SQL_QUAD: + return Long.class.getName(); + case GDS.SQL_TYPE_TIME: + return java.sql.Time.class.getName(); + case GDS.SQL_TYPE_DATE: + return java.sql.Date.class.getName(); + case GDS.SQL_INT64: + if (getXsqlvar(column).sqlscale == 0) { + return Long.class.getName(); + } + else { + return BigDecimal.class.getName(); + } + default: + throw new SQLException("Unkown sql type"); + } + } + + + //private methods + + private XSQLVAR getXsqlvar(int columnIndex) { + return stmt.getOutSqlda().sqlvar[columnIndex - 1]; } + } Index: FBRowSet.java =================================================================== RCS file: /cvsroot/firebird/client-java/src/org/firebirdsql/jdbc/FBRowSet.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -U3 -r1.1.1.1 -r1.2 --- FBRowSet.java 2001/05/09 14:26:08 1.1.1.1 +++ FBRowSet.java 2001/06/14 04:48:01 1.2 @@ -26,6 +26,9 @@ // imports -------------------------------------- +import org.firebirdsql.jca.FBManagedConnection; +import org.firebirdsql.gds.isc_stmt_handle; + import javax.sql.RowSet; import javax.sql.RowSetListener; @@ -76,6 +79,11 @@ */ public class FBRowSet extends FBResultSet implements RowSet { + + FBRowSet(FBManagedConnection mc, FBStatement fbstatement, isc_stmt_handle stmt) { + super(mc, fbstatement, stmt); + } + //----------------------------------------------------------------------- // Properties Index: FBRowSetMetaData.java =================================================================== RCS file: /cvsroot/firebird/client-java/src/org/firebirdsql/jdbc/FBRowSetMetaData.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -U3 -r1.1.1.1 -r1.2 --- FBRowSetMetaData.java 2001/05/09 14:26:13 1.1.1.1 +++ FBRowSetMetaData.java 2001/06/14 04:48:01 1.2 @@ -26,9 +26,12 @@ // imports -------------------------------------- + import javax.sql.RowSetMetaData; import java.sql.SQLException; +import java.sql.*; +import org.firebirdsql.gds.isc_stmt_handle; /** * @@ -38,7 +41,6 @@ */ -import java.sql.*; /** * <P>The RowSetMetaData interface extends ResultSetMetaData with @@ -48,6 +50,10 @@ */ public class FBRowSetMetaData extends FBResultSetMetaData implements RowSetMetaData { + + FBRowSetMetaData(isc_stmt_handle stmt) { + super(stmt); + } /** * Set the number of columns in the RowSet. Index: FBStatement.java =================================================================== RCS file: /cvsroot/firebird/client-java/src/org/firebirdsql/jdbc/FBStatement.java,v retrieving revision 1.2 retrieving revision 1.3 diff -U3 -r1.2 -r1.3 --- FBStatement.java 2001/05/25 19:52:52 1.2 +++ FBStatement.java 2001/06/14 04:48:01 1.3 @@ -34,6 +34,7 @@ import org.firebirdsql.jca.FBManagedConnection; import org.firebirdsql.gds.GDSException; +import org.firebirdsql.gds.isc_stmt_handle; /** * @@ -60,10 +61,16 @@ */ public class FBStatement implements Statement { - private FBManagedConnection mc; + private FBConnection c; + protected FBManagedConnection mc; - FBStatement(FBManagedConnection mc) { - this.mc = mc; + protected isc_stmt_handle fixedStmt = null; + + private FBResultSet currentRs = null; + + FBStatement(FBConnection c) { + this.c = c; + mc = c.mc; } /** @@ -75,7 +82,10 @@ * @exception SQLException if a database access error occurs */ public ResultSet executeQuery(String sql) throws SQLException { - throw new SQLException("Not yet implemented"); + if (!execute(sql)) { + throw new SQLException("query did not return a result set: " + sql); + } + return getResultSet(); } @@ -92,7 +102,10 @@ * @exception SQLException if a database access error occurs */ public int executeUpdate(String sql) throws SQLException { - throw new SQLException("Not yet implemented"); + if (execute(sql)) { + throw new SQLException("update statement returned results!"); + } + return getUpdateCount(); } @@ -110,7 +123,18 @@ * @exception SQLException if a database access error occurs */ public void close() throws SQLException { - throw new SQLException("Not yet implemented"); + if (fixedStmt != null) { + try { + mc.closeStatement(fixedStmt, true); + } + catch (GDSException ge) { + throw new SQLException("could not close statement: " + ge.toString()); + } + finally { + fixedStmt = null; + currentRs = null; + } + } } @@ -324,7 +348,13 @@ */ public boolean execute(String sql) throws SQLException { try { - return mc.executeSQL(sql); + closeResultSet(); + if (fixedStmt == null) { + fixedStmt = mc.getAllocatedStatement(); + } + mc.prepareSQL(fixedStmt, sql, false); + mc.executeStatement(fixedStmt); + return (fixedStmt.getOutSqlda().sqld > 0); } catch (GDSException ge) { throw new SQLException("GDS exception: " + ge.toString()); @@ -342,7 +372,14 @@ * @see #execute */ public ResultSet getResultSet() throws SQLException { - throw new SQLException("Not yet implemented"); + if (currentRs != null) { + throw new SQLException("Only one resultset at a time/statement!"); + } + if (fixedStmt == null) { + throw new SQLException("No statement just executed"); + } + currentRs = new FBResultSet(mc, this, fixedStmt); + return currentRs; } @@ -357,7 +394,19 @@ * @see #execute */ public int getUpdateCount() throws SQLException { - throw new SQLException("Not yet implemented"); + try { + FBManagedConnection.SqlInfo i = mc.getSqlInfo(fixedStmt); +System.out.println("InsertCount: " + i.getInsertCount()); +System.out.println("UpdateCount: " + i.getUpdateCount()); +System.out.println("DeleteCount: " + i.getDeleteCount()); + +System.out.println("returning: " + Math.max(i.getInsertCount(), Math.max(i.getUpdateCount(), i.getDeleteCount()))); + + return Math.max(i.getInsertCount(), Math.max(i.getUpdateCount(), i.getDeleteCount())); + } + catch (GDSException ge) { + throw new SQLException("Could not get UpdateCount: " + ge); + } } @@ -595,8 +644,29 @@ * @see <a href="package-summary.html#2.0 API">What Is in the JDBC * 2.0 API</a> */ - public Connection getConnection() throws SQLException { - throw new SQLException("Not yet implemented"); + public Connection getConnection() { + return c; + } + + //package level + + void closeResultSet() throws SQLException { + if (currentRs != null) { + try { + mc.closeStatement(fixedStmt, false); + } + catch (GDSException ge) { + throw new SQLException("problem closing resultset: " + ge); + } + currentRs = null; + } + } + + public void forgetResultSet() { //yuck should be package + currentRs = null; + if (fixedStmt != null) { + fixedStmt.clearRows(); + } } } |