baliuka 02/03/17 09:35:49
Modified: simplestore/src/test/org/apache/commons/simplestore
TestSample.java
Added: simplestore/src/java/org/apache/commons/simplestore/persistence
PersistenceManager.java
PersistenceManagerFactory.java
simplestore/src/java/org/apache/commons/simplestore/persistence/impl
PersistenceManagerImpl.java
Log:
Added fatory interface for persitence manager
Revision Changes Path
1.1
jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/PersistenceManager.java
Index: PersistenceManager.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache Cocoon" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.simplestore.persistence;
/**
*@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
*@version $Id: PersistenceManager.java,v 1.1 2002/03/17 17:35:48 baliuka Exp $
*/
public interface PersistenceManager {
public Transaction getTransaction();
public Object getOID( Object pc );
public Object createInstance( Class aclass );
public Object findInstance( Class clasz, Object oid ) throws StorageException;
public java.util.Set findAll(Class clasz) throws StorageException;
public void removeInstance(Object pc);
}
1.1
jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/PersistenceManagerFactory.java
Index: PersistenceManagerFactory.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache Cocoon" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.simplestore.persistence;
/**
*@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
*@version $Id: PersistenceManagerFactory.java,v 1.1 2002/03/17 17:35:48 baliuka
Exp $
*/
public interface PersistenceManagerFactory {
public PersistenceManager getPersistenceManager();
}
1.1
jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/PersistenceManagerImpl.java
Index: PersistenceManagerImpl.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache Cocoon" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.simplestore.persistence.impl;
import org.apache.commons.simplestore.cache.Cache;
import org.apache.commons.simplestore.cache.impl.SoftRefMemoryCache;
import org.apache.commons.simplestore.persistence.MetaObject;
import org.apache.commons.simplestore.persistence.Persistent;
import org.apache.commons.simplestore.persistence.Storage;
import org.apache.commons.simplestore.persistence.StorageException;
import org.apache.commons.simplestore.persistence.Transaction;
import org.apache.commons.simplestore.persistence.TransactionManager;
import org.apache.commons.simplestore.persistence.Context;
import org.apache.commons.simplestore.persistence.PersistenceManager;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Set;
/**
*@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
*@version $Id: PersistenceManagerImpl.java,v 1.1 2002/03/17 17:35:48 baliuka Exp
$
*/
public class PersistenceManagerImpl implements PersistenceManager{
private static PersistenceManager pm;
private Context context;
/**
* Creates new PersiatenceManager
*
*@param storage
*@param transactionManager
*/
protected PersistenceManagerImpl(Context context) {
this.context = context;
}
public static PersistenceManager getPersistenceManager( Context context ) {
if (pm == null) {
pm = new PersistenceManagerImpl( context );
}
return pm;
}
public Transaction getTransaction() {
return context.getTransactionManager().getTransaction();
}
public Object getOID( Object pc ) {
return ((Persistent) pc).getOID();
}
public Object createInstance( Class aclass ) {
Persistent p = context.getMetaClass(aclass).newInstance();
context.getCache().put( p.getOID(), p );
return p;
}
public Object findInstance( Class clasz, Object oid ) throws StorageException {
return context.getStorage().retrieveObject( clasz, oid );
}
public Set findAll(Class clasz) throws StorageException {
return context.getStorage().retrieveAll(clasz);
}
public void removeInstance(Object pc) {
MetaObject p = ((Persistent) pc).getMetaObject();
if (p != null) {
p.remove();
}
}
public void registerClass(Class clasz) throws StorageException {
context.getStorage().registerClass(clasz);
}
}
1.16 +4 -3
jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestSample.java
Index: TestSample.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestSample.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- TestSample.java 17 Mar 2002 13:36:25 -0000 1.15
+++ TestSample.java 17 Mar 2002 17:35:48 -0000 1.16
@@ -57,7 +57,8 @@
import org.apache.commons.simplestore.jdbc.DriverDataSource;
import org.apache.commons.simplestore.persistence.Transaction;
import org.apache.commons.simplestore.persistence.impl.DBStorage;
-import org.apache.commons.simplestore.persistence.impl.PersistenceManager;
+import org.apache.commons.simplestore.persistence.impl.PersistenceManagerImpl;
+import org.apache.commons.simplestore.persistence.PersistenceManager;
import org.apache.commons.simplestore.persistence.impl.ContextImpl;
import org.apache.commons.simplestore.persistence.impl.MetaClassImpl;
import org.apache.commons.simplestore.persistence.impl.ConnectionFactory;
@@ -75,7 +76,7 @@
/**
*@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
- *@version $Id: TestSample.java,v 1.15 2002/03/17 13:36:25 baliuka Exp $
+ *@version $Id: TestSample.java,v 1.16 2002/03/17 17:35:48 baliuka Exp $
*/
public class TestSample extends TestCase implements
org.apache.commons.simplestore.tools.Constants{
@@ -261,7 +262,7 @@
storage,
SoftRefMemoryCache.getInstance(new java.util.HashMap(),0xFF),
storage );
- pm = PersistenceManager.getPersistenceManager(context);
+ pm = PersistenceManagerImpl.getPersistenceManager(context);
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>