Read write lock implementation 87/88187/3
authorTschaen, Brendan <ctschaen@att.com>
Tue, 21 May 2019 17:19:40 +0000 (13:19 -0400)
committerTschaen, Brendan <ctschaen@att.com>
Wed, 22 May 2019 19:29:58 +0000 (15:29 -0400)
Change-Id: Ifd680da39305adf36e8a4946643a17e9e0a4df97
Issue-ID: MUSIC-326
Signed-off-by: Tschaen, Brendan <ctschaen@att.com>
mdbc-server/src/main/java/org/onap/music/mdbc/MDBCUtils.java
mdbc-server/src/main/java/org/onap/music/mdbc/MdbcConnection.java
mdbc-server/src/main/java/org/onap/music/mdbc/ProxyStatement.java [deleted file]
mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestClient.java
mdbc-server/src/main/java/org/onap/music/mdbc/mixins/LockRequest.java
mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java
mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java
mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MusicMixinTest.java
mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MySQLMixinTest.java [moved from mdbc-server/src/test/java/org/onap/music/mdbc/MySQLMixinTest.java with 96% similarity]
mdbc-server/src/test/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpointTest.java

index ae2b869..a02e6d0 100755 (executable)
@@ -38,6 +38,7 @@ import org.onap.music.logging.format.ErrorTypes;
 import org.onap.music.mdbc.mixins.MusicMixin;
 import org.onap.music.mdbc.mixins.Utils;
 import org.onap.music.mdbc.query.SQLOperation;
+import org.onap.music.mdbc.query.SQLOperationType;
 import org.onap.music.mdbc.tables.Operation;
 import org.onap.music.mdbc.tables.StagingTable;
 
@@ -119,4 +120,21 @@ public class MDBCUtils {
                }
            return ranges;
     }
+
+    /**
+     * determine the type of operation contained in the table to query map
+     * 
+     * @param tableToQueryType
+     * @return write if any table has a write query. Read otherwise
+     */
+    public static SQLOperationType getOperationType(Map<String, List<SQLOperation>> tableToQueryType) {
+        for (List<org.onap.music.mdbc.query.SQLOperation> tablesOps : tableToQueryType.values()) {
+            for (org.onap.music.mdbc.query.SQLOperation op : tablesOps) {
+                if (op.getOperationType() != SQLOperationType.READ) {
+                    return SQLOperationType.WRITE;
+                }
+            }
+        }
+        return SQLOperationType.READ;
+    }
 }
\ No newline at end of file
index b4d7bb9..3743638 100755 (executable)
@@ -54,6 +54,7 @@ import org.onap.music.mdbc.ownership.DagNode;
 import org.onap.music.mdbc.ownership.OwnershipAndCheckpoint;
 import org.onap.music.mdbc.query.QueryProcessor;
 import org.onap.music.mdbc.query.SQLOperation;
+import org.onap.music.mdbc.query.SQLOperationType;
 import org.onap.music.mdbc.tables.MusicTxDigestDaemon;
 import org.onap.music.mdbc.tables.MusicRangeInformationRow;
 import org.onap.music.mdbc.tables.StagingTable;
@@ -500,10 +501,10 @@ public class MdbcConnection implements Connection {
     public void preStatementHook(final String sql) throws MDBCServiceException, SQLException {
         //TODO: verify ownership of keys here
         //Parse tables from the sql query
-        Map<String, List<SQLOperation>> tableToInstruction = QueryProcessor.parseSqlQuery(sql, table_set);
+        Map<String, List<SQLOperation>> tableToQueryType = QueryProcessor.parseSqlQuery(sql, table_set);
         //Check ownership of keys
         String defaultSchema = dbi.getSchema();
-        List<Range> queryTables = MDBCUtils.getTables(defaultSchema, tableToInstruction);
+        List<Range> queryTables = MDBCUtils.getTables(defaultSchema, tableToQueryType);
         if (this.partition!=null) {
             List<Range> snapshot = this.partition.getSnapshot();
             if(snapshot!=null){
@@ -512,8 +513,8 @@ public class MdbcConnection implements Connection {
         }
         // filter out ranges that fall under Eventually consistent
         // category as these tables do not need ownership
-        List<Range> scQueryTables = filterEveTables( queryTables);
-        DatabasePartition tempPartition = own(scQueryTables);
+        List<Range> scQueryTables = filterEveTables(queryTables);
+        DatabasePartition tempPartition = own(scQueryTables, MDBCUtils.getOperationType(tableToQueryType));
         if(tempPartition!=null && tempPartition != partition) {
             this.partition.updateDatabasePartition(tempPartition);
             statemanager.getOwnAndCheck().reloadAlreadyApplied(this.partition);
@@ -576,7 +577,7 @@ public class MdbcConnection implements Connection {
      * @return
      * @throws MDBCServiceException
      */
-    private DatabasePartition own(List<Range> ranges) throws MDBCServiceException {
+    private DatabasePartition own(List<Range> ranges, SQLOperationType lockType) throws MDBCServiceException {
         if(ranges==null||ranges.isEmpty()){
             return null;
         }
@@ -584,7 +585,7 @@ public class MdbcConnection implements Connection {
         OwnershipAndCheckpoint ownAndCheck = statemanager.getOwnAndCheck();
         UUID ownOpId = MDBCUtils.generateTimebasedUniqueKey();
         try {
-            final OwnershipReturn ownershipReturn = ownAndCheck.own(mi, ranges, partition, ownOpId);
+            final OwnershipReturn ownershipReturn = ownAndCheck.own(mi, ranges, partition, ownOpId, lockType);
             if(ownershipReturn==null){
                 return null;
             }
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/ProxyStatement.java b/mdbc-server/src/main/java/org/onap/music/mdbc/ProxyStatement.java
deleted file mode 100755 (executable)
index 2c3e6b9..0000000
+++ /dev/null
@@ -1,1302 +0,0 @@
-/*
- * ============LICENSE_START====================================================
- * org.onap.music.mdbc
- * =============================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
- * =============================================================================
- * Licensed 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.
- * ============LICENSE_END======================================================
- */
-package org.onap.music.mdbc;
-
-import java.io.InputStream;
-import java.io.Reader;
-import java.math.BigDecimal;
-import java.net.URL;
-import java.sql.Array;
-import java.sql.Blob;
-import java.sql.CallableStatement;
-import java.sql.Clob;
-import java.sql.Connection;
-import java.sql.Date;
-import java.sql.NClob;
-import java.sql.ParameterMetaData;
-import java.sql.PreparedStatement;
-import java.sql.Ref;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.RowId;
-import java.sql.SQLException;
-import java.sql.SQLWarning;
-import java.sql.SQLXML;
-import java.sql.Statement;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.util.Calendar;
-import java.util.Map;
-
-import org.onap.music.exceptions.MDBCServiceException;
-import org.onap.music.exceptions.QueryException;
-import org.onap.music.logging.EELFLoggerDelegate;
-
-/**
- * ProxyStatement is a proxy Statement that front ends Statements from the underlying JDBC driver.  It passes all operations through,
- * and invokes the MusicSqlManager when there is the possibility that database tables have been created or dropped.
- *
- * @author Robert Eby
- */
-public class ProxyStatement implements CallableStatement {
-       private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ProxyStatement.class);
-       private static final String DATASTAX_PREFIX = "com.datastax.driver";
-
-       private final Statement stmt;           // the Statement that we are proxying
-       private final MdbcConnection mConn;
-
-       public ProxyStatement(Statement s, MdbcConnection mConn) {
-               this.stmt = s;
-               this.mConn = mConn;
-       }
-
-       @Override
-       public <T> T unwrap(Class<T> iface) throws SQLException {
-               return stmt.unwrap(iface);
-       }
-
-       @Override
-       public boolean isWrapperFor(Class<?> iface) throws SQLException {
-               return stmt.isWrapperFor(iface);
-       }
-
-       @Override
-       public ResultSet executeQuery(String sql) throws SQLException {
-               logger.debug("executeQuery: "+sql);
-               ResultSet r = null;
-               try {
-                       mConn.preStatementHook(sql);
-                       r = stmt.executeQuery(sql);
-                       mConn.postStatementHook(sql);
-                       synchronizeTables(sql);
-               } catch (SQLException e) {
-                       String nm = e.getClass().getName();
-                       logger.warn("executeQuery: exception "+nm);
-                       if (!nm.startsWith(DATASTAX_PREFIX))
-                               throw e;
-               } catch (MDBCServiceException e) {
-                   throw new SQLException(e.getMessage(), e);
-               }
-
-               return r;
-       }
-
-       @Override
-       public int executeUpdate(String sql) throws SQLException {
-               logger.debug("executeUpdate: "+sql);
-               int n = 0;
-               try {
-                       mConn.preStatementHook(sql);
-                       n = stmt.executeUpdate(sql);
-                       mConn.postStatementHook(sql);
-                       synchronizeTables(sql);
-               } catch (SQLException e) {
-                       String nm = e.getClass().getName();
-                       logger.warn("executeUpdate: exception "+nm);
-                       if (!nm.startsWith(DATASTAX_PREFIX))
-                               throw e;
-        } catch (MDBCServiceException e) {
-                   throw new SQLException(e.getMessage(), e);
-               }
-               return n;
-       }
-
-       @Override
-       public void close() throws SQLException {
-               stmt.close();
-       }
-
-       @Override
-       public int getMaxFieldSize() throws SQLException {
-               return stmt.getMaxFieldSize();
-       }
-
-       @Override
-       public void setMaxFieldSize(int max) throws SQLException {
-               stmt.setMaxFieldSize(max);
-       }
-
-       @Override
-       public int getMaxRows() throws SQLException {
-               return stmt.getMaxRows();
-       }
-
-       @Override
-       public void setMaxRows(int max) throws SQLException {
-               stmt.setMaxRows(max);
-       }
-
-       @Override
-       public void setEscapeProcessing(boolean enable) throws SQLException {
-               stmt.setEscapeProcessing(enable);
-       }
-
-       @Override
-       public int getQueryTimeout() throws SQLException {
-               return stmt.getQueryTimeout();
-       }
-
-       @Override
-       public void setQueryTimeout(int seconds) throws SQLException {
-               stmt.setQueryTimeout(seconds);
-       }
-
-       @Override
-       public void cancel() throws SQLException {
-               stmt.cancel();
-       }
-
-       @Override
-       public SQLWarning getWarnings() throws SQLException {
-               return stmt.getWarnings();
-       }
-
-       @Override
-       public void clearWarnings() throws SQLException {
-               stmt.clearWarnings();
-       }
-
-       @Override
-       public void setCursorName(String name) throws SQLException {
-               stmt.setCursorName(name);
-       }
-
-       @Override
-       public boolean execute(String sql) throws SQLException {
-               logger.debug("execute: "+sql);
-               boolean b = false;
-               try {
-                       mConn.preStatementHook(sql);
-                       b = stmt.execute(sql);
-                       mConn.postStatementHook(sql);
-                       synchronizeTables(sql);
-               } catch (SQLException e) {
-                       String nm = e.getClass().getName();
-                       // Note: this seems to be the only call Camunda uses, so it is the only one I am fixing for now.
-                       boolean ignore = nm.startsWith(DATASTAX_PREFIX);
-//                     ignore |= (nm.startsWith("org.h2.jdbc.JdbcSQLException") && e.getMessage().contains("already exists"));
-                       if (ignore) {
-                               logger.warn("execute: exception (IGNORED) "+nm);
-                       } else {
-                               logger.warn("execute: exception "+nm);
-                               throw e;
-                       }
-        } catch (MDBCServiceException e) {
-                   throw new SQLException(e.getMessage(), e);
-               }
-               return b;
-       }
-
-       @Override
-       public ResultSet getResultSet() throws SQLException {
-               return stmt.getResultSet();
-       }
-
-       @Override
-       public int getUpdateCount() throws SQLException {
-               return stmt.getUpdateCount();
-       }
-
-       @Override
-       public boolean getMoreResults() throws SQLException {
-               return stmt.getMoreResults();
-       }
-
-       @Override
-       public void setFetchDirection(int direction) throws SQLException {
-               stmt.setFetchDirection(direction);
-       }
-
-       @Override
-       public int getFetchDirection() throws SQLException {
-               return stmt.getFetchDirection();
-       }
-
-       @Override
-       public void setFetchSize(int rows) throws SQLException {
-               stmt.setFetchSize(rows);
-       }
-
-       @Override
-       public int getFetchSize() throws SQLException {
-               return stmt.getFetchSize();
-       }
-
-       @Override
-       public int getResultSetConcurrency() throws SQLException {
-               return stmt.getResultSetConcurrency();
-       }
-
-       @Override
-       public int getResultSetType() throws SQLException {
-               return stmt.getResultSetType();
-       }
-
-       @Override
-       public void addBatch(String sql) throws SQLException {
-               stmt.addBatch(sql);
-       }
-
-       @Override
-       public void clearBatch() throws SQLException {
-               stmt.clearBatch();
-       }
-
-       @Override
-       public int[] executeBatch() throws SQLException {
-               logger.debug("executeBatch");
-               int[] n = null;
-               //\TODO check if this is still invalid in Metric
-               try {
-                       logger.warn("executeBatch() is not supported by MDBC; your results may be incorrect as a result.");
-                       n = stmt.executeBatch();
-                       synchronizeTables(null);
-               } catch (SQLException e) {
-                       String nm = e.getClass().getName();
-                       logger.warn("executeBatch: exception "+nm);
-                       if (!nm.startsWith(DATASTAX_PREFIX))
-                               throw e;
-        }
-
-               return n;
-       }
-
-       @Override
-       public Connection getConnection() throws SQLException {
-               return stmt.getConnection();
-       }
-
-       @Override
-       public boolean getMoreResults(int current) throws SQLException {
-               return stmt.getMoreResults(current);
-       }
-
-       @Override
-       public ResultSet getGeneratedKeys() throws SQLException {
-               return stmt.getGeneratedKeys();
-       }
-
-       @Override
-       public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
-               logger.debug("executeUpdate: "+sql);
-               int n = 0;
-               try {
-                       mConn.preStatementHook(sql);
-                       n = stmt.executeUpdate(sql, autoGeneratedKeys);
-                       mConn.postStatementHook(sql);
-                       synchronizeTables(sql);
-               } catch (SQLException e) {
-                       String nm = e.getClass().getName();
-                       logger.warn("executeUpdate: exception "+nm);
-                       if (!nm.startsWith(DATASTAX_PREFIX))
-                               throw e;
-               }catch (MDBCServiceException e) {
-                   throw new SQLException(e.getMessage(), e);
-               }
-               return n;
-       }
-
-       @Override
-       public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
-               logger.debug("executeUpdate: "+sql);
-               int n = 0;
-               try {
-                       mConn.preStatementHook(sql);
-                       n = stmt.executeUpdate(sql, columnIndexes);
-                       mConn.postStatementHook(sql);
-                       synchronizeTables(sql);
-               } catch (SQLException e) {
-                       String nm = e.getClass().getName();
-                       logger.warn("executeUpdate: exception "+nm);
-                       if (!nm.startsWith(DATASTAX_PREFIX))
-                               throw e;
-               }catch (MDBCServiceException e) {
-                   throw new SQLException(e.getMessage(), e);
-               }
-               return n;
-       }
-
-       @Override
-       public int executeUpdate(String sql, String[] columnNames) throws SQLException {
-               logger.debug("executeUpdate: "+sql);
-               int n = 0;
-               try {
-                       mConn.preStatementHook(sql);
-                       n = stmt.executeUpdate(sql, columnNames);
-                       mConn.postStatementHook(sql);
-                       synchronizeTables(sql);
-               } catch (SQLException e) {
-                       String nm = e.getClass().getName();
-                       logger.warn("executeUpdate: exception "+nm);
-                       if (!nm.startsWith(DATASTAX_PREFIX))
-                               throw e;
-               }catch (MDBCServiceException e) {
-                   throw new SQLException(e.getMessage(), e);
-               }
-               return n;
-       }
-
-       @Override
-       public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
-               logger.debug("execute: "+sql);
-               boolean b = false;
-               try {
-                       mConn.preStatementHook(sql);
-                       b = stmt.execute(sql, autoGeneratedKeys);
-                       mConn.postStatementHook(sql);
-                       synchronizeTables(sql);
-               } catch (SQLException e) {
-                       String nm = e.getClass().getName();
-                       logger.warn("execute: exception "+nm);
-                       if (!nm.startsWith(DATASTAX_PREFIX))
-                               throw e;
-               }catch (MDBCServiceException e) {
-                   throw new SQLException(e.getMessage(), e);
-               }
-               return b;
-       }
-
-       @Override
-       public boolean execute(String sql, int[] columnIndexes) throws SQLException {
-               logger.debug("execute: "+sql);
-               boolean b = false;
-               try {
-                       mConn.preStatementHook(sql);
-                       b = stmt.execute(sql, columnIndexes);
-                       mConn.postStatementHook(sql);
-                       synchronizeTables(sql);
-               } catch (SQLException e) {
-                       String nm = e.getClass().getName();
-                       logger.warn("execute: exception "+nm);
-                       if (!nm.startsWith(DATASTAX_PREFIX))
-                               throw e;
-               }catch (MDBCServiceException e) {
-                   throw new SQLException(e.getMessage(), e);
-               }
-               return b;
-       }
-
-       @Override
-       public boolean execute(String sql, String[] columnNames) throws SQLException {
-               logger.debug("execute: "+sql);
-               boolean b = false;
-               try {
-                       mConn.preStatementHook(sql);
-                       b = stmt.execute(sql, columnNames);
-                       mConn.postStatementHook(sql);
-                       synchronizeTables(sql);
-               } catch (SQLException e) {
-                       String nm = e.getClass().getName();
-                       logger.warn("execute: exception "+nm);
-                       if (!nm.startsWith(DATASTAX_PREFIX))
-                               throw e;
-               }catch (MDBCServiceException e) {
-                   throw new SQLException(e.getMessage(), e);
-               }
-               return b;
-       }
-
-       @Override
-       public int getResultSetHoldability() throws SQLException {
-               return stmt.getResultSetHoldability();
-       }
-
-       @Override
-       public boolean isClosed() throws SQLException {
-               return stmt.isClosed();
-       }
-
-       @Override
-       public void setPoolable(boolean poolable) throws SQLException {
-               stmt.setPoolable(poolable);
-       }
-
-       @Override
-       public boolean isPoolable() throws SQLException {
-               return stmt.isPoolable();
-       }
-
-       @Override
-       public void closeOnCompletion() throws SQLException {
-               stmt.closeOnCompletion();
-       }
-
-       @Override
-       public boolean isCloseOnCompletion() throws SQLException {
-               return stmt.isCloseOnCompletion();
-       }
-
-       @Override
-       public ResultSet executeQuery() throws SQLException {
-               logger.debug("executeQuery");
-               return ((PreparedStatement)stmt).executeQuery();
-       }
-
-       @Override
-       public int executeUpdate() throws SQLException {
-               logger.debug("executeUpdate");
-               return ((PreparedStatement)stmt).executeUpdate();
-       }
-
-       @Override
-       public void setNull(int parameterIndex, int sqlType) throws SQLException {
-               ((PreparedStatement)stmt).setNull(parameterIndex, sqlType);
-       }
-
-       @Override
-       public void setBoolean(int parameterIndex, boolean x) throws SQLException {
-               ((PreparedStatement)stmt).setBoolean(parameterIndex, x);
-       }
-
-       @Override
-       public void setByte(int parameterIndex, byte x) throws SQLException {
-               ((PreparedStatement)stmt).setByte(parameterIndex, x);
-       }
-
-       @Override
-       public void setShort(int parameterIndex, short x) throws SQLException {
-               ((PreparedStatement)stmt).setShort(parameterIndex, x);
-       }
-
-       @Override
-       public void setInt(int parameterIndex, int x) throws SQLException {
-               ((PreparedStatement)stmt).setInt(parameterIndex, x);
-       }
-
-       @Override
-       public void setLong(int parameterIndex, long x) throws SQLException {
-               ((PreparedStatement)stmt).setLong(parameterIndex, x);
-       }
-
-       @Override
-       public void setFloat(int parameterIndex, float x) throws SQLException {
-               ((PreparedStatement)stmt).setFloat(parameterIndex, x);
-       }
-
-       @Override
-       public void setDouble(int parameterIndex, double x) throws SQLException {
-               ((PreparedStatement)stmt).setDouble(parameterIndex, x);
-       }
-
-       @Override
-       public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
-               ((PreparedStatement)stmt).setBigDecimal(parameterIndex, x);
-       }
-
-       @Override
-       public void setString(int parameterIndex, String x) throws SQLException {
-               ((PreparedStatement)stmt).setString(parameterIndex, x);
-       }
-
-       @Override
-       public void setBytes(int parameterIndex, byte[] x) throws SQLException {
-               ((PreparedStatement)stmt).setBytes(parameterIndex, x);
-       }
-
-       @Override
-       public void setDate(int parameterIndex, Date x) throws SQLException {
-               ((PreparedStatement)stmt).setDate(parameterIndex, x);
-       }
-
-       @Override
-       public void setTime(int parameterIndex, Time x) throws SQLException {
-               ((PreparedStatement)stmt).setTime(parameterIndex, x);
-       }
-
-       @Override
-       public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
-               ((PreparedStatement)stmt).setTimestamp(parameterIndex, x);
-       }
-
-       @Override
-       public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
-               ((PreparedStatement)stmt).setAsciiStream(parameterIndex, x, length);
-       }
-
-       @SuppressWarnings("deprecation")
-       @Override
-       public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
-               ((PreparedStatement)stmt).setUnicodeStream(parameterIndex, x, length);
-       }
-
-       @Override
-       public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
-               ((PreparedStatement)stmt).setBinaryStream(parameterIndex, x, length);
-       }
-
-       @Override
-       public void clearParameters() throws SQLException {
-               ((PreparedStatement)stmt).clearParameters();
-       }
-
-       @Override
-       public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
-               ((PreparedStatement)stmt).setObject(parameterIndex, x, targetSqlType);
-       }
-
-       @Override
-       public void setObject(int parameterIndex, Object x) throws SQLException {
-               ((PreparedStatement)stmt).setObject(parameterIndex, x);
-       }
-
-       @Override
-       public boolean execute() throws SQLException {
-               return ((PreparedStatement)stmt).execute();
-       }
-
-       @Override
-       public void addBatch() throws SQLException {
-               ((PreparedStatement)stmt).addBatch();
-       }
-
-       @Override
-       public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
-               ((PreparedStatement)stmt).setCharacterStream(parameterIndex, reader, length);
-       }
-
-       @Override
-       public void setRef(int parameterIndex, Ref x) throws SQLException {
-               ((PreparedStatement)stmt).setRef(parameterIndex, x);
-       }
-
-       @Override
-       public void setBlob(int parameterIndex, Blob x) throws SQLException {
-               ((PreparedStatement)stmt).setBlob(parameterIndex, x);
-       }
-
-       @Override
-       public void setClob(int parameterIndex, Clob x) throws SQLException {
-               ((PreparedStatement)stmt).setClob(parameterIndex, x);
-       }
-
-       @Override
-       public void setArray(int parameterIndex, Array x) throws SQLException {
-               ((PreparedStatement)stmt).setArray(parameterIndex, x);
-       }
-
-       @Override
-       public ResultSetMetaData getMetaData() throws SQLException {
-               return ((PreparedStatement)stmt).getMetaData();
-       }
-
-       @Override
-       public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
-               ((PreparedStatement)stmt).setDate(parameterIndex, x, cal);
-       }
-
-       @Override
-       public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
-               ((PreparedStatement)stmt).setTime(parameterIndex, x, cal);
-       }
-
-       @Override
-       public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
-               ((CallableStatement)stmt).setTimestamp(parameterIndex, x, cal);
-       }
-
-       @Override
-       public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
-               ((CallableStatement)stmt).setNull(parameterIndex, sqlType, typeName);
-       }
-
-       @Override
-       public void setURL(int parameterIndex, URL x) throws SQLException {
-               ((CallableStatement)stmt).setURL(parameterIndex, x);
-       }
-
-       @Override
-       public ParameterMetaData getParameterMetaData() throws SQLException {
-               return ((CallableStatement)stmt).getParameterMetaData();
-       }
-
-       @Override
-       public void setRowId(int parameterIndex, RowId x) throws SQLException {
-               ((CallableStatement)stmt).setRowId(parameterIndex, x);
-       }
-
-       @Override
-       public void setNString(int parameterIndex, String value) throws SQLException {
-               ((CallableStatement)stmt).setNString(parameterIndex, value);
-       }
-
-       @Override
-       public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException {
-               ((CallableStatement)stmt).setNCharacterStream(parameterIndex, value, length);
-       }
-
-       @Override
-       public void setNClob(int parameterIndex, NClob value) throws SQLException {
-               ((CallableStatement)stmt).setNClob(parameterIndex, value);
-       }
-
-       @Override
-       public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
-               ((CallableStatement)stmt).setClob(parameterIndex, reader, length);
-       }
-
-       @Override
-       public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException {
-               ((CallableStatement)stmt).setBlob(parameterIndex, inputStream, length);
-       }
-
-       @Override
-       public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
-               ((CallableStatement)stmt).setNClob(parameterIndex, reader, length);
-       }
-
-       @Override
-       public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
-               ((CallableStatement)stmt).setSQLXML(parameterIndex, xmlObject);
-       }
-
-       @Override
-       public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException {
-               ((CallableStatement)stmt).setObject(parameterIndex, x, targetSqlType, scaleOrLength);
-       }
-
-       @Override
-       public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
-               ((CallableStatement)stmt).setAsciiStream(parameterIndex, x, length);
-       }
-
-       @Override
-       public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
-               ((CallableStatement)stmt).setBinaryStream(parameterIndex, x, length);
-       }
-
-       @Override
-       public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {
-               ((CallableStatement)stmt).setCharacterStream(parameterIndex, reader, length);
-       }
-
-       @Override
-       public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
-               ((CallableStatement)stmt).setAsciiStream(parameterIndex, x);
-       }
-
-       @Override
-       public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
-               ((CallableStatement)stmt).setBinaryStream(parameterIndex, x);
-       }
-
-       @Override
-       public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
-               ((CallableStatement)stmt).setCharacterStream(parameterIndex, reader);
-       }
-
-       @Override
-       public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
-               ((CallableStatement)stmt).setNCharacterStream(parameterIndex, value);
-       }
-
-       @Override
-       public void setClob(int parameterIndex, Reader reader) throws SQLException {
-               ((CallableStatement)stmt).setClob(parameterIndex, reader);
-       }
-
-       @Override
-       public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
-               ((CallableStatement)stmt).setBlob(parameterIndex, inputStream);
-       }
-
-       @Override
-       public void setNClob(int parameterIndex, Reader reader) throws SQLException {
-               ((CallableStatement)stmt).setNClob(parameterIndex, reader);
-       }
-
-       @Override
-       public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
-               ((CallableStatement)stmt).registerOutParameter(parameterIndex, sqlType);
-       }
-
-       @Override
-       public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
-               ((CallableStatement)stmt).registerOutParameter(parameterIndex, sqlType, scale);
-       }
-
-       @Override
-       public boolean wasNull() throws SQLException {
-               return ((CallableStatement)stmt).wasNull();
-       }
-
-       @Override
-       public String getString(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getString(parameterIndex);
-       }
-
-       @Override
-       public boolean getBoolean(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getBoolean(parameterIndex);
-       }
-
-       @Override
-       public byte getByte(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getByte(parameterIndex);
-       }
-
-       @Override
-       public short getShort(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getShort(parameterIndex);
-       }
-
-       @Override
-       public int getInt(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getInt(parameterIndex);
-       }
-
-       @Override
-       public long getLong(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getLong(parameterIndex);
-       }
-
-       @Override
-       public float getFloat(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getFloat(parameterIndex);
-       }
-
-       @Override
-       public double getDouble(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getDouble(parameterIndex);
-       }
-
-       @SuppressWarnings("deprecation")
-       @Override
-       public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
-               return ((CallableStatement)stmt).getBigDecimal(parameterIndex, scale);
-       }
-
-       @Override
-       public byte[] getBytes(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getBytes(parameterIndex);
-       }
-
-       @Override
-       public Date getDate(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getDate(parameterIndex);
-       }
-
-       @Override
-       public Time getTime(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getTime(parameterIndex);
-       }
-
-       @Override
-       public Timestamp getTimestamp(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getTimestamp(parameterIndex);
-       }
-
-       @Override
-       public Object getObject(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getObject(parameterIndex);
-       }
-
-       @Override
-       public BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getBigDecimal(parameterIndex);
-       }
-
-       @Override
-       public Object getObject(int parameterIndex, Map<String, Class<?>> map) throws SQLException {
-               return ((CallableStatement)stmt).getObject(parameterIndex, map);
-       }
-
-       @Override
-       public Ref getRef(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getRef(parameterIndex);
-       }
-
-       @Override
-       public Blob getBlob(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getBlob(parameterIndex);
-       }
-
-       @Override
-       public Clob getClob(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getClob(parameterIndex);
-       }
-
-       @Override
-       public Array getArray(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getArray(parameterIndex);
-       }
-
-       @Override
-       public Date getDate(int parameterIndex, Calendar cal) throws SQLException {
-               return ((CallableStatement)stmt).getDate(parameterIndex, cal);
-       }
-
-       @Override
-       public Time getTime(int parameterIndex, Calendar cal) throws SQLException {
-               return ((CallableStatement)stmt).getTime(parameterIndex, cal);
-       }
-
-       @Override
-       public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException {
-               return ((CallableStatement)stmt).getTimestamp(parameterIndex, cal);
-       }
-
-       @Override
-       public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException {
-               ((CallableStatement)stmt).registerOutParameter(parameterIndex, sqlType, typeName);
-       }
-
-       @Override
-       public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
-               ((CallableStatement)stmt).registerOutParameter(parameterName, sqlType);
-       }
-
-       @Override
-       public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
-               ((CallableStatement)stmt).registerOutParameter(parameterName, sqlType, scale);
-       }
-
-       @Override
-       public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
-               ((CallableStatement)stmt).registerOutParameter(parameterName, sqlType, typeName);
-       }
-
-       @Override
-       public URL getURL(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getURL(parameterIndex);
-       }
-
-       @Override
-       public void setURL(String parameterName, URL val) throws SQLException {
-               ((CallableStatement)stmt).setURL(parameterName, val);
-       }
-
-       @Override
-       public void setNull(String parameterName, int sqlType) throws SQLException {
-               ((CallableStatement)stmt).setNull(parameterName, sqlType);
-       }
-
-       @Override
-       public void setBoolean(String parameterName, boolean x) throws SQLException {
-               ((CallableStatement)stmt).setBoolean(parameterName, x);
-       }
-
-       @Override
-       public void setByte(String parameterName, byte x) throws SQLException {
-               ((CallableStatement)stmt).setByte(parameterName, x);
-       }
-
-       @Override
-       public void setShort(String parameterName, short x) throws SQLException {
-               ((CallableStatement)stmt).setShort(parameterName, x);
-       }
-
-       @Override
-       public void setInt(String parameterName, int x) throws SQLException {
-               ((CallableStatement)stmt).setInt(parameterName, x);
-       }
-
-       @Override
-       public void setLong(String parameterName, long x) throws SQLException {
-               ((CallableStatement)stmt).setLong(parameterName, x);
-       }
-
-       @Override
-       public void setFloat(String parameterName, float x) throws SQLException {
-               ((CallableStatement)stmt).setFloat(parameterName, x);
-       }
-
-       @Override
-       public void setDouble(String parameterName, double x) throws SQLException {
-               ((CallableStatement)stmt).setDouble(parameterName, x);
-       }
-
-       @Override
-       public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
-               ((CallableStatement)stmt).setBigDecimal(parameterName, x);
-       }
-
-       @Override
-       public void setString(String parameterName, String x) throws SQLException {
-               ((CallableStatement)stmt).setString(parameterName, x);
-       }
-
-       @Override
-       public void setBytes(String parameterName, byte[] x) throws SQLException {
-               ((CallableStatement)stmt).setBytes(parameterName, x);
-       }
-
-       @Override
-       public void setDate(String parameterName, Date x) throws SQLException {
-               ((CallableStatement)stmt).setDate(parameterName, x);
-       }
-
-       @Override
-       public void setTime(String parameterName, Time x) throws SQLException {
-               ((CallableStatement)stmt).setTime(parameterName, x);
-       }
-
-       @Override
-       public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
-               ((CallableStatement)stmt).setTimestamp(parameterName, x);
-       }
-
-       @Override
-       public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
-               ((CallableStatement)stmt).setAsciiStream(parameterName, x, length);
-       }
-
-       @Override
-       public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
-               ((CallableStatement)stmt).setBinaryStream(parameterName, x, length);
-       }
-
-       @Override
-       public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException {
-               ((CallableStatement)stmt).setObject(parameterName, x, targetSqlType, scale);
-       }
-
-       @Override
-       public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
-               ((CallableStatement)stmt).setObject(parameterName, x, targetSqlType);
-       }
-
-       @Override
-       public void setObject(String parameterName, Object x) throws SQLException {
-               ((CallableStatement)stmt).setObject(parameterName, x);
-       }
-
-       @Override
-       public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
-               ((CallableStatement)stmt).setCharacterStream(parameterName, reader, length);
-       }
-
-       @Override
-       public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
-               ((CallableStatement)stmt).setDate(parameterName, x, cal);
-       }
-
-       @Override
-       public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
-               ((CallableStatement)stmt).setTime(parameterName, x, cal);
-       }
-
-       @Override
-       public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
-               ((CallableStatement)stmt).setTimestamp(parameterName, x, cal);
-       }
-
-       @Override
-       public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
-               ((CallableStatement)stmt).setNull(parameterName, sqlType, typeName);
-       }
-
-       @Override
-       public String getString(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getString(parameterName);
-       }
-
-       @Override
-       public boolean getBoolean(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getBoolean(parameterName);
-       }
-
-       @Override
-       public byte getByte(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getByte(parameterName);
-       }
-
-       @Override
-       public short getShort(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getShort(parameterName);
-       }
-
-       @Override
-       public int getInt(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getInt(parameterName);
-       }
-
-       @Override
-       public long getLong(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getLong(parameterName);
-       }
-
-       @Override
-       public float getFloat(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getFloat(parameterName);
-       }
-
-       @Override
-       public double getDouble(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getDouble(parameterName);
-       }
-
-       @Override
-       public byte[] getBytes(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getBytes(parameterName);
-       }
-
-       @Override
-       public Date getDate(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getDate(parameterName);
-       }
-
-       @Override
-       public Time getTime(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getTime(parameterName);
-       }
-
-       @Override
-       public Timestamp getTimestamp(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getTimestamp(parameterName);
-       }
-
-       @Override
-       public Object getObject(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getObject(parameterName);
-       }
-
-       @Override
-       public BigDecimal getBigDecimal(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getBigDecimal(parameterName);
-       }
-
-       @Override
-       public Object getObject(String parameterName, Map<String, Class<?>> map) throws SQLException {
-               return ((CallableStatement)stmt).getObject(parameterName, map);
-       }
-
-       @Override
-       public Ref getRef(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getRef(parameterName);
-       }
-
-       @Override
-       public Blob getBlob(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getBlob(parameterName);
-       }
-
-       @Override
-       public Clob getClob(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getClob(parameterName);
-       }
-
-       @Override
-       public Array getArray(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getArray(parameterName);
-       }
-
-       @Override
-       public Date getDate(String parameterName, Calendar cal) throws SQLException {
-               return ((CallableStatement)stmt).getDate(parameterName, cal);
-       }
-
-       @Override
-       public Time getTime(String parameterName, Calendar cal) throws SQLException {
-               return ((CallableStatement)stmt).getTime(parameterName, cal);
-       }
-
-       @Override
-       public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
-               return ((CallableStatement)stmt).getTimestamp(parameterName, cal);
-       }
-
-       @Override
-       public URL getURL(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getURL(parameterName);
-       }
-
-       @Override
-       public RowId getRowId(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getRowId(parameterIndex);
-       }
-
-       @Override
-       public RowId getRowId(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getRowId(parameterName);
-       }
-
-       @Override
-       public void setRowId(String parameterName, RowId x) throws SQLException {
-               ((CallableStatement)stmt).setRowId(parameterName, x);
-       }
-
-       @Override
-       public void setNString(String parameterName, String value) throws SQLException {
-               ((CallableStatement)stmt).setNString(parameterName, value);
-       }
-
-       @Override
-       public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException {
-               ((CallableStatement)stmt).setNCharacterStream(parameterName, value, length);
-       }
-
-       @Override
-       public void setNClob(String parameterName, NClob value) throws SQLException {
-               ((CallableStatement)stmt).setNClob(parameterName, value);
-       }
-
-       @Override
-       public void setClob(String parameterName, Reader reader, long length) throws SQLException {
-               ((CallableStatement)stmt).setClob(parameterName, reader, length);
-       }
-
-       @Override
-       public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException {
-               ((CallableStatement)stmt).setBlob(parameterName, inputStream, length);
-       }
-
-       @Override
-       public void setNClob(String parameterName, Reader reader, long length) throws SQLException {
-               ((CallableStatement)stmt).setNClob(parameterName, reader, length);
-       }
-
-       @Override
-       public NClob getNClob(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getNClob(parameterIndex);
-       }
-
-       @Override
-       public NClob getNClob(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getNClob(parameterName);
-       }
-
-       @Override
-       public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
-               ((CallableStatement)stmt).setSQLXML(parameterName, xmlObject);
-       }
-
-       @Override
-       public SQLXML getSQLXML(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getSQLXML(parameterIndex);
-       }
-
-       @Override
-       public SQLXML getSQLXML(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getSQLXML(parameterName);
-       }
-
-       @Override
-       public String getNString(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getNString(parameterIndex);
-       }
-
-       @Override
-       public String getNString(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getNString(parameterName);
-       }
-
-       @Override
-       public Reader getNCharacterStream(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getNCharacterStream(parameterIndex);
-       }
-
-       @Override
-       public Reader getNCharacterStream(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getNCharacterStream(parameterName);
-       }
-
-       @Override
-       public Reader getCharacterStream(int parameterIndex) throws SQLException {
-               return ((CallableStatement)stmt).getCharacterStream(parameterIndex);
-       }
-
-       @Override
-       public Reader getCharacterStream(String parameterName) throws SQLException {
-               return ((CallableStatement)stmt).getCharacterStream(parameterName);
-       }
-
-       @Override
-       public void setBlob(String parameterName, Blob x) throws SQLException {
-               ((CallableStatement)stmt).setBlob(parameterName, x);
-       }
-
-       @Override
-       public void setClob(String parameterName, Clob x) throws SQLException {
-               ((CallableStatement)stmt).setClob(parameterName, x);
-       }
-
-       @Override
-       public void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException {
-               ((CallableStatement)stmt).setAsciiStream(parameterName, x, length);
-       }
-
-       @Override
-       public void setBinaryStream(String parameterName, InputStream x, long length) throws SQLException {
-               ((CallableStatement)stmt).setBinaryStream(parameterName, x, length);
-       }
-
-       @Override
-       public void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException {
-               ((CallableStatement)stmt).setCharacterStream(parameterName, reader, length);
-       }
-
-       @Override
-       public void setAsciiStream(String parameterName, InputStream x) throws SQLException {
-               ((CallableStatement)stmt).setAsciiStream(parameterName, x);
-       }
-
-       @Override
-       public void setBinaryStream(String parameterName, InputStream x) throws SQLException {
-               ((CallableStatement)stmt).setBinaryStream(parameterName, x);
-       }
-
-       @Override
-       public void setCharacterStream(String parameterName, Reader reader) throws SQLException {
-               ((CallableStatement)stmt).setCharacterStream(parameterName, reader);
-       }
-
-       @Override
-       public void setNCharacterStream(String parameterName, Reader value) throws SQLException {
-               ((CallableStatement)stmt).setNCharacterStream(parameterName, value);
-       }
-
-       @Override
-       public void setClob(String parameterName, Reader reader) throws SQLException {
-               ((CallableStatement)stmt).setClob(parameterName, reader);
-       }
-
-       @Override
-       public void setBlob(String parameterName, InputStream inputStream) throws SQLException {
-               ((CallableStatement)stmt).setBlob(parameterName, inputStream);
-       }
-
-       @Override
-       public void setNClob(String parameterName, Reader reader) throws SQLException {
-               ((CallableStatement)stmt).setNClob(parameterName, reader);
-       }
-
-       @Override
-       public <T> T getObject(int parameterIndex, Class<T> type) throws SQLException {
-               return ((CallableStatement)stmt).getObject(parameterIndex, type);
-       }
-
-       @Override
-       public <T> T getObject(String parameterName, Class<T> type) throws SQLException {
-               return ((CallableStatement)stmt).getObject(parameterName, type);
-       }
-
-       private void synchronizeTables(String sql) {
-               if (sql == null || sql.trim().toLowerCase().startsWith("create")) {
-                       if (mConn != null) {
-                               try {
-                                       mConn.synchronizeTables();
-                               } catch (QueryException e) {
-                                       
-                                       e.printStackTrace();
-                               }
-                       }
-               }
-       }
-}
index 1c42865..fea329d 100644 (file)
@@ -20,6 +20,7 @@
 package org.onap.music.mdbc.examples;\r
 \r
 import java.sql.*;\r
+import java.util.Scanner;\r
 import org.apache.calcite.avatica.remote.Driver;\r
 \r
 public class MdbcTestClient {\r
@@ -107,9 +108,11 @@ public class MdbcTestClient {
 \r
         final String insertSQL = "INSERT INTO Persons VALUES (1, 'Martinez', 'Juan', 'KACB', 'ATLANTA');";\r
         final String insertSQL1 = "DELETE FROM Persons WHERE PersonID=2;";\r
-        final String insertSQL2 = "INSERT INTO Persons2 VALUES (2, 'Smith', 'JOHN', 'GNOC', 'BEDMINSTER');";\r
+        final String insertSQL2 = "INSERT INTO Persons VALUES (2, 'Smith', 'JOHN', 'GNOC', 'BEDMINSTER');";\r
         final String insertSQL3 = "UPDATE Persons SET FirstName='JOSH' WHERE LastName='Smith';";\r
         final String insertSQL4 = "UPDATE Persons SET FirstName='JOHN' WHERE LastName='Smith';";\r
+        \r
+        final String selectSQL1 = "SELECT * FROM Persons;";\r
 \r
         Statement insertStmt;\r
         try {\r
@@ -120,17 +123,31 @@ public class MdbcTestClient {
         }\r
 \r
         try {\r
-            execute = insertStmt.execute(insertSQL);\r
+            //execute = insertStmt.execute(insertSQL);\r
             //execute = insertStmt.execute(insertSQL1);\r
-            execute = insertStmt.execute(insertSQL2);\r
+            //execute = insertStmt.execute(insertSQL2);\r
             //execute = insertStmt.execute(insertSQL3);\r
             //execute = insertStmt.execute(insertSQL4);\r
+            \r
+            ///*\r
+            ResultSet rs = insertStmt.executeQuery(selectSQL1);\r
+            while (rs.next()) {\r
+                System.out.printf("%d, %s, %s\n", rs.getInt("PersonID"), rs.getString("FirstName"), rs.getString("LastName"));\r
+            }\r
+            //pause for user input\r
+            Scanner scanner = new Scanner(System.in);\r
+            System.out.println("Please hit <Enter> to complete the transaction and continue");\r
+            String line = scanner.nextLine();\r
+            scanner.close();\r
+            //*/\r
 \r
         } catch (SQLException e) {\r
             e.printStackTrace();\r
             return;\r
         }\r
 \r
+        \r
+        \r
         try {\r
             connection.commit();\r
         } catch (SQLException e) {\r
index e8b400b..66c7c3e 100644 (file)
@@ -23,11 +23,12 @@ package org.onap.music.mdbc.mixins;
 import java.util.List;
 import java.util.UUID;
 import org.onap.music.mdbc.Range;
+import org.onap.music.mdbc.query.SQLOperationType;
 
 public class LockRequest {
-    private final String table;
     private final UUID id;
     private final List<Range> toLockRanges;
+    private SQLOperationType lockType;
     private int numOfAttempts;
 
     /**
@@ -36,10 +37,24 @@ public class LockRequest {
      * @param id
      * @param toLockRanges
      */
-    public LockRequest(String table, UUID id, List<Range> toLockRanges) {
-        this.table = table;
+    public LockRequest(UUID id, List<Range> toLockRanges) {
         this.id = id;
         this.toLockRanges = toLockRanges;
+        lockType = SQLOperationType.WRITE;
+        numOfAttempts = 1;
+    }
+    
+    /**
+     * 
+     * @param table
+     * @param id
+     * @param toLockRanges
+     * @param lockType
+     */
+    public LockRequest(UUID id, List<Range> toLockRanges, SQLOperationType lockType) {
+        this.id = id;
+        this.toLockRanges = toLockRanges;
+        this.lockType = lockType;
         numOfAttempts = 1;
     }
 
@@ -50,10 +65,6 @@ public class LockRequest {
     public List<Range> getToLockRanges() {
         return toLockRanges;
     }
-
-    public String getTable() {
-        return table;
-    }
     
     /**
      * Number of times you've requested this lock
@@ -66,4 +77,8 @@ public class LockRequest {
     public void incrementAttempts() {
         numOfAttempts++;        
     }
+    
+    public SQLOperationType getLockType() {
+        return lockType;
+    }
 }
\ No newline at end of file
index 5a322f3..d934473 100644 (file)
@@ -61,6 +61,7 @@ import org.onap.music.mdbc.StateManager;
 import org.onap.music.mdbc.TableInfo;
 import org.onap.music.mdbc.ownership.Dag;
 import org.onap.music.mdbc.ownership.DagNode;
+import org.onap.music.mdbc.query.SQLOperationType;
 import org.onap.music.mdbc.tables.MriReference;
 import org.onap.music.mdbc.tables.MusicRangeInformationRow;
 import org.onap.music.mdbc.tables.MusicTxDigestId;
@@ -107,7 +108,7 @@ public class MusicMixin implements MusicInterface {
     /** The default property value to use for the Cassandra IP address. */
     public static final String DEFAULT_MUSIC_ADDRESS  = "localhost";
     /** The default property value to use for the Cassandra replication factor. */
-    public static final int    DEFAULT_MUSIC_RFACTOR  = 3;
+    public static final int    DEFAULT_MUSIC_RFACTOR  = 1;
     /** The default property value to use for the MDBC timeout */
     public static final long DEFAULT_TIMEOUT = 5*60*60*1000;//default of 5 hours
     /** The default primary string column, if none is provided. */
@@ -1198,7 +1199,7 @@ public class MusicMixin implements MusicInterface {
                          Map<UUID, LockResult> alreadyHeldLocks)
         throws MDBCServiceException{
         List<Range> newRanges = new ArrayList<>();
-        String newFullyQualifiedKey = music_ns + "." + request.getTable() + "." + pending.getKey().toString();
+        String newFullyQualifiedKey = music_ns + "." + musicRangeInformationTableName + "." + pending.getKey().toString();
         String newLockId;
         boolean success;
         if (currentLockRef.containsKey(pending.getKey())) {
@@ -2074,8 +2075,9 @@ public class MusicMixin implements MusicInterface {
 
     @Override
     public LockResult requestLock(LockRequest request) throws MDBCServiceException{
-        String fullyQualifiedKey= music_ns+"."+ request.getTable()+"."+request.getId();
-        String lockId = MusicCore.createLockReference(fullyQualifiedKey);
+        String fullyQualifiedKey= music_ns+"."+ musicRangeInformationTableName + "." + request.getId();
+        boolean isWrite = (request.getLockType()==SQLOperationType.WRITE);
+        String lockId = MusicCore.createLockReference(fullyQualifiedKey, isWrite);
         ReturnType lockReturn = acquireLock(fullyQualifiedKey,lockId);
         if(lockReturn.getResult() == ResultType.FAILURE) {
             //\TODO Improve the exponential backoff
@@ -2090,6 +2092,14 @@ public class MusicMixin implements MusicInterface {
         return new LockResult(true, request.getId(),lockId,true,null);
     }
 
+    /**
+     *  fixes the DAG in case the previous owner failed while trying to own the row
+     * @param latestDag
+     * @param rows
+     * @param ranges
+     * @param locks
+     * @throws MDBCServiceException
+     */
     private void recoverFromFailureAndUpdateDag(Dag latestDag,List<MusicRangeInformationRow> rows,List<Range> ranges,
                                                 Map<UUID,LockResult> locks) throws MDBCServiceException{
         Pair<List<Range>,Set<DagNode>> rangesAndDependents = latestDag.getIncompleteRangesAndDependents();
index 110cc80..c7a2b5b 100644 (file)
@@ -37,6 +37,7 @@ import org.onap.music.mdbc.mixins.LockResult;
 import org.onap.music.mdbc.mixins.MusicInterface;
 import org.onap.music.mdbc.mixins.MusicInterface.OwnershipReturn;
 import org.onap.music.mdbc.mixins.MusicMixin;
+import org.onap.music.mdbc.query.SQLOperationType;
 import org.onap.music.mdbc.tables.MriReference;
 import org.onap.music.mdbc.tables.MusicRangeInformationRow;
 import org.onap.music.mdbc.tables.MusicTxDigestId;
@@ -278,7 +279,7 @@ public class OwnershipAndCheckpoint{
      * @throws MDBCServiceException
      */
     public OwnershipReturn own(MusicInterface mi, List<Range> ranges,
-            DatabasePartition currPartition, UUID opId) throws MDBCServiceException {
+            DatabasePartition currPartition, UUID opId, SQLOperationType lockType) throws MDBCServiceException {
         
         if (ranges == null || ranges.isEmpty()) {
               return null;
@@ -299,7 +300,7 @@ public class OwnershipAndCheckpoint{
         while ( (toOwn.isDifferent(currentlyOwn) || !currentlyOwn.isOwned() ) &&
                 !timeout(opId)
             ) {
-            takeOwnershipOfDag(mi, currPartition, opId, newLocks, toOwn);
+            takeOwnershipOfDag(mi, currPartition, opId, newLocks, toOwn, lockType);
             currentlyOwn=toOwn;
             //TODO instead of comparing dags, compare rows
             rangesToOwnRows = extractRowsForRange(mi, rangesToOwn, false);
@@ -325,24 +326,25 @@ public class OwnershipAndCheckpoint{
      * @param opId
      * @param newLocks
      * @param toOwn
+     * @param lockType 
      * @throws MDBCServiceException
      */
     private void takeOwnershipOfDag(MusicInterface mi, DatabasePartition partition, UUID opId,
-            Map<UUID, LockResult> newLocks, Dag toOwn) throws MDBCServiceException {
+            Map<UUID, LockResult> newLocks, Dag toOwn, SQLOperationType lockType) throws MDBCServiceException {
         
         while(toOwn.hasNextToOwn()){
             DagNode node = toOwn.nextToOwn();
             MusicRangeInformationRow row = node.getRow();
-            UUID uuid = row.getPartitionIndex();
-            if (partition.isLocked() && partition.getMRIIndex().equals(uuid) ) {
+            UUID uuidToOwn = row.getPartitionIndex();
+            if (partition.isLocked() && partition.getMRIIndex().equals(uuidToOwn) ) {
                 toOwn.setOwn(node);
-                newLocks.put(uuid, new LockResult(true, uuid, partition.getLockId(),
+                newLocks.put(uuidToOwn, new LockResult(true, uuidToOwn, partition.getLockId(),
                         false, partition.getSnapshot()));
-            } else if ( newLocks.containsKey(uuid) || !row.getIsLatest() ) {
+            } else if ( newLocks.containsKey(uuidToOwn) || !row.getIsLatest() ) {
                 toOwn.setOwn(node);
             } else {
-                LockRequest request = new LockRequest(MusicMixin.musicRangeInformationTableName,uuid,
-                        new ArrayList(node.getRangeSet()));
+                LockRequest request = new LockRequest(uuidToOwn,
+                        new ArrayList<>(node.getRangeSet()), lockType);
                 LockResult result = null;
                 boolean owned = false;
                 while(!owned && !timeout(opId)){
@@ -366,7 +368,7 @@ public class OwnershipAndCheckpoint{
                 }
                 if(owned){
                     toOwn.setOwn(node);
-                    newLocks.put(uuid,result);
+                    newLocks.put(uuidToOwn,result);
                 }
                 else{
                     break;
index c8d284e..e1dcc81 100644 (file)
@@ -62,6 +62,8 @@ import org.onap.music.mdbc.Range;
 
 import org.onap.music.mdbc.StateManager;
 import org.onap.music.mdbc.proto.ProtoDigest.Digest.CompleteDigest;
+import org.onap.music.mdbc.query.SQLOperation;
+import org.onap.music.mdbc.query.SQLOperationType;
 import org.onap.music.mdbc.tables.MusicRangeInformationRow;
 import org.onap.music.mdbc.tables.MusicTxDigestId;
 import org.onap.music.mdbc.tables.StagingTable;
@@ -130,7 +132,8 @@ public class MusicMixinTest {
 
         DatabasePartition currentPartition = new DatabasePartition(MDBCUtils.generateTimebasedUniqueKey());
         try {
-            mixin.getStateManager().getOwnAndCheck().own(mixin,ranges,currentPartition, MDBCUtils.generateTimebasedUniqueKey());
+            mixin.getStateManager().getOwnAndCheck().own(mixin,ranges,currentPartition,
+                    MDBCUtils.generateTimebasedUniqueKey(), SQLOperationType.WRITE);
         } catch (MDBCServiceException e) {
             fail("failure when running own function");
         }
@@ -186,7 +189,8 @@ public class MusicMixinTest {
         DatabasePartition currentPartition = new DatabasePartition(MDBCUtils.generateTimebasedUniqueKey());
         MusicInterface.OwnershipReturn own = null;
         try {
-            own = mixin.getStateManager().getOwnAndCheck().own(mixin,range123, currentPartition, MDBCUtils.generateTimebasedUniqueKey());
+            own = mixin.getStateManager().getOwnAndCheck().own(mixin,range123, currentPartition,
+                    MDBCUtils.generateTimebasedUniqueKey(), SQLOperationType.WRITE);
         } catch (MDBCServiceException e) {
             fail("failure when running own function");
         }
@@ -231,7 +235,8 @@ public class MusicMixinTest {
         MusicRangeInformationRow node3Row = mixin.getMusicRangeInformation(db3.getMRIIndex());
         assertFalse(node3Row.getIsLatest());
     }
-
+    
+    
     @Test
     public void relinquish() {
     }
@@ -18,7 +18,7 @@
  * ============LICENSE_END======================================================
  */
 
-package org.onap.music.mdbc;
+package org.onap.music.mdbc.mixins;
 
 import java.util.Properties;
 import org.junit.*;
@@ -26,7 +26,7 @@ import org.junit.*;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
-
+import org.onap.music.mdbc.MdbcTestUtils;
 import org.onap.music.mdbc.MdbcTestUtils.DBType;
 import org.onap.music.mdbc.mixins.MySQLMixin;
 
index f2fbd1f..2435762 100644 (file)
@@ -51,7 +51,9 @@ import org.onap.music.mdbc.StateManager;
 import org.onap.music.mdbc.MdbcTestUtils;
 import org.onap.music.mdbc.TestUtils;
 import org.onap.music.mdbc.mixins.LockResult;
+import org.onap.music.mdbc.mixins.MusicInterface;
 import org.onap.music.mdbc.mixins.MusicInterface.OwnershipReturn;
+import org.onap.music.mdbc.query.SQLOperationType;
 import org.onap.music.mdbc.mixins.MusicMixin;
 import org.onap.music.mdbc.mixins.MySQLMixin;
 import org.onap.music.mdbc.tables.MusicRangeInformationRow;
@@ -175,7 +177,7 @@ public class OwnershipAndCheckpointTest {
 
         OwnershipReturn own=null;
         try {
-            own = ownAndCheck.own(musicMixin, ranges, currentPartition, ownOpId);
+            own = ownAndCheck.own(musicMixin, ranges, currentPartition, ownOpId, SQLOperationType.WRITE);
         } catch (MDBCServiceException e) {
             fail("failure when running own function");
         }
@@ -251,6 +253,32 @@ public class OwnershipAndCheckpointTest {
 
         checkData();
     }
+
+    
+    @Test
+    public void readOwn() throws Exception {
+        Range range = new Range("TABLE1");
+        MusicInterface mi = MdbcTestUtils.getMusicMixin();
+        List<Range> ranges = new ArrayList<>();
+        ranges.add(range);
+        final DatabasePartition partition = TestUtils.createBasicRow(range, mi, MdbcTestUtils.getServerName());
+        TestUtils.unlockRow(MdbcTestUtils.getKeyspace(), MdbcTestUtils.getMriTableName(), partition);
+
+        DatabasePartition currentPartition = new DatabasePartition(MDBCUtils.generateTimebasedUniqueKey());
+        MusicInterface.OwnershipReturn own1, own2;
+        try {
+            own1 = ownAndCheck.own(mi, ranges, currentPartition,
+                    MDBCUtils.generateTimebasedUniqueKey(), SQLOperationType.READ);
+            // acquire the table again, should be allowed since they're both reads
+            own2 = ownAndCheck.own(mi, ranges, currentPartition,
+                    MDBCUtils.generateTimebasedUniqueKey(), SQLOperationType.READ);
+        } catch (MDBCServiceException e) {
+            fail("failure when running own function");
+            return;
+        }
+
+        assertEquals(own1.getRangeId(), own2.getRangeId());
+    }
     
     private void cleanAlreadyApplied(OwnershipAndCheckpoint ownAndCheck) {
         ownAndCheck.getAlreadyApplied().clear();