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/05/14 19:02:51 UTC
cvs commit: jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore TestPersistentClassType.java TestSample.java
baliuka 02/05/14 10:02:51
Modified: simplestore build.xml
simplestore/src/java/org/apache/commons/simplestore/jdbc
DriverDataSource.java
simplestore/src/java/org/apache/commons/simplestore/persistence/impl
PersistentProxy.java
simplestore/src/java/org/apache/commons/simplestore/tools
Enhancer.java
simplestore/src/test/org/apache/commons/simplestore
TestPersistentClassType.java TestSample.java
Log:
Minor changes
Revision Changes Path
1.26 +3 -3 jakarta-commons-sandbox/simplestore/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/build.xml,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- build.xml 12 May 2002 08:24:47 -0000 1.25
+++ build.xml 14 May 2002 17:02:50 -0000 1.26
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="compile" name="simplestore">
-<!-- "simplestore" component of the Jakarta Commons Subproject $Id: build.xml,v 1.25 2002/05/12 08:24:47 baliuka Exp $ -->
+<!-- "simplestore" component of the Jakarta Commons Subproject $Id: build.xml,v 1.26 2002/05/14 17:02:50 baliuka Exp $ -->
<!-- ========== Executable Targets ======================================== -->
@@ -183,9 +183,9 @@
<target depends="build-test" description="runs (junit) unit tests" name="test">
<java classname="${test.runner}" failonerror="${test.failonerror}" fork="yes" maxmemory="${maxmemory}">
<!-- jvmarg value="-Xrunhprof:cpu=times,file=debug.txt" / -->
- <jvmarg value="-verbose:gc" />
+ <!-- jvmarg value="-verbose:gc" / -->
<!-- jvmarg value="-verbose:class" / -->
- <sysproperty key="DEBUG" value="true"/>
+ <sysproperty key="DEBUG" value="false"/>
<arg value="${test.entry}"/>
<classpath>
<pathelement path="${build.home}/classes"/>
1.15 +162 -82 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/jdbc/DriverDataSource.java
Index: DriverDataSource.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/jdbc/DriverDataSource.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- DriverDataSource.java 12 May 2002 19:05:20 -0000 1.14
+++ DriverDataSource.java 14 May 2002 17:02:50 -0000 1.15
@@ -78,16 +78,16 @@
/**
*@author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
* baliuka@mwm.lt</a>
- *@version $Id: DriverDataSource.java,v 1.14 2002/05/12 19:05:20 baliuka Exp $
+ *@version $Id: DriverDataSource.java,v 1.15 2002/05/14 17:02:50 baliuka Exp $
*
*/
public class DriverDataSource implements ConnectionFactory {
private final Properties properties = new Properties();
- private ConnectionWrapper connection[] = null;
+ private Connection connection[] = null;
+
-
private Driver driver;
/** Holds value of property user. */
@@ -143,10 +143,6 @@
this.url = url;
}
- public void setLogWriter(PrintWriter printWriter) throws SQLException { }
-
- public void setLoginTimeout(int param) throws SQLException { }
-
/**
* Setter for property maxConnections.
*
@@ -172,8 +168,8 @@
}
try {
- this.driver = (Driver) Class.forName(driver,true,
- this.getClass().getClassLoader() ).newInstance();
+ this.driver = (Driver) Class.forName(driver,true,
+ this.getClass().getClassLoader() ).newInstance();
} catch (Exception e) {
e.printStackTrace();
throw new SimplestoreException(e.getMessage());
@@ -221,36 +217,30 @@
synchronized (this) {
if (connection == null) {
- connection =
- new ConnectionWrapper[
- maxConnections < 1 ? 1 : maxConnections
- ];
+ connection =
+ new Connection[
+ maxConnections < 1 ? 1 : maxConnections
+ ];
}
int i = 0;
while ( true ) { // must loop and wait not used connection
- if (connection[i] != null) {
- if (!connection[i].isLocked()) {
-
+ if (connection[i] != null) {
+ if ( !ConnectionProxy.isLocked( connection[i] ) ) {
- if (connection[ i ].isClosed()) { // expired ?
- try {
-
- connection[ i ].release();
-
- } catch (Exception ignore) {
-
- }
+
+ if ( ConnectionProxy.isClosed( connection[ i ] )) { // expired ?
+ ConnectionProxy.release( connection[ i ] );
connection[ i ] = newConnection();
}
break;
}
}else {
- connection[i] = newConnection();
- break;
- }
+ connection[i] = newConnection();
+ break;
+ }
i = ( i + 1 ) % connection.length;
try{
@@ -264,24 +254,13 @@
}
- connection[i].lock();
+ ConnectionProxy.lock( connection[i] ) ;
return connection[i];
}
}
- public PrintWriter getLogWriter() throws SQLException {
- return new PrintWriter(System.out);
- }
-
- public Connection getConnection(String str, String str1) throws SQLException {
- return getConnection();
- }
-
- public int getLoginTimeout() throws SQLException {
- return 0;
- }
/**
* Getter for property maxConnections.
@@ -292,66 +271,167 @@
return maxConnections;
}
- private ConnectionWrapper newConnection() throws SQLException {
+ private Connection newConnection() throws SQLException {
Connection con = driver.connect(url, properties);
con.setAutoCommit(false);
return ConnectionProxy.create(con,this);
}
-
+
}
-
+
class ConnectionProxy implements InvocationHandler {
private Thread used;
private Connection connection;
private ConnectionFactory ds;
+ private final java.util.List jdbcResources = new java.util.ArrayList();
+
+
+ static boolean isClosed(Object conn){
+ try{
+
+ ConnectionProxy proxy = (ConnectionProxy)
+ java.lang.reflect.Proxy.getInvocationHandler(conn);
+
+ return proxy.connection.isClosed();
+ }catch( Exception e ){
+ return true;
+ }
+ }
- ConnectionProxy( Connection connection, ConnectionFactory ds ) {
+
+
+ static boolean isLocked(Object conn){
+ ConnectionProxy proxy = (ConnectionProxy)
+ java.lang.reflect.Proxy.getInvocationHandler(conn);
+
+ return proxy.used == null || !proxy.used.isAlive() ||
+ proxy.used == Thread.currentThread();
+
+ }
+ static void lock(Object conn){
+ ConnectionProxy proxy = (ConnectionProxy)
+ java.lang.reflect.Proxy.getInvocationHandler(conn);
+
+ proxy.used = Thread.currentThread();
+ }
+ static void release(Object conn){
+ ConnectionProxy proxy = (ConnectionProxy)
+ java.lang.reflect.Proxy.getInvocationHandler(conn);
+ try{
+
+ proxy.connection.close();
+
+ }catch(Exception e){
+
+ }
+ }
+
+
+
+ ConnectionProxy( Connection connection, ConnectionFactory ds ) {
this.connection = connection;
this.ds = ds;
}
+
+ private void close() throws Exception{
+
+ for( int i = jdbcResources.size() - 1; i >= 0; i-- ){
+
+ Object res = jdbcResources.get(i);
+
+ if ( res instanceof java.sql.Statement ){
+ try{
+ ((java.sql.Statement)res).close();
+ }catch( Exception e ){}
+
+ }else if ( res instanceof java.sql.ResultSet ){
+ try{
+ ((java.sql.ResultSet)res).close();
+ }catch( Exception e ){}
+ }
+
+ }
+ jdbcResources.clear();
+ used = null;
+ synchronized( ds ){
+ ds.notifyAll();
+ }
+
+ }
+
+ private Object getStatementProxy(final Object stmt){
+
+ return java.lang.reflect.Proxy.newProxyInstance(
+ stmt.getClass().getClassLoader(),
+ stmt.getClass().getInterfaces(),
+ new java.lang.reflect.InvocationHandler(){
+
+ public Object invoke(Object stmtObject,java.lang.reflect.Method stmtMethod,Object[] stmtArgs)
+ throws Throwable{
+ try{
+
+ Object stmtResult = stmtMethod.invoke(stmt, stmtArgs);
+
+ if( stmtResult != null && (stmtResult instanceof java.sql.ResultSet) ){
+
+ jdbcResources.add(stmtResult);
+
+ }
+ return stmtResult;
+
+ }catch( java.lang.reflect.InvocationTargetException itex ){
+
+ throw itex.getTargetException().fillInStackTrace();
+ }
+ }
+ }
+ );
+
+
+ }
public Object invoke(Object object,java.lang.reflect.Method method,Object[] args)
- throws Throwable{
- try{
- if( method.getName().equals("close") ) {
- used = null;
- synchronized( ds ){
- ds.notifyAll();
- }
-
- return null;
- }else if (method.getName().equals("release")){
- connection.close();
- return null;
- }else if (method.getName().equals("isLocked")){
-
- return ( used == null || !used.isAlive() ||
- used == Thread.currentThread()
-
- ) ? Boolean.FALSE : Boolean.TRUE ;
-
-
- }else if (method.getName().equals("lock")){
-
- used = Thread.currentThread();
-
- return null;
- }else return method.invoke(connection,args) ;
- }catch( java.lang.reflect.InvocationTargetException ite ){
- throw ite.getTargetException().fillInStackTrace();
- }
+ throws Throwable{
+ try{
+
+ if( method.getName().equals("close") ) {
+ close();
+ return null;
+
+ }else {
+
+ Object result = method.invoke(connection, args );
+
+ if ( result != null && (result instanceof java.sql.Statement) ){
+
+ jdbcResources.add(result);
+ result = getStatementProxy( result );
+
+
+ }
+
+
+ return result;
+
+
+ }
+ }catch( java.lang.reflect.InvocationTargetException ite ){
+
+ throw ite.getTargetException().fillInStackTrace();
+ }
}
- public static ConnectionWrapper create(Connection connection, ConnectionFactory ds){
- return (ConnectionWrapper)
- java.lang.reflect.Proxy.newProxyInstance(
- ConnectionWrapper.class.getClassLoader(),
- new Class[]{ConnectionWrapper.class},
- new ConnectionProxy(connection,ds)
- );
-
- }
-
+ public static java.sql.Connection create(Connection connection, ConnectionFactory ds){
+
+ return (Connection)
+ java.lang.reflect.Proxy.newProxyInstance(
+ Connection.class.getClassLoader(),
+ new Class[]{java.sql.Connection.class},
+ new ConnectionProxy(connection,ds)
+ );
+
+ }
+
}
1.34 +2 -5 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/PersistentProxy.java
Index: PersistentProxy.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/PersistentProxy.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- PersistentProxy.java 12 May 2002 11:40:02 -0000 1.33
+++ PersistentProxy.java 14 May 2002 17:02:51 -0000 1.34
@@ -77,7 +77,7 @@
* baliuka@mwm.lt</a>
*@author Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">
* g-froehlich@gmx.de</a>
- *@version $Id: PersistentProxy.java,v 1.33 2002/05/12 11:40:02 baliuka Exp $
+ *@version $Id: PersistentProxy.java,v 1.34 2002/05/14 17:02:51 baliuka Exp $
*/
public class PersistentProxy
implements MetaObject, org.apache.commons.simplestore.tools.Constants ,
@@ -247,10 +247,7 @@
throws Throwable{
if( e != null ){
- if( DEBUG ){
- e.printStackTrace();
- }
- throw e;
+ throw e;
}
if( invokedSuper ){
if( e != null){
1.26 +5 -4 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/tools/Enhancer.java
Index: Enhancer.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/tools/Enhancer.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- Enhancer.java 7 May 2002 20:16:17 -0000 1.25
+++ Enhancer.java 14 May 2002 17:02:51 -0000 1.26
@@ -135,7 +135,7 @@
* </pre>
*@author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
* baliuka@mwm.lt</a>
- *@version $Id: Enhancer.java,v 1.25 2002/05/07 20:16:17 baliuka Exp $
+ *@version $Id: Enhancer.java,v 1.26 2002/05/14 17:02:51 baliuka Exp $
*/
public class Enhancer implements org.apache.bcel.Constants ,
Constants{
@@ -415,9 +415,10 @@
|| java.lang.reflect.Modifier.isProtected(mod))) {
methodSet.add(new MethodWrapper(methods[i]));
+ /*
if( DEBUG ){
System.out.println("added:" + methods[i]);
- }
+ }*/
}
}
}
@@ -923,10 +924,10 @@
mg.setMaxStack();
mg.setMaxLocals();
Method result = getMethod(mg);
- if (DEBUG) {
+ /* if (DEBUG) {
System.err.println(mg.getMethod());
System.err.println(mg.getMethod().getCode());
- }
+ }*/
return result;
}
static class MethodWrapper {
1.5 +1 -5 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestPersistentClassType.java 11 Mar 2002 09:53:08 -0000 1.4
+++ TestPersistentClassType.java 14 May 2002 17:02:51 -0000 1.5
@@ -57,7 +57,7 @@
/**
*@author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
* baliuka@mwm.lt</a>
- *@version $Id: TestPersistentClassType.java,v 1.4 2002/03/11 09:53:08 baliuka Exp $
+ *@version $Id: TestPersistentClassType.java,v 1.5 2002/05/14 17:02:51 baliuka Exp $
*/
public abstract class TestPersistentClassType implements TestPersistent,
org.apache.commons.simplestore.tools.Constants{
@@ -67,10 +67,6 @@
}
public void doSomething(String arg){
- if( DEBUG ){
- this.setStrVal("done Something " + arg);
- System.out.println(getStrVal());
- }
}
public void setNuls(){
1.25 +1 -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.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- TestSample.java 11 May 2002 16:48:16 -0000 1.24
+++ TestSample.java 14 May 2002 17:02:51 -0000 1.25
@@ -72,7 +72,7 @@
/**
*@author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
* baliuka@mwm.lt</a>
- *@version $Id: TestSample.java,v 1.24 2002/05/11 16:48:16 baliuka Exp $
+ *@version $Id: TestSample.java,v 1.25 2002/05/14 17:02:51 baliuka Exp $
*/
public class TestSample extends TestCase implements org.apache.commons.simplestore.tools.Constants{
@@ -200,8 +200,6 @@
transaction.begin();
TestPersistentClassType object = (TestPersistentClassType) pm.createInstance(TestPersistentClassType.class);
object.setStrVal("Test roolback on new created " + object);
- if( DEBUG )
- System.out.println(object.getStrVal());
transaction.rollback();
transaction.begin();
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>