Skip to content

Commit

Permalink
Fix for mistake I did in 632a969
Browse files Browse the repository at this point in the history
- fixed copy and paste, equals instead of == for string
- reduced noise in logs - don't log twice, better set the exception cause.

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Sep 18, 2022
1 parent d1247f3 commit e4752ad
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public int getId() {
*/
public static TxIsolationLevel byId(int id) throws IllegalArgumentException {
return Stream.of(TxIsolationLevel.values()).filter(v -> v.getId() == id).findAny()
.orElseThrow(() -> new IllegalArgumentException("Invalid transaction isolation id; the transaction "
+ "isolation level can be any of the following: " + Stream.of(TxIsolationLevel.values())
.map(t -> Integer.toString(t.getId())).collect(Collectors.joining(", "))));
.orElseThrow(() -> new IllegalArgumentException("Invalid transaction isolation level id=" + id
+ "; possible values: " + Stream.of(TxIsolationLevel.values()).map(t -> Integer.toString(t.getId()))
.collect(Collectors.joining(", "))));
}


Expand All @@ -115,10 +115,10 @@ public static TxIsolationLevel byId(int id) throws IllegalArgumentException {
* @throws IllegalArgumentException if the name is not valid.
*/
public static TxIsolationLevel byName(String name) throws IllegalArgumentException {
return Stream.of(TxIsolationLevel.values()).filter(v -> v.getName() == name).findAny()
.orElseThrow(() -> new IllegalArgumentException("Invalid transaction isolation; the transaction"
+ " isolation level can be empty or any of the following: " + Stream.of(TxIsolationLevel.values())
.map(TxIsolationLevel::getName).collect(Collectors.joining(", "))));
return Stream.of(TxIsolationLevel.values()).filter(v -> v.getName().equals(name)).findAny()
.orElseThrow(() -> new IllegalArgumentException(
"Invalid transaction isolation level '" + name + "'; possible values: " + Stream
.of(TxIsolationLevel.values()).map(TxIsolationLevel::getName).collect(Collectors.joining(", "))));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,26 @@

package com.sun.gjc.spi;

import static com.sun.gjc.common.DataSourceSpec.CONNECTIONVALIDATIONREQUIRED;
import static com.sun.gjc.common.DataSourceSpec.GUARANTEEISOLATIONLEVEL;
import static com.sun.gjc.common.DataSourceSpec.TRANSACTIONISOLATION;
import static com.sun.gjc.common.DataSourceSpec.VALIDATIONCLASSNAME;
import static com.sun.gjc.common.DataSourceSpec.VALIDATIONMETHOD;
import static com.sun.gjc.util.SecurityUtils.getPasswordCredential;
import static com.sun.gjc.util.SecurityUtils.isPasswordCredentialEqual;
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.SEVERE;
import com.sun.appserv.connectors.internal.spi.MCFLifecycleListener;
import com.sun.enterprise.util.i18n.StringManager;
import com.sun.gjc.common.DataSourceObjectBuilder;
import com.sun.gjc.common.DataSourceSpec;
import com.sun.gjc.monitoring.JdbcStatsProvider;
import com.sun.gjc.util.SQLTraceDelegator;
import com.sun.logging.LogDomains;

import jakarta.resource.ResourceException;
import jakarta.resource.spi.ConfigProperty;
import jakarta.resource.spi.ConnectionManager;
import jakarta.resource.spi.ConnectionRequestInfo;
import jakarta.resource.spi.LazyEnlistableConnectionManager;
import jakarta.resource.spi.ManagedConnection;
import jakarta.resource.spi.ManagedConnectionFactory;
import jakarta.resource.spi.ResourceAdapter;
import jakarta.resource.spi.ResourceAdapterAssociation;
import jakarta.resource.spi.ResourceAllocationException;
import jakarta.resource.spi.ValidatingManagedConnectionFactory;
import jakarta.resource.spi.security.PasswordCredential;

import java.io.Externalizable;
import java.io.IOException;
Expand Down Expand Up @@ -62,26 +72,16 @@
import org.glassfish.external.probe.provider.StatsProviderManager;
import org.glassfish.resourcebase.resources.api.PoolInfo;

import com.sun.appserv.connectors.internal.spi.MCFLifecycleListener;
import com.sun.enterprise.util.i18n.StringManager;
import com.sun.gjc.common.DataSourceObjectBuilder;
import com.sun.gjc.common.DataSourceSpec;
import com.sun.gjc.monitoring.JdbcStatsProvider;
import com.sun.gjc.util.SQLTraceDelegator;
import com.sun.logging.LogDomains;

import jakarta.resource.ResourceException;
import jakarta.resource.spi.ConfigProperty;
import jakarta.resource.spi.ConnectionManager;
import jakarta.resource.spi.ConnectionRequestInfo;
import jakarta.resource.spi.LazyEnlistableConnectionManager;
import jakarta.resource.spi.ManagedConnection;
import jakarta.resource.spi.ManagedConnectionFactory;
import jakarta.resource.spi.ResourceAdapter;
import jakarta.resource.spi.ResourceAdapterAssociation;
import jakarta.resource.spi.ResourceAllocationException;
import jakarta.resource.spi.ValidatingManagedConnectionFactory;
import jakarta.resource.spi.security.PasswordCredential;
import static com.sun.gjc.common.DataSourceSpec.CONNECTIONVALIDATIONREQUIRED;
import static com.sun.gjc.common.DataSourceSpec.GUARANTEEISOLATIONLEVEL;
import static com.sun.gjc.common.DataSourceSpec.TRANSACTIONISOLATION;
import static com.sun.gjc.common.DataSourceSpec.VALIDATIONCLASSNAME;
import static com.sun.gjc.common.DataSourceSpec.VALIDATIONMETHOD;
import static com.sun.gjc.util.SecurityUtils.getPasswordCredential;
import static com.sun.gjc.util.SecurityUtils.isPasswordCredentialEqual;
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.SEVERE;

/**
* <code>ManagedConnectionFactory</code> implementation for Generic JDBC
Expand Down Expand Up @@ -489,14 +489,13 @@ protected void setIsolation(ManagedConnectionImpl managedConnectionImpl) throws
}

String tranIsolation = spec.getDetail(TRANSACTIONISOLATION);
if (tranIsolation != null && !tranIsolation.equals("")) {
if (tranIsolation != null && !tranIsolation.isEmpty()) {
int tranIsolationInt = getTransactionIsolationInt(tranIsolation);
try {
connection.setTransactionIsolation(tranIsolationInt);
managedConnectionImpl.setLastTransactionIsolationLevel(tranIsolationInt);
} catch (SQLException sqle) {
_logger.log(SEVERE, "jdbc.exc_tx_iso", sqle);
throw new ResourceException("The transaction isolation could " + "not be set: " + sqle.getMessage());
throw new ResourceException("The transaction isolation could not be set!", sqle);
}
}
}
Expand All @@ -521,30 +520,26 @@ void resetIsolation(ManagedConnectionImpl managedConnectionImpl, int tranIsol) t
}

String transactionIsolation = spec.getDetail(TRANSACTIONISOLATION);
if (transactionIsolation != null && !transactionIsolation.equals("")) {
if (transactionIsolation != null && !transactionIsolation.isEmpty()) {
String guaranteeIsolationLevel = spec.getDetail(GUARANTEEISOLATIONLEVEL);

if (guaranteeIsolationLevel != null && !guaranteeIsolationLevel.equals("")) {
boolean guarantee = Boolean.valueOf(guaranteeIsolationLevel.toLowerCase(Locale.getDefault()));

if (guaranteeIsolationLevel != null && !guaranteeIsolationLevel.isEmpty()) {
boolean guarantee = Boolean.valueOf(guaranteeIsolationLevel);
if (guarantee) {
int tranIsolationInt = getTransactionIsolationInt(transactionIsolation);
try {
if (tranIsolationInt != connection.getTransactionIsolation()) {
connection.setTransactionIsolation(tranIsolationInt);
}
} catch (SQLException sqle) {
_logger.log(SEVERE, "jdbc.exc_tx_iso", sqle);
throw new ResourceException("The isolation level could not be set: " + sqle.getMessage());
throw new ResourceException("The isolation level could not be set!", sqle);
}
} else {
try {
if (tranIsol != connection.getTransactionIsolation()) {
connection.setTransactionIsolation(tranIsol);
}
} catch (SQLException sqle) {
_logger.log(SEVERE, "jdbc.exc_tx_iso", sqle);
throw new ResourceException("The isolation level could not be set: " + sqle.getMessage());
throw new ResourceException("The isolation level could not be set!", sqle);
}
}
}
Expand Down

0 comments on commit e4752ad

Please sign in to comment.