| /* |
| * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0, which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * This Source Code may also be made available under the following Secondary |
| * Licenses when the conditions for such availability set forth in the |
| * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, |
| * version 2 with the GNU Classpath Exception, which is available at |
| * https://www.gnu.org/software/classpath/license.html. |
| * |
| * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| */ |
| |
| package com.sun.gjc.spi.base; |
| |
| import java.util.Arrays; |
| |
| /** |
| * |
| * @author Shalini M |
| */ |
| public class CacheObjectKey { |
| public static final String CALLABLE_STATEMENT = "CS"; |
| public static final String PREPARED_STATEMENT = "PS"; |
| |
| protected String sql; |
| protected String statementType; |
| protected int resultSetType; |
| protected int resultSetConcurrency; |
| protected int resultSetHoldability; |
| protected int autoGeneratedKeys; |
| protected int[] columnIndexes; |
| protected String[] columnNames; |
| |
| /** |
| * Get the value of columnNames |
| * |
| * @return the value of columnNames |
| */ |
| public String[] getColumnNames() { |
| return columnNames; |
| } |
| |
| /** |
| * Set the value of columnNames |
| * |
| * @param columnNames new value of columnNames |
| */ |
| public void setColumnNames(String[] columnNames) { |
| this.columnNames = columnNames; |
| } |
| |
| /** |
| * Get the value of columnIndexes |
| * |
| * @return the value of columnIndexes |
| */ |
| public int[] getColumnIndexes() { |
| return columnIndexes; |
| } |
| |
| /** |
| * Set the value of columnIndexes |
| * |
| * @param columnIndexes new value of columnIndexes |
| */ |
| public void setColumnIndexes(int[] columnIndexes) { |
| this.columnIndexes = columnIndexes; |
| } |
| |
| public CacheObjectKey(String sql, String statementType, int resultSetType, int resultSetConcurrency) { |
| this.sql = sql; |
| this.statementType = statementType; |
| this.resultSetType = resultSetType; |
| this.resultSetConcurrency = resultSetConcurrency; |
| } |
| |
| public CacheObjectKey(String sql, String statementType, int resultSetType, int resultSetConcurrency, |
| int resultSetHoldability) { |
| this.sql = sql; |
| this.statementType = statementType; |
| this.resultSetType = resultSetType; |
| this.resultSetConcurrency = resultSetConcurrency; |
| this.resultSetHoldability = resultSetHoldability; |
| } |
| |
| public CacheObjectKey(String sql, String statementType, int[] columnIndexes) { |
| this.sql = sql; |
| this.statementType = statementType; |
| this.columnIndexes = columnIndexes; |
| } |
| |
| public CacheObjectKey(String sql, String statementType, String[] columnNames) { |
| this.sql = sql; |
| this.statementType = statementType; |
| this.columnNames = columnNames; |
| } |
| |
| public CacheObjectKey(String sql, String statementType, int autoGeneratedKeys) { |
| this.sql = sql; |
| this.statementType = statementType; |
| this.autoGeneratedKeys = autoGeneratedKeys; |
| } |
| |
| public int getAutoGeneratedKeys() { |
| return autoGeneratedKeys; |
| } |
| |
| public void setAutoGeneratedKeys(int autoGeneratedKeys) { |
| this.autoGeneratedKeys = autoGeneratedKeys; |
| } |
| |
| /** |
| * Get the value of resultSetConcurrency |
| * |
| * @return the value of resultSetConcurrency |
| */ |
| public int getResultSetConcurrency() { |
| return resultSetConcurrency; |
| } |
| |
| /** |
| * Set the value of resultSetConcurrency |
| * |
| * @param resultSetConcurrency new value of resultSetConcurrency |
| */ |
| public void setResultSetConcurrency(int resultSetConcurrency) { |
| this.resultSetConcurrency = resultSetConcurrency; |
| } |
| |
| /** |
| * Get the value of resultSetType |
| * |
| * @return the value of resultSetType |
| */ |
| public int getResultSetType() { |
| return resultSetType; |
| } |
| |
| /** |
| * Set the value of resultSetType |
| * |
| * @param resultSetType new value of resultSetType |
| */ |
| public void setResultSetType(int resultSetType) { |
| this.resultSetType = resultSetType; |
| } |
| |
| /** |
| * Get the value of resultSetHoldability |
| * |
| * @return the value of resultSetHoldability |
| */ |
| public int getResultSetHoldability() { |
| return resultSetHoldability; |
| } |
| |
| /** |
| * Set the value of resultSetHoldability |
| * |
| * @param resultSetHoldability new value of resultSetHoldability |
| */ |
| public void setResultSetHoldability(int resultSetHoldability) { |
| this.resultSetHoldability = resultSetHoldability; |
| } |
| |
| public CacheObjectKey() { |
| } |
| |
| /** |
| * Get the value of statementType |
| * |
| * @return the value of statementType |
| */ |
| public String getStatementType() { |
| return statementType; |
| } |
| |
| /** |
| * Set the value of statementType |
| * |
| * @param statementType new value of statementType |
| */ |
| public void setStatementType(String statementType) { |
| this.statementType = statementType; |
| } |
| |
| /** |
| * Get the value of sql |
| * |
| * @return the value of sql |
| */ |
| public String getSql() { |
| return sql; |
| } |
| |
| /** |
| * Set the value of sql |
| * |
| * @param sql new value of sql |
| */ |
| public void setSql(String sql) { |
| this.sql = sql; |
| } |
| |
| /** |
| * Check for the equality of the CacheObjectKey with the object passed by 1. |
| * comparing the sql string values 2. comparing the statement type values 3. |
| * comapring the getClass() values |
| * |
| * @param obj obj which is to be checked against this object |
| * @return boolean |
| */ |
| @Override |
| public boolean equals(Object obj) { |
| if (obj == null) { |
| return false; |
| } |
| if (getClass() != obj.getClass()) { |
| return false; |
| } |
| final CacheObjectKey other = (CacheObjectKey) obj; |
| if (this.sql == null || other.sql == null || !this.sql.equals(other.sql)) { |
| return false; |
| } |
| if (this.statementType == null || other.statementType == null |
| || !this.statementType.equals(other.statementType)) { |
| return false; |
| } |
| if (this.resultSetType != other.resultSetType) { |
| return false; |
| } |
| if (this.resultSetConcurrency != other.resultSetConcurrency) { |
| return false; |
| } |
| if (this.resultSetHoldability != other.resultSetHoldability) { |
| return false; |
| } |
| if (CacheObjectKey.PREPARED_STATEMENT.equals(other.statementType)) { |
| if (this.autoGeneratedKeys != other.autoGeneratedKeys) { |
| return false; |
| } |
| // Iterate through the columnNames/columnIndexes to see if equal |
| if (this.columnIndexes != null && other.columnIndexes != null) { |
| if (!Arrays.equals(this.columnIndexes, other.columnIndexes)) { |
| return false; |
| } |
| } |
| if (this.columnNames != null && other.columnNames != null) { |
| if (!Arrays.equals(this.columnNames, other.columnNames)) { |
| return false; |
| } |
| } |
| } |
| return true; |
| } |
| |
| /** |
| * Generate hashCode for this object using the sql and statementType fields |
| * |
| * @return has integer value |
| */ |
| @Override |
| public int hashCode() { |
| int hash = 7; |
| hash = 41 * hash + (this.sql != null ? this.sql.hashCode() : 0); |
| hash = 41 * hash + (this.statementType != null ? this.statementType.hashCode() : 0); |
| hash = 41 * hash + this.resultSetType; |
| hash = 41 * hash + this.resultSetConcurrency; |
| hash = 41 * hash + this.resultSetHoldability; |
| if (CacheObjectKey.PREPARED_STATEMENT.equals(this.statementType)) { |
| hash = 41 * hash + this.autoGeneratedKeys; |
| if (this.columnIndexes != null) { |
| for (int i : this.columnIndexes) { |
| hash = 41 * hash + ((Integer) i).hashCode(); |
| } |
| } |
| if (this.columnNames != null) { |
| for (String str : columnNames) { |
| hash = 41 * hash + str.hashCode(); |
| } |
| } |
| } |
| return hash; |
| } |
| } |