Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. 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. See accompanying
* LICENSE file.
*/
package com.pivotal.gemfirexd.thrift.server;
import java.nio.ByteBuffer;
import java.security.SecureRandom;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import com.gemstone.gemfire.internal.cache.locks.NonReentrantLock;
import com.gemstone.gemfire.internal.shared.ClientSharedUtils;
import com.gemstone.gnu.trove.TIntArrayList;
import com.pivotal.gemfirexd.internal.impl.jdbc.EmbedConnection;
import com.pivotal.gemfirexd.internal.impl.jdbc.EmbedStatement;
import com.pivotal.gemfirexd.internal.shared.common.reference.SQLState;
import com.pivotal.gemfirexd.thrift.OpenConnectionArgs;
import com.pivotal.gemfirexd.thrift.SecurityMechanism;
import com.pivotal.gemfirexd.thrift.StatementAttrs;
import com.pivotal.gemfirexd.thrift.gfxdConstants;
import com.pivotal.gemfirexd.thrift.common.ThriftExceptionUtil;
/**
* Holder for a connection on the server side for each open client connection.
*
* @author swale
* @since gfxd 1.1
*/
final class ConnectionHolder {
private final EmbedConnection conn;
private final int connId;
private final ByteBuffer token;
private final String clientHostName;
private final String clientID;
private final String userName;
private final boolean useStringForDecimal;
private EmbedStatement reusableStatement;
private final ArrayList activeStatements;
private final NonReentrantLock sync;
ConnectionHolder(final EmbedConnection conn, final OpenConnectionArgs args,
final int connId, final SecureRandom rnd) throws SQLException {
this.conn = conn;
this.connId = connId;
// generate a unique ID for the connection; this is a secure random string
// rather than the internal long connection ID to ensure security and is
// checked in every client-server RPC call if the client has so requested
if (args.getSecurity() == SecurityMechanism.PLAIN
|| args.getSecurity() == SecurityMechanism.DIFFIE_HELLMAN) {
int tokenSize = gfxdConstants.DEFAULT_SESSION_TOKEN_SIZE;
if (args.isSetTokenSize()) {
if (args.getTokenSize() < tokenSize) {
// don't accept small token sizes
throw ThriftExceptionUtil.newSQLException(
SQLState.NET_CONNECT_AUTH_FAILED, null,
"specified connection token size " + args.getTokenSize()
+ " smaller than minimum allowed of " + tokenSize);
}
else {
tokenSize = args.getTokenSize();
}
}
byte[] rndBytes = new byte[tokenSize];
rnd.nextBytes(rndBytes);
this.token = ByteBuffer.wrap(rndBytes);
}
else {
// no other security mechanism supported yet
throw ThriftExceptionUtil.newSQLException(
SQLState.NET_CONNECT_AUTH_FAILED, null,
"unsupported security mechanism " + args.getSecurity());
}
this.clientHostName = args.getClientHostName();
this.clientID = args.getClientID();
this.userName = args.getUserName();
this.useStringForDecimal = args.isSetUseStringForDecimal()
&& args.useStringForDecimal;
this.reusableStatement = (EmbedStatement)conn.createStatement();
this.activeStatements = new ArrayList(4);
this.sync = new NonReentrantLock(true);
}
final class StatementHolder {
private final Statement stmt;
private final StatementAttrs stmtAttrs;
private final int stmtId;
private final String sql;
private int singleCursorId;
private Object resultSets;
private TIntArrayList cursorIds;
private StatementHolder(Statement stmt, StatementAttrs attrs, int stmtId,
String sql) {
this.stmt = stmt;
this.stmtAttrs = attrs;
this.stmtId = stmtId;
this.sql = sql;
this.singleCursorId = gfxdConstants.INVALID_ID;
}
final ConnectionHolder getConnectionHolder() {
return ConnectionHolder.this;
}
final Statement getStatement() {
return this.stmt;
}
final int getStatementId() {
return this.stmtId;
}
final String getSQL() {
return this.sql;
}
final StatementAttrs getStatementAttrs() {
return this.stmtAttrs;
}
void addResultSet(ResultSet rs, int cursorId) {
final NonReentrantLock sync = ConnectionHolder.this.sync;
sync.lock();
try {
addResultSetNoLock(rs, cursorId);
} finally {
sync.unlock();
}
}
private void addResultSetNoLock(ResultSet rs, int cursorId) {
if (this.resultSets == null) {
this.resultSets = rs;
this.singleCursorId = cursorId;
}
else if (this.singleCursorId != gfxdConstants.INVALID_ID) {
assert this.resultSets instanceof ResultSet: "unexpected resultset "
+ this.resultSets;
ArrayList