Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL string template - first commit #21

Open
wants to merge 1 commit into
base: path_template_v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/java.base/share/classes/java/lang/StringTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,19 @@ public StringTemplate mapValues(Function<Object, Object> mapper) {
return Factory.createStringTemplate(fragments(), values);
}

/**
* TBD
* @param <T> TBD
* @param owner TBD
* @param supplier TBD
* @return TBD
*/
public <T> T getMetaData(Object owner, Supplier<T> supplier) {
Objects.requireNonNull(owner, "owner must not be null");
Objects.requireNonNull(supplier, "supplier must not be null");
return sharedData.getMetaData(owner, supplier);
}

/**
* Test this {@link StringTemplate} against another {@link StringTemplate} for equality.
*
Expand Down Expand Up @@ -944,7 +957,7 @@ public List<Class<?>> getTypes(StringTemplate st) {
public <T> T getMetaData(StringTemplate st, Object owner, Supplier<T> supplier) {
Objects.requireNonNull(st, "st must not be null");
Objects.requireNonNull(owner, "owner must not be null");
Objects.requireNonNull(st, "supplier must not be null");
Objects.requireNonNull(supplier, "supplier must not be null");
return st.sharedData.getMetaData(owner, supplier);
}

Expand Down
1 change: 1 addition & 0 deletions src/java.base/share/classes/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
exports jdk.internal.javac to
java.compiler,
java.desktop, // for ScopedValue
java.sql,
jdk.compiler,
jdk.incubator.vector, // participates in preview features
jdk.jartool, // participates in preview features
Expand Down
242 changes: 242 additions & 0 deletions src/java.sql/share/classes/java/sql/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Properties;
import java.util.concurrent.Executor;

import jdk.internal.javac.PreviewFeature;

/**
* <P>A connection (session) with a specific
* database. SQL statements are executed and results are returned
Expand Down Expand Up @@ -277,6 +279,7 @@ PreparedStatement prepareStatement(String sql)
*
* @throws SQLException if a database access error occurs
*/
@Override
void close() throws SQLException;

/**
Expand Down Expand Up @@ -1712,4 +1715,243 @@ default void setShardingKey(ShardingKey shardingKey)
throws SQLException {
throw new SQLFeatureNotSupportedException("setShardingKey not implemented");
}

/////
/**
* TBD
*
* @param autoGeneratedKeys a flag indicating whether auto-generated keys
* should be returned; one of
* {@code Statement.RETURN_GENERATED_KEYS} or
* {@code Statement.NO_GENERATED_KEYS}
* @param sql TBD
* @return TBD
* @throws SQLException TBD
* @throws SQLFeatureNotSupportedException TBD
*/
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
default PreparedStatement prepareStatement(int autoGeneratedKeys, StringTemplate sql)
throws SQLException {
return SQLTemplateSupport.prepareStatement(sql, this,
query -> prepareStatement(query, autoGeneratedKeys));
}


/**
* TBD
*
* @param resultSetType one of the following {@code ResultSet}
* constants:
* {@code ResultSet.TYPE_FORWARD_ONLY},
* {@code ResultSet.TYPE_SCROLL_INSENSITIVE}, or
* {@code ResultSet.TYPE_SCROLL_SENSITIVE}
* @param resultSetConcurrency one of the following {@code ResultSet}
* constants:
* {@code ResultSet.CONCUR_READ_ONLY} or
* {@code ResultSet.CONCUR_UPDATABLE}
* @param resultSetHoldability one of the following {@code ResultSet}
* constants:
* {@code ResultSet.HOLD_CURSORS_OVER_COMMIT} or
* {@code ResultSet.CLOSE_CURSORS_AT_COMMIT}
* @param sql TBD
* @return TBD
* @throws SQLException TBD
* @throws SQLFeatureNotSupportedException TBD
*/
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
default PreparedStatement prepareStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability,
StringTemplate sql) throws SQLException {
return SQLTemplateSupport.prepareStatement(sql, this,
query -> prepareStatement(query, resultSetType, resultSetConcurrency, resultSetHoldability));
}

/**
* TBD
*
* @param resultSetType a result set type; one of
* {@code ResultSet.TYPE_FORWARD_ONLY},
* {@code ResultSet.TYPE_SCROLL_INSENSITIVE}, or
* {@code ResultSet.TYPE_SCROLL_SENSITIVE}
* @param resultSetConcurrency a concurrency type; one of
* {@code ResultSet.CONCUR_READ_ONLY} or
* {@code ResultSet.CONCUR_UPDATABLE}
* @param sql TBD
* @return TBD
* @throws SQLException TBD
* @throws SQLFeatureNotSupportedException TBD
*/
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
default PreparedStatement prepareStatement(int resultSetType, int resultSetConcurrency, StringTemplate sql)
throws SQLException {
return SQLTemplateSupport.prepareStatement(sql, this,
query -> prepareStatement(query, resultSetType, resultSetConcurrency));
}
/**
* TBD
* Result sets created using the returned {@code PreparedStatement}
* object will by default be type {@code TYPE_FORWARD_ONLY}
* and have a concurrency level of {@code CONCUR_READ_ONLY}.
* The holdability of the created result sets can be determined by
* calling {@link #getHoldability}.
*
* @param sql TBD
* @return TBD
* @throws SQLException TBD
*/
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
default PreparedStatement prepareStatement(StringTemplate sql) throws SQLException {
return SQLTemplateSupport.prepareStatement(sql, this, query -> prepareStatement(query));
}

/**
* Creates a default {@code PreparedStatement} object capable
* of returning the auto-generated keys designated by the given array.
* This array contains the indexes of the columns in the target
* table that contain the auto-generated keys that should be made
* available. The driver will ignore the array if the SQL statement
* is not an {@code INSERT} statement, or an SQL statement able to return
* auto-generated keys (the list of such statements is vendor-specific).
*<p>
* An SQL statement with or without IN parameters can be
* pre-compiled and stored in a {@code PreparedStatement} object. This
* object can then be used to efficiently execute this statement
* multiple times.
* <P>
* <B>Note:</B> This method is optimized for handling
* parametric SQL statements that benefit from precompilation. If
* the driver supports precompilation,
* the method {@code prepareStatement} will send
* the statement to the database for precompilation. Some drivers
* may not support precompilation. In this case, the statement may
* not be sent to the database until the {@code PreparedStatement}
* object is executed. This has no direct effect on users; however, it does
* affect which methods throw certain SQLExceptions.
* <P>
* Result sets created using the returned {@code PreparedStatement}
* object will by default be type {@code TYPE_FORWARD_ONLY}
* and have a concurrency level of {@code CONCUR_READ_ONLY}.
* The holdability of the created result sets can be determined by
* calling {@link #getHoldability}.
*
* @param columnIndexes an array of column indexes indicating the columns
* that should be returned from the inserted row or rows
* @param sql TBD
* @return TBD
* @throws SQLException TBD
* @throws SQLFeatureNotSupportedException TBD
*/
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
default PreparedStatement prepareStatement(int columnIndexes[], StringTemplate sql)
throws SQLException {
return SQLTemplateSupport.prepareStatement(sql, this,
query -> prepareStatement(query, columnIndexes));
}

/**
* Creates a default {@code PreparedStatement} object capable
* of returning the auto-generated keys designated by the given array.
* This array contains the names of the columns in the target
* table that contain the auto-generated keys that should be returned.
* The driver will ignore the array if the SQL statement
* is not an {@code INSERT} statement, or an SQL statement able to return
* auto-generated keys (the list of such statements is vendor-specific).
* <P>
* An SQL statement with or without IN parameters can be
* pre-compiled and stored in a {@code PreparedStatement} object. This
* object can then be used to efficiently execute this statement
* multiple times.
* <P>
* <B>Note:</B> This method is optimized for handling
* parametric SQL statements that benefit from precompilation. If
* the driver supports precompilation,
* the method {@code prepareStatement} will send
* the statement to the database for precompilation. Some drivers
* may not support precompilation. In this case, the statement may
* not be sent to the database until the {@code PreparedStatement}
* object is executed. This has no direct effect on users; however, it does
* affect which methods throw certain SQLExceptions.
* <P>
* Result sets created using the returned {@code PreparedStatement}
* object will by default be type {@code TYPE_FORWARD_ONLY}
* and have a concurrency level of {@code CONCUR_READ_ONLY}.
* The holdability of the created result sets can be determined by
* calling {@link #getHoldability}.
*
* @param columnNames an array of column names indicating the columns
* that should be returned from the inserted row or rows
* @param sql TBD
* @return TBD
* @throws SQLException TBD
* @throws SQLFeatureNotSupportedException TBD
*/
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
default PreparedStatement prepareStatement(String columnNames[], StringTemplate sql)
throws SQLException {
return SQLTemplateSupport.prepareStatement(sql, this,
query -> prepareStatement(query, columnNames));
}

/**
* TBD
*
* @param sql TBD
* @param resultSetType one of the following {@code ResultSet}
* constants:
* {@code ResultSet.TYPE_FORWARD_ONLY},
* {@code ResultSet.TYPE_SCROLL_INSENSITIVE}, or
* {@code ResultSet.TYPE_SCROLL_SENSITIVE}
* @param resultSetConcurrency one of the following {@code ResultSet}
* constants:
* {@code ResultSet.CONCUR_READ_ONLY} or
* {@code ResultSet.CONCUR_UPDATABLE}
* @param resultSetHoldability one of the following {@code ResultSet}
* constants:
* {@code ResultSet.HOLD_CURSORS_OVER_COMMIT} or
* {@code ResultSet.CLOSE_CURSORS_AT_COMMIT}
* @return TBD
* @throws SQLException TBS
* @throws SQLFeatureNotSupportedException TBD
*/
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
default boolean call(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability,
StringTemplate sql) throws SQLException {

return SQLTemplateSupport.call(sql, this,
query -> prepareCall(query, resultSetType, resultSetConcurrency, resultSetHoldability));
}

/**
* TBD
*
* @param sql TBD
* @param resultSetType a result set type; one of
* {@code ResultSet.TYPE_FORWARD_ONLY},
* {@code ResultSet.TYPE_SCROLL_INSENSITIVE}, or
* {@code ResultSet.TYPE_SCROLL_SENSITIVE}
* @param resultSetConcurrency a concurrency type; one of
* {@code ResultSet.CONCUR_READ_ONLY} or
* {@code ResultSet.CONCUR_UPDATABLE}
* @return TBD
* @throws SQLException TBD
* @throws SQLFeatureNotSupportedException TBD
*/
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
default boolean call(int resultSetType,
int resultSetConcurrency,
StringTemplate sql) throws SQLException {
return SQLTemplateSupport.call(sql, this,
query -> prepareCall(query, resultSetType, resultSetConcurrency));
}
/**
* TBD
* @param sql TBD
* @return TBD
* @throws SQLException TBD
*/
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
default boolean call(StringTemplate sql) throws SQLException {
return SQLTemplateSupport.call(sql, this, query -> prepareCall(query));
}
}
Loading