[Commits] Rev 411: Small refactoring : remove yet another unnecessary level of abstraction - MySQLQueryFactory. Use MySQLQuery directory in file:///H:/bzr/mariadb-java-client/

Vladislav Vaintroub wlad at montyprogram.com
Mon Feb 18 16:20:55 EET 2013


At file:///H:/bzr/mariadb-java-client/

------------------------------------------------------------
revno: 411
revision-id: wlad at montyprogram.com-20130218142040-5fxdqk654g1bhhx1
parent: wlad at montyprogram.com-20130214213233-c7afc117vtzn5g7b
committer: Vladislav Vaintroub <wlad at montyprogram.com>
branch nick: mariadb-java-client
timestamp: Mon 2013-02-18 15:20:40 +0100
message:
  Small refactoring : remove yet another unnecessary level of abstraction - MySQLQueryFactory. Use MySQLQuery directory
-------------- next part --------------
=== modified file 'src/main/java/org/mariadb/jdbc/Driver.java'
--- a/src/main/java/org/mariadb/jdbc/Driver.java	2013-01-12 18:27:29 +0000
+++ b/src/main/java/org/mariadb/jdbc/Driver.java	2013-02-18 14:20:40 +0000
@@ -51,7 +51,6 @@ package org.mariadb.jdbc;
 
 import org.mariadb.jdbc.internal.SQLExceptionMapper;
 import org.mariadb.jdbc.internal.common.QueryException;
-import org.mariadb.jdbc.internal.common.query.MySQLQueryFactory;
 import org.mariadb.jdbc.internal.mysql.MySQLProtocol;
 
 import java.sql.Connection;
@@ -110,7 +109,7 @@ public final class Driver implements jav
 
             MySQLProtocol protocol = new MySQLProtocol(jdbcUrl, userName,  password,  info);
 
-            return MySQLConnection.newConnection(protocol, new MySQLQueryFactory());
+            return MySQLConnection.newConnection(protocol);
         } catch (QueryException e) {
             SQLExceptionMapper.throwException(e, null, null);
             return null;

=== modified file 'src/main/java/org/mariadb/jdbc/MySQLConnection.java'
--- a/src/main/java/org/mariadb/jdbc/MySQLConnection.java	2013-02-07 22:13:02 +0000
+++ b/src/main/java/org/mariadb/jdbc/MySQLConnection.java	2013-02-18 14:20:40 +0000
@@ -52,7 +52,6 @@ package org.mariadb.jdbc;
 import org.mariadb.jdbc.internal.SQLExceptionMapper;
 import org.mariadb.jdbc.internal.common.*;
 import org.mariadb.jdbc.internal.common.packet.RawPacket;
-import org.mariadb.jdbc.internal.common.query.QueryFactory;
 import org.mariadb.jdbc.internal.mysql.MySQLProtocol;
 
 import java.sql.*;
@@ -76,10 +75,6 @@ public final class MySQLConnection
      * the properties for the client.
      */
     private final Properties clientInfoProperties;
-    /**
-     * a query factory.
-     */
-    private final QueryFactory queryFactory;
 
     private ParameterizedBatchHandlerFactory parameterizedBatchHandlerFactory;
 
@@ -95,20 +90,18 @@ public final class MySQLConnection
      * Creates a new connection with a given protocol and query factory.
      *
      * @param protocol     the protocol to use.
-     * @param queryFactory the query factory to use.
      */
-    private MySQLConnection( MySQLProtocol protocol, QueryFactory queryFactory) {
+    private MySQLConnection( MySQLProtocol protocol) {
         this.protocol = protocol;
         clientInfoProperties = new Properties();
-        this.queryFactory = queryFactory;
 
     }
     
     MySQLProtocol getProtocol() {
         return protocol;
     }
-    public static MySQLConnection newConnection(MySQLProtocol protocol, QueryFactory queryFactory) throws SQLException {
-        MySQLConnection connection = new MySQLConnection(protocol, queryFactory);
+    public static MySQLConnection newConnection(MySQLProtocol protocol) throws SQLException {
+        MySQLConnection connection = new MySQLConnection(protocol);
         
         boolean fastConnect =  protocol.getInfo().get("fastConnect") != null ;
         String sessionVariables = protocol.getInfo().getProperty("sessionVariables");
@@ -150,7 +143,7 @@ public final class MySQLConnection
      * @throws SQLException if we cannot create the statement.
      */
     public Statement createStatement() throws SQLException {
-        return new MySQLStatement(protocol, this, queryFactory);
+        return new MySQLStatement(this);
     }
 
     /**
@@ -167,7 +160,6 @@ public final class MySQLConnection
         return new MySQLPreparedStatement(protocol,
                 this,
                 sql,
-                queryFactory,
                 parameterizedBatchHandlerFactory.get(sql, protocol));
     }
 

=== modified file 'src/main/java/org/mariadb/jdbc/MySQLDataSource.java'
--- a/src/main/java/org/mariadb/jdbc/MySQLDataSource.java	2012-12-21 18:15:36 +0000
+++ b/src/main/java/org/mariadb/jdbc/MySQLDataSource.java	2013-02-18 14:20:40 +0000
@@ -52,7 +52,6 @@ package org.mariadb.jdbc;
 
 import org.mariadb.jdbc.internal.SQLExceptionMapper;
 import org.mariadb.jdbc.internal.common.QueryException;
-import org.mariadb.jdbc.internal.common.query.MySQLQueryFactory;
 import org.mariadb.jdbc.internal.mysql.MySQLProtocol;
 
 import javax.sql.*;
@@ -287,8 +286,7 @@ public class MySQLDataSource implements 
     public Connection getConnection() throws SQLException {
         createUrl();
         try {
-            return MySQLConnection.newConnection(new MySQLProtocol(url, username, password, info),
-                    new MySQLQueryFactory());
+            return MySQLConnection.newConnection(new MySQLProtocol(url, username, password, info));
         } catch (QueryException e) {
             SQLExceptionMapper.throwException(e, null, null);
             return null;
@@ -307,8 +305,7 @@ public class MySQLDataSource implements 
     public Connection getConnection(final String username, final String password) throws SQLException {
         createUrl();
         try {
-            return MySQLConnection.newConnection(new MySQLProtocol(url, username, password, new Properties()),
-                    new MySQLQueryFactory());
+            return MySQLConnection.newConnection(new MySQLProtocol(url, username, password, new Properties()));
         } catch (QueryException e) {
             SQLExceptionMapper.throwException(e, null, null);
             return null;

=== modified file 'src/main/java/org/mariadb/jdbc/MySQLPreparedStatement.java'
--- a/src/main/java/org/mariadb/jdbc/MySQLPreparedStatement.java	2013-02-12 21:29:01 +0000
+++ b/src/main/java/org/mariadb/jdbc/MySQLPreparedStatement.java	2013-02-18 14:20:40 +0000
@@ -53,8 +53,8 @@ import org.mariadb.jdbc.internal.common.
 import org.mariadb.jdbc.internal.common.QueryException;
 import org.mariadb.jdbc.internal.common.Utils;
 import org.mariadb.jdbc.internal.common.query.IllegalParameterException;
+import org.mariadb.jdbc.internal.common.query.MySQLParameterizedQuery;
 import org.mariadb.jdbc.internal.common.query.ParameterizedQuery;
-import org.mariadb.jdbc.internal.common.query.QueryFactory;
 import org.mariadb.jdbc.internal.common.query.parameters.*;
 import org.mariadb.jdbc.internal.mysql.MySQLProtocol;
 
@@ -78,16 +78,15 @@ public class MySQLPreparedStatement exte
     public MySQLPreparedStatement(final MySQLProtocol protocol,
                                   final MySQLConnection connection,
                                   final String query,
-                                  final QueryFactory queryFactory,
                                   final ParameterizedBatchHandler parameterizedBatchHandler) throws SQLException {
-        super(protocol, connection, queryFactory);
+        super(connection);
         useFractionalSeconds =
                 ((MySQLProtocol)protocol).getInfo().getProperty("useFractionalSeconds") != null;
 
         if(log.isLoggable(Level.FINEST)) {
             log.finest("Creating prepared statement for " + query);
         }
-        dQuery = queryFactory.createParameterizedQuery(Utils.nativeSQL(query, connection.noBackslashEscapes),
+        dQuery = new MySQLParameterizedQuery(Utils.nativeSQL(query, connection.noBackslashEscapes),
                 connection.noBackslashEscapes);
         this.parameterizedBatchHandler = parameterizedBatchHandler;
     }
@@ -185,10 +184,10 @@ public class MySQLPreparedStatement exte
      */
     public void addBatch() throws SQLException {
         parameterizedBatchHandler.addToBatch(dQuery);
-        dQuery = getQueryFactory().createParameterizedQuery(dQuery);
+        dQuery = new MySQLParameterizedQuery(dQuery);
     }
     public void addBatch(final String sql) throws SQLException {
-        parameterizedBatchHandler.addToBatch(getQueryFactory().createParameterizedQuery(sql, connection.noBackslashEscapes));
+        parameterizedBatchHandler.addToBatch(new MySQLParameterizedQuery(sql, connection.noBackslashEscapes));
     }
     @Override
     public int[] executeBatch() throws SQLException {

=== modified file 'src/main/java/org/mariadb/jdbc/MySQLStatement.java'
--- a/src/main/java/org/mariadb/jdbc/MySQLStatement.java	2013-02-13 16:28:01 +0000
+++ b/src/main/java/org/mariadb/jdbc/MySQLStatement.java	2013-02-18 14:20:40 +0000
@@ -53,8 +53,8 @@ import org.mariadb.jdbc.internal.SQLExce
 import org.mariadb.jdbc.internal.common.Protocol;
 import org.mariadb.jdbc.internal.common.QueryException;
 import org.mariadb.jdbc.internal.common.Utils;
+import org.mariadb.jdbc.internal.common.query.MySQLQuery;
 import org.mariadb.jdbc.internal.common.query.Query;
-import org.mariadb.jdbc.internal.common.query.QueryFactory;
 import org.mariadb.jdbc.internal.common.queryresults.ModifyQueryResult;
 import org.mariadb.jdbc.internal.common.queryresults.QueryResult;
 import org.mariadb.jdbc.internal.common.queryresults.ResultSetType;
@@ -88,10 +88,6 @@ public class MySQLStatement implements S
      * are warnings cleared?
      */
     private boolean warningsCleared;
-    /**
-     * creates queries.
-     */
-    private final QueryFactory queryFactory;
 
 
     private int queryTimeout;
@@ -112,18 +108,12 @@ public class MySQLStatement implements S
 
     /**
      * Creates a new Statement.
-     *
-     * @param protocol     the protocol to use.
      * @param connection   the connection to return in getConnection.
-     * @param queryFactory the query factory to produce internal queries.
      */
 
-    public MySQLStatement(final MySQLProtocol protocol,
-                         final MySQLConnection connection,
-                         final QueryFactory queryFactory) {
-        this.protocol = protocol;
+    public MySQLStatement(MySQLConnection connection) {
+        this.protocol = connection.getProtocol();
         this.connection = connection;
-        this.queryFactory = queryFactory;
         this.escapeProcessing = true;
         cachedResultSets = new LinkedList<Object>();
 
@@ -333,7 +323,7 @@ public class MySQLStatement implements S
         if (escapeProcessing) {
             queryString = Utils.nativeSQL(queryString,connection.noBackslashEscapes);
         }
-        return queryFactory.createQuery(queryString);
+        return new MySQLQuery(queryString);
     }
 
 
@@ -371,9 +361,6 @@ public class MySQLStatement implements S
         return executeQuery(stringToQuery(queryString));
     }
 
-    public QueryFactory getQueryFactory() {
-        return queryFactory;
-    }
 
     /**
      * Releases this <code>Statement</code> object's database and JDBC resources immediately instead of waiting for this
@@ -1075,10 +1062,10 @@ public class MySQLStatement implements S
      * @since 1.2
      */
     public void addBatch(final String sql) throws SQLException {
-        this.protocol.addToBatch(queryFactory.createQuery(sql));
+        this.protocol.addToBatch(new MySQLQuery(sql));
     }
     public void addBatch(final byte[] sql) throws SQLException {
-        this.protocol.addToBatch(queryFactory.createQuery(sql));
+        this.protocol.addToBatch(new MySQLQuery(sql));
     }
 
     /**

=== removed file 'src/main/java/org/mariadb/jdbc/internal/common/query/MySQLQueryFactory.java'
--- a/src/main/java/org/mariadb/jdbc/internal/common/query/MySQLQueryFactory.java	2012-12-21 18:15:36 +0000
+++ b/src/main/java/org/mariadb/jdbc/internal/common/query/MySQLQueryFactory.java	1970-01-01 00:00:00 +0000
@@ -1,68 +0,0 @@
-/*
-MariaDB Client for Java
-
-Copyright (c) 2012 Monty Program Ab.
-
-This library is free software; you can redistribute it and/or modify it under
-the terms of the GNU Lesser General Public License as published by the Free
-Software Foundation; either version 2.1 of the License, or (at your option)
-any later version.
-
-This library is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
-for more details.
-
-You should have received a copy of the GNU Lesser General Public License along
-with this library; if not, write to Monty Program Ab info at montyprogram.com.
-
-This particular MariaDB Client for Java file is work
-derived from a Drizzle-JDBC. Drizzle-JDBC file which is covered by subject to
-the following copyright and notice provisions:
-
-Copyright (c) 2009-2011, Marcus Eriksson
-
-Redistribution and use in source and binary forms, with or without modification,
-are permitted provided that the following conditions are met:
-Redistributions of source code must retain the above copyright notice, this list
-of conditions and the following disclaimer.
-
-Redistributions in binary form must reproduce the above copyright notice, this
-list of conditions and the following disclaimer in the documentation and/or
-other materials provided with the distribution.
-
-Neither the name of the driver nor the names of its contributors may not be
-used to endorse or promote products derived from this software without specific
-prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS  AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
-OF SUCH DAMAGE.
-*/
-                         
-package org.mariadb.jdbc.internal.common.query;
-
-public class MySQLQueryFactory implements QueryFactory {
-    public Query createQuery(final String query) {
-        return new MySQLQuery(query);
-    }
-    
-    public MySQLQuery createQuery(byte[] query)
-    {
-        return new MySQLQuery(query);
-    }
-    public ParameterizedQuery createParameterizedQuery( String query, boolean noBackslashEscapes) {
-        return new MySQLParameterizedQuery(query, noBackslashEscapes);
-    }
-
-    public ParameterizedQuery createParameterizedQuery( ParameterizedQuery dQuery) {
-        return new MySQLParameterizedQuery(dQuery);
-    }
-}



More information about the commits mailing list