openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r1006010 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/
Date Fri, 08 Oct 2010 20:32:21 GMT
Author: mikedd
Date: Fri Oct  8 20:32:21 2010
New Revision: 1006010

URL: http://svn.apache.org/viewvc?rev=1006010&view=rev
Log:
Filter connection setup SQL from SybaseDictionary.decorate when running unit tests. 

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/FilteringJDBCListener.java
  (with props)
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeAll.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeDisableSelective.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeEnableSelective.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeNone.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java?rev=1006010&r1=1006009&r2=1006010&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java
Fri Oct  8 20:32:21 2010
@@ -67,6 +67,9 @@ public class SybaseDictionary
 
     private static Constructor<SybaseConnection> sybaseConnectionImpl;
     
+    public static String RIGHT_TRUNCATION_ON_SQL = "set string_rtruncation on";
+    public static String NUMERIC_TRUNCATION_OFF_SQL = "set arithabort numeric_truncation
off";
+    
     static {
         try {
             sybaseConnectionImpl = ConcreteClassGenerator.getConcreteConstructor(SybaseConnection.class,

@@ -163,6 +166,7 @@ public class SybaseDictionary
         supportsNullUpdateAction = false;
         supportsDefaultUpdateAction = false;
         supportsCascadeUpdateAction = false;
+        
     }
 
     @Override
@@ -311,13 +315,20 @@ public class SybaseDictionary
     public Connection decorate(Connection conn)
         throws SQLException {
         conn = super.decorate(conn);
+        Connection savedConn = conn;
+        
+//        if(ignoreConnectionSetup) { 
+//            if(conn instanceof DelegatingConnection) { 
+//                conn = ((DelegatingConnection)conn).getInnermostDelegate();
+//            }
+//        }
+        
         // In order for Sybase to raise the truncation exception when the 
         // string length is greater than the column length for Char, VarChar, 
         // Binary, VarBinary, the "set string_rtruncation on" must be executed. 
         // This setting is effective for the duration of current connection.
         if (setStringRightTruncationOn) {
-            String str = "set string_rtruncation on";
-            PreparedStatement stmnt = prepareStatement(conn, str);        
+            PreparedStatement stmnt = prepareStatement(conn, RIGHT_TRUNCATION_ON_SQL);  
     
             stmnt.execute();
             stmnt.close();
         }
@@ -327,13 +338,13 @@ public class SybaseDictionary
         // precision.  This setting specifies that the operation should not 
         // fail if a numeric truncation occurs.
         if (ignoreNumericTruncation) {
-            String str = "set arithabort numeric_truncation off";
-            PreparedStatement stmnt = prepareStatement(conn, str);        
+            PreparedStatement stmnt = prepareStatement(conn, NUMERIC_TRUNCATION_OFF_SQL);
       
             stmnt.execute();
             stmnt.close();            
-        }        
+        }
+        
         
-        return ConcreteClassGenerator.newInstance(sybaseConnectionImpl, conn);
+        return ConcreteClassGenerator.newInstance(sybaseConnectionImpl, savedConn);
     }
     
     /**

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java?rev=1006010&r1=1006009&r2=1006010&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java
Fri Oct  8 20:32:21 2010
@@ -156,20 +156,6 @@ public abstract class AbstractCacheModeT
         public void run();
     }
 
-    /**
-     * Simple JDBCListener which stores the executed sql in a List. The List is
-     * provided by the getSql() method so that subclasses may use separate
-     * lists.
-     */
-    public class Listener extends AbstractJDBCListener {
-        @Override
-        public void beforeExecuteStatement(JDBCEvent event) {
-            if (event.getSQL() != null && getSql() != null) {
-                getSql().add(event.getSQL());
-            }
-        }
-    }
-
     // =======================================================================
     // Test utilities
     // =======================================================================

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java?rev=1006010&r1=1006009&r2=1006010&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java
Fri Oct  8 20:32:21 2010
@@ -25,6 +25,7 @@ import javax.persistence.Cache;
 
 import org.apache.openjpa.lib.jdbc.JDBCListener;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.test.FilteringJDBCListener;
 
 public class TestCacheModeAll extends AbstractCacheModeTestCase {
 
@@ -48,7 +49,7 @@ public class TestCacheModeAll extends Ab
 
     public JDBCListener getListener() {
         if (listener == null) {
-            listener = new Listener();
+            listener = new FilteringJDBCListener(getSql());
         }
         return listener;
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java?rev=1006010&r1=1006009&r2=1006010&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java
Fri Oct  8 20:32:21 2010
@@ -31,6 +31,7 @@ import org.apache.openjpa.persistence.ca
 import org.apache.openjpa.persistence.cache.jpa.model.UnspecifiedEntity;
 import org.apache.openjpa.persistence.cache.jpa.model.XmlCacheableEntity;
 import org.apache.openjpa.persistence.cache.jpa.model.XmlUncacheableEntity;
+import org.apache.openjpa.persistence.test.FilteringJDBCListener;
 
 public class TestCacheModeDisableSelective extends AbstractCacheModeTestCase {
 
@@ -56,7 +57,7 @@ public class TestCacheModeDisableSelecti
 
     public JDBCListener getListener() {
         if (listener == null) {
-            listener = new Listener();
+            listener =  new FilteringJDBCListener(getSql());
         }
         return listener;
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java?rev=1006010&r1=1006009&r2=1006010&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java
Fri Oct  8 20:32:21 2010
@@ -25,6 +25,7 @@ import javax.persistence.Cache;
 
 import org.apache.openjpa.lib.jdbc.JDBCListener;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.test.FilteringJDBCListener;
 
 public class TestCacheModeEmpty extends AbstractCacheModeTestCase {
     
@@ -48,7 +49,7 @@ public class TestCacheModeEmpty extends 
 
     public JDBCListener getListener() {
         if (listener == null) {
-            listener = new Listener();
+            listener =  new FilteringJDBCListener(getSql());
         }
         return listener;
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java?rev=1006010&r1=1006009&r2=1006010&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java
Fri Oct  8 20:32:21 2010
@@ -31,6 +31,7 @@ import org.apache.openjpa.persistence.ca
 import org.apache.openjpa.persistence.cache.jpa.model.UnspecifiedEntity;
 import org.apache.openjpa.persistence.cache.jpa.model.XmlCacheableEntity;
 import org.apache.openjpa.persistence.cache.jpa.model.XmlUncacheableEntity;
+import org.apache.openjpa.persistence.test.FilteringJDBCListener;
 
 public class TestCacheModeEnableSelective extends AbstractCacheModeTestCase {
 
@@ -56,7 +57,7 @@ public class TestCacheModeEnableSelectiv
 
     public JDBCListener getListener() {
         if (listener == null) {
-            listener = new Listener();
+            listener = new FilteringJDBCListener(getSql());
         }
         return listener;
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java?rev=1006010&r1=1006009&r2=1006010&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java
Fri Oct  8 20:32:21 2010
@@ -25,6 +25,7 @@ import javax.persistence.Cache;
 
 import org.apache.openjpa.lib.jdbc.JDBCListener;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.test.FilteringJDBCListener;
 
 public class TestCacheModeNone extends AbstractCacheModeTestCase {
 
@@ -48,7 +49,7 @@ public class TestCacheModeNone extends A
 
     public JDBCListener getListener() {
         if (listener == null) {
-            listener = new Listener();
+            listener = new FilteringJDBCListener(getSql());
         }
         return listener;
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java?rev=1006010&r1=1006009&r2=1006010&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java
Fri Oct  8 20:32:21 2010
@@ -25,6 +25,7 @@ import javax.persistence.Cache;
 
 import org.apache.openjpa.lib.jdbc.JDBCListener;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.test.FilteringJDBCListener;
 
 public class TestCacheModeUnspecified extends AbstractCacheModeTestCase {
 
@@ -48,7 +49,7 @@ public class TestCacheModeUnspecified ex
 
     public JDBCListener getListener() {
         if (listener == null) {
-            listener = new Listener();
+            listener = new FilteringJDBCListener(getSql());
         }
         return listener;
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeAll.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeAll.java?rev=1006010&r1=1006009&r2=1006010&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeAll.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeAll.java
Fri Oct  8 20:32:21 2010
@@ -27,6 +27,7 @@ import javax.persistence.Cache;
 
 import org.apache.openjpa.lib.jdbc.JDBCListener;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.test.FilteringJDBCListener;
 
 public class TestPropertyCacheModeAll extends AbstractCacheModeTestCase {
 
@@ -52,7 +53,7 @@ public class TestPropertyCacheModeAll ex
 
     public JDBCListener getListener() {
         if (listener == null) {
-            listener = new Listener();
+            listener = new FilteringJDBCListener(getSql());
         }
         return listener;
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeDisableSelective.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeDisableSelective.java?rev=1006010&r1=1006009&r2=1006010&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeDisableSelective.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeDisableSelective.java
Fri Oct  8 20:32:21 2010
@@ -33,6 +33,7 @@ import org.apache.openjpa.persistence.ca
 import org.apache.openjpa.persistence.cache.jpa.model.UnspecifiedEntity;
 import org.apache.openjpa.persistence.cache.jpa.model.XmlCacheableEntity;
 import org.apache.openjpa.persistence.cache.jpa.model.XmlUncacheableEntity;
+import org.apache.openjpa.persistence.test.FilteringJDBCListener;
 
 public class TestPropertyCacheModeDisableSelective extends AbstractCacheModeTestCase {
 
@@ -60,7 +61,7 @@ public class TestPropertyCacheModeDisabl
 
     public JDBCListener getListener() {
         if (listener == null) {
-            listener = new Listener();
+            listener = new FilteringJDBCListener(getSql());
         }
         return listener;
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeEnableSelective.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeEnableSelective.java?rev=1006010&r1=1006009&r2=1006010&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeEnableSelective.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeEnableSelective.java
Fri Oct  8 20:32:21 2010
@@ -33,6 +33,7 @@ import org.apache.openjpa.persistence.ca
 import org.apache.openjpa.persistence.cache.jpa.model.UnspecifiedEntity;
 import org.apache.openjpa.persistence.cache.jpa.model.XmlCacheableEntity;
 import org.apache.openjpa.persistence.cache.jpa.model.XmlUncacheableEntity;
+import org.apache.openjpa.persistence.test.FilteringJDBCListener;
 
 public class TestPropertyCacheModeEnableSelective extends AbstractCacheModeTestCase {
 
@@ -60,7 +61,7 @@ public class TestPropertyCacheModeEnable
 
     public JDBCListener getListener() {
         if (listener == null) {
-            listener = new Listener();
+            listener = new FilteringJDBCListener(getSql());
         }
         return listener;
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeNone.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeNone.java?rev=1006010&r1=1006009&r2=1006010&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeNone.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeNone.java
Fri Oct  8 20:32:21 2010
@@ -27,6 +27,7 @@ import javax.persistence.Cache;
 
 import org.apache.openjpa.lib.jdbc.JDBCListener;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.test.FilteringJDBCListener;
 
 public class TestPropertyCacheModeNone extends AbstractCacheModeTestCase {
 
@@ -52,7 +53,7 @@ public class TestPropertyCacheModeNone e
 
     public JDBCListener getListener() {
         if (listener == null) {
-            listener = new Listener();
+            listener = new FilteringJDBCListener(getSql());
         }
         return listener;
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java?rev=1006010&r1=1006009&r2=1006010&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java
Fri Oct  8 20:32:21 2010
@@ -27,6 +27,7 @@ import javax.persistence.Cache;
 
 import org.apache.openjpa.lib.jdbc.JDBCListener;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.test.FilteringJDBCListener;
 
 public class TestPropertyCacheModeUnspecified extends AbstractCacheModeTestCase {
     
@@ -52,7 +53,7 @@ public class TestPropertyCacheModeUnspec
 
     public JDBCListener getListener() {
         if (listener == null) {
-            listener = new Listener();
+            listener = new FilteringJDBCListener(getSql());
         }
         return listener;
     }

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/FilteringJDBCListener.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/FilteringJDBCListener.java?rev=1006010&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/FilteringJDBCListener.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/FilteringJDBCListener.java
Fri Oct  8 20:32:21 2010
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.test;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.openjpa.jdbc.sql.SybaseDictionary;
+import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
+import org.apache.openjpa.lib.jdbc.JDBCEvent;
+
+/**
+ * JDBC listener suitable for use by the OpenJPA junit bucket. Some DBDictionaries (e.g.
Sybase) generate a lot of
+ * noise during connection setup - making testcases that rely on SQL count or sequences brittle.
+ * 
+ * This JDBC listener removes these noisy sql statements.
+ */
+public class FilteringJDBCListener extends AbstractJDBCListener {
+
+    /**
+     * Set of SQL statements which will be filtered out by this listener.
+     */
+    private Set<String> _ignoredSQL = new HashSet<String>();
+    
+    private List<String> _sqlStatements; 
+
+    public FilteringJDBCListener(List<String> sql) {
+        _sqlStatements = sql;
+        
+        // ignore connection setup SQL for Sybase
+        _ignoredSQL.add(SybaseDictionary.NUMERIC_TRUNCATION_OFF_SQL);
+        _ignoredSQL.add(SybaseDictionary.RIGHT_TRUNCATION_ON_SQL);
+    }
+
+    @Override
+    public void beforeExecuteStatement(JDBCEvent event) {
+        String sql = event.getSQL();
+        if (sql != null && _sqlStatements != null && !_ignoredSQL.contains(sql))
{
+            _sqlStatements.add(sql);
+        }
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/FilteringJDBCListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java?rev=1006010&r1=1006009&r2=1006010&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java
Fri Oct  8 20:32:21 2010
@@ -20,8 +20,11 @@ package org.apache.openjpa.persistence.t
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
+import org.apache.openjpa.jdbc.sql.SybaseDictionary;
 import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
 import org.apache.openjpa.lib.jdbc.JDBCEvent;
 import org.apache.openjpa.lib.jdbc.JDBCListener;
@@ -41,7 +44,7 @@ public abstract class SQLListenerTestCas
         Object[] copy = new Object[props.length + 2];
         System.arraycopy(props, 0, copy, 0, props.length);
         copy[copy.length - 2] = "openjpa.jdbc.JDBCListeners";
-        copy[copy.length - 1] = new JDBCListener[] { new Listener() };
+        copy[copy.length - 1] = new JDBCListener[] { new FilteringJDBCListener(sql) };
         super.setUp(copy); 
     }
 
@@ -211,17 +214,6 @@ public abstract class SQLListenerTestCas
     	return buf.toString();
     }
 
-    public class Listener
-        extends AbstractJDBCListener {
-
-        @Override
-        public void beforeExecuteStatement(JDBCEvent event) {
-            if (event.getSQL() != null && sql != null) {
-                sql.add(event.getSQL());
-            }
-        }
-    }
-
     public enum SQLAssertType {
         SQL, NotSQL, ContainsSQL, AllSQLInOrder, AllExactSQLInOrder, 
         AllSQLAnyOrder, NoneSQLAnyOrder, AnySQLAnyOrder



Mime
View raw message