You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2002/06/16 12:26:47 UTC
cvs commit: jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore TestPersistentClassType.java TestSample.java
baliuka 2002/06/16 03:26:47
Modified: simplestore/src/java/org/apache/commons/simplestore/persistence
MetaObject.java
simplestore/src/java/org/apache/commons/simplestore/persistence/impl
PersistenceManagerImpl.java
simplestore/src/jdbc/org/apache/commons/simplestore/jdbc
DBPersistenceManagerFactory.java
TypeNameMapImpl.java TypeNameMapImpl.properties
simplestore/src/jdo/org/apache/commons/simplestore/jdo
JDOPersistenceManagerImpl.java
simplestore/src/test/org/apache/commons/simplestore
TestPersistentClassType.java TestSample.java
Added: simplestore/src/java/org/apache/commons/simplestore/persistence
Query.java QueryManager.java
simplestore/src/query/org/apache/commons/simplestore/query
JexQuery.java JexQueryManager.java
Log:
Revision Changes Path
1.8 +7 -1 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/MetaObject.java
Index: MetaObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/MetaObject.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- MetaObject.java 9 Jun 2002 08:01:31 -0000 1.7
+++ MetaObject.java 16 Jun 2002 10:26:46 -0000 1.8
@@ -65,6 +65,12 @@
public interface MetaObject extends Cloneable {
+
+ static final public int DIRTY = 8;
+ static final public int DELETED = 4;
+ static final public int NEW_CREATED = 2;
+ static final public int CLEAN = 1;
+
/** Returns OID for persistent object
* @return OID
*/
1.1 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/Query.java
Index: Query.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 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">
* baliuka@mwm.lt</a>
*@version $Id: Query.java,v 1.1 2002/06/16 10:26:46 baliuka Exp $
*/
public interface Query {
public void bind(String name,Object value);
public void compile();
public java.util.Iterator execute();
public void close();
}
1.1 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/QueryManager.java
Index: QueryManager.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 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">
* baliuka@mwm.lt</a>
*@version $Id: QueryManager.java,v 1.1 2002/06/16 10:26:46 baliuka Exp $
*/
public interface QueryManager extends Spi {
public Query newQuery(Class candidates, String lang, String queryString );
}
1.8 +3 -2 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/PersistenceManagerImpl.java
Index: PersistenceManagerImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/PersistenceManagerImpl.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- PersistenceManagerImpl.java 9 Jun 2002 08:01:31 -0000 1.7
+++ PersistenceManagerImpl.java 16 Jun 2002 10:26:46 -0000 1.8
@@ -78,7 +78,8 @@
public class PersistenceManagerImpl implements PersistenceManager{
- private Context context;
+ protected Context context;
+
private static final Object ALL = "org.apache.commons.simplestore."+
"persistence.PersistenceManagerImpl.ALL";
1.3 +2 -2 jakarta-commons-sandbox/simplestore/src/jdbc/org/apache/commons/simplestore/jdbc/DBPersistenceManagerFactory.java
Index: DBPersistenceManagerFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/jdbc/org/apache/commons/simplestore/jdbc/DBPersistenceManagerFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DBPersistenceManagerFactory.java 9 Jun 2002 08:01:31 -0000 1.2
+++ DBPersistenceManagerFactory.java 16 Jun 2002 10:26:46 -0000 1.3
@@ -139,7 +139,7 @@
is.close();
MetaClass mcs[] = mclass.classes();
- TypeNameMap tnm = new TypeNameMapImpl( props );
+ TypeNameMap tnm = new TypeNameMapImpl( props, url );
java.sql.Connection connection = ds.getConnection();
java.sql.Statement statement = connection.createStatement();
1.2 +13 -3 jakarta-commons-sandbox/simplestore/src/jdbc/org/apache/commons/simplestore/jdbc/TypeNameMapImpl.java
Index: TypeNameMapImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/jdbc/org/apache/commons/simplestore/jdbc/TypeNameMapImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TypeNameMapImpl.java 25 May 2002 13:48:59 -0000 1.1
+++ TypeNameMapImpl.java 16 Jun 2002 10:26:46 -0000 1.2
@@ -63,10 +63,16 @@
public class TypeNameMapImpl implements TypeNameMap {
java.util.Properties map;
+ String sufix;
/** Creates a new instance of TypeNameMapImpl */
- public TypeNameMapImpl(java.util.Properties map) {
+ public TypeNameMapImpl(java.util.Properties map,String url) {
this.map = map;
+ java.util.StringTokenizer parser = new java.util.StringTokenizer(url,":");
+ parser.nextToken();
+ sufix = parser.nextToken();
+
+
}
public String getTypeName(Class clasz) {
@@ -88,7 +94,11 @@
}
}
- return map.getProperty(clasz.getName());
+ String typeName = map.getProperty(clasz.getName() + "." + sufix);
+ if(typeName != null)
+ return typeName;
+
+ return map.getProperty( clasz.getName() );
}
}
1.3 +14 -3 jakarta-commons-sandbox/simplestore/src/jdbc/org/apache/commons/simplestore/jdbc/TypeNameMapImpl.properties
Index: TypeNameMapImpl.properties
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/jdbc/org/apache/commons/simplestore/jdbc/TypeNameMapImpl.properties,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TypeNameMapImpl.properties 9 Jun 2002 08:01:31 -0000 1.2
+++ TypeNameMapImpl.properties 16 Jun 2002 10:26:46 -0000 1.3
@@ -1,4 +1,11 @@
# Sample ResourceBundle properties file
+# Type mapping used for "CREATE TABLE" only and it is
+# optional for preexisting database
+# Use sufix to define RDMS specific type mmapings
+# Type mapping implementation parses driver's URL to find sufix
+# for URL like "jdbc:postgresql:" sufix is subprotocol ("postgresql")
+
+# DEFAULT:
java.lang.Integer=INT
java.lang.Byte=INT
java.lang.Short=INT
@@ -7,9 +14,13 @@
java.lang.Float=FLOAT
java.lang.Boolean=INT
java.lang.Long=BIGINT
-java.lang.String=TEXT
+java.lang.String=LONGVARCHAR
java.sql.Date=DATE
+java.sql.Time=TIME
+java.sql.Timestamp=TIMESTAMP
java.util.Date=DATE
-
-
+[B=BLOB
+# POSTGRESQL:
+java.lang.String.postgresql=TEXT
+[B.postgresql=BYTEA
1.2 +7 -7 jakarta-commons-sandbox/simplestore/src/jdo/org/apache/commons/simplestore/jdo/JDOPersistenceManagerImpl.java
Index: JDOPersistenceManagerImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/jdo/org/apache/commons/simplestore/jdo/JDOPersistenceManagerImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JDOPersistenceManagerImpl.java 12 Jun 2002 18:13:52 -0000 1.1
+++ JDOPersistenceManagerImpl.java 16 Jun 2002 10:26:47 -0000 1.2
@@ -385,12 +385,12 @@
);
Object oid = mclass.nextOID();
JDOStateManagerImpl mo = new JDOStateManagerImpl(
- mclass,
- pc,
- this,
- context,
- oid
- );
+ mclass,
+ pc,
+ this,
+ context,
+ oid
+ );
context.getTransactionManager().getTransaction().add(mo);
mo.setState( true, MetaObject.NEW_CREATED );
pc.jdoReplaceStateManager(mo);
1.1 jakarta-commons-sandbox/simplestore/src/query/org/apache/commons/simplestore/query/JexQuery.java
Index: JexQuery.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 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.query;
import org.apache.commons.simplestore.persistence.*;
import org.apache.commons.jex.Expression;
/**
*@author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
* baliuka@mwm.lt</a>
*@version $Id: JexQuery.java,v 1.1 2002/06/16 10:26:47 baliuka Exp $
*/
public class JexQuery implements Query{
Class candidates;
org.apache.commons.jex.Context jexContext;
Context context;
String query;
Expression expr;
/** Creates a new instance of JexQuery */
public JexQuery( org.apache.commons.jex.Context jexContext,
Context context,
Class candidates,
String query ) {
this.candidates = candidates;
this.jexContext = jexContext;
this.context = context;
this.query = query;
}
public void bind(String name, Object value) {
jexContext.getVariables().declareVariable(name,value);
}
public java.util.Iterator execute() {
final java.util.List results = new java.util.Vector();
EnumeratorCallback enum = new EnumeratorCallback(){
public boolean nextObject(Object obj){
if(select(obj)){
results.add(obj);
}
return true;
}
};
context.getStorage().enumerate(candidates,enum);
return results.iterator();
}
public void compile() {
expr = jexContext.getCompiler().compileExpression(query);
}
public void close() {
}
private boolean select( Object next ){
Object result = expr.evaluate(jexContext, new Object[]{next});
if( result == null ){
return false;
}else if( result instanceof Boolean ){
return ((Boolean)result).booleanValue();
}else if ( result instanceof Number ){
return ((Number)result).intValue() != 0;
}else if ( result instanceof String ){
return "true".equals(result);
}else return false;
}
}
1.1 jakarta-commons-sandbox/simplestore/src/query/org/apache/commons/simplestore/query/JexQueryManager.java
Index: JexQueryManager.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 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.query;
import org.apache.commons.simplestore.persistence.*;
/**
*@author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
* baliuka@mwm.lt</a>
*@version $Id: JexQueryManager.java,v 1.1 2002/06/16 10:26:47 baliuka Exp $
*/
public class JexQueryManager implements QueryManager{
protected Context context;
/** Creates a new instance of JEXQueryManager */
public JexQueryManager() {
}
public Query newQuery(Class candidates, String lang, String queryString) {
return new JexQuery(new org.apache.commons.jex.Context(),
context,
candidates,
lang + ":" + queryString
);
}
public void setContext(Context context) {
this.context = context;
}
}
1.6 +4 -2 jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestPersistentClassType.java
Index: TestPersistentClassType.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestPersistentClassType.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestPersistentClassType.java 14 May 2002 17:02:51 -0000 1.5
+++ TestPersistentClassType.java 16 Jun 2002 10:26:47 -0000 1.6
@@ -108,6 +108,8 @@
public abstract boolean getBoolVal();
-
+ public abstract byte[] getByteArray();
+
+ public abstract void setByteArray( byte[] ba );
}
1.32 +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.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- TestSample.java 9 Jun 2002 08:01:31 -0000 1.31
+++ TestSample.java 16 Jun 2002 10:26:47 -0000 1.32
@@ -104,7 +104,7 @@
TestPersistentClassType object1 = (TestPersistentClassType) pm.createInstance(TestPersistentClassType.class);
Object oid = pm.getOID(object1);
object1.doSomething(object1.toString());
-
+ object1.setByteArray( new byte[]{0,1,2,3,4,5,6,7,8,9});
transaction.commit();
@@ -127,7 +127,7 @@
object3.setIntVal(0);
object3.setFloatVal(2f);
- object3.setStrVal1("Q\\000AAAAAA");
+ object3.setStrVal1("QAAAAAA");
object3.setBoolVal(true);
object3.setParent(object2);
@@ -183,6 +183,7 @@
object.getIntVal();
object.getFloatVal();
object.getStrVal1();
+ object.getByteArray();
TestPersistentClassType parent = object.getParent();
if(parent != null){
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>