Skip to content
Merged
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
12 changes: 9 additions & 3 deletions src/main/java/org/apache/ibatis/transaction/Transaction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,37 +19,42 @@
import java.sql.SQLException;

/**
* Wraps a database connection.
* Handles the connection lifecycle that comprises: its creation, preparation, commit/rollback and close.
* Wraps a database connection. Handles the connection lifecycle that comprises: its creation, preparation,
* commit/rollback and close.
*
* @author Clinton Begin
*/
public interface Transaction {

/**
* Retrieve inner database connection.
*
* @return DataBase connection
*
* @throws SQLException
* the SQL exception
*/
Connection getConnection() throws SQLException;

/**
* Commit inner database connection.
*
* @throws SQLException
* the SQL exception
*/
void commit() throws SQLException;

/**
* Rollback inner database connection.
*
* @throws SQLException
* the SQL exception
*/
void rollback() throws SQLException;

/**
* Close inner database connection.
*
* @throws SQLException
* the SQL exception
*/
Expand All @@ -59,6 +64,7 @@ public interface Transaction {
* Get transaction timeout if set.
*
* @return the timeout
*
* @throws SQLException
* the SQL exception
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,7 @@ public interface TransactionFactory {

/**
* Sets transaction factory custom properties.
*
* @param props
* the new properties
*/
Expand All @@ -40,18 +41,28 @@ default void setProperties(Properties props) {

/**
* Creates a {@link Transaction} out of an existing connection.
* @param conn Existing database connection
*
* @param conn
* Existing database connection
*
* @return Transaction
*
* @since 3.1.0
*/
Transaction newTransaction(Connection conn);

/**
* Creates a {@link Transaction} out of a datasource.
* @param dataSource DataSource to take the connection from
* @param level Desired isolation level
* @param autoCommit Desired autocommit
*
* @param dataSource
* DataSource to take the connection from
* @param level
* Desired isolation level
* @param autoCommit
* Desired autocommit
*
* @return Transaction
*
* @since 3.1.0
*/
Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,10 +27,9 @@
import org.apache.ibatis.transaction.TransactionException;

/**
* {@link Transaction} that makes use of the JDBC commit and rollback facilities directly.
* It relies on the connection retrieved from the dataSource to manage the scope of the transaction.
* Delays connection retrieval until getConnection() is called.
* Ignores commit or rollback requests when autocommit is on.
* {@link Transaction} that makes use of the JDBC commit and rollback facilities directly. It relies on the connection
* retrieved from the dataSource to manage the scope of the transaction. Delays connection retrieval until
* getConnection() is called. Ignores commit or rollback requests when autocommit is on.
*
* @author Clinton Begin
*
Expand All @@ -50,7 +49,8 @@ public JdbcTransaction(DataSource ds, TransactionIsolationLevel desiredLevel, bo
this(ds, desiredLevel, desiredAutoCommit, false);
}

public JdbcTransaction(DataSource ds, TransactionIsolationLevel desiredLevel, boolean desiredAutoCommit, boolean skipSetAutoCommitOnClose) {
public JdbcTransaction(DataSource ds, TransactionIsolationLevel desiredLevel, boolean desiredAutoCommit,
boolean skipSetAutoCommitOnClose) {
dataSource = ds;
level = desiredLevel;
autoCommit = desiredAutoCommit;
Expand Down Expand Up @@ -111,9 +111,10 @@ protected void setDesiredAutoCommit(boolean desiredAutoCommit) {
} catch (SQLException e) {
// Only a very poorly implemented driver would fail here,
// and there's not much we can do about that.
throw new TransactionException("Error configuring AutoCommit. "
+ "Your driver may not support getAutoCommit() or setAutoCommit(). "
+ "Requested setting: " + desiredAutoCommit + ". Cause: " + e, e);
throw new TransactionException(
"Error configuring AutoCommit. " + "Your driver may not support getAutoCommit() or setAutoCommit(). "
+ "Requested setting: " + desiredAutoCommit + ". Cause: " + e,
e);
}
}

Expand All @@ -132,8 +133,7 @@ protected void resetAutoCommit() {
}
} catch (SQLException e) {
if (log.isDebugEnabled()) {
log.debug("Error resetting autocommit to true "
+ "before closing the connection. Cause: " + e);
log.debug("Error resetting autocommit to true " + "before closing the connection. Cause: " + e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,10 +26,9 @@
import org.apache.ibatis.transaction.Transaction;

/**
* {@link Transaction} that lets the container manage the full lifecycle of the transaction.
* Delays connection retrieval until getConnection() is called.
* Ignores all commit or rollback requests.
* By default, it closes the connection but can be configured not to do it.
* {@link Transaction} that lets the container manage the full lifecycle of the transaction. Delays connection retrieval
* until getConnection() is called. Ignores all commit or rollback requests. By default, it closes the connection but
* can be configured not to do it.
*
* @author Clinton Begin
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,7 +53,7 @@ public Transaction newTransaction(Connection conn) {
@Override
public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) {
// Silently ignores autocommit and isolation level, as managed transactions are entirely
// controlled by an external manager. It's silently ignored so that
// controlled by an external manager. It's silently ignored so that
// code remains portable between managed and unmanaged configurations.
return new ManagedTransaction(ds, level, closeConnection);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/apache/ibatis/type/Alias.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,15 +23,16 @@

/**
* The annotation that specify alias name.
*
* <p>
* <b>How to use:</b>
*
* <pre>
* &#064;Alias("Email")
* public class UserEmail {
* // ...
* }
* </pre>
*
* @author Clinton Begin
*/
@Documented
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/org/apache/ibatis/type/BaseTypeHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,9 +26,9 @@
/**
* The base {@link TypeHandler} for references a generic type.
* <p>
* Important: Since 3.5.0, This class never call the {@link ResultSet#wasNull()} and
* {@link CallableStatement#wasNull()} method for handling the SQL {@code NULL} value.
* In other words, {@code null} value handling should be performed on subclass.
* Important: Since 3.5.0, This class never call the {@link ResultSet#wasNull()} and {@link CallableStatement#wasNull()}
* method for handling the SQL {@code NULL} value. In other words, {@code null} value handling should be performed on
* subclass.
* </p>
*
* @author Clinton Begin
Expand All @@ -48,6 +48,7 @@ public abstract class BaseTypeHandler<T> extends TypeReference<T> implements Typ
*
* @param c
* the new configuration
*
* @deprecated Since 3.5.0 - See https://github.com/mybatis/mybatis-3/issues/1203. This property will remove future.
*/
@Deprecated
Expand All @@ -65,16 +66,16 @@ public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbc
ps.setNull(i, jdbcType.TYPE_CODE);
} catch (SQLException e) {
throw new TypeException("Error setting null for parameter #" + i + " with JdbcType " + jdbcType + " . "
+ "Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. "
+ "Cause: " + e, e);
+ "Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. "
+ "Cause: " + e, e);
}
} else {
try {
setNonNullParameter(ps, i, parameter, jdbcType);
} catch (Exception e) {
throw new TypeException("Error setting non null for parameter #" + i + " with JdbcType " + jdbcType + " . "
+ "Try setting a different JdbcType for this parameter or a different configuration property. "
+ "Cause: " + e, e);
+ "Try setting a different JdbcType for this parameter or a different configuration property. " + "Cause: "
+ e, e);
}
}
}
Expand All @@ -84,7 +85,8 @@ public T getResult(ResultSet rs, String columnName) throws SQLException {
try {
return getNullableResult(rs, columnName);
} catch (Exception e) {
throw new ResultMapException("Error attempting to get column '" + columnName + "' from result set. Cause: " + e, e);
throw new ResultMapException("Error attempting to get column '" + columnName + "' from result set. Cause: " + e,
e);
}
}

Expand All @@ -93,7 +95,8 @@ public T getResult(ResultSet rs, int columnIndex) throws SQLException {
try {
return getNullableResult(rs, columnIndex);
} catch (Exception e) {
throw new ResultMapException("Error attempting to get column #" + columnIndex + " from result set. Cause: " + e, e);
throw new ResultMapException("Error attempting to get column #" + columnIndex + " from result set. Cause: " + e,
e);
}
}

Expand All @@ -102,11 +105,13 @@ public T getResult(CallableStatement cs, int columnIndex) throws SQLException {
try {
return getNullableResult(cs, columnIndex);
} catch (Exception e) {
throw new ResultMapException("Error attempting to get column #" + columnIndex + " from callable statement. Cause: " + e, e);
throw new ResultMapException(
"Error attempting to get column #" + columnIndex + " from callable statement. Cause: " + e, e);
}
}

public abstract void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException;
public abstract void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType)
throws SQLException;

/**
* Gets the nullable result.
Expand All @@ -115,7 +120,9 @@ public T getResult(CallableStatement cs, int columnIndex) throws SQLException {
* the rs
* @param columnName
* Column name, when configuration <code>useColumnLabel</code> is <code>false</code>
*
* @return the nullable result
*
* @throws SQLException
* the SQL exception
*/
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/org/apache/ibatis/type/BigDecimalTypeHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,20 +33,17 @@ public void setNonNullParameter(PreparedStatement ps, int i, BigDecimal paramete
}

@Override
public BigDecimal getNullableResult(ResultSet rs, String columnName)
throws SQLException {
public BigDecimal getNullableResult(ResultSet rs, String columnName) throws SQLException {
return rs.getBigDecimal(columnName);
}

@Override
public BigDecimal getNullableResult(ResultSet rs, int columnIndex)
throws SQLException {
public BigDecimal getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
return rs.getBigDecimal(columnIndex);
}

@Override
public BigDecimal getNullableResult(CallableStatement cs, int columnIndex)
throws SQLException {
public BigDecimal getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
return cs.getBigDecimal(columnIndex);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +28,8 @@
public class BigIntegerTypeHandler extends BaseTypeHandler<BigInteger> {

@Override
public void setNonNullParameter(PreparedStatement ps, int i, BigInteger parameter, JdbcType jdbcType) throws SQLException {
public void setNonNullParameter(PreparedStatement ps, int i, BigInteger parameter, JdbcType jdbcType)
throws SQLException {
ps.setBigDecimal(i, new BigDecimal(parameter));
}

Expand Down
Loading