@Override public void terminate() { remotes.remove(this.secretKey); closePortals(); this.preparedMap.clear(); try { if (this.connection != null) { if (!this.connection.getAutoCommit()) { this.connection.rollback(false); } this.connection.close(); } } catch (SQLException e) { //ignore } this.client.terminated(); }
/** * Retrieves the major version number of the underlying database. * @return intValue of database's minor version * @throws SQLException if a database access error occurs. */ public int getDatabaseMajorVersion() throws SQLException { return Integer.valueOf(driverConnection.getServerConnection().getServerVersion().split("[.]")[0]); //$NON-NLS-1$ }
/** * <p>Creates a Statement object that will produce ResultSet objects of the type * resultSetType and concurrency level resultSetConcurrency.</p> * @param intvalue indicating the ResultSet's type * @param intValue indicating the ResultSet's concurrency * @return Statement object. */ public StatementImpl createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { return createStatement(resultSetType, resultSetConcurrency, ResultSet.HOLD_CURSORS_OVER_COMMIT); }
@Override public void rollback(String txnId) throws SQLException { getConnection().rollback(); getConnection().setAutoCommit(true); } }
if (options != null) { if (options.isContinuous()) { if (!this.driverConnection.getServerConnection().supportsContinuous()) { throw new TeiidSQLException(JDBCPlugin.Util.getString("JDBC.continuous")); //$NON-NLS-1$ Properties p = this.getMMConnection().getPayload(); if (p == null) { p = new Properties(); this.getMMConnection().setPayload(p); this.getMMConnection().changeUser(value, this.getMMConnection().getPassword()); } else if (key.equalsIgnoreCase(TeiidURL.CONNECTION.PASSWORD)) { this.getMMConnection().setPassword(value); } else if (ExecutionProperties.NEWINSTANCE.equalsIgnoreCase(key)) { this.driverConnection.setExecutionProperty(key, value); this.getMMConnection().saveTransactionCharacteristics(); if (StringUtil.endsWithIgnoreCase(characteristic, "only")) { //$NON-NLS-1$ this.getMMConnection().setReadOnly(true); } else if (StringUtil.endsWithIgnoreCase(characteristic, "write")) { //$NON-NLS-1$ this.getMMConnection().setReadOnly(false); } else { int i = characteristic.indexOf("level"); //$NON-NLS-1$ this.getConnection().setAutoCommit(false); success = true; } finally { if (!success) {
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT, Statement.RETURN_GENERATED_KEYS); }
public void recycleConnection() { this.payload = null; try { //close all open statements this.closeStatements(); } catch (SQLException e) { logger.log(Level.WARNING, JDBCPlugin.Util.getString("MMXAConnection.rolling_back_error"), e); //$NON-NLS-1$ } try { //rollback if still in a transaction if (!this.getAutoCommit()) { logger.warning(JDBCPlugin.Util.getString("MMXAConnection.rolling_back")); //$NON-NLS-1$ if (this.getTransactionXid() == null) { this.rollback(false); } else { this.rollbackTransaction(getTransactionXid()); } } } catch (SQLException e) { logger.log(Level.WARNING, JDBCPlugin.Util.getString("MMXAConnection.rolling_back_error"), e); //$NON-NLS-1$ } }
private ResultsFuture<ResultsMessage> execute(final RequestMessage reqMsg, boolean synch) throws SQLException, TeiidSQLException { this.getConnection().beginLocalTxnIfNeeded(); this.currentRequestID = this.driverConnection.nextRequestID(); reqMsg.setExecutionPayload(this.getMMConnection().getPayload()); reqMsg.setFetchSize(this.fetchSize); reqMsg.setRowLimit(this.maxRows); reqMsg.setTransactionIsolation(this.driverConnection.getTransactionIsolation()); reqMsg.setSync(synch && useCallingThread()); if (queryTimeoutMS > 0 && (!synch || this.driverConnection.getServerConnection().isLocal())) { final Task c = cancellationTimer.add(cancelTask, queryTimeoutMS); compeletionListener = new ResultsFuture.CompletionListener<ResultsMessage>() {
if (show.equalsIgnoreCase("PLAN")) { //$NON-NLS-1$ List<ArrayList<Object>> records = new ArrayList<ArrayList<Object>>(1); PlanNode plan = driverConnection.getCurrentPlanDescription(); String connDebugLog = driverConnection.getDebugLog(); if (plan != null || connDebugLog != null) { ArrayList<Object> row = new ArrayList<Object>(3); Collection<Annotation> annos = driverConnection.getAnnotations(); for (Annotation annotation : annos) { ArrayList<Object> row = new ArrayList<Object>(4); for (String key : driverConnection.getExecutionProperties().stringPropertyNames()) { ArrayList<Object> row = new ArrayList<Object>(4); row.add(key); row.add(driverConnection.getExecutionProperties().get(key)); records.add(row); List<ArrayList<Object>> records = new ArrayList<ArrayList<Object>>(1); ArrayList<Object> row = new ArrayList<Object>(1); switch (driverConnection.getTransactionIsolation()) { case Connection.TRANSACTION_READ_COMMITTED: row.add("READ COMMITTED"); //$NON-NLS-1$ return booleanFuture(true); List<List<String>> records = Collections.singletonList(Collections.singletonList(driverConnection.getExecutionProperty(show))); createResultSet(records, new String[] {show}, new String[] {DataTypeManager.DefaultDataTypes.STRING}); return booleanFuture(true);
public ResultSet getTypeInfo() throws SQLException { if (driverConnection.getServerConnection().getServerVersion().compareTo("09.03") >= 0) { //$NON-NLS-1$ //use the system table ResultSetMetaData rmetadata = null; ResultSetImpl results = null; PreparedStatement prepareQuery = null; List<List<?>> records = new ArrayList<List<?>>(); try { prepareQuery = driverConnection.prepareStatement(QUERY_TYPEINFO); results = (ResultSetImpl) prepareQuery.executeQuery(); while (results.next ()) { List<Object> currentRow = new ArrayList<Object>(); for(int i=0; i < results.getMetaData().getColumnCount(); i++) { currentRow.add(results.getObject(i+1)); } records.add(currentRow); } rmetadata = results.getMetaData(); return dummyStatement().createResultSet(records, rmetadata); } catch (Exception e) { throw TeiidSQLException.create(e, JDBCPlugin.Util.getString("MMDatabaseMetadata.getTypeInfo_error", e.getMessage())); //$NON-NLS-1$ } finally { if (prepareQuery != null) { prepareQuery.close(); } } } return getStaticTypeInfo(); }
@Test public void testTransactionStatements() throws Exception { ConnectionImpl conn = Mockito.mock(ConnectionImpl.class); Properties p = new Properties(); Mockito.stub(conn.getExecutionProperties()).toReturn(p); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); assertFalse(statement.execute("start transaction")); //$NON-NLS-1$ Mockito.verify(conn).setAutoCommit(false); assertFalse(statement.execute("commit")); //$NON-NLS-1$ Mockito.verify(conn).setAutoCommit(true); assertFalse(statement.execute("start transaction")); //$NON-NLS-1$ assertFalse(statement.execute("rollback")); //$NON-NLS-1$ Mockito.verify(conn).rollback(false); assertFalse(statement.execute("abort transaction")); //$NON-NLS-1$ Mockito.verify(conn, Mockito.times(2)).rollback(false); assertFalse(statement.execute("rollback work")); //$NON-NLS-1$ Mockito.verify(conn, Mockito.times(3)).rollback(false); assertFalse(statement.execute("start transaction isolation level repeatable read")); //$NON-NLS-1$ Mockito.verify(conn).setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); }
@Test public void testDisableLocalTransations() throws Exception { ServerConnection mock = Mockito.mock(ServerConnection.class); DQP dqp = Mockito.mock(DQP.class); Mockito.stub(mock.getService(DQP.class)).toReturn(dqp); ConnectionImpl conn = new ConnectionImpl(mock, new Properties(), "x"); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); assertTrue(conn.getAutoCommit()); statement.execute("set disablelocaltxn true"); assertFalse(statement.execute("start transaction")); //$NON-NLS-1$ conn.beginLocalTxnIfNeeded(); assertFalse(conn.isInLocalTxn()); statement.execute("set disablelocaltxn false"); assertFalse(statement.execute("start transaction")); //$NON-NLS-1$ conn.beginLocalTxnIfNeeded(); assertTrue(conn.isInLocalTxn()); }
SessionMetadata sm = ((LocalServerConnection)this.connection.getServerConnection()).getWorkContext().getSession(); sm.addAttchment(ODBCServerRemoteImpl.class, this); setConnectionProperties(this.connection); while (keys.hasMoreElements()) { String key = (String)keys.nextElement(); this.connection.setExecutionProperty(key, this.props.getProperty(key)); StatementImpl s = this.connection.createStatement(); try { s.execute("select teiid_session_set('resolve_groupby_positional', true)"); //$NON-NLS-1$
String sessionId = conn.getServerConnection().getLogonResult().getSessionID(); if (cache && !Boolean.valueOf(conn.getExecutionProperty(ExecutionProperties.RESULT_SET_CACHE_MODE))) { sql += " /* "+ sessionId +" */"; //$NON-NLS-1$ //$NON-NLS-2$ final PreparedStatement stmt = conn.prepareStatement(sql, cache?ResultSet.TYPE_SCROLL_INSENSITIVE:ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
@Override public void close() throws SQLException { if (this.connection != null) { this.connection.close(); } }
Mockito.stub(conn.getConnectionProps()).toReturn(new Properties()); DQP dqp = Mockito.mock(DQP.class); ServerConnection serverConn = Mockito.mock(ServerConnection.class); Mockito.stub(conn.getServerConnection()).toReturn(serverConn); Mockito.stub(serverConn.getLogonResult()).toReturn(logonResult); Mockito.stub(logonResult.getTimeZone()).toReturn(TimeZone.getDefault()); rm.setUpdateResult(true); results.getResultsReceiver().receiveResults(rm); Mockito.stub(conn.getDQP()).toReturn(dqp);
private void updateSessionProperties() { String encoding = getEncoding(); if (encoding != null) { //this may be unnecessary this.client.setEncoding(encoding, false); } String appName = this.connection.getExecutionProperty(PgBackendProtocol.APPLICATION_NAME); if (appName != null) { String existing = props.getProperty(PgBackendProtocol.APPLICATION_NAME); if (!EquivalenceUtil.areEqual(appName, existing)) { try { SessionMetadata sm = ((LocalServerConnection)connection.getServerConnection()).getWorkContext().getSession(); sm.setApplicationName(appName); } catch (SQLException e) { //connection invalid } this.client.sendParameterStatus(PgBackendProtocol.APPLICATION_NAME, appName); this.props.put(PgBackendProtocol.APPLICATION_NAME, appName); } } }
@SuppressWarnings("unchecked") @Test public void testTransactionStatementsAsynch() throws Exception { ConnectionImpl conn = Mockito.mock(ConnectionImpl.class); Mockito.stub(conn.submitSetAutoCommitTrue(Mockito.anyBoolean())).toReturn((ResultsFuture)ResultsFuture.NULL_FUTURE); Properties p = new Properties(); Mockito.stub(conn.getExecutionProperties()).toReturn(p); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); statement.submitExecute("start transaction", null); //$NON-NLS-1$ Mockito.verify(conn).setAutoCommit(false); statement.submitExecute("commit", null); //$NON-NLS-1$ Mockito.verify(conn).submitSetAutoCommitTrue(true); statement.submitExecute("start transaction", null); //$NON-NLS-1$ statement.submitExecute("rollback", null); //$NON-NLS-1$ Mockito.verify(conn).submitSetAutoCommitTrue(false); }
if (!connection.getAutoCommit()) { connection.rollback(false); if (!HONOR_DECLARE_FETCH_TXN && sql.equalsIgnoreCase("BEGIN") && connection.getAutoCommit()) { //$NON-NLS-1$ next = reader.readStatement(); if (next != null && (cursorSelectPattern.matcher(next)).matches()) {