baliuka 02/03/10 04:32:31 Modified: simplestore build.xml simplestore/src/java/org/apache/commons/simplestore/cache/impl SoftRefMemoryCache.java simplestore/src/java/org/apache/commons/simplestore/persistence MetaObject.java simplestore/src/java/org/apache/commons/simplestore/persistence/impl AbstractStorage.java DBStorage.java MetaClassImpl.java PersistentProxy.java TransactionImpl.java simplestore/src/java/org/apache/commons/simplestore/tools Enhancer.java simplestore/src/test/org/apache/commons/simplestore TestPersistent.java TestPersistentClassType.java TestSample.java Added: simplestore/src/java/org/apache/commons/simplestore/tools Constants.java Log: Fixed a lot of bugs, new bugs added :) Revision Changes Path 1.18 +2 -1 jakarta-commons-sandbox/simplestore/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/build.xml,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- build.xml 7 Mar 2002 14:20:27 -0000 1.17 +++ build.xml 10 Mar 2002 12:32:30 -0000 1.18 @@ -2,7 +2,7 @@ <!-- "simplestore" component of the Jakarta Commons Subproject - $Id: build.xml,v 1.17 2002/03/07 14:20:27 froehlich Exp $ + $Id: build.xml,v 1.18 2002/03/10 12:32:30 baliuka Exp $ --> <!-- ========== Executable Targets ======================================== --> @@ -130,6 +130,7 @@ <target name="test" depends="build-test" description="runs (junit) unit tests"> <java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}" maxmemory="${maxmemory}"> + <sysproperty key="DEBUG" value="true"/> <arg value="${test.entry}"/> <classpath> <pathelement path=" ${build.home}/classes" /> 1.4 +3 -3 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/cache/impl/SoftRefMemoryCache.java Index: SoftRefMemoryCache.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/cache/impl/SoftRefMemoryCache.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SoftRefMemoryCache.java 9 Mar 2002 19:07:49 -0000 1.3 +++ SoftRefMemoryCache.java 10 Mar 2002 12:32:30 -0000 1.4 @@ -65,11 +65,11 @@ * [EMAIL PROTECTED]</a> *@author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> - *@version $Id: SoftRefMemoryCache.java,v 1.3 2002/03/09 19:07:49 baliuka Exp $ + *@version $Id: SoftRefMemoryCache.java,v 1.4 2002/03/10 12:32:30 baliuka Exp $ */ -public class SoftRefMemoryCache implements Cache { +public class SoftRefMemoryCache implements Cache, org.apache.commons.simplestore.tools.Constants { - private static boolean DEBUG = System.getProperty("DEBUG") != null; + private int m_current = 0; private int m_maxStrongRefCount; 1.3 +4 -4 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/MetaObject.java Index: MetaObject.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/MetaObject.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MetaObject.java 23 Feb 2002 12:11:30 -0000 1.2 +++ MetaObject.java 10 Mar 2002 12:32:30 -0000 1.3 @@ -59,18 +59,18 @@ /** *@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> - *@version $Id: MetaObject.java,v 1.2 2002/02/23 12:11:30 baliuka Exp $ + *@version $Id: MetaObject.java,v 1.3 2002/03/10 12:32:30 baliuka Exp $ */ public interface MetaObject extends Cloneable { public Object getOID(); - public Object getProperty(String name); + public Object getProperty(int index); - public void setProperty(String name, Object value); + public void setProperty(int index, Object value); - public Map getProperties(); + public Object[] getProperties(); public Class getPersistentClass(); 1.4 +25 -19 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/AbstractStorage.java Index: AbstractStorage.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/AbstractStorage.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AbstractStorage.java 17 Feb 2002 14:09:04 -0000 1.3 +++ AbstractStorage.java 10 Mar 2002 12:32:30 -0000 1.4 @@ -68,7 +68,7 @@ /** *@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> - *@version $Id: AbstractStorage.java,v 1.3 2002/02/17 14:09:04 baliuka Exp $ + *@version $Id: AbstractStorage.java,v 1.4 2002/03/10 12:32:30 baliuka Exp $ */ public abstract class AbstractStorage @@ -110,8 +110,9 @@ public void commit() { try { - getTransaction().commit(); - internalCommit(); + // getTransaction().commit(); + // internalCommit(); + throw new java.lang.NoSuchMethodError(); } catch (Throwable t) { // TODO t.printStackTrace(); @@ -121,8 +122,9 @@ public void begin() { try { - getTransaction().begin(); - internalBegin(); + // getTransaction().begin(); + // internalBegin(); + throw new java.lang.NoSuchMethodError(); } catch (Throwable t) { // TODO throw new RuntimeException(t.getClass() + ":" + t.getMessage()); @@ -133,7 +135,7 @@ try { //TODO implement roolback internalRollback(); - objects.clear(); + // objects.clear(); } catch (Throwable t) { throw new RuntimeException(t.getClass() + ":" + t.getMessage()); } @@ -142,8 +144,9 @@ public void rollback() { try { - getTransaction().rollback(); - internalRollback(); + // getTransaction().rollback(); + // internalRollback(); + throw new java.lang.NoSuchMethodError(); } catch (Throwable t) { // TODO throw new RuntimeException(t.getClass() + ":" + t.getMessage()); @@ -152,32 +155,35 @@ } public void commit(Set objects) { - + MetaObject pp = null; try { + Iterator iterator = objects.iterator(); while (iterator.hasNext()) { - MetaObject pp = (MetaObject) iterator.next(); - if (pp.isNew()) { + pp = (MetaObject) iterator.next(); + if ( pp.isNew() && !pp.isDeleted() ) { createObject(pp); - + pp.setDirty(false); + continue; } - if (pp.isDirty() && !pp.isNew()) { + if ( pp.isDirty() && !pp.isDeleted() ) { storeObject(pp); - + pp.setDirty(false); + continue; } - if (pp.isDeleted()) { - + if ( pp.isDeleted() ) { removeObject(pp); + continue; } - pp.setDirty(false); + throw new java.lang.IllegalStateException(pp.toString()); } - objects.clear(); + // objects.clear(); internalCommit(); } catch (Throwable t) { // TODO t.printStackTrace(); - throw new RuntimeException("Error"); + throw new RuntimeException(t.getMessage() + " " + pp); } } 1.6 +49 -51 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/DBStorage.java Index: DBStorage.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/DBStorage.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- DBStorage.java 9 Mar 2002 19:07:49 -0000 1.5 +++ DBStorage.java 10 Mar 2002 12:32:30 -0000 1.6 @@ -85,12 +85,12 @@ /** *@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> - *@version $Id: DBStorage.java,v 1.5 2002/03/09 19:07:49 baliuka Exp $ + *@version $Id: DBStorage.java,v 1.6 2002/03/10 12:32:30 baliuka Exp $ */ -public class DBStorage extends AbstractStorage { +public class DBStorage extends AbstractStorage implements org.apache.commons.simplestore.tools.Constants { - private final static boolean DEBUG = System.getProperty("DEBUG") != null; private final static String CONNECTION = "org.apache.commons.simplestore.jdbc.DBStorage.connection"; + //TODO : must be in MetaClass private static Properties procedures = new Properties(); private DataSource ds; private Context context; @@ -108,7 +108,7 @@ public static Object toSQLType(Object object) { if ( object == null ) { - return null; + return null; } if (object instanceof Boolean) { boolean value = ((Boolean) object).booleanValue(); @@ -155,26 +155,26 @@ } - if (rs != null && eh != null) { - - ResultSetMetaData rsmd = rs.getMetaData(); - int cnt = rsmd.getColumnCount(); - - while (rs.next()) { - result++; - for (int i = 1; i <= cnt; i++) { - String name = rsmd.getColumnName(i); - Object val = rs.getObject(i); - eh.nextResult(i, name, val, rsmd.getColumnType(i)); - } + if (rs != null && eh != null) { + + ResultSetMetaData rsmd = rs.getMetaData(); + int cnt = rsmd.getColumnCount(); + + while (rs.next()) { + result++; + for (int i = 1; i <= cnt; i++) { + String name = rsmd.getColumnName(i); + Object val = rs.getObject(i); + eh.nextResult(i, name, val, rsmd.getColumnType(i)); } - } + + } } finally { if ( rs != null ) { - rs.close(); + rs.close(); } if ( statement != null ) { statement.close(); @@ -191,7 +191,7 @@ } - + //TODO : must be removed public void registerClass(Class clasz) { try { @@ -210,11 +210,11 @@ } public Object retrieveObject( final Class clasz, Object id ) throws StorageException { - + Persistent result = (Persistent) context.getCache().get(id); if (result != null) { - return result; + return result; } @@ -223,7 +223,6 @@ final String sql = "SELECT * FROM " + mClass.getName() + " WHERE "+mClass.getOIDName()+"=?"; result = (Persistent) mClass.newInstance( id ); final MetaObject pc = result.getMetaObject(); - final Map map = pc.getProperties(); ResultSetHandler rsh = new ResultSetHandler() { @@ -231,13 +230,15 @@ public void nextResult(int index, String name, Object value, int type) throws StorageException { try { + if ( name.equalsIgnoreCase(mClass.getOIDName())) { + return; + } + int propIndex = mClass.getPropertyIndex( name ); if (value != null) { - String property = descriptors[ propIndex ].getName(); - if (name.equalsIgnoreCase(mClass.getOIDName())) { - return; - } - map.put(property, value ); + + pc.setProperty(propIndex,value); + } } catch (Throwable t) { t.printStackTrace(); @@ -250,8 +251,8 @@ if ( excecute( sql, new Object[]{id}, rsh) == 0 ) { throw new ObjectNotFound(pc.getOID().toString(), null); } - - context.getCache().put(id, result); + + context.getCache().put(id, result); return result; } @@ -261,7 +262,7 @@ final MetaClass mClass = context.getMetaClass(clasz); final String sql = "SELECT ID AS INTERNAL_OID, * FROM " + mClass.getName(); final Set objects = new HashSet(); - + excecute( sql, null, new QueryHandler(objects, clasz)); return objects; @@ -285,8 +286,7 @@ final MetaClass mClass = context.getMetaClass(clasz); final String name = mClass.getName(); final java.beans.PropertyDescriptor[] beanProps = mClass.getProperties(); - final List values = new ArrayList( beanProps.length + 1); - final Map map = properties.getProperties(); + final List values = new ArrayList( beanProps.length + 1 ); final StringBuffer names = new StringBuffer( beanProps.length * 10 ); @@ -294,10 +294,9 @@ java.beans.PropertyDescriptor descriptor = beanProps[i]; if (descriptor.getWriteMethod() != null) { - Object value = toSQLType(map.get(descriptor.getName())); names.append( mClass.getPropertyName(i) ); names.append("=?,"); - values.add(value); + values.add(toSQLType(properties.getProperty(i))); } } @@ -308,7 +307,7 @@ final String sql = "UPDATE " + name + " SET " + names; if ( excecute( sql, values.toArray(), null) == 0 ) { - throw new ObjectNotFound(properties.getOID().toString(), null); + throw new ObjectNotFound(properties.getOID().toString(), null); } } @@ -334,7 +333,6 @@ final String name = mClass.getName(); final Object id = properties.getOID(); final java.beans.PropertyDescriptor[] beanProps = mClass.getProperties(); - final Map map = properties.getProperties(); final List values = new ArrayList( beanProps.length + 1 ); String names = ""; @@ -346,7 +344,7 @@ java.beans.PropertyDescriptor descriptor = beanProps[i]; if (descriptor.getWriteMethod() != null) { - Object value = toSQLType(map.get(descriptor.getName())); + Object value = toSQLType( properties.getProperty(i) ); if (value == null) { continue; } @@ -356,9 +354,9 @@ } } - final String sql = "INSERT INTO " + name + - "(" + mClass.getOIDName() + names + - ")VALUES(?" + params + ")"; + final String sql = "INSERT INTO " + name + + "(" + mClass.getOIDName() + names + + ")VALUES(?" + params + ")"; excecute( sql, values.toArray(), null); @@ -369,11 +367,11 @@ final MetaClass mClass = context.getMetaClass(obj.getPersistentClass()); final String name = mClass.getName(); final Object id = obj.getOID(); - final String sql = "DELETE FROM " + name + - " WHERE "+ mClass.getOIDName() + "=?"; + final String sql = "DELETE FROM " + name + + " WHERE "+ mClass.getOIDName() + "=?"; if ( excecute( sql, new Object[]{id}, null) == 0 ) { - throw new ObjectNotFound(obj.getOID().toString(), null); + throw new ObjectNotFound(obj.getOID().toString(), null); } } @@ -426,7 +424,7 @@ } class QueryHandler implements ResultSetHandler { - Map map; + Object props[]; Set objects; MetaClass mClass ; java.beans.PropertyDescriptor[] descriptors; @@ -439,28 +437,28 @@ public void nextResult(int index, String name, Object value, int type) throws StorageException { try { + name = name.toUpperCase(); if (index == 1) { Persistent p = (Persistent) context.getCache().get(value); if ( p != null ) { - map = null; + props = null; objects.add(p); return; } p = mClass.newInstance( value ); MetaObject pc = p.getMetaObject(); - map = pc.getProperties(); + props = pc.getProperties(); objects.add(p); + context.getCache().put(value,p); return; } - - if ( name.equalsIgnoreCase( mClass.getOIDName() ) || map == null) { + + if ( name.equals( mClass.getOIDName() ) || props == null) { return; } - String property = descriptors[ mClass.getPropertyIndex( name ) ].getName(); - Class propType = descriptors[ mClass.getPropertyIndex( name ) ].getPropertyType(); - map.put( property, value ); + props[ mClass.getPropertyIndex( name ) ] = value ; } catch (Throwable t) { t.printStackTrace(); 1.6 +41 -34 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/MetaClassImpl.java Index: MetaClassImpl.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/MetaClassImpl.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- MetaClassImpl.java 9 Mar 2002 19:07:49 -0000 1.5 +++ MetaClassImpl.java 10 Mar 2002 12:32:30 -0000 1.6 @@ -65,12 +65,11 @@ * *@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> - *@version $Id: MetaClassImpl.java,v 1.5 2002/03/09 19:07:49 baliuka Exp $ + *@version $Id: MetaClassImpl.java,v 1.6 2002/03/10 12:32:30 baliuka Exp $ */ -public class MetaClassImpl implements MetaClass { - - private static final boolean DEBUG = System.getProperty("DEBUG") != null; - +public class MetaClassImpl implements MetaClass, org.apache.commons.simplestore.tools.Constants { + + private static java.util.Map persitentClasses = new java.util.Hashtable(); private Class clasz; private String sqlName; @@ -85,6 +84,7 @@ private Field getField( String id ){ + Field field = (Field)fields.get(id); if ( field == null ){ for( int i = 0; i < descriptors.length; i++ ){ @@ -273,10 +273,13 @@ * @return Meta data for class */ public MetaClass forClass(Class clasz) { - MetaClass mc = (MetaClass)persitentClasses.get(clasz); + MetaClassImpl mc = (MetaClassImpl)persitentClasses.get(clasz.getName()); if( mc == null ){ mc = new MetaClassImpl(clasz); + System.out.println("create " + clasz.getName()); + persitentClasses.put(clasz.getName(),mc); } + mc.setContext(context); return mc; @@ -301,32 +304,33 @@ private void setDescriptors(){ try{ descriptors = java.beans.Introspector.getBeanInfo( clasz ).getPropertyDescriptors(); + /* java.util.List abstractProps = new java.util.Vector(); - + for( int i = 0; i < descriptors.length; i++ ){ - + if( descriptors[i].getReadMethod() != null && descriptors[i].getWriteMethod() != null ) { - + if( java.lang.reflect.Modifier.isAbstract( descriptors[i].getReadMethod().getModifiers() ) && java.lang.reflect.Modifier.isAbstract( descriptors[i].getWriteMethod().getModifiers() ) ){ abstractProps.add(descriptors[i]); } }else if ( descriptors[i].getReadMethod() != null && java.lang.reflect.Modifier.isAbstract( descriptors[i].getReadMethod().getModifiers() )){ - + abstractProps.add(descriptors[i]); - + }else if ( descriptors[i].getWriteMethod() != null && java.lang.reflect.Modifier.isAbstract( descriptors[i].getWriteMethod().getModifiers() )){ - + abstractProps.add(descriptors[i]); } - + } - - + + descriptors = (java.beans.PropertyDescriptor[])abstractProps.toArray(new java.beans.PropertyDescriptor[]{}); - + */ }catch( Exception e ){ e.printStackTrace(); throw new Error(e.getMessage()); @@ -340,6 +344,8 @@ for( int i = 0; i < descriptors.length; i++ ){ String name = getField(descriptors[i].getName()).getName(); if( name == null ){ + if(DEBUG) + System.out.println("No mapping for " + descriptors[i].getName() ); name = toSQLName(descriptors[i].getName()); getField(descriptors[i].getName()).setName(name); } @@ -361,8 +367,7 @@ private void indexMethods(){ try{ setDescriptors(); - - + if( DEBUG ) throw new Error(); for( int i = 0; i < descriptors.length; i++ ){ properties.put( toSQLName(descriptors[i].getName()),new Integer(i) ); @@ -448,8 +453,9 @@ public int getPropertyIndex(String field) { Integer index = (Integer)properties.get( field.toUpperCase() ); - if( index == null ) + if( index == null ){ throw new java.lang.NoSuchFieldError( clasz.getName() + "." + field ); + } return index.intValue(); } @@ -475,7 +481,9 @@ } - static class StorageHandlerImpl implements StorageHandler { + static class StorageHandlerImpl + implements StorageHandler , + org.apache.commons.simplestore.tools.Constants { MetaClassImpl currentClass ; @@ -485,7 +493,6 @@ } - private static final boolean DEBUG = System.getProperty("DEBUG") != null; public void setDocumentLocator(org.xml.sax.Locator locator ){} @@ -510,50 +517,50 @@ public final void skippedEntity(java.lang.String name) throws SAXException {} public void handle_reference(final Attributes meta) throws SAXException { - if (DEBUG) System.out.println("handle_reference: " + meta); + currentField.setReferenceClass( meta.getValue("mclass") ); currentField.setReferenceField( meta.getValue("field") ); } public void start_validator(final Attributes meta) throws SAXException { - if (DEBUG) System.out.println("start_validator: " + meta); + } public void end_validator() throws SAXException { - if (DEBUG) System.out.println("end_validator()"); + } public void handle_property(final java.lang.String data, final Attributes meta) throws SAXException { - if (DEBUG) System.out.println("handle_property: " + data); + } public void start_field(final Attributes meta) throws SAXException { - if (DEBUG) System.out.println("start_field: " + meta); currentField = currentClass.getField( meta.getValue("id") ); currentField.setName( meta.getValue("name") ); } public void end_field() throws SAXException { - if (DEBUG) System.out.println("end_field()"); + } public void start_storage(final Attributes meta) throws SAXException { - if (DEBUG) System.out.println("start_storage: " + meta); + } public void end_storage() throws SAXException { - if ( DEBUG ) System.out.println("end_storage()"); + } public void start_mclass(final Attributes meta) throws SAXException { - if ( DEBUG ) System.out.println("start_mclass: " + meta); + try{ - Class clasz = Class.forName( meta.getValue("id")) ; - currentClass = (MetaClassImpl)persitentClasses.get(clasz); + Class clasz = Class.forName( meta.getValue("id"),true, + Thread.currentThread().getContextClassLoader()) ; + currentClass = (MetaClassImpl)persitentClasses.get(clasz.getName()); if ( currentClass == null ){ currentClass = new MetaClassImpl(); currentClass.clasz = clasz; - persitentClasses.put(currentClass.clasz,currentClass); + persitentClasses.put(clasz.getName(),currentClass); } currentClass.setDescriptors(); currentClass.sqlName = meta.getValue("name"); @@ -566,7 +573,7 @@ } public void end_mclass() throws SAXException { - if (DEBUG) System.out.println("end_mclass()"); + currentClass.indexMethodsFromMetaData(); } 1.11 +32 -35 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/PersistentProxy.java Index: PersistentProxy.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/PersistentProxy.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- PersistentProxy.java 9 Mar 2002 19:07:49 -0000 1.10 +++ PersistentProxy.java 10 Mar 2002 12:32:30 -0000 1.11 @@ -75,12 +75,12 @@ * [EMAIL PROTECTED]</a> *@author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> - *@version $Id: PersistentProxy.java,v 1.10 2002/03/09 19:07:49 baliuka Exp $ + *@version $Id: PersistentProxy.java,v 1.11 2002/03/10 12:32:30 baliuka Exp $ */ public class PersistentProxy -implements MetaObject, /*InvocationHandler,*/ MethodInterceptor,Cloneable, Serializable { +implements MetaObject, org.apache.commons.simplestore.tools.Constants , + MethodInterceptor,Cloneable, Serializable { - private static final boolean DEBUG = System.getProperty("DEBUG") != null; private static Map DEFAULTS = new Hashtable(); private static Method HASH_CODE; @@ -90,7 +90,7 @@ private static Method GET_META_OBJECT; - private Map m_map = new HashMap(); + private Object m_props[] ; private Object m_oid = null; private boolean m_dirty = false; private boolean m_deleted = false; @@ -112,6 +112,7 @@ m_context = context; m_clazz = clazz; m_metaClass = context.getMetaClass(clazz); + m_props = new Object[ m_metaClass.getProperties().length]; } @@ -121,6 +122,7 @@ boolean newCreated, Context context ) { try{ + PersistentProxy handler = new PersistentProxy( persistent, oid, newCreated, context ); Class[] interfaces; @@ -133,10 +135,6 @@ Persistent p = (Persistent) Enhancer.enhance( persistent,interfaces,handler); - // Proxy.newProxyInstance( - // Thread.currentThread().getContextClassLoader(), - // new Class[]{persistent, Persistent.class}, - // handler ); handler.m_object = p; if ( newCreated ) { @@ -148,14 +146,14 @@ return p; }catch(Throwable t){ t.printStackTrace(); - throw new Error(t.getLocalizedMessage()); + throw new Error(t.getMessage()); } } public void setDirty(boolean dirty) { m_dirty = dirty; - m_newCreated = false; + } public boolean isDeleted() { @@ -170,21 +168,20 @@ return this; } - public Map getProperties() { - return m_map; + public Object[] getProperties() { + return m_props; } - public Object getProperty(String name) { + public Object getProperty(int index) { - return m_map.get(name); + return m_props[index]; } - public void setProperty(String name, Object value) { - Object old = m_map.get(name); + public void setProperty(int index, Object value) { + Object old = m_props[ index ]; if (old == null || !old.equals(value)) { - m_dirty = true; m_context.getTransactionManager().getTransaction().add(this); - m_map.put(name, value); + m_props[ index ] = value; } } @@ -258,7 +255,11 @@ if(DEBUG){ System.out.println("Invoke super:" + method); } - return true; + if( method.equals(HASH_CODE) || + method.equals(TO_STRING) || + method.equals(EQUALS) ){ + return false; + }else return true; } public Object beforeInvoke(Object obj,Method method,Object[] args) throws Throwable{ return null; @@ -297,25 +298,22 @@ } public Object handleProperty(Object obj, Method method, Object[] obj2) throws Throwable { - String name = method.getName(); + if( m_clean || m_deleted ) throw new IllegalStateException("Object properties invalidated"); - if (name.startsWith("set")) { + int index = m_metaClass.getPropertyIndex( method ); + + if ( method.getReturnType() == Void.TYPE && obj2.length == 1 ) { if( obj2[0] != null && m_metaClass.isReference(method) ){ - setProperty(name.substring(3), ((Persistent)obj2[0]).getOID()); + setProperty(index, ((Persistent)obj2[0]).getOID()); }else{ - setProperty(name.substring(3), obj2[0]); + setProperty(index, obj2[0]); } - + m_dirty = true; return null; - } else if ( name.startsWith("get") || name.startsWith("is") ) { - if ( method.getName().startsWith("get") ) { - name = method.getName().substring(3); - } else { - name = method.getName().substring(2); - } - Object value = getProperty(name); + } else if( obj2.length == 0 ){ + Object value = getProperty(index); if( value != null && m_metaClass.isReference( method ) ){ return m_context.getStorage(). retrieveObject(method.getReturnType(),value); @@ -330,7 +328,7 @@ } return m_typeConverter.convert( value , method.getReturnType() ); } - throw new java.lang.NoSuchMethodError("pure method " + method.getName()); + throw new java.lang.NoSuchMethodError("pure method invoked: " + method); } public void remove() { @@ -341,13 +339,12 @@ public Object clone() throws CloneNotSupportedException { PersistentProxy cln = (PersistentProxy) super.clone(); - cln.m_map = (Map) ((HashMap) m_map).clone(); + cln.m_props = (Object[])m_props.clone(); return cln; } public void assign(MetaObject mo) { - m_map.clear(); - m_map.putAll( mo.getProperties() ); + System.arraycopy(mo.getProperties(),0,m_props,0,m_props.length); m_oid = mo.getOID(); m_object = mo.getObject(); m_clazz = mo.getPersistentClass(); 1.3 +15 -5 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/TransactionImpl.java Index: TransactionImpl.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/TransactionImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TransactionImpl.java 11 Feb 2002 20:30:09 -0000 1.2 +++ TransactionImpl.java 10 Mar 2002 12:32:30 -0000 1.3 @@ -68,10 +68,12 @@ /** *@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> - *@version $Id: TransactionImpl.java,v 1.2 2002/02/11 20:30:09 froehlich Exp $ + *@version $Id: TransactionImpl.java,v 1.3 2002/03/10 12:32:30 baliuka Exp $ */ -public class TransactionImpl implements InternalTransaction { +public class TransactionImpl + implements org.apache.commons.simplestore.tools.Constants , + InternalTransaction { private static Cache instances = SoftRefMemoryCache.getInstance(new HashMap(), 0x00); @@ -132,6 +134,7 @@ transaction.commit(objects); complete = true; storedState.clear(); + objects.clear(); } public void begin() { @@ -151,6 +154,7 @@ } storedState.clear(); transaction.rollback(objects); + objects.clear(); complete = true; } @@ -159,6 +163,9 @@ if (objects.add(props)) { try { storedState.put(props.getOID(), props.clone()); + if(DEBUG){ + System.out.println("Added to transaction: " + props); + } } catch (CloneNotSupportedException cnse) { throw new UnsupportedOperationException(cnse.getMessage()); } @@ -166,15 +173,18 @@ } public void begin(Set objects) { - transaction.begin(objects); + // transaction.begin(objects); + throw new java.lang.NoSuchMethodError(); } public void rollback(Set objects) { - transaction.rollback(objects); + throw new java.lang.NoSuchMethodError(); + // transaction.rollback(objects); } public void commit(Set objects) { - transaction.commit(objects); + // transaction.commit(objects); + throw new java.lang.NoSuchMethodError(); } public void removeAttribute(String name) { 1.13 +5 -3 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/tools/Enhancer.java Index: Enhancer.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/tools/Enhancer.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- Enhancer.java 9 Mar 2002 19:07:49 -0000 1.12 +++ Enhancer.java 10 Mar 2002 12:32:30 -0000 1.13 @@ -98,10 +98,12 @@ /** *@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> - *@version $Id: Enhancer.java,v 1.12 2002/03/09 19:07:49 baliuka Exp $ + *@version $Id: Enhancer.java,v 1.13 2002/03/10 12:32:30 baliuka Exp $ */ -public class Enhancer implements org.apache.bcel.Constants { - static boolean DEBUG = System.getProperty("DEBUG") != null; +public class Enhancer implements org.apache.bcel.Constants , Constants{ + + + static final String INTERCEPTOR_CLASS = MethodInterceptor.class.getName(); static final ObjectType BOOLEAN_OBJECT = new ObjectType(Boolean.class.getName()); 1.1 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/tools/Constants.java Index: Constants.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache Cocoon" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.simplestore.tools; /** *@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> *@version $Id: Constants.java,v 1.1 2002/03/10 12:32:30 baliuka Exp $ */ public interface Constants { static public final boolean DEBUG = System.getProperty("DEBUG","false").equals("true"); } 1.4 +2 -2 jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestPersistent.java Index: TestPersistent.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestPersistent.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestPersistent.java 28 Feb 2002 18:28:41 -0000 1.3 +++ TestPersistent.java 10 Mar 2002 12:32:31 -0000 1.4 @@ -57,11 +57,11 @@ /** *@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> - *@version $Id: TestPersistent.java,v 1.3 2002/02/28 18:28:41 baliuka Exp $ + *@version $Id: TestPersistent.java,v 1.4 2002/03/10 12:32:31 baliuka Exp $ */ public interface TestPersistent { - public TestPersistent getParent(); + public void setParent(TestPersistent tp); 1.2 +11 -8 jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestPersistentClassType.java Index: TestPersistentClassType.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestPersistentClassType.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TestPersistentClassType.java 9 Mar 2002 19:07:49 -0000 1.1 +++ TestPersistentClassType.java 10 Mar 2002 12:32:31 -0000 1.2 @@ -57,21 +57,24 @@ /** *@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> - *@version $Id: TestPersistentClassType.java,v 1.1 2002/03/09 19:07:49 baliuka Exp $ + *@version $Id: TestPersistentClassType.java,v 1.2 2002/03/10 12:32:31 baliuka Exp $ */ -public abstract class TestPersistentClassType implements TestPersistent{ +public abstract class TestPersistentClassType implements TestPersistent, + org.apache.commons.simplestore.tools.Constants{ /** Creates a new instance of TestPersistentClassType */ public TestPersistentClassType() { } public void doSomething(String arg){ - - this.setStrVal("done Something " + arg); - System.out.println(getStrVal()); + if( DEBUG ){ + this.setStrVal("done Something " + arg); + System.out.println(getStrVal()); + } } - + public abstract TestPersistentClassType getParent(); + public abstract void setDateVal(java.util.Date val) ; public abstract void setBoolVal(boolean val) ; @@ -94,13 +97,13 @@ public abstract String getStrVal1(); - public abstract void setParent(TestPersistent tp); + public abstract void setParent(TestPersistentClassType tp); public abstract int getIntVal(); public abstract boolean getBoolVal(); - public abstract TestPersistent getParent(); + } 1.10 +10 -10 jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestSample.java Index: TestSample.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestSample.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- TestSample.java 9 Mar 2002 19:07:49 -0000 1.9 +++ TestSample.java 10 Mar 2002 12:32:31 -0000 1.10 @@ -72,9 +72,9 @@ /** *@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> - *@version $Id: TestSample.java,v 1.9 2002/03/09 19:07:49 baliuka Exp $ + *@version $Id: TestSample.java,v 1.10 2002/03/10 12:32:31 baliuka Exp $ */ -public class TestSample extends TestCase { +public class TestSample extends TestCase implements org.apache.commons.simplestore.tools.Constants{ PersistenceManager pm; @@ -91,7 +91,7 @@ junit.textui.TestRunner.main(testCaseName); } - public void _testCreate() throws java.lang.Exception { + public void testCreate() throws java.lang.Exception { for (int i = 0; i < 10; i++) { Transaction transaction = pm.getTransaction(); @@ -123,13 +123,14 @@ } - public void _testRetrieve() throws java.lang.Exception { + public void testRetrieve() throws java.lang.Exception { Transaction transaction = pm.getTransaction(); transaction.begin(); java.util.Set objects = pm.findAll(TestPersistentClassType.class); - System.out.println("retrieved " + objects.size()); + if( DEBUG ) + System.out.println("retrieved " + objects.size()); java.util.Iterator i = objects.iterator(); while (i.hasNext()) { @@ -150,9 +151,6 @@ } public void testRollback() throws java.lang.Exception { - _testCreate(); - - _testRetrieve(); Transaction transaction = pm.getTransaction(); @@ -177,12 +175,13 @@ transaction.begin(); TestPersistentClassType object = (TestPersistentClassType) pm.createInstance(TestPersistentClassType.class); object.setStrVal("Test roolback on new created " + object); + if( DEBUG ) System.out.println(object.getStrVal()); transaction.rollback(); transaction.begin(); try{ - System.out.println(object.getStrVal()); + object.getStrVal(); fail("Exception expected " + object); }catch( Exception e ){ } @@ -230,7 +229,8 @@ try { stmt.executeUpdate(sql); } catch (java.sql.SQLException e) { - System.out.println(e.getMessage());// exists ? + if(DEBUG) + System.out.println(e.getMessage());// exists ? } stmt.close(); } finally {
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>