commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From froehl...@apache.org
Subject cvs commit: jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence TransactionManager.java TransactionImpl.java Transaction.java StorageException.java Storage.java PersistentProxy.java Persistent.java PersistenceManager.java ObjectNotFound.java MetaObject.java InternalTransaction.java AbstractStorage.java
Date Sat, 09 Feb 2002 18:51:44 GMT
froehlich    02/02/09 10:51:43

  Modified:    simplestore/src/sample/org/apache/commons/simplestore/persistence
                        TransactionManager.java TransactionImpl.java
                        Transaction.java StorageException.java Storage.java
                        PersistentProxy.java Persistent.java
                        PersistenceManager.java ObjectNotFound.java
                        MetaObject.java InternalTransaction.java
                        AbstractStorage.java
  Log:
  added full license and reformated with jedit's JavaStyle
  
  Revision  Changes    Path
  1.2       +57 -12    jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/TransactionManager.java
  
  Index: TransactionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/TransactionManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TransactionManager.java	7 Feb 2002 16:25:36 -0000	1.1
  +++ TransactionManager.java	9 Feb 2002 18:51:43 -0000	1.2
  @@ -1,22 +1,67 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 apache@apache.org.
  + *
  + * 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.persistence;
   
   /**
  - *
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: TransactionManager.java,v 1.1 2002/02/07 16:25:36 baliuka Exp $
  + *@version    $Id: TransactionManager.java,v 1.2 2002/02/09 18:51:43 froehlich Exp $
    */
   public interface TransactionManager {
   
       public InternalTransaction getTransaction();
  -    
  +
   }
   
  
  
  
  1.2       +127 -74   jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/TransactionImpl.java
  
  Index: TransactionImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/TransactionImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TransactionImpl.java	7 Feb 2002 16:25:36 -0000	1.1
  +++ TransactionImpl.java	9 Feb 2002 18:51:43 -0000	1.2
  @@ -1,124 +1,177 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 apache@apache.org.
  + *
  + * 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.persistence;
   
   import org.apache.commons.simplestore.*;
   /**
  - *
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: TransactionImpl.java,v 1.1 2002/02/07 16:25:36 baliuka Exp $
  + *@version    $Id: TransactionImpl.java,v 1.2 2002/02/09 18:51:43 froehlich Exp $
    */
   
  -public class TransactionImpl implements InternalTransaction{
  -    
  -    static private Store instances = SoftRefMemoryStore.getInstance( new java.util.HashMap(), null , 0x00 );    
  -    
  -   
  +public class TransactionImpl implements InternalTransaction {
  +
  +    private static Store instances = SoftRefMemoryStore.getInstance(new java.util.HashMap(), null, 0x00);
  +
       int threadId = getCurrentThreadId();
       InternalTransaction transaction;
       java.util.Set objects;
       java.util.Map attributes = new java.util.HashMap();
       boolean complete = true;
  -    
  -    /** Creates new TransactionImpl */
  -    public TransactionImpl( InternalTransaction transaction, java.util.Set objects) {
  +
  +    /**
  +     * Creates new TransactionImpl
  +     *
  +     *@param  transaction
  +     *@param  objects
  +     */
  +    public TransactionImpl(InternalTransaction transaction, java.util.Set objects) {
           this.objects = objects;
           this.transaction = transaction;
  - 
  +
       }
  -    
  -    private static int getCurrentThreadId(){
  -        return System.identityHashCode( Thread.currentThread() );
  -    }
  -    
  -    public static InternalTransaction getInstance(InternalTransaction transaction){
  -        
  +
  +    public static InternalTransaction getInstance(InternalTransaction transaction) {
  +
           Number threadId = new Integer(getCurrentThreadId());
           InternalTransaction tr = (InternalTransaction) instances.get(threadId);
  -        if( tr != null )return tr;
  -        
  -        tr = new TransactionImpl(transaction,new java.util.HashSet());
  -        instances.put(threadId,tr);
  -        
  +        if (tr != null) {
  +            return tr;
  +        }
  +
  +        tr = new TransactionImpl(transaction, new java.util.HashSet());
  +        instances.put(threadId, tr);
  +
           return tr;
  -        
  -        
  +
  +    }
  +
  +    private static int getCurrentThreadId() {
  +        return System.identityHashCode(Thread.currentThread());
  +    }
  +
  +    public void setAttribute(String name, Object value) {
  +
  +        attributes.put(name, value);
  +    }
  +
  +    public int getThreadId() {
  +
  +        return threadId;
       }
  -    
  +
  +    public Object getAttribute(String name) {
  +        return attributes.get(name);
  +    }
  +
       public void commit() {
           checkState();
           checkState(!complete);
           transaction.commit(objects);
           complete = true;
  -        
  +
       }
  -    
  +
       public void begin() {
           checkState();
  -        checkState( complete );
  -        transaction.begin( objects );
  +        checkState(complete);
  +        transaction.begin(objects);
           complete = false;
       }
  -    
  +
       public void rollback() {
           checkState();
  -        checkState( !complete );
  -        transaction.rollback( objects );
  +        checkState(!complete);
  +        transaction.rollback(objects);
           complete = true;
       }
  -    
  -    public int  getThreadId(){
  -        
  -        return threadId;
  -        
  -    }
  -    
  -    void checkState( boolean b ){
  -        if( !b  )
  -            throw new  java.lang.IllegalStateException("Illegal Transaction state");
  -    }
  -    void checkState(){
  -        int id = getCurrentThreadId();
  -        if( threadId != id )
  -            throw new  java.lang.IllegalStateException("Accessed Transaction " + threadId + " in " + id);
  -    }
  -    
  +
       public void add(MetaObject props) {
           checkState();
           objects.add(props);
  -        
  +
       }
  -    
  +
       public void begin(java.util.Set objects) {
           transaction.begin(objects);
       }
  -    
  +
       public void rollback(java.util.Set objects) {
           transaction.rollback(objects);
       }
  -    
  +
       public void commit(java.util.Set objects) {
           transaction.commit(objects);
       }
  -    
  -    public Object getAttribute(String name) {
  -        return attributes.get(name);
  -    }    
  -    
  +
       public void removeAttribute(String name) {
           attributes.remove(name);
  -    }    
  -    
  -    public void setAttribute(String name, Object value) {
  -        
  -        attributes.put(name,value);
       }
  -    
  +
  +    void checkState(boolean b) {
  +        if (!b) {
  +            throw new java.lang.IllegalStateException("Illegal Transaction state");
  +        }
  +    }
  +
  +    void checkState() {
  +        int id = getCurrentThreadId();
  +        if (threadId != id) {
  +            throw new java.lang.IllegalStateException("Accessed Transaction " + threadId + " in " + id);
  +        }
  +    }
  +
   }
  +
  
  
  
  1.2       +60 -15    jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/Transaction.java
  
  Index: Transaction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/Transaction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Transaction.java	7 Feb 2002 16:25:36 -0000	1.1
  +++ Transaction.java	9 Feb 2002 18:51:43 -0000	1.2
  @@ -1,27 +1,72 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 apache@apache.org.
  + *
  + * 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.persistence;
   
   /**
  - *
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: Transaction.java,v 1.1 2002/02/07 16:25:36 baliuka Exp $
  + *@version    $Id: Transaction.java,v 1.2 2002/02/09 18:51:43 froehlich Exp $
    */
   public interface Transaction {
  -    
  +
       void begin();
  -    
  +
       void commit();
  -    
  +
       void rollback();
  -    
  +
       // TODO Transaction Synchronization
   }
   
  
  
  
  1.2       +68 -24    jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/StorageException.java
  
  Index: StorageException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/StorageException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StorageException.java	7 Feb 2002 16:25:36 -0000	1.1
  +++ StorageException.java	9 Feb 2002 18:51:43 -0000	1.2
  @@ -1,47 +1,91 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 apache@apache.org.
  + *
  + * 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.persistence;
   
   /**
  - *
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: StorageException.java,v 1.1 2002/02/07 16:25:36 baliuka Exp $
  + *@version    $Id: StorageException.java,v 1.2 2002/02/09 18:51:43 froehlich Exp $
    */
   public class StorageException extends java.lang.Exception {
   
       public Throwable detail;
  +
       /**
        * Creates new <code>StorageException</code> without detail message.
        */
  -    public StorageException() {
  -    }
  +    public StorageException() { }
   
   
       /**
        * Constructs an <code>StorageException</code> with the specified detail message.
  -     * @param msg the detail message.
  -     * @param detail the detail Throwable.
  +     *
  +     *@param  msg     the detail message.
  +     *@param  detail  the detail Throwable.
        */
  -    public StorageException(String msg,Throwable detail ) {
  +    public StorageException(String msg, Throwable detail) {
           super(msg);
           this.detail = detail;
       }
  -    
  +
       public java.lang.String getMessage() {
  -        
  -        return super.getMessage() + ( detail == null ? "" : " : " +  detail.getMessage()  ) ;
  -        
  -    }    
  -    
  -    
  -    
  +
  +        return super.getMessage() + (detail == null ? "" : " : " + detail.getMessage());
  +    }
  +
  +
   }
   
   
  
  
  
  1.2       +71 -28    jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/Storage.java
  
  Index: Storage.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/Storage.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Storage.java	7 Feb 2002 16:25:36 -0000	1.1
  +++ Storage.java	9 Feb 2002 18:51:43 -0000	1.2
  @@ -1,39 +1,82 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 apache@apache.org.
  + *
  + * 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.persistence;
   
   import org.apache.commons.simplestore.*;
   /**
  - *
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: Storage.java,v 1.1 2002/02/07 16:25:36 baliuka Exp $
  + *@version    $Id: Storage.java,v 1.2 2002/02/09 18:51:43 froehlich Exp $
    */
   
   public interface Storage {
  -   
  -   
  -   public void storeObject( MetaObject properties )throws StorageException;
  -    
  -   public Object retrieveObject( Class clasz, Object id )throws StorageException;
  -   
  -   public void registerClass( Class clasz )throws StorageException;
  -    
  -   public void setContext( Store store );
  -   
  -   public java.util.Set retrieveAll( Class clasz )throws StorageException;
  -    
  -   public java.util.Set query( Class clasz, String procName,Object[] args )throws StorageException; 
  -   
  -   public void close()throws StorageException;
  -    
  -    
  +
  +    public void storeObject(MetaObject properties) throws StorageException;
  +
  +    public Object retrieveObject(Class clasz, Object id) throws StorageException;
  +
  +    public void registerClass(Class clasz) throws StorageException;
  +
  +    public void setContext(Store store);
  +
  +    public java.util.Set retrieveAll(Class clasz) throws StorageException;
  +
  +    public java.util.Set query(Class clasz, String procName, Object[] args) throws StorageException;
  +
  +    public void close() throws StorageException;
  +
   
   }
   
  
  
  
  1.4       +303 -266  jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/PersistentProxy.java
  
  Index: PersistentProxy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/PersistentProxy.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PersistentProxy.java	9 Feb 2002 14:58:51 -0000	1.3
  +++ PersistentProxy.java	9 Feb 2002 18:51:43 -0000	1.4
  @@ -1,336 +1,373 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 apache@apache.org.
  + *
  + * 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.persistence;
   
   import java.lang.reflect.*;
   
   /**
  - *
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: PersistentProxy.java,v 1.3 2002/02/09 14:58:51 baliuka Exp $
  + *@version    $Id: PersistentProxy.java,v 1.4 2002/02/09 18:51:43 froehlich Exp $
    */
   public class PersistentProxy implements MetaObject, InvocationHandler, java.io.Serializable {
  -    
  -    
  +
       private static Method HASH_CODE;
       private static Method EQUALS;
       private static Method TO_STRING;
       private static Method GET_OID;
       private static Method GET_META_OBJECT;
       private static java.util.Map defaults = new java.util.Hashtable();
  -    
  -    static{
  -        
  -        try{
  -            
  -            GET_OID         = Persistent.class.getMethod("getOID",null);
  -            GET_META_OBJECT = Persistent.class.getMethod("getMetaObject",null);
  -            
  -            
  -            HASH_CODE       = Object.class.getMethod("hashCode",null);
  -            TO_STRING       = Object.class.getMethod("toString",null);
  -            EQUALS          = Object.class.getMethod("equals",new Class[]{Object.class});
  -            
  -           defaults.put( byte.class,new java.lang.Byte((byte)0) );
  -           defaults.put( short.class,new java.lang.Short((short)0) );
  -           defaults.put( int.class,new java.lang.Integer(0) );
  -           defaults.put( long.class,new java.lang.Long(0) );
  -           defaults.put( float.class,new java.lang.Float(0) );
  -           defaults.put( double.class,new java.lang.Double(0) );
  -           defaults.put( char.class,new java.lang.Character('\u0000') );
  -           defaults.put( boolean.class,new java.lang.Boolean(false) );
  -        
  -        }catch(Exception e){
  -            e.printStackTrace();
  -            throw new Error(e.getMessage());
  -            
  -        }
  -        
  -    }
  -    
  +
       java.util.Map map = new java.util.HashMap();
  -    
  -    Object  oid  = null;
  -    Persistent  object;
  +
  +    Object oid = null;
  +    Persistent object;
       Class pClass;
       TransactionManager transactionManager;
  -    boolean dirty   = false;
  +    boolean dirty = false;
       boolean deleted = false;
  -    boolean newCreated ;
  -    
  -    
  -    /** Creates new ValueProxy */
  -    public PersistentProxy(Class pClass,Object oid, boolean newCreated, TransactionManager transactionManager) {
  -        
  +    boolean newCreated;
  +
  +
  +    /**
  +     * Creates new ValueProxy
  +     *
  +     *@param  pClass
  +     *@param  oid
  +     *@param  newCreated
  +     *@param  transactionManager
  +     */
  +    public PersistentProxy(Class pClass, Object oid, boolean newCreated, TransactionManager transactionManager) {
  +
           this.oid = oid;
           this.newCreated = newCreated;
           this.transactionManager = transactionManager;
  -        this.pClass  = pClass;
  -        
  +        this.pClass = pClass;
  +
       }
  -    
  -    public java.lang.Object handleEquals(java.lang.Object obj ){
  -        
  -        if( obj == null   ){
  -            return new Boolean(false);
  +
  +
  +    public static Persistent getPersitent(Class persistent, Object oid, boolean newCreated, TransactionManager transactionManager) {
  +        PersistentProxy handler = new PersistentProxy(persistent, oid, newCreated, transactionManager);
  +        Persistent p = (Persistent) Proxy.newProxyInstance(
  +                Thread.currentThread().getContextClassLoader(), new Class[]{persistent, Persistent.class}, handler);
  +        handler.object = p;
  +        if (newCreated) {
  +
  +            MetaObject mo = p.getMetaObject();
  +            transactionManager.getTransaction().add(mo);
           }
  -        
  -        if(! (obj instanceof Persistent ) ){
  -            return new Boolean(false);
  +        return p;
  +    }
  +// TODO must be converter interface
  +    public static Object convertNumber(Number number, Class cls) {
  +
  +        if (cls.equals(Byte.class)) {
  +            return new Byte(number.byteValue());
  +        } else if (cls.equals(Short.class)) {
  +            return new Short(number.shortValue());
  +        } else if (cls.equals(Integer.class)) {
  +            return new Integer(number.intValue());
  +        } else if (cls.equals(Long.class)) {
  +            return new Long(number.longValue());
  +        } else if (cls.equals(Float.class)) {
  +            return new Float(number.floatValue());
  +        } else if (cls.equals(Double.class)) {
  +            return new Double(number.doubleValue());
  +        } else if (cls.equals(Boolean.class)) {
  +            return new Boolean(number.intValue() != 0);
  +        } else if (cls.equals(Character.TYPE)) {
  +            return new Character(number.toString().charAt(0));
  +        } else {
  +            throw new java.lang.UnsupportedOperationException("Number class = " + number.getClass().getName() + " Target Class " + cls.getName());
           }
  -        
  -        Persistent object = (Persistent)obj;
  -        
  -        
  -        if( oid == null ){
  -            
  -            return new Boolean( oid == object.getOID() );
  -            
  -        }else{
  -            
  -            return new Boolean( oid.equals( object.getOID() ) );
  +
  +    }
  +    // TODO must be converter interface
  +    public static Object convertPrimityve(Number number, Class cls) {
  +
  +        if (cls.equals(Byte.TYPE)) {
  +            return new Byte(number.byteValue());
  +        } else if (cls.equals(Short.TYPE)) {
  +            return new Short(number.shortValue());
  +        } else if (cls.equals(Integer.TYPE)) {
  +            return new Integer(number.intValue());
  +        } else if (cls.equals(Long.TYPE)) {
  +            return new Long(number.longValue());
  +        } else if (cls.equals(Float.TYPE)) {
  +            return new Float(number.floatValue());
  +        } else if (cls.equals(Double.TYPE)) {
  +            return new Double(number.doubleValue());
  +        } else if (cls.equals(Boolean.TYPE)) {
  +            return new Boolean(number.intValue() != 0);
  +        } else if (cls.equals(Character.TYPE)) {
  +            return new Character(number.toString().charAt(0));
  +        } else {
  +            throw new java.lang.UnsupportedOperationException("Number class = " + number.getClass().getName() + " Target Class " + cls.getName());
           }
  -        
  -        
  +
       }
  -    
  -    public java.lang.Object invoke(Object obj, Method method, Object[] obj2) throws java.lang.Throwable {
  -        
  -        synchronized( this ){
  -            
  -            if ( GET_META_OBJECT.equals( method) ){
  -                return this;
  -                
  -            }else if( TO_STRING.equals( method ) ){
  -                
  -                return oid + "";
  -                
  -            }else if( GET_OID.equals( method ) ){
  -                
  -                return oid;
  -                
  -            }else if ( HASH_CODE.equals( method ) ){
  -                
  -                if(oid == null){
  -                    return new Integer(0);
  +    // TODO must be converter interface
  +    public static Object convert(Object object, Class cls) {
  +        try {
  +            if (cls.isPrimitive()) {
  +                if (object == null) {
  +                    return defaults.get(cls);
                   }
  -                return new Integer(oid.hashCode());
  -                
  -            }else if( EQUALS.equals(method) ){
  -                
  -                return handleEquals(obj2[0]);
  -                
  -                
  -            } else{
  -                
  -                return  handleProperty(obj,method,obj2);
  -                
  +                if (object instanceof Number) {
  +                    return convertPrimityve((Number) object, cls);
  +                }
  +            }
  +
  +            if (object == null) {
  +                return null;
               }
  -            
  +
  +            if (cls.isAssignableFrom(object.getClass())) {
  +                return object;
  +            }
  +
  +            // if( object instanceof String ){ ?????
  +            //     return org.apache.commons.beanutils.ConvertUtils.convert((String)object,cls);
  +            // }
  +
  +
  +            if (cls.isAssignableFrom(Number.class) && object instanceof Number) {
  +                return convertNumber((Number) object, cls);
  +            }
  +
  +            if (cls.equals(Boolean.class) && object instanceof Number) {
  +                return new Boolean(((Number) object).intValue() != 0);
  +            }
  +
  +            if (cls.equals(Character.TYPE)) {
  +                return new Character(object.toString().charAt(0));
  +            }
  +
  +            throw new java.lang.UnsupportedOperationException(cls.getName() + ":" + object);
  +        } catch (Throwable t) {
  +            // TODO
  +            t.printStackTrace();
  +            throw new RuntimeException(t.getClass().getName() + ":" + t.getMessage());
           }
       }
  -    
  -    
  -    public java.lang.Object handleProperty(java.lang.Object obj, java.lang.reflect.Method method, java.lang.Object[] obj2) throws java.lang.Throwable {
  -        
  -        String name = method.getName();
  -        
  -        
  -        if( name.startsWith("set")){
  -            
  -            setProperty(name.substring(3), obj2[0] );
  -            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);
  -            if( value == null && method.getReturnType().isPrimitive() )
  -                value = convert(value, method.getReturnType());
  -            return value;
  -            
  +
  +    public void setProperty(String name, Object value) {
  +
  +        Object old = map.put(name, value);
  +        if (old == null || !old.equals(value)) {
  +            dirty = true;
  +            transactionManager.getTransaction().add(this);
           }
  -        
  -        throw new java.lang.IllegalStateException("pure method " + method.getName());
  -        
  -        
       }
  -    
  -    
  -    public static Persistent getPersitent(Class persistent,Object oid,boolean newCreated, TransactionManager transactionManager){
  -        PersistentProxy handler = new PersistentProxy(persistent,oid,newCreated, transactionManager);
  -        Persistent p =  (Persistent)Proxy.newProxyInstance(
  -        Thread.currentThread().getContextClassLoader(),new Class[]{persistent,Persistent.class},handler);
  -        handler.object = p; 
  -        if( newCreated ) {
  -            
  -            MetaObject mo = p.getMetaObject();
  -            transactionManager.getTransaction().add(mo);
  -        }
  -        return p;
  -        
  +
  +    public void setDirty(boolean dirty) {
  +        this.dirty = dirty;
  +        this.newCreated = false;
       }
  -    
  -    
  +
  +
       public boolean isDeleted() {
           return deleted;
       }
  -    
  +
       public boolean isNew() {
           return newCreated;
       }
  -    
  +
       public MetaObject getMetaObject() {
           return this;
       }
  -    
  -    public void setProperty( String name, Object value ) {
  -        
  -        Object old = map.put(name,value);
  -        if( old == null || !old.equals(value )){
  -            dirty = true;
  -            transactionManager.getTransaction().add( this );
  -        }
  -        
  -    }
  -    
  +
       public java.util.Map getProperties() {
           return map;
       }
  -    
  +
       public Object getProperty(String name) {
  -        return  map.get(name);
  -        
  +        return map.get(name);
       }
  -    
  +
       public boolean isLoaded() {
           return true;
       }
  -    
  -    public void remove() {
  -        deleted = true;
  -    }
  -    
  +
       public Class getPersistentClass() {
           return pClass;
       }
  -    
  +
       public Object getOID() {
           return oid;
       }
  -    
  +
       public boolean isDirty() {
           return dirty;
       }
  -    
  -    public void setDirty(boolean dirty) {
  -        this.dirty = dirty;
  -        this.newCreated = false;
  -    }
  -    
  +
       public Persistent getObject() {
           return object;
       }
  -// TODO must be converter interface
  -    public static Object convertNumber(Number number,Class cls){
  -        
  -        if(cls.equals(Byte.class))
  -            return new Byte(number.byteValue());
  -        else if( cls.equals(Short.class) )
  -            return new Short(number.shortValue());
  -        else if(cls.equals(Integer.class))
  -            return new Integer(number.intValue());
  -        else if( cls.equals( Long.class ) )
  -            return new Long(number.longValue());
  -        else if( cls.equals( Float.class ) )
  -            return new Float(number.floatValue());
  -        else if( cls.equals( Double.class ) )
  -            return new Double(number.doubleValue());
  -        else if( cls.equals( Boolean.class ) )
  -            return new Boolean( number.intValue() != 0  );
  -        else if( cls.equals( Character.TYPE ) )
  -            return new Character( number.toString().charAt(0)  );
  -        else
  -            throw new java.lang.UnsupportedOperationException( "Number class = " + number.getClass().getName() + " Target Class " + cls.getName());
  -        
  -    }
  -    // TODO must be converter interface
  -    public static Object convertPrimityve(Number number,Class cls){
  -        
  -        if(cls.equals(Byte.TYPE))
  -            return new Byte(number.byteValue());
  -        else if (cls.equals(Short.TYPE))
  -            return new Short( number.shortValue());
  -        else if(cls.equals(Integer.TYPE))
  -            return new Integer(number.intValue());
  -        else if ( cls.equals( Long.TYPE ) )
  -            return new Long(number.longValue());
  -        else if ( cls.equals( Float.TYPE ) )
  -            return new Float(number.floatValue());
  -        else if ( cls.equals( Double.TYPE ) )
  -            return new Double(number.doubleValue());
  -        else if ( cls.equals( Boolean.TYPE ) )
  -            return new Boolean( number.intValue() != 0  );
  -        else if ( cls.equals( Character.TYPE ) )
  -            return new Character( number.toString().charAt(0)  );
  -        else
  -            throw new java.lang.UnsupportedOperationException( "Number class = " + number.getClass().getName() + " Target Class " + cls.getName());
  -        
  +
  +    public java.lang.Object handleEquals(java.lang.Object obj) {
  +
  +        if (obj == null) {
  +            return new Boolean(false);
  +        }
  +
  +        if (!(obj instanceof Persistent)) {
  +            return new Boolean(false);
  +        }
  +
  +        Persistent object = (Persistent) obj;
  +
  +        if (oid == null) {
  +
  +            return new Boolean(oid == object.getOID());
  +        } else {
  +
  +            return new Boolean(oid.equals(object.getOID()));
  +        }
  +
       }
  -    // TODO must be converter interface
  -    public static Object convert(Object object,Class cls){
  -        try{
  -            if( cls.isPrimitive() ){
  -                if( object == null ){
  -                    return defaults.get(cls);
  -                }
  -                if( object instanceof Number ){
  -                    return convertPrimityve((Number)object,cls);
  +
  +    public java.lang.Object invoke(Object obj, Method method, Object[] obj2) throws java.lang.Throwable {
  +
  +        synchronized (this) {
  +
  +            if (GET_META_OBJECT.equals(method)) {
  +                return this;
  +            } else if (TO_STRING.equals(method)) {
  +
  +                return oid + "";
  +            } else if (GET_OID.equals(method)) {
  +
  +                return oid;
  +            } else if (HASH_CODE.equals(method)) {
  +
  +                if (oid == null) {
  +                    return new Integer(0);
                   }
  -                
  -            }
  -            
  -            if(object == null){
  -                return null;
  -            }
  -            
  -            if( cls.isAssignableFrom(object.getClass())  ){
  -                return object;
  -            }
  -            
  -           // if( object instanceof String ){ ?????
  -           //     return org.apache.commons.beanutils.ConvertUtils.convert((String)object,cls);
  -           // }
  -            
  -            
  -            if( cls.isAssignableFrom(Number.class ) && object instanceof Number ){
  -                return convertNumber((Number)object,cls);
  +                return new Integer(oid.hashCode());
  +            } else if (EQUALS.equals(method)) {
  +
  +                return handleEquals(obj2[0]);
  +
  +            } else {
  +
  +                return handleProperty(obj, method, obj2);
               }
  -            
  -            if( cls.equals( Boolean.class ) && object instanceof Number ){
  -                return new Boolean((( Number )object).intValue() != 0  );
  +
  +        }
  +    }
  +
  +
  +    public java.lang.Object handleProperty(java.lang.Object obj, java.lang.reflect.Method method, java.lang.Object[] obj2) throws java.lang.Throwable {
  +
  +        String name = method.getName();
  +
  +        if (name.startsWith("set")) {
  +
  +            setProperty(name.substring(3), obj2[0]);
  +            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);
               }
  -            
  -            if( cls.equals( Character.TYPE ) ){
  -                return new Character( object.toString().charAt(0)  );
  +            Object value = getProperty(name);
  +            if (value == null && method.getReturnType().isPrimitive()) {
  +                value = convert(value, method.getReturnType());
               }
  -            
  -            throw new java.lang.UnsupportedOperationException( cls.getName() + ":" + object );
  -            
  -        }catch(Throwable t){
  -            // TODO
  -            t.printStackTrace();
  -            throw new RuntimeException( t.getClass().getName() + ":" + t.getMessage() );
  +            return value;
  +        }
  +
  +        throw new java.lang.IllegalStateException("pure method " + method.getName());
  +
  +    }
  +
  +    public void remove() {
  +        deleted = true;
  +    }
  +
  +    static {
  +
  +        try {
  +
  +            GET_OID = Persistent.class.getMethod("getOID", null);
  +            GET_META_OBJECT = Persistent.class.getMethod("getMetaObject", null);
  +
  +            HASH_CODE = Object.class.getMethod("hashCode", null);
  +            TO_STRING = Object.class.getMethod("toString", null);
  +            EQUALS = Object.class.getMethod("equals", new Class[]{Object.class});
  +
  +            defaults.put(byte.class, new java.lang.Byte((byte) 0));
  +            defaults.put(short.class, new java.lang.Short((short) 0));
  +            defaults.put(int.class, new java.lang.Integer(0));
  +            defaults.put(long.class, new java.lang.Long(0));
  +            defaults.put(float.class, new java.lang.Float(0));
  +            defaults.put(double.class, new java.lang.Double(0));
  +            defaults.put(char.class, new java.lang.Character('\u0000'));
  +            defaults.put(boolean.class, new java.lang.Boolean(false));
  +
  +        } catch (Exception e) {
  +            e.printStackTrace();
  +            throw new Error(e.getMessage());
           }
  +
       }
  -        
  +
   }
  +
  
  
  
  1.2       +61 -16    jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/Persistent.java
  
  Index: Persistent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/Persistent.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Persistent.java	7 Feb 2002 16:25:36 -0000	1.1
  +++ Persistent.java	9 Feb 2002 18:51:43 -0000	1.2
  @@ -1,25 +1,70 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 apache@apache.org.
  + *
  + * 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.persistence;
   
   /**
  - *
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: Persistent.java,v 1.1 2002/02/07 16:25:36 baliuka Exp $
  + *@version    $Id: Persistent.java,v 1.2 2002/02/09 18:51:43 froehlich Exp $
    */
   
   public interface Persistent {
  -    
  -  public Object getOID();
  -  
  -  public  MetaObject getMetaObject(); 
  -  
  +
  +    public Object getOID();
  +
  +    public MetaObject getMetaObject();
  +
   }
   
  
  
  
  1.3       +122 -76   jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/PersistenceManager.java
  
  Index: PersistenceManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/PersistenceManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PersistenceManager.java	9 Feb 2002 13:49:47 -0000	1.2
  +++ PersistenceManager.java	9 Feb 2002 18:51:43 -0000	1.3
  @@ -1,116 +1,162 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 apache@apache.org.
  + *
  + * 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.persistence;
   
   import org.apache.commons.simplestore.*;
   
   /**
  - *
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: PersistenceManager.java,v 1.2 2002/02/09 13:49:47 baliuka Exp $
  + *@version    $Id: PersistenceManager.java,v 1.3 2002/02/09 18:51:43 froehlich Exp $
    */
   
   public class PersistenceManager {
  -  
  +
       private static PersistenceManager pm;
  -    
  +
  +    private static java.security.SecureRandom seeder = new java.security.SecureRandom();
  +
       private Storage storage;
       private TransactionManager transactionManager;
  -    private Store store = SoftRefMemoryStore.getInstance( new java.util.HashMap(), null , 0xFF );
  -    
  -    /** Creates new PersiatenceManager */
  -    protected  PersistenceManager( Storage storage, TransactionManager transactionManager ) {
  +    private Store store = SoftRefMemoryStore.getInstance(new java.util.HashMap(), null, 0xFF);
  +
  +    /**
  +     * Creates new PersiatenceManager
  +     *
  +     *@param  storage
  +     *@param  transactionManager
  +     */
  +    protected PersistenceManager(Storage storage, TransactionManager transactionManager) {
           this.storage = storage;
           this.transactionManager = transactionManager;
  -        
  +
       }
  -    
  -    static public PersistenceManager getPersistenceManager( Storage storage,TransactionManager transactions ){
  -        if( pm == null ){
  -            pm = new PersistenceManager( storage,transactions );
  +
  +    public static PersistenceManager getPersistenceManager(Storage storage, TransactionManager transactions) {
  +        if (pm == null) {
  +            pm = new PersistenceManager(storage, transactions);
               storage.setContext(pm.store);
  -        }  
  +        }
           return pm;
  -        
       }
  -    
  -    public Transaction getTransaction(){
  -    
  +
  +    public Transaction getTransaction() {
  +
           return transactionManager.getTransaction();
  -    
       }
  -    
  -    public Object createInstance( Class aclass ){
  -        
  +
  +    public Object getOID(Object pc) {
  +
  +        return ((Persistent) pc).getOID();
  +
  +    }
  +
  +    public Object createInstance(Class aclass) {
  +
           Object id = generateOID(aclass);
  -        Persistent p = PersistentProxy.getPersitent(aclass,id,true,transactionManager);
  -        store.put(id,p);
  -        
  +        Persistent p = PersistentProxy.getPersitent(aclass, id, true, transactionManager);
  +        store.put(id, p);
  +
           return p;
  -        
       }
  -    
  -    public Object findInstance( Class clasz,Object oid )throws StorageException{
  -    
  -         return storage.retrieveObject(clasz, oid );
  -        
  -    }
  -   public java.util.Set findAll( Class clasz )throws StorageException{
  -   
  -       return storage.retrieveAll( clasz );
  -   }
  -    
  -    public void removeInstance(Object pc){
  -        
  -        MetaObject p = ((Persistent)pc).getMetaObject();
  -        if( p != null )
  +
  +    public Object findInstance(Class clasz, Object oid) throws StorageException {
  +
  +        return storage.retrieveObject(clasz, oid);
  +    }
  +
  +    public java.util.Set findAll(Class clasz) throws StorageException {
  +
  +        return storage.retrieveAll(clasz);
  +    }
  +
  +    public void removeInstance(Object pc) {
  +
  +        MetaObject p = ((Persistent) pc).getMetaObject();
  +        if (p != null) {
               p.remove();
  -        
  +        }
       }
  -   public Object getOID( Object pc ){
  -        
  -        return ((Persistent)pc).getOID();
  -        
  -        
  -    }
  - 
  -    public void registerClass( Class clasz )throws StorageException{
  -    
  +
  +    public void registerClass(Class clasz) throws StorageException {
  +
           storage.registerClass(clasz);
  -       
  +
       }
  -   
  -   
  -    private static java.security.SecureRandom seeder = new java.security.SecureRandom();
  -    
  -    private synchronized Object  generateOID( Class aclass ){
  -      
  -   //TODO ADD interface OIDGenerator  
  -        
  +
  +    private synchronized Object generateOID(Class aclass) {
  +
  +        //TODO ADD interface OIDGenerator
  +
           byte[] bytes = new byte[8];
           int value = seeder.nextInt();
           int i = 0;
  -        
  +
           bytes[i++] = (byte) ((value >>> 24) & 0xFF);
           bytes[i++] = (byte) ((value >>> 16) & 0xFF);
           bytes[i++] = (byte) ((value >>> 8) & 0xFF);
           bytes[i++] = (byte) (value & 0xFF);
  -       
  -        value = (int) System.currentTimeMillis() & 0xFFFFFFFF; 
  -       
  +
  +        value = (int) System.currentTimeMillis() & 0xFFFFFFFF;
  +
           bytes[i++] = (byte) ((value >>> 24) & 0xFF);
           bytes[i++] = (byte) ((value >>> 16) & 0xFF);
           bytes[i++] = (byte) ((value >>> 8) & 0xFF);
           bytes[i++] = (byte) (value & 0xFF);
  -        
  -      return new Long( new java.math.BigInteger(bytes).longValue());
  -      
  +
  +        return new Long(new java.math.BigInteger(bytes).longValue());
       }
   }
  +
  
  
  
  1.2       +66 -19    jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/ObjectNotFound.java
  
  Index: ObjectNotFound.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/ObjectNotFound.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ObjectNotFound.java	9 Feb 2002 11:09:22 -0000	1.1
  +++ ObjectNotFound.java	9 Feb 2002 18:51:43 -0000	1.2
  @@ -1,33 +1,80 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 apache@apache.org.
  + *
  + * 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.persistence;
   
   /**
  - *
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: ObjectNotFound.java,v 1.1 2002/02/09 11:09:22 baliuka Exp $
  + *@version    $Id: ObjectNotFound.java,v 1.2 2002/02/09 18:51:43 froehlich Exp $
    */
   public class ObjectNotFound extends StorageException {
  -    
  +
       /**
        * Creates a new instance of <code>ObjectNotFound</code> without detail message.
        */
  -    public ObjectNotFound() {
  -    }
  -    
  -    
  +    public ObjectNotFound() { }
  +
  +
       /**
        * Constructs an instance of <code>ObjectNotFound</code> with the specified detail message.
  -     * @param msg the detail message.
  +     *
  +     *@param  msg  the detail message.
  +     *@param  th
        */
  -    public ObjectNotFound(String msg,Throwable th) {
  -        super(msg,th);
  +    public ObjectNotFound(String msg, Throwable th) {
  +        super(msg, th);
       }
   }
  +
  
  
  
  1.3       +70 -25    jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/MetaObject.java
  
  Index: MetaObject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/MetaObject.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MetaObject.java	9 Feb 2002 13:49:47 -0000	1.2
  +++ MetaObject.java	9 Feb 2002 18:51:43 -0000	1.3
  @@ -1,44 +1,89 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 apache@apache.org.
  + *
  + * 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.persistence;
   
   /**
  - *
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: MetaObject.java,v 1.2 2002/02/09 13:49:47 baliuka Exp $
  + *@version    $Id: MetaObject.java,v 1.3 2002/02/09 18:51:43 froehlich Exp $
    */
   
  -public interface MetaObject  {
  -    
  +public interface MetaObject {
  +
       public Object getOID();
  -    
  +
       public Object getProperty(String name);
  -    
  -    public void setProperty(String name,Object value);
  -    
  +
  +    public void setProperty(String name, Object value);
  +
       public java.util.Map getProperties();
  -    
  +
       public Class getPersistentClass();
  -    
  +
       public boolean isDirty();
  -    
  +
       public boolean isNew();
  -    
  +
       public boolean isDeleted();
  -    
  +
       public void remove();
  -    
  +
       public boolean isLoaded();
  -    
  +
       public void setDirty(boolean dirty);
  -    
  +
       public Persistent getObject();
   }
   
  
  
  
  1.2       +68 -24    jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/InternalTransaction.java
  
  Index: InternalTransaction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/InternalTransaction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InternalTransaction.java	7 Feb 2002 16:25:36 -0000	1.1
  +++ InternalTransaction.java	9 Feb 2002 18:51:43 -0000	1.2
  @@ -1,36 +1,80 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 apache@apache.org.
  + *
  + * 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.persistence;
   
   /**
  - *
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: InternalTransaction.java,v 1.1 2002/02/07 16:25:36 baliuka Exp $
  + *@version    $Id: InternalTransaction.java,v 1.2 2002/02/09 18:51:43 froehlich Exp $
    */
   
   public interface InternalTransaction extends Transaction {
  -    
  +
       public void begin(java.util.Set objects);
  -    
  +
       public void commit(java.util.Set objects);
  -    
  +
       public void rollback(java.util.Set objects);
  -    
  -    void add( MetaObject props);
  -    
  -    void setAttribute(String name,Object value);
  -    
  -    Object getAttribute(String name );
  -    
  -    void removeAttribute(String name );
  -    
  -    
  +
  +    void add(MetaObject props);
  +
  +    void setAttribute(String name, Object value);
  +
  +    Object getAttribute(String name);
  +
  +    void removeAttribute(String name);
  +
   }
   
  
  
  
  1.3       +117 -69   jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/AbstractStorage.java
  
  Index: AbstractStorage.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/AbstractStorage.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractStorage.java	9 Feb 2002 13:49:47 -0000	1.2
  +++ AbstractStorage.java	9 Feb 2002 18:51:43 -0000	1.3
  @@ -1,140 +1,188 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 apache@apache.org.
  + *
  + * 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.persistence;
   
   import org.apache.commons.simplestore.*;
   
   /**
  - *
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: AbstractStorage.java,v 1.2 2002/02/09 13:49:47 baliuka Exp $
  + *@version    $Id: AbstractStorage.java,v 1.3 2002/02/09 18:51:43 froehlich Exp $
    */
   
  -public abstract class AbstractStorage implements Storage, InternalTransaction, TransactionManager{
  -    
  +public abstract class AbstractStorage implements Storage, InternalTransaction, TransactionManager {
  +
       java.util.Map attributes = new java.util.HashMap();
  -    
  -    protected abstract void createObject(  MetaObject properties )throws StorageException;
  -    protected abstract void removeObject(  MetaObject properties )throws StorageException;
  -    protected abstract void internalCommit()throws StorageException;
  -    protected abstract void internalRollback()throws StorageException;
  -    protected abstract void internalBegin()throws StorageException;
  -    
  -    
  -    
  -    
  +
  +    public void setAttribute(String name, Object value) {
  +
  +        attributes.put(name, value);
  +    }
  +
  +
  +
       public InternalTransaction getTransaction() {
  -        
  +
           return TransactionImpl.getInstance(this);
  -        
       }
  -    
  -    
  +
  +    public Object getAttribute(String name) {
  +        return attributes.get(name);
  +    }
  +
  +
       public void begin(java.util.Set objects) {
  -        try{
  +        try {
               internalBegin();
  -        }catch(java.lang.Throwable t){
  +        } catch (java.lang.Throwable t) {
               // TODO
               t.printStackTrace();
               throw new RuntimeException(t.getClass() + ":" + t.getMessage());
           }
       }
  -    
  +
       public void add(MetaObject props) {
  -        ((InternalTransaction)getTransaction()).add(props);
  +        ((InternalTransaction) getTransaction()).add(props);
       }
  -    
  +
       public void commit() {
  -        try{
  +        try {
               getTransaction().commit();
               internalCommit();
  -        }catch(java.lang.Throwable t){
  +        } catch (java.lang.Throwable t) {
               // TODO
               t.printStackTrace();
               throw new RuntimeException(t.getClass() + ":" + t.getMessage());
           }
       }
  -    
  +
       public void begin() {
  -        try{
  +        try {
               getTransaction().begin();
               internalBegin();
  -        }catch(java.lang.Throwable t){
  +        } catch (java.lang.Throwable t) {
               // TODO
               throw new RuntimeException(t.getClass() + ":" + t.getMessage());
           }
       }
  -    
  +
       public void rollback(java.util.Set objects) {
  -        try{
  +        try {
               //TODO implement roolback
               internalRollback();
               objects.clear();
  -        }catch(java.lang.Throwable t){
  +        } catch (java.lang.Throwable t) {
               throw new RuntimeException(t.getClass() + ":" + t.getMessage());
           }
       }
  -    
  +
       public void rollback() {
  -        
  -        try{
  +
  +        try {
               getTransaction().rollback();
               internalRollback();
  -        }catch(java.lang.Throwable t){
  +        } catch (java.lang.Throwable t) {
               // TODO
               throw new RuntimeException(t.getClass() + ":" + t.getMessage());
           }
  -        
  +
       }
  -    
  +
       public void commit(java.util.Set objects) {
  -        
  -        
  -        try{
  +
  +        try {
               java.util.Iterator iterator = objects.iterator();
  -            while(iterator.hasNext()){
  -                
  -                MetaObject pp = (MetaObject)iterator.next();
  -                if( pp.isNew() ){
  +            while (iterator.hasNext()) {
  +
  +                MetaObject pp = (MetaObject) iterator.next();
  +                if (pp.isNew()) {
                       createObject(pp);
  -                    
  +
                   }
  -                if( pp.isDirty() && ! pp.isNew() ){
  +                if (pp.isDirty() && !pp.isNew()) {
                       storeObject(pp);
  -                    
  +
                   }
  -                if( pp.isDeleted() ){
  -                    
  +                if (pp.isDeleted()) {
  +
                       removeObject(pp);
                   }
                   pp.setDirty(false);
               }
               objects.clear();
               internalCommit();
  -        }catch( Throwable t ){
  +        } catch (Throwable t) {
               // TODO
               t.printStackTrace();
               throw new java.lang.RuntimeException("Error");
           }
  -        
  -    }
  -    public Object getAttribute(String name) {
  -        return attributes.get(name);
  +
       }
  -    
  +
       public void removeAttribute(String name) {
           attributes.remove(name);
       }
  -    
  -    public void setAttribute(String name, Object value) {
  -        
  -        attributes.put(name,value);
  -    }
  +
  +    protected abstract void createObject(MetaObject properties) throws StorageException;
  +
  +    protected abstract void removeObject(MetaObject properties) throws StorageException;
  +
  +    protected abstract void internalCommit() throws StorageException;
  +
  +    protected abstract void internalRollback() throws StorageException;
  +
  +    protected abstract void internalBegin() throws StorageException;
   }
  +
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message