All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pivotal.gemfirexd.internal.client.am.stmtcache.StatementKey Maven / Gradle / Ivy

The newest version!
/*

   Derby - Class com.pivotal.gemfirexd.internal.client.am.stmtcache.StatementKey

   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 com.pivotal.gemfirexd.internal.client.am.stmtcache;

import java.sql.ResultSet;
import java.sql.Statement;

import com.pivotal.gemfirexd.internal.shared.common.sanity.SanityManager;

/**
 * A key representing a java.sql.PreparedStatement or a
 * java.sql.CallableStatement.
 * 

* The key takes a number of statement related attributes into account, and is * used to insert and look up cached statement objects in the JDBC statement * cache. *

* Key instances are created by a statement key factory. * * @see StatementKeyFactory */ //@Immutable public class StatementKey { /** Tells if the key represents a CallableStatement. */ private final boolean isCallableStatement; /** The SQL query of the statement. */ private final String sql; /** The compilation schema for the statement. */ private final String schema; /** The result set type for the statement. */ private final int type; /** The result set concurrency for the statement. */ private final int concurrency; /** Result set holdability for the statement. */ private final int holdability; /** Tells if the associated statement returns auto-generated keys. */ private final int autogeneratedKeys; /** * Creates a statement key with all the common properties. * * @param isCallableStatement true is this is a key for a * java.sql.CallableStatement * @param sql SQL query string * @param schema compilation schema * @param rsType result set type * @param rsConcurrency result set concurrency * @param rsHoldability result set holdability * @param autogeneratedKeys if auto-generated keys are returned * * @throws IllegalArgumentException if {@code schema} is {@code null} */ StatementKey(boolean isCallableStatement, String sql, String schema, int rsType, int rsConcurrency, int rsHoldability, int autogeneratedKeys) { if (schema == null) { // Not localized (yet), because this should never reach the user. throw new IllegalArgumentException("schema is "); } this.isCallableStatement = isCallableStatement; this.sql = sql; this.schema = schema; this.type = rsType; this.concurrency = rsConcurrency; this.holdability = rsHoldability; this.autogeneratedKeys = autogeneratedKeys; // In sane builds, make sure valid JDBC values are passed. if (SanityManager.DEBUG_ASSERT) { SanityManager.ASSERT( rsType == ResultSet.TYPE_FORWARD_ONLY || rsType == ResultSet.TYPE_SCROLL_INSENSITIVE || rsType == ResultSet.TYPE_SCROLL_SENSITIVE, "Invalid result set type: " + rsType); SanityManager.ASSERT( rsConcurrency == ResultSet.CONCUR_READ_ONLY || rsConcurrency == ResultSet.CONCUR_UPDATABLE, "Invalid result set concurrency: " + rsConcurrency); SanityManager.ASSERT( rsHoldability == ResultSet.HOLD_CURSORS_OVER_COMMIT || rsHoldability == ResultSet.CLOSE_CURSORS_AT_COMMIT, "Invalid result set holdability: " + rsHoldability); SanityManager.ASSERT( autogeneratedKeys == Statement.NO_GENERATED_KEYS || autogeneratedKeys == Statement.RETURN_GENERATED_KEYS, "Invalid autogenerated key value: " + autogeneratedKeys); } } public boolean equals(Object obj) { if (!(obj instanceof StatementKey)) { return false; } final StatementKey other = (StatementKey)obj; if (this.holdability != other.holdability) { return false; } if (this.autogeneratedKeys != other.autogeneratedKeys) { return false; } if (this.isCallableStatement != other.isCallableStatement) { return false; } if (!this.schema.equals(other.schema)) { return false; } if (this.sql == null && other.sql != null) { return false; } if (!this.sql.equals(other.sql)) { return false; } if (this.type != other.type) { return false; } if (this.concurrency != other.concurrency) { return false; } return true; } public int hashCode() { int hash = 7; hash = 47 * hash + (this.isCallableStatement ? 1 : 0); hash = 47 * hash + (this.sql == null ? 3 : this.sql.hashCode()); hash = 47 * hash + this.schema.hashCode(); hash = 47 * hash + this.type; hash = 47 * hash + this.concurrency; hash = 47 * hash + this.holdability; hash = 47 * hash + this.autogeneratedKeys; return hash; } public String toString() { return "'" + sql + "' in '" + schema + "', rsh = " + holdability + ", rst = " + type + ", rsc = " + concurrency + ", autogenKeys = " + autogeneratedKeys + ", isCallableStatement = " + isCallableStatement; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy