Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using non-blocking optimization to compile function.
Browse files Browse the repository at this point in the history
lucky8987 committed Dec 30, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent adb64c7 commit 807c3ed
Showing 2 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import java.util.Map;
import java.util.Set;

import java.util.concurrent.atomic.AtomicBoolean;
import javax.sql.DataSource;

import org.apache.commons.logging.Log;
@@ -70,7 +71,7 @@ public abstract class AbstractJdbcCall {
* Has this operation been compiled? Compilation means at least checking
* that a DataSource or JdbcTemplate has been provided.
*/
private volatile boolean compiled;
private final AtomicBoolean compiled = new AtomicBoolean(false);

/** The generated string used for call statement. */
@Nullable
@@ -284,19 +285,18 @@ public void addDeclaredRowMapper(String parameterName, RowMapper<?> rowMapper) {
* @throws org.springframework.dao.InvalidDataAccessApiUsageException if the object hasn't
* been correctly initialized, for example if no DataSource has been provided
*/
public final synchronized void compile() throws InvalidDataAccessApiUsageException {
if (!isCompiled()) {
if (getProcedureName() == null) {
throw new InvalidDataAccessApiUsageException("Procedure or Function name is required");
}
public final void compile() throws InvalidDataAccessApiUsageException {
if (getProcedureName() == null) {
throw new InvalidDataAccessApiUsageException("Procedure or Function name is required");
}
if (compiled.compareAndSet(false, true)) {
try {
this.jdbcTemplate.afterPropertiesSet();
}
catch (IllegalArgumentException ex) {
throw new InvalidDataAccessApiUsageException(ex.getMessage());
}
compileInternal();
this.compiled = true;
if (logger.isDebugEnabled()) {
logger.debug("SqlCall for " + (isFunction() ? "function" : "procedure") +
" [" + getProcedureName() + "] compiled");
@@ -341,7 +341,7 @@ protected void onCompileInternal() {
* @return whether this operation is compiled and ready to use
*/
public boolean isCompiled() {
return this.compiled;
return this.compiled.get();
}

/**
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
import java.util.Locale;
import java.util.Map;

import java.util.concurrent.atomic.AtomicBoolean;
import javax.sql.DataSource;

import org.apache.commons.logging.Log;
@@ -82,7 +83,7 @@ public abstract class AbstractJdbcInsert {
* Has this operation been compiled? Compilation means at least checking
* that a DataSource or JdbcTemplate has been provided.
*/
private volatile boolean compiled;
private final AtomicBoolean compiled = new AtomicBoolean(false);

/** The generated string used for insert statement. */
private String insertString = "";
@@ -271,23 +272,22 @@ public boolean isQuoteIdentifiers() {
* @throws InvalidDataAccessApiUsageException if the object hasn't been correctly initialized,
* for example if no DataSource has been provided
*/
public final synchronized void compile() throws InvalidDataAccessApiUsageException {
if (!isCompiled()) {
if (getTableName() == null) {
throw new InvalidDataAccessApiUsageException("Table name is required");
}
if (isQuoteIdentifiers() && this.declaredColumns.isEmpty()) {
throw new InvalidDataAccessApiUsageException(
"Explicit column names must be provided when using quoted identifiers");
}
public final void compile() throws InvalidDataAccessApiUsageException {
if (getTableName() == null) {
throw new InvalidDataAccessApiUsageException("Table name is required");
}
if (isQuoteIdentifiers() && this.declaredColumns.isEmpty()) {
throw new InvalidDataAccessApiUsageException(
"Explicit column names must be provided when using quoted identifiers");
}
if (this.compiled.compareAndSet(false, true)) {
try {
this.jdbcTemplate.afterPropertiesSet();
}
catch (IllegalArgumentException ex) {
throw new InvalidDataAccessApiUsageException(ex.getMessage());
}
compileInternal();
this.compiled = true;
if (logger.isDebugEnabled()) {
logger.debug("JdbcInsert for table [" + getTableName() + "] compiled");
}
@@ -323,7 +323,7 @@ protected void onCompileInternal() {
* @return whether this operation is compiled and ready to use
*/
public boolean isCompiled() {
return this.compiled;
return this.compiled.get();
}

/**

0 comments on commit 807c3ed

Please sign in to comment.