Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
Source Code for Connector/J 8.0.31 - User Impl
Where to get the Java source code for Connector/J 8.0 User Impl module?
✍: FYIcenter.com
Java source code files for Connector/J 8.0 User Impl module are:
⏎ com/mysql/cj/xdevapi/PreparableStatement.java
/* * Copyright (c) 2019, 2020, Oracle and/or its affiliates. * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, version 2.0, as published by the * Free Software Foundation. * * This program is also distributed with certain software (including but not * limited to OpenSSL) that is licensed under separate terms, as designated in a * particular file or component or in included license documentation. The * authors of MySQL hereby grant you an additional permission to link the * program and your derivative works with the separately licensed software that * they have included with MySQL. * * Without limiting anything contained in the foregoing, this file, which is * part of MySQL Connector/J, is also subject to the Universal FOSS Exception, * version 1.0, a copy of which can be found at * http://oss.oracle.com/licenses/universal-foss-exception. * * This program 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 General Public License, version 2.0, * for more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ package com.mysql.cj.xdevapi; import java.lang.ref.PhantomReference; import java.lang.ref.ReferenceQueue; import com.mysql.cj.MysqlxSession; import com.mysql.cj.protocol.x.XMessage; import com.mysql.cj.protocol.x.XMessageBuilder; import com.mysql.cj.protocol.x.XProtocolError; /** * Abstract class, common to all X DevAPI statement classes that can be prepared. * * @param <RES_T> * result interface */ public abstract class PreparableStatement<RES_T> { protected enum PreparedState { UNSUPPORTED, // Preparing statements is completely unsupported in the server currently being used. UNPREPARED, // Statement is not prepared yet, next execution will run unprepared. SUSPENDED, // Preparing statements is currently suspended but it is expected to resume sometime later. PREPARED, // The statement is prepared and ready for execution. PREPARE, // The statement shall be prepared on next execution. DEALLOCATE, // The statement shall be deallocated on next execution. REPREPARE; // The statement shall be deallocated and immediately re-prepared on next execution. } protected int preparedStatementId = 0; protected PreparedState preparedState = PreparedState.UNPREPARED; protected MysqlxSession mysqlxSession; /** * Helper method to return an {@link XMessageBuilder} instance from {@link MysqlxSession} in use. * * @return * the {@link XMessageBuilder} instance from current {@link MysqlxSession} */ protected XMessageBuilder getMessageBuilder() { return (XMessageBuilder) this.mysqlxSession.<XMessage>getMessageBuilder(); } /** * Mark this preparable statement to be deallocated on next execution, if it is currently prepared, or cancel the next prepare. */ protected void resetPrepareState() { if (this.preparedState == PreparedState.PREPARED || this.preparedState == PreparedState.REPREPARE) { this.preparedState = PreparedState.DEALLOCATE; } else if (this.preparedState == PreparedState.PREPARE) { this.preparedState = PreparedState.UNPREPARED; } } /** * Mark this preparable statement to be deallocated and re-prepared on next execution, if it is currently prepared. */ protected void setReprepareState() { if (this.preparedState == PreparedState.PREPARED) { this.preparedState = PreparedState.REPREPARE; } } /** * Executes synchronously this statement either directly or using prepared statements if: * 1. Prepared statements are supported by the server. * 2. The statement is executed repeatedly without changing its structure. * * @return * the object returned from the low level statement execution */ public RES_T execute() { for (;;) { switch (this.preparedState) { case UNSUPPORTED: // Fall-back to non-prepared statement execution. return executeStatement(); case UNPREPARED: // Execute as non-prepared this time but mark as to be prepared on next execution. RES_T result = executeStatement(); this.preparedState = PreparedState.PREPARE; return result; case SUSPENDED: // An error occurred in some previous prepare. If the server doesn't support prepared statements then mark it as unsupported, otherwise wait // until the server is ready to accept new prepare attempts, executing non-prepared in the meantime. if (!this.mysqlxSession.supportsPreparedStatements()) { this.preparedState = PreparedState.UNSUPPORTED; } else if (this.mysqlxSession.readyForPreparingStatements()) { this.preparedState = PreparedState.PREPARE; } else { return executeStatement(); } break; case PREPARE: // Prepare this statement. If it succeeds then immediately follow with its execution, otherwise mark it as prepare suspended and let the // following iteration to decide what to do next. this.preparedState = prepareStatement() ? PreparedState.PREPARED : PreparedState.SUSPENDED; break; case PREPARED: // The statement is already prepared and can be executed safely. return executePreparedStatement(); case DEALLOCATE: // Deallocate this statement and set it as unprepared so that it may be prepared later again. deallocatePrepared(); this.preparedState = PreparedState.UNPREPARED; break; case REPREPARE: // Deallocate this statement and set it as to prepare so that it gets prepared and executed right away. deallocatePrepared(); this.preparedState = PreparedState.PREPARE; break; } } } /** * Executes the statement directly (non-prepared). Implementation is dependent on the statement type. * * @return * the object returned from the lower level statement execution */ protected abstract RES_T executeStatement(); /** * Returns the {@link XMessage} needed to prepare this statement. Implementation is dependent on the statement type. * * @return * the {@link XMessage} that prepares this statement */ protected abstract XMessage getPrepareStatementXMessage(); /** * Prepares a statement on the server to be later executed. * * @return * <code>true</code> if the statement was successfully prepared, <code>false</code> otherwise */ private boolean prepareStatement() { if (!this.mysqlxSession.supportsPreparedStatements()) { return false; } try { this.preparedStatementId = this.mysqlxSession.getNewPreparedStatementId(this); this.mysqlxSession.query(getPrepareStatementXMessage(), new UpdateResultBuilder<>()); } catch (XProtocolError e) { if (this.mysqlxSession.failedPreparingStatement(this.preparedStatementId, e)) { this.preparedStatementId = 0; return false; } this.preparedStatementId = 0; throw e; } catch (Throwable t) { this.preparedStatementId = 0; throw t; } return true; } /** * Executes a previously server-prepared statement. Implementation is dependent on the statement type. * * @return * the object returned from the lower level statement execution */ protected abstract RES_T executePreparedStatement(); /** * Deallocate this prepared statement from current {@link MysqlxSession}. */ protected void deallocatePrepared() { if (this.preparedState == PreparedState.PREPARED || this.preparedState == PreparedState.DEALLOCATE || this.preparedState == PreparedState.REPREPARE) { try { this.mysqlxSession.query(getMessageBuilder().buildPrepareDeallocate(this.preparedStatementId), new UpdateResultBuilder<>()); } finally { this.mysqlxSession.freePreparedStatementId(this.preparedStatementId); this.preparedStatementId = 0; } } } /** * {@link PhantomReference} to track prepared statement ids. An instance of this class must be kept until the prepared statement is properly deallocated. If * proper deallocation does not happen, this is used to identify abandoned prepared statements and proceed with its deallocation after the object is * destructed by using a {@link ReferenceQueue}. */ public static class PreparableStatementFinalizer extends PhantomReference<PreparableStatement<?>> { int prepredStatementId; public PreparableStatementFinalizer(PreparableStatement<?> referent, ReferenceQueue<? super PreparableStatement<?>> q, int preparedStatementId) { super(referent, q); this.prepredStatementId = preparedStatementId; } public int getPreparedStatementId() { return this.prepredStatementId; } } }
⏎ com/mysql/cj/xdevapi/PreparableStatement.java
Or download all of them as a single archive file:
File name: mysql-connector-java-user-impl-8.0.31.zip File size: 429580 bytes Release date: 2022-09-03 Download
⇒ Downloading mysql-connector-java-5.1.40.zip
⇐ Source Code for Connector/J 8.0.31 - User API
2023-05-09, 7618👍, 0💬
Popular Posts:
JAX-RPC is an API for building Web services and clients that used remote procedure calls (RPC) and X...
What Is js.jar in Rhino JavaScript 1.7R5? js.jar in Rhino JavaScript 1.7R5 is the JAR file for Rhino...
JDK 11 jdk.javadoc.jmod is the JMOD file for JDK 11 Java Document tool, which can be invoked by the ...
GJT (Giant Java Tree) implementation of XML Pull Parser. JAR File Size and Download Location: File n...
JDK 11 jdk.javadoc.jmod is the JMOD file for JDK 11 Java Document tool, which can be invoked by the ...