Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 31819 invoked from network); 6 Jun 2002 17:42:41 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 6 Jun 2002 17:42:41 -0000 Received: (qmail 17623 invoked by uid 97); 6 Jun 2002 17:42:42 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 17607 invoked by uid 97); 6 Jun 2002 17:42:41 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 17596 invoked by uid 97); 6 Jun 2002 17:42:40 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Date: 6 Jun 2002 17:42:32 -0000 Message-ID: <20020606174232.67011.qmail@icarus.apache.org> From: baliuka@apache.org To: jakarta-commons-sandbox-cvs@apache.org Subject: cvs commit: jakarta-commons-sandbox/simplestore/src/jdbc/org/apache/commons/simplestore/jdbc DBStorage.java DriverDataSource.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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 * baliuka@mwm.lt - *@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 * baliuka@mwm.lt - *@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: For additional commands, e-mail: