You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2002/06/06 19:42:32 UTC
cvs commit: jakarta-commons-sandbox/simplestore/src/jdbc/org/apache/commons/simplestore/jdbc DBStorage.java DriverDataSource.java
baliuka 2002/06/06 10:42:32
Modified: simplestore/src/jdbc/org/apache/commons/simplestore/jdbc
DBStorage.java DriverDataSource.java
Log:
Revision Changes Path
1.2 +31 -22 jakarta-commons-sandbox/simplestore/src/jdbc/org/apache/commons/simplestore/jdbc/DBStorage.java
Index: DBStorage.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/jdbc/org/apache/commons/simplestore/jdbc/DBStorage.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DBStorage.java 25 May 2002 13:48:59 -0000 1.1
+++ DBStorage.java 6 Jun 2002 17:42:32 -0000 1.2
@@ -77,7 +77,7 @@
/**
*@author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
* baliuka@mwm.lt</a>
- *@version $Id: DBStorage.java,v 1.1 2002/05/25 13:48:59 baliuka Exp $
+ *@version $Id: DBStorage.java,v 1.2 2002/06/06 17:42:32 baliuka Exp $
*/
public class DBStorage extends AbstractStorage implements org.apache.commons.simplestore.tools.Constants {
@@ -136,9 +136,7 @@
while (rs.next()) {
result++;
for (int i = 1; i <= cnt; i++) {
- String name = rsmd.getColumnName(i);
- Object val = rs.getObject(i);
- if(! eh.nextResult(i, name, val, rsmd.getColumnType(i))){
+ if(! eh.nextResult(i - 1, rs.getObject(i) ) ){
break;
}
}
@@ -167,23 +165,22 @@
final MetaClass mClass = context.getMetaClass( clasz );
final java.beans.PropertyDescriptor[] descriptors = mClass.getProperties();
- final String sql = "SELECT * FROM " + mClass.getName() + " WHERE "+mClass.getOIDName()+"=?";
+ final String sql = "SELECT * FROM " + propertyList(mClass) + " WHERE "+mClass.getOIDName()+"=?";
Persistent result = (Persistent) mClass.newInstance( id );
final MetaObject pc = result.getMetaObject();
final Object props[] = pc.getProperties();
ResultSetHandler rsh =
new ResultSetHandler() {
- public boolean nextResult(int index, String name, Object value, int type) throws StorageException {
+ public boolean nextResult(int index, Object value ) throws StorageException {
try {
- if ( name.equalsIgnoreCase(mClass.getOIDName())) {
+ if ( index == 0 ) {
//OID is known
return true;
}
-
- int propIndex = mClass.getPropertyIndex( name );
- props[ propIndex ] = value;
+
+ props[ index ] = value;
return true;
} catch (Throwable t) {
t.printStackTrace();
@@ -203,13 +200,28 @@
public void enumerateInternal(final Class clasz, Set objects, final EnumeratorCallback callback) throws StorageException {
final MetaClass mClass = context.getMetaClass(clasz);
- final String sql = "SELECT "+ mClass.getOIDName() + " AS " + INTERNAL_OID + ", * FROM " + mClass.getName();
+ final String sql = "SELECT " + propertyList(mClass) + " FROM " + mClass.getName();
excecute( sql, null, new QueryHandler(objects,clasz,callback));
}
+ private String propertyList(MetaClass mclass){
+ final java.beans.PropertyDescriptor[] beanProps = mclass.getProperties();
+
+ StringBuffer names = new StringBuffer();
+ names.append(mclass.getName());
+ for (int i = 0; i < beanProps.length; i++) {
+ java.beans.PropertyDescriptor descriptor = beanProps[i];
+ if (descriptor.getWriteMethod() != null) {
+ names.append("," + mclass.getPropertyName(i) );
+
+ }
+ }
+
+ return names.toString() + " ";
+ }
public void storeObject(MetaObject properties) throws StorageException {
@@ -359,8 +371,7 @@
final MetaClass mClass = context.getMetaClass(clasz);
- final String sql = "SELECT "+ mClass.getOIDName() + " AS " + INTERNAL_OID +
- ", * FROM " + mClass.getName() +
+ final String sql = "SELECT "+ propertyList(mClass) + " FROM " + mClass.getName() +
" WHERE " + mClass.getPropertyName(index) + "=?";
excecute( sql, new Object[]{value}, new QueryHandler(objects, clasz,
@@ -391,10 +402,10 @@
this.callback = callback;
}
- public boolean nextResult(int index, String name, Object value, int type) throws StorageException {
+ public boolean nextResult(int index, Object value ) throws StorageException {
try {
- name = name.toUpperCase();
- if (index == 1) {
+
+ if (index == 0) {
//try to find in cache first
Persistent p = (Persistent) context.getCache().get(value);
if ( p != null ) {
@@ -411,14 +422,12 @@
return callback.nextObject(p);
}
-
- }
-
- if ( name.equals( mClass.getOIDName() ) || props == null) {
return true;
}
- props[ mClass.getPropertyIndex( name ) ] = value ;
+
+
+ props[ index ] = value ;
return true;
@@ -431,7 +440,7 @@
interface ResultSetHandler {
- public boolean nextResult(int index, String name, Object value, int type) throws StorageException;
+ public boolean nextResult(int index, Object value) throws StorageException;
}
}
1.2 +2 -3 jakarta-commons-sandbox/simplestore/src/jdbc/org/apache/commons/simplestore/jdbc/DriverDataSource.java
Index: DriverDataSource.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/jdbc/org/apache/commons/simplestore/jdbc/DriverDataSource.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DriverDataSource.java 25 May 2002 13:48:59 -0000 1.1
+++ DriverDataSource.java 6 Jun 2002 17:42:32 -0000 1.2
@@ -78,7 +78,7 @@
/**
*@author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
* baliuka@mwm.lt</a>
- *@version $Id: DriverDataSource.java,v 1.1 2002/05/25 13:48:59 baliuka Exp $
+ *@version $Id: DriverDataSource.java,v 1.2 2002/06/06 17:42:32 baliuka Exp $
*
*/
public class DriverDataSource implements ConnectionFactory {
@@ -341,8 +341,7 @@
for( int i = jdbcResources.size() - 1; i >= 0; i-- ){
Object res = jdbcResources.get(i);
-
- if ( res instanceof java.sql.Statement ){
+ if ( res instanceof java.sql.Statement ){
try{
((java.sql.Statement)res).close();
}catch( Exception e ){}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>