Skip to content

Commit

Permalink
Using non-blocking optimization to compile function.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky8987 committed Dec 30, 2024
1 parent adb64c7 commit 807c3ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit 807c3ed

Please sign in to comment.