You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ha...@apache.org on 2001/10/29 18:59:24 UTC
cvs commit: jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/server AbstractDatabaseManager.java
hammant 01/10/29 09:59:24
Modified: apps/db/src/java/org/apache/avalon/db/driver
ApacheDBResultSet.java ApacheDBStatement.java
apps/db/src/java/org/apache/avalon/db/results Result.java
RowSet.java
apps/db/src/java/org/apache/avalon/db/server
AbstractDatabaseManager.java
Added: apps/db/src/java/org/apache/avalon/db/results Columns.java
Log:
ResultSet - work on getters
Revision Changes Path
1.3 +116 -123 jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/ApacheDBResultSet.java
Index: ApacheDBResultSet.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/ApacheDBResultSet.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ApacheDBResultSet.java 2001/10/29 15:18:16 1.2
+++ ApacheDBResultSet.java 2001/10/29 17:59:23 1.3
@@ -12,6 +12,8 @@
import org.apache.avalon.db.common.FeatureNotImplemented;
import org.apache.avalon.db.transport.ResultSetReply;
+import org.apache.avalon.db.results.RowSet;
+import org.apache.avalon.db.results.Columns;
import java.sql.*;
@@ -29,17 +31,19 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class ApacheDBResultSet extends AbstractDriver implements ResultSet {
private ApacheDBConnection mApacheDBConnection;
- private ResultSetReply mReply;
+ private RowSet mRowSet;
private int mResultSetConcurrency;
+ private int mCursor = -1;
+ private int mOffset = 0;
- public ApacheDBResultSet(ApacheDBConnection apacheDBConnection, ResultSetReply reply) {
+ public ApacheDBResultSet(ApacheDBConnection apacheDBConnection, RowSet rowSet) {
mApacheDBConnection = apacheDBConnection;
- mReply = reply;
+ mRowSet = rowSet;
}
@@ -63,10 +67,8 @@
* @exception SQLException if a database access error occurs
*/
public boolean next() throws SQLException {
-
- debug();
-
- return false;
+ mCursor++;
+ return (mCursor < mRowSet.getRowCount());
}
/**
@@ -122,10 +124,7 @@
* @exception SQLException if a database access error occurs
*/
public String getString(int columnIndex) throws SQLException {
-
- debug();
-
- return null;
+ return mRowSet.getRow(this.mCursor)[columnIndex].toString();
}
/**
@@ -141,10 +140,13 @@
* @exception SQLException if a database access error occurs
*/
public boolean getBoolean(int columnIndex) throws SQLException {
-
- debug();
-
- return false;
+ Object obj = mRowSet.getRow(this.mCursor)[columnIndex];
+ if (obj instanceof Boolean) {
+ return ((Boolean) obj).booleanValue();
+ } else {
+ // "true" is true, all else false.
+ return Boolean.valueOf(obj.toString()).booleanValue();
+ }
}
/**
@@ -160,10 +162,12 @@
* @exception SQLException if a database access error occurs
*/
public byte getByte(int columnIndex) throws SQLException {
-
- debug();
-
- return 0;
+ Object obj = mRowSet.getRow(this.mCursor)[columnIndex];
+ if (obj instanceof Byte) {
+ return ((Byte) obj).byteValue();
+ } else {
+ return Byte.parseByte(obj.toString());
+ }
}
/**
@@ -179,10 +183,12 @@
* @exception SQLException if a database access error occurs
*/
public short getShort(int columnIndex) throws SQLException {
-
- debug();
-
- return 0;
+ Object obj = mRowSet.getRow(this.mCursor)[columnIndex];
+ if (obj instanceof Short) {
+ return ((Short) obj).shortValue();
+ } else {
+ return Short.parseShort(obj.toString());
+ }
}
/**
@@ -198,10 +204,12 @@
* @exception SQLException if a database access error occurs
*/
public int getInt(int columnIndex) throws SQLException {
-
- debug();
-
- return 0;
+ Object obj = mRowSet.getRow(this.mCursor)[columnIndex];
+ if (obj instanceof Integer) {
+ return ((Integer) obj).intValue();
+ } else {
+ return Integer.parseInt(obj.toString());
+ }
}
/**
@@ -217,10 +225,12 @@
* @exception SQLException if a database access error occurs
*/
public long getLong(int columnIndex) throws SQLException {
-
- debug();
-
- return 0;
+ Object obj = mRowSet.getRow(this.mCursor)[columnIndex];
+ if (obj instanceof Long) {
+ return ((Long) obj).longValue();
+ } else {
+ return Long.parseLong(obj.toString());
+ }
}
/**
@@ -236,10 +246,12 @@
* @exception SQLException if a database access error occurs
*/
public float getFloat(int columnIndex) throws SQLException {
-
- debug();
-
- return 0;
+ Object obj = mRowSet.getRow(this.mCursor)[columnIndex];
+ if (obj instanceof Float) {
+ return ((Float) obj).floatValue();
+ } else {
+ return Float.parseFloat(obj.toString());
+ }
}
/**
@@ -255,10 +267,12 @@
* @exception SQLException if a database access error occurs
*/
public double getDouble(int columnIndex) throws SQLException {
-
- debug();
-
- return 0;
+ Object obj = mRowSet.getRow(this.mCursor)[columnIndex];
+ if (obj instanceof Double) {
+ return ((Double) obj).doubleValue();
+ } else {
+ return Double.parseDouble(obj.toString());
+ }
}
/**
@@ -293,10 +307,19 @@
* @exception SQLException if a database access error occurs
*/
public byte[] getBytes(int columnIndex) throws SQLException {
-
- debug();
-
- return new byte[0];
+ // is this a byte representation of a string. i.e. 2 bytes per char?
+ // or a plain byte array. or both.
+ Object obj = mRowSet.getRow(this.mCursor)[columnIndex];
+ if (obj instanceof Byte[]) {
+ Byte[] bytesObj = (Byte[]) obj;
+ byte[] bytes = new byte[bytesObj.length];
+ for (int f = 0; f < bytes.length; f++ ) {
+ bytes[f] = bytesObj[f].byteValue();
+ }
+ return bytes;
+ } else {
+ return obj.toString().getBytes();
+ }
}
/**
@@ -312,10 +335,12 @@
* @exception SQLException if a database access error occurs
*/
public Date getDate(int columnIndex) throws SQLException {
-
- debug();
-
- return null;
+ Object obj = mRowSet.getRow(this.mCursor)[columnIndex];
+ if (obj instanceof Date) {
+ return (Date) obj;
+ } else {
+ return Date.valueOf(obj.toString());
+ }
}
/**
@@ -331,10 +356,12 @@
* @exception SQLException if a database access error occurs
*/
public Time getTime(int columnIndex) throws SQLException {
-
- debug();
-
- return null;
+ Object obj = mRowSet.getRow(this.mCursor)[columnIndex];
+ if (obj instanceof Time) {
+ return (Time) obj;
+ } else {
+ return Time.valueOf(obj.toString());
+ }
}
/**
@@ -350,10 +377,12 @@
* @exception SQLException if a database access error occurs
*/
public Timestamp getTimestamp(int columnIndex) throws SQLException {
-
- debug();
-
- return null;
+ Object obj = mRowSet.getRow(this.mCursor)[columnIndex];
+ if (obj instanceof Timestamp) {
+ return (Timestamp) obj;
+ } else {
+ return Timestamp.valueOf(obj.toString());
+ }
}
/**
@@ -464,10 +493,7 @@
* @exception SQLException if a database access error occurs
*/
public String getString(String columnName) throws SQLException {
-
- debug();
-
- return null;
+ return getString(getIndex(columnName));
}
/**
@@ -483,12 +509,19 @@
* @exception SQLException if a database access error occurs
*/
public boolean getBoolean(String columnName) throws SQLException {
-
- debug();
+ return getBoolean(getIndex(columnName));
+ }
- return false;
+ private int getIndex(String columnName) throws SQLException {
+ Columns cols = mRowSet.getColumns();
+ int ix = cols.getIndex(columnName);
+ if (ix < 0) {
+ throw new SQLException("Column name " + columnName + " not found");
+ }
+ return ix;
}
+
/**
* Gets the value of the designated column in the current row
* of this <code>ResultSet</code> object as
@@ -502,10 +535,7 @@
* @exception SQLException if a database access error occurs
*/
public byte getByte(String columnName) throws SQLException {
-
- debug();
-
- return 0;
+ return getByte(getIndex(columnName));
}
/**
@@ -521,10 +551,7 @@
* @exception SQLException if a database access error occurs
*/
public short getShort(String columnName) throws SQLException {
-
- debug();
-
- return 0;
+ return getShort(getIndex(columnName));
}
/**
@@ -540,10 +567,7 @@
* @exception SQLException if a database access error occurs
*/
public int getInt(String columnName) throws SQLException {
-
- debug();
-
- return 0;
+ return getInt(getIndex(columnName));
}
/**
@@ -559,10 +583,7 @@
* @exception SQLException if a database access error occurs
*/
public long getLong(String columnName) throws SQLException {
-
- debug();
-
- return 0;
+ return getLong(getIndex(columnName));
}
/**
@@ -578,10 +599,7 @@
* @exception SQLException if a database access error occurs
*/
public float getFloat(String columnName) throws SQLException {
-
- debug();
-
- return 0;
+ return getFloat(getIndex(columnName));
}
/**
@@ -597,10 +615,7 @@
* @exception SQLException if a database access error occurs
*/
public double getDouble(String columnName) throws SQLException {
-
- debug();
-
- return 0;
+ return getDouble(getIndex(columnName));
}
/**
@@ -635,10 +650,7 @@
* @exception SQLException if a database access error occurs
*/
public byte[] getBytes(String columnName) throws SQLException {
-
- debug();
-
- return new byte[0];
+ return getBytes(getIndex(columnName));
}
/**
@@ -654,10 +666,7 @@
* @exception SQLException if a database access error occurs
*/
public Date getDate(String columnName) throws SQLException {
-
- debug();
-
- return null;
+ return getDate(getIndex(columnName));
}
/**
@@ -674,10 +683,7 @@
* @exception SQLException if a database access error occurs
*/
public Time getTime(String columnName) throws SQLException {
-
- debug();
-
- return null;
+ return getTime(getIndex(columnName));
}
/**
@@ -693,10 +699,7 @@
* @exception SQLException if a database access error occurs
*/
public Timestamp getTimestamp(String columnName) throws SQLException {
-
- debug();
-
- return null;
+ return getTimestamp(getIndex(columnName));
}
/**
@@ -907,10 +910,7 @@
* @exception SQLException if a database access error occurs
*/
public Object getObject(int columnIndex) throws SQLException {
-
- debug();
-
- return null;
+ return mRowSet.getRow(this.mCursor)[columnIndex];
}
/**
@@ -941,10 +941,7 @@
* @exception SQLException if a database access error occurs
*/
public Object getObject(String columnName) throws SQLException {
-
- debug();
-
- return null;
+ return getObject(getIndex(columnName));
}
/**
@@ -958,10 +955,7 @@
* @exception SQLException if a database access error occurs
*/
public int findColumn(String columnName) throws SQLException {
-
- debug();
-
- return 0;
+ return getIndex(columnName);
}
/**
@@ -1021,10 +1015,12 @@
* 2.0 API</a>
*/
public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
-
- debug();
-
- return null;
+ Object obj = mRowSet.getRow(this.mCursor)[columnIndex];
+ if (obj instanceof BigDecimal) {
+ return (BigDecimal) obj;
+ } else {
+ throw new SQLException("Can;t convert to BIGDecimal");
+ }
}
/**
@@ -1045,10 +1041,7 @@
*
*/
public BigDecimal getBigDecimal(String columnName) throws SQLException {
-
- debug();
-
- return null;
+ return getBigDecimal(getIndex(columnName));
}
/**
1.4 +3 -3 jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/ApacheDBStatement.java
Index: ApacheDBStatement.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/ApacheDBStatement.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ApacheDBStatement.java 2001/10/29 15:18:16 1.3
+++ ApacheDBStatement.java 2001/10/29 17:59:23 1.4
@@ -21,7 +21,7 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public class ApacheDBStatement extends AbstractDriver implements Statement {
@@ -57,7 +57,7 @@
handleSQLException(reply);
ResultSetReply resultSetReply = (ResultSetReply) reply;
mRowSet = resultSetReply.getRowSet();
- mResultSet = new ApacheDBResultSet(mApacheDBConnection,resultSetReply);
+ mResultSet = new ApacheDBResultSet(mApacheDBConnection,mRowSet);
return mResultSet;
}
@@ -332,7 +332,7 @@
if (reply instanceof ResultSetReply) {
ResultSetReply rsReply = (ResultSetReply) reply;
mRowSet = rsReply.getRowSet();
- mResultSet = new ApacheDBResultSet(mApacheDBConnection,rsReply);
+ mResultSet = new ApacheDBResultSet(mApacheDBConnection,mRowSet);
return true;
} else if (reply instanceof UpdateReply) {
mUpdateCount = ((UpdateReply) reply).getRowCount();
1.2 +3 -2 jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/results/Result.java
Index: Result.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/results/Result.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Result.java 2001/10/28 14:09:21 1.1
+++ Result.java 2001/10/29 17:59:23 1.2
@@ -8,6 +8,7 @@
*/
package org.apache.avalon.db.results;
+import java.io.Serializable;
/**
@@ -15,6 +16,6 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version * $Revision: 1.1 $
+ * @version * $Revision: 1.2 $
*/
-public interface Result {}
+public interface Result extends Serializable {}
1.2 +8 -2 jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/results/RowSet.java
Index: RowSet.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/results/RowSet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RowSet.java 2001/10/28 14:09:21 1.1
+++ RowSet.java 2001/10/29 17:59:23 1.2
@@ -8,6 +8,7 @@
*/
package org.apache.avalon.db.results;
+import org.apache.avalon.db.data.Row;
/**
@@ -15,6 +16,11 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version * $Revision: 1.1 $
+ * @version * $Revision: 1.2 $
*/
-public interface RowSet extends Result {}
+public interface RowSet extends Result {
+ Columns getColumns();
+ int getRowCount();
+ int getPageNumber();
+ Object[] getRow(int ix);
+}
1.1 jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/results/Columns.java
Index: Columns.java
===================================================================
/*
* Created by IntelliJ IDEA.
* User: Administrator
* Date: Oct 29, 2001
* Time: 5:24:50 PM
* To change template for new interface use
* Code Style | Class Templates options (Tools | IDE Options).
*/
package org.apache.avalon.db.results;
import java.io.Serializable;
public interface Columns extends Serializable {
String[] getHeadings();
String[] getTypes();
int getIndex(String columnName);
}
1.3 +2 -2 jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/server/AbstractDatabaseManager.java
Index: AbstractDatabaseManager.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/server/AbstractDatabaseManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractDatabaseManager.java 2001/10/29 15:18:16 1.2
+++ AbstractDatabaseManager.java 2001/10/29 17:59:24 1.3
@@ -27,7 +27,7 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public abstract class AbstractDatabaseManager extends AbstractLoggable {
@@ -76,7 +76,7 @@
//TODO
break;
- case (Request.INSERTINTO) :
+ case (Request.INSERT) :
//TODO
break;
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>