cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1327984 - in /cxf/trunk/rt/ws/rm/src: main/java/org/apache/cxf/ws/rm/persistence/jdbc/ main/resources/schemas/configuration/ test/java/org/apache/cxf/ws/rm/persistence/jdbc/
Date Thu, 19 Apr 2012 15:13:30 GMT
Author: ay
Date: Thu Apr 19 15:13:29 2012
New Revision: 1327984

URL: http://svn.apache.org/viewvc?rev=1327984&view=rev
Log:
[CXF-4249] Make RMTxStore's current schema name to be configurable

Added:
    cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreTwoSchemasTest.java
  (with props)
Modified:
    cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
    cxf/trunk/rt/ws/rm/src/main/resources/schemas/configuration/wsrm-manager.xsd
    cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java

Modified: cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java?rev=1327984&r1=1327983&r2=1327984&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
(original)
+++ cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
Thu Apr 19 15:13:29 2012
@@ -41,6 +41,7 @@ import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import java.util.regex.Pattern;
 
 import javax.annotation.PostConstruct;
 
@@ -136,6 +137,9 @@ public class RMTxStore implements RMStor
         "SELECT MSG_NO, SEND_TO, CONTENT FROM {0} WHERE SEQ_ID = ?";
     private static final String ALTER_TABLE_STMT_STR =
         "ALTER TABLE {0} ADD {1} {2}";
+    private static final String CREATE_SCHEMA_STMT_STR = "CREATE SCHEMA {0}";
+    private static final String SET_CURRENT_SCHEMA_STMT_STR = "SET CURRENT SCHEMA {0}";
+    
     private static final String DERBY_TABLE_EXISTS_STATE = "X0Y32";
     private static final int ORACLE_TABLE_EXISTS_CODE = 955;
     
@@ -165,6 +169,7 @@ public class RMTxStore implements RMStor
     private String url = MessageFormat.format("jdbc:derby:{0};create=true", DEFAULT_DATABASE_NAME);
     private String userName;
     private String password;
+    private String schemaName;
     
     private String tableExistsState = DERBY_TABLE_EXISTS_STATE;
     private int tableExistsCode = ORACLE_TABLE_EXISTS_CODE;
@@ -203,6 +208,18 @@ public class RMTxStore implements RMStor
         return userName;
     }
     
+    public String getSchemaName() {
+        return schemaName;
+    }
+
+    public void setSchemaName(String sn) {
+        if (sn == null || Pattern.matches("[a-zA-Z\\d]{1,32}", sn)) {
+            schemaName = sn;
+        } else {
+            throw new IllegalArgumentException("Invalid schema name: " + sn);
+        }
+    }
+
     public String getTableExistsState() {
         return tableExistsState;
     }
@@ -736,6 +753,30 @@ public class RMTxStore implements RMStor
             }
         }
     }
+    
+    protected void setCurrentSchema() throws SQLException {
+        if (schemaName == null || connection == null) {
+            return;
+        }
+        
+        Statement stmt = connection.createStatement();
+        // schemaName has been verified at setSchemaName(String)
+        try {
+            stmt.executeUpdate(MessageFormat.format(CREATE_SCHEMA_STMT_STR, 
+                                                    schemaName));
+        } catch (SQLException ex) {
+            // pass through to assume it is already created
+        }
+        stmt.close();
+        stmt = connection.createStatement();
+        try {
+            stmt.executeUpdate(MessageFormat.format(SET_CURRENT_SCHEMA_STMT_STR, 
+                                                    schemaName));
+        } catch (SQLException ex) {
+            throw ex;
+        }
+        stmt.close();
+    }
 
     @PostConstruct     
     public synchronized void init() {
@@ -755,7 +796,6 @@ public class RMTxStore implements RMStor
             try {
                 LOG.log(Level.FINE, "Using url: " + url);
                 connection = DriverManager.getConnection(url, userName, password);
-    
             } catch (SQLException ex) {
                 LogUtils.log(LOG, Level.SEVERE, "CONNECT_EXC", ex);
                 return;
@@ -764,6 +804,7 @@ public class RMTxStore implements RMStor
         
         try {
             connection.setAutoCommit(true);
+            setCurrentSchema();
             createTables();
         } catch (SQLException ex) {
             LogUtils.log(LOG, Level.SEVERE, "CONNECT_EXC", ex);

Modified: cxf/trunk/rt/ws/rm/src/main/resources/schemas/configuration/wsrm-manager.xsd
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/main/resources/schemas/configuration/wsrm-manager.xsd?rev=1327984&r1=1327983&r2=1327984&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/main/resources/schemas/configuration/wsrm-manager.xsd (original)
+++ cxf/trunk/rt/ws/rm/src/main/resources/schemas/configuration/wsrm-manager.xsd Thu Apr 19
15:13:29 2012
@@ -168,6 +168,13 @@
               </xs:documentation>
             </xs:annotation>
           </xs:attribute>
+           <xs:attribute name="schemaName" type="xs:string">
+            <xs:annotation>
+              <xs:documentation>
+                  The default schema name.          
+              </xs:documentation>
+            </xs:annotation>
+          </xs:attribute>
         </xs:extension>
       </xs:complexContent>
     </xs:complexType>

Modified: cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java?rev=1327984&r1=1327983&r2=1327984&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java
(original)
+++ cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java
Thu Apr 19 15:13:29 2012
@@ -46,6 +46,7 @@ public class RMTxStoreConfigurationTest 
         assertEquals("scott", store.getUserName());
         assertEquals("tiger", store.getPassword());
         assertEquals("jdbc:derby://localhost:1527/rmdb;create=true", store.getUrl());
+        assertNull("schema should be unset", store.getSchemaName());
     }
    
     @Test

Added: cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreTwoSchemasTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreTwoSchemasTest.java?rev=1327984&view=auto
==============================================================================
--- cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreTwoSchemasTest.java
(added)
+++ cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreTwoSchemasTest.java
Thu Apr 19 15:13:29 2012
@@ -0,0 +1,138 @@
+/**
+ * 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.cxf.ws.rm.persistence.jdbc;
+
+import java.text.MessageFormat;
+
+import org.apache.cxf.ws.rm.ProtocolVariation;
+import org.apache.cxf.ws.rm.SourceSequence;
+import org.apache.cxf.ws.rm.v200702.Identifier;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * 
+ */
+public class RMTxStoreTwoSchemasTest extends Assert {
+    private static final String TEST_DB_NAME = "rmdb3";
+
+    private static final String CLIENT_ENDPOINT_ID = 
+        "{http://apache.org/greeter_control}GreeterService/GreeterPort";
+    
+    private static RMTxStore store1;
+    private static RMTxStore store2;
+
+    private IMocksControl control;
+    
+    @BeforeClass 
+    public static void setUpOnce() {
+        RMTxStore.deleteDatabaseFiles(TEST_DB_NAME, true);
+
+        store1 = createStore("ONE");
+        store2 = createStore("TWO");
+    }
+    
+    @AfterClass
+    public static void tearDownOnce() {
+        RMTxStore.deleteDatabaseFiles(TEST_DB_NAME, false);
+    }
+
+    private static RMTxStore createStore(String sn) {
+        RMTxStore store = new RMTxStore();
+        store.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
+        
+        // workaround for the db file deletion problem during the tests
+        store.setUrl(MessageFormat.format("jdbc:derby:{0};create=true", TEST_DB_NAME));
+
+        // use the specified schema 
+        store.setSchemaName(sn);
+        store.init();
+        
+        return store;
+    }
+
+    @Before
+    public void setUp() {
+        control = EasyMock.createNiceControl();        
+    }
+    
+    @Test
+    public void testSetCurrentSchema() throws Exception {
+        // schema should  have been set during initialisation
+        // but verify the operation is idempotent
+        store1.setCurrentSchema();
+    }
+    
+    @Test
+    public void testStoreIsolation() throws Exception {
+        SourceSequence seq = control.createMock(SourceSequence.class);
+        Identifier sid1 = new Identifier();
+        sid1.setValue("sequence1");
+        EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
+        EasyMock.expect(seq.getExpires()).andReturn(null);
+        EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
+        EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
+        EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
+        
+        control.replay();
+        store1.createSourceSequence(seq);   
+        control.verify();        
+        
+        SourceSequence rseq = store1.getSourceSequence(sid1);
+        assertNotNull(rseq);
+        
+        rseq = store2.getSourceSequence(sid1);
+        assertNull(rseq);
+        
+        control.reset();
+        EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
+        EasyMock.expect(seq.getExpires()).andReturn(null);
+        EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
+        EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
+        EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
+        
+        control.replay();
+        store2.createSourceSequence(seq);   
+        control.verify();
+        
+        rseq = store2.getSourceSequence(sid1);
+        assertNotNull(rseq);
+ 
+        // create another store
+        RMTxStore store3 = createStore(null);
+        store3.init();
+
+        rseq = store3.getSourceSequence(sid1);
+        assertNull(rseq);
+
+        // switch to the store1's schema
+        store3.setSchemaName(store1.getSchemaName());
+        store3.init();
+        
+        rseq = store3.getSourceSequence(sid1);
+        assertNotNull(rseq);
+    }
+}
\ No newline at end of file

Propchange: cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreTwoSchemasTest.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message