mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Add SpiTxnLogger as main point to log SQL, SUM and TXN messages on a per transaction basis
This commit is contained in:
1 parent
bc4d9837c6
commit
9720cd8189
31 files changed
+307
-198
No files matched your search
@@ -10,18 +10,25 @@ package io.ebeaninternal.api;
|
|||||||
public interface SpiLogManager {
|
public interface SpiLogManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the SQL logger.
|
* Enable bind logging.
|
||||||
|
*/
|
||||||
|
boolean enableBindLog();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger used for general transactions.
|
||||||
|
*/
|
||||||
|
SpiTxnLogger logger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger used for read only transactions.
|
||||||
|
*/
|
||||||
|
SpiTxnLogger readOnlyLogger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hmmmm, return the SQL logger for logging truncate statements.
|
||||||
|
* <p>
|
||||||
|
* Maybe we should get rid of this
|
||||||
*/
|
*/
|
||||||
SpiLogger sql();
|
SpiLogger sql();
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the TXN logger.
|
|
||||||
*/
|
|
||||||
SpiLogger txn();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the Summary logger.
|
|
||||||
*/
|
|
||||||
SpiLogger sum();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -27,10 +27,6 @@ public interface SpiTransaction extends Transaction {
|
|||||||
*/
|
*/
|
||||||
String getLabel();
|
String getLabel();
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the string prefix with the transaction id and label used in logging.
|
|
||||||
*/
|
|
||||||
String getLogPrefix();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if generated SQL and Bind values should be logged to the
|
* Return true if generated SQL and Bind values should be logged to the
|
||||||
@@ -47,12 +43,14 @@ public interface SpiTransaction extends Transaction {
|
|||||||
/**
|
/**
|
||||||
* Log a message to the SQL logger.
|
* Log a message to the SQL logger.
|
||||||
*/
|
*/
|
||||||
void logSql(String msg);
|
void logSql(String... msg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a message to the SUMMARY logger.
|
* Log a message to the SUMMARY logger.
|
||||||
*/
|
*/
|
||||||
void logSummary(String msg);
|
void logSummary(String... msg);
|
||||||
|
|
||||||
|
void logTxn(String... args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a "Deferred Relationship" that requires an additional update later.
|
* Register a "Deferred Relationship" that requires an additional update later.
|
||||||
|
|||||||
@@ -137,10 +137,6 @@ public abstract class SpiTransactionProxy implements SpiTransaction {
|
|||||||
transaction.setDocStoreBatchSize(batchSize);
|
transaction.setDocStoreBatchSize(batchSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLogPrefix() {
|
|
||||||
return transaction.getLogPrefix();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isLogSql() {
|
public boolean isLogSql() {
|
||||||
@@ -153,15 +149,20 @@ public abstract class SpiTransactionProxy implements SpiTransaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logSql(String msg) {
|
public void logSql(String... msg) {
|
||||||
transaction.logSql(msg);
|
transaction.logSql(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logSummary(String msg) {
|
public void logSummary(String... msg) {
|
||||||
transaction.logSummary(msg);
|
transaction.logSummary(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logTxn(String... args) {
|
||||||
|
transaction.logTxn(args);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSkipCache(boolean skipCache) {
|
public void setSkipCache(boolean skipCache) {
|
||||||
transaction.setSkipCache(skipCache);
|
transaction.setSkipCache(skipCache);
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package io.ebeaninternal.api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Per Transaction logging of SQL, TXN and Summary messages.
|
||||||
|
*/
|
||||||
|
public interface SpiTxnLogger {
|
||||||
|
|
||||||
|
String id();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is debug logging enabled.
|
||||||
|
*/
|
||||||
|
boolean isLogSql();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is summary logging enabled.
|
||||||
|
*/
|
||||||
|
boolean isLogSummary();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a SQL message.
|
||||||
|
*/
|
||||||
|
void sql(String[] msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a Summary message.
|
||||||
|
*/
|
||||||
|
void sum(String[] msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a Transaction message.
|
||||||
|
*/
|
||||||
|
void txn(String[] args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transaction Committed.
|
||||||
|
*/
|
||||||
|
void notifyCommit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query only transaction completed.
|
||||||
|
*/
|
||||||
|
void notifyQueryOnly();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transaction Rolled back.
|
||||||
|
*/
|
||||||
|
void notifyRollback(Throwable cause);
|
||||||
|
}
|
||||||
@@ -151,7 +151,7 @@ public abstract class AbstractSqlQueryRequest implements CancelableQuery {
|
|||||||
}
|
}
|
||||||
if (isLogSql()) {
|
if (isLogSql()) {
|
||||||
long micros = (System.nanoTime() - startNano) / 1000L;
|
long micros = (System.nanoTime() - startNano) / 1000L;
|
||||||
transaction.logSql(Str.add(TrimLogSql.trim(sql), "; --bind(", bindLog, ") --micros(", micros + ")"));
|
transaction.logSql(TrimLogSql.trim(sql), "; --bind(", bindLog, ") --micros(", String.valueOf(micros), ")");
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|||||||
@@ -691,7 +691,7 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
|
|||||||
/**
|
/**
|
||||||
* Log the SQL if the logLevel is appropriate.
|
* Log the SQL if the logLevel is appropriate.
|
||||||
*/
|
*/
|
||||||
public void logSql(String sql) {
|
public void logSql(String... sql) {
|
||||||
transaction.logSql(sql);
|
transaction.logSql(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -932,16 +932,16 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
|
|||||||
String name = beanDescriptor.name();
|
String name = beanDescriptor.name();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case INSERT:
|
case INSERT:
|
||||||
transaction.logSummary("Inserted [" + name + "] [" + (idValue == null ? "" : idValue) + draft);
|
transaction.logSummary("Inserted [" , name , "] [" , (idValue == null ? "" : idValue.toString()) , draft);
|
||||||
break;
|
break;
|
||||||
case UPDATE:
|
case UPDATE:
|
||||||
transaction.logSummary("Updated [" + name + "] [" + idValue + draft);
|
transaction.logSummary("Updated [" , name , "] [" , idValue.toString() , draft);
|
||||||
break;
|
break;
|
||||||
case DELETE:
|
case DELETE:
|
||||||
transaction.logSummary("Deleted [" + name + "] [" + idValue + draft);
|
transaction.logSummary("Deleted [" , name , "] [" , idValue.toString() , draft);
|
||||||
break;
|
break;
|
||||||
case DELETE_SOFT:
|
case DELETE_SOFT:
|
||||||
transaction.logSummary("SoftDelete [" + name + "] [" + idValue + draft);
|
transaction.logSummary("SoftDelete [" , name , "] [" , idValue.toString() , draft);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
+2
-6
@@ -1,12 +1,8 @@
|
|||||||
package io.ebeaninternal.server.core;
|
package io.ebeaninternal.server.core;
|
||||||
|
|
||||||
import io.ebean.CallableSql;
|
import io.ebean.CallableSql;
|
||||||
import io.ebeaninternal.api.BindParams;
|
import io.ebeaninternal.api.*;
|
||||||
import io.ebeaninternal.api.BindParams.Param;
|
import io.ebeaninternal.api.BindParams.Param;
|
||||||
import io.ebeaninternal.api.SpiCallableSql;
|
|
||||||
import io.ebeaninternal.api.SpiEbeanServer;
|
|
||||||
import io.ebeaninternal.api.SpiTransaction;
|
|
||||||
import io.ebeaninternal.api.TransactionEventTable;
|
|
||||||
import io.ebeaninternal.server.persist.PersistExecute;
|
import io.ebeaninternal.server.persist.PersistExecute;
|
||||||
|
|
||||||
import java.sql.CallableStatement;
|
import java.sql.CallableStatement;
|
||||||
@@ -86,7 +82,7 @@ public final class PersistRequestCallableSql extends PersistRequest {
|
|||||||
persistExecute.collectSqlCall(label, startNanos);
|
persistExecute.collectSqlCall(label, startNanos);
|
||||||
}
|
}
|
||||||
if (transaction.isLogSummary()) {
|
if (transaction.isLogSummary()) {
|
||||||
transaction.logSummary("CallableSql label[" + callableSql.getLabel() + "]" + " rows[" + rowCount + "]" + " bind[" + bindLog + "]");
|
transaction.logSummary("CallableSql label[", callableSql.getLabel(), "] rows[", String.valueOf(rowCount), "] bind[", bindLog, "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
// register table modifications with the transaction event
|
// register table modifications with the transaction event
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public final class PersistRequestOrmUpdate extends PersistRequest {
|
|||||||
OrmUpdateType ormUpdateType = ormUpdate.getOrmUpdateType();
|
OrmUpdateType ormUpdateType = ormUpdate.getOrmUpdateType();
|
||||||
String tableName = ormUpdate.getBaseTable();
|
String tableName = ormUpdate.getBaseTable();
|
||||||
if (transaction.isLogSummary()) {
|
if (transaction.isLogSummary()) {
|
||||||
transaction.logSummary(ormUpdateType + " table[" + tableName + "] rows[" + rowCount + "] bind[" + bindLog + "]");
|
transaction.logSummary(ormUpdateType.toString(), " table[", tableName, "] rows[", String.valueOf(rowCount), "] bind[", bindLog, "]");
|
||||||
}
|
}
|
||||||
if (ormUpdate.isNotifyCache()) {
|
if (ormUpdate.isNotifyCache()) {
|
||||||
// add the modification info to the TransactionEvent
|
// add the modification info to the TransactionEvent
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ public final class PersistRequestUpdateSql extends PersistRequest {
|
|||||||
*/
|
*/
|
||||||
public void logSqlBatchBind() {
|
public void logSqlBatchBind() {
|
||||||
if (transaction.isLogSql()) {
|
if (transaction.isLogSql()) {
|
||||||
transaction.logSql(Str.add(" -- bind(", bindLog, ")"));
|
transaction.logSql(" -- bind(", bindLog, ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ public final class PersistRequestUpdateSql extends PersistRequest {
|
|||||||
persistExecute.collectSqlUpdate(label, startNanos);
|
persistExecute.collectSqlUpdate(label, startNanos);
|
||||||
}
|
}
|
||||||
if (transaction.isLogSql() && !batchThisRequest) {
|
if (transaction.isLogSql() && !batchThisRequest) {
|
||||||
transaction.logSql(Str.add(TrimLogSql.trim(updateSql.getGeneratedSql()), "; -- bind(", bindLog, ") rows(", String.valueOf(rowCount), ")"));
|
transaction.logSql(TrimLogSql.trim(updateSql.getGeneratedSql()), "; -- bind(", bindLog, ") rows(", String.valueOf(rowCount), ")");
|
||||||
}
|
}
|
||||||
if (updateSql.isAutoTableMod()) {
|
if (updateSql.isAutoTableMod()) {
|
||||||
// add the modification info to the TransactionEvent
|
// add the modification info to the TransactionEvent
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public final class RelationalQueryRequest extends AbstractSqlQueryRequest {
|
|||||||
public void logSummary() {
|
public void logSummary() {
|
||||||
if (transaction.isLogSummary()) {
|
if (transaction.isLogSummary()) {
|
||||||
long micros = (System.nanoTime() - startNano) / 1000L;
|
long micros = (System.nanoTime() - startNano) / 1000L;
|
||||||
transaction.logSummary("SqlQuery rows[" + rows + "] micros[" + micros + "] bind[" + bindLog + "]");
|
transaction.logSummary("SqlQuery rows[", String.valueOf(rows), "] micros[", String.valueOf(micros), "] bind[", bindLog, "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,22 +2,30 @@ package io.ebeaninternal.server.logger;
|
|||||||
|
|
||||||
import io.ebeaninternal.api.SpiLogManager;
|
import io.ebeaninternal.api.SpiLogManager;
|
||||||
import io.ebeaninternal.api.SpiLogger;
|
import io.ebeaninternal.api.SpiLogger;
|
||||||
|
import io.ebeaninternal.api.SpiTxnLogger;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
public final class DLogManager implements SpiLogManager {
|
public final class DLogManager implements SpiLogManager {
|
||||||
|
|
||||||
private final SpiLogger sql;
|
private final SpiLogger sql;
|
||||||
private final SpiLogger summary;
|
private final SpiLogger summary;
|
||||||
private final SpiLogger txn;
|
private final SpiLogger txn;
|
||||||
|
private final boolean useIds;
|
||||||
|
private final AtomicLong counter = new AtomicLong(1000);
|
||||||
|
private final DTxnLogger readOnly;
|
||||||
|
|
||||||
public DLogManager(SpiLogger sql, SpiLogger summary, SpiLogger txn) {
|
public DLogManager(SpiLogger sql, SpiLogger summary, SpiLogger txn) {
|
||||||
this.sql = sql;
|
this.sql = sql;
|
||||||
this.summary = summary;
|
this.summary = summary;
|
||||||
this.txn = txn;
|
this.txn = txn;
|
||||||
|
this.useIds = txn.isDebug();
|
||||||
|
this.readOnly = new DTxnLogger(null, sql, summary, txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SpiLogger txn() {
|
public boolean enableBindLog() {
|
||||||
return txn;
|
return sql.isDebug();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,8 +34,13 @@ public final class DLogManager implements SpiLogManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SpiLogger sum() {
|
public SpiTxnLogger logger() {
|
||||||
return summary;
|
String id = useIds ? Long.toString(counter.incrementAndGet()) : "";
|
||||||
|
return new DTxnLogger(id, sql, summary, txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SpiTxnLogger readOnlyLogger() {
|
||||||
|
return readOnly;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package io.ebeaninternal.server.logger;
|
||||||
|
|
||||||
|
import io.ebeaninternal.api.SpiLogger;
|
||||||
|
import io.ebeaninternal.api.SpiTxnLogger;
|
||||||
|
import io.ebeaninternal.server.util.Str;
|
||||||
|
|
||||||
|
final class DTxnLogger implements SpiTxnLogger {
|
||||||
|
|
||||||
|
private final String id;
|
||||||
|
private final String logPrefix;
|
||||||
|
private final SpiLogger sql;
|
||||||
|
private final SpiLogger sum;
|
||||||
|
private final SpiLogger txn;
|
||||||
|
|
||||||
|
DTxnLogger(String id, SpiLogger sql, SpiLogger sum, SpiLogger txn) {
|
||||||
|
this.id = id;
|
||||||
|
this.logPrefix = id == null ? "" : "txn[" + id + "] ";
|
||||||
|
this.sql = sql;
|
||||||
|
this.sum = sum;
|
||||||
|
this.txn = txn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String id() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLogSql() {
|
||||||
|
return sql.isDebug();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLogSummary() {
|
||||||
|
return sum.isDebug();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sql(String[] msg) {
|
||||||
|
sql.debug(Str.add(logPrefix, msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sum(String[] msg) {
|
||||||
|
sum.debug(Str.add(logPrefix, msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void txn(String[] msg) {
|
||||||
|
txn.debug(Str.add(logPrefix, msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyCommit() {
|
||||||
|
txn.debug(Str.add(logPrefix, "Commit"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyQueryOnly() {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyRollback(Throwable cause) {
|
||||||
|
if (txn.isDebug()) {
|
||||||
|
String msg = logPrefix + "Rollback";
|
||||||
|
if (cause != null) {
|
||||||
|
msg += " error: " + formatThrowable(cause);
|
||||||
|
}
|
||||||
|
txn.debug(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatThrowable(Throwable e) {
|
||||||
|
if (e == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
formatThrowable(e, sb);
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void formatThrowable(Throwable e, StringBuilder sb) {
|
||||||
|
sb.append(e.toString());
|
||||||
|
StackTraceElement[] stackTrace = e.getStackTrace();
|
||||||
|
if (stackTrace.length > 0) {
|
||||||
|
sb.append(" stack0: ");
|
||||||
|
sb.append(stackTrace[0]);
|
||||||
|
}
|
||||||
|
Throwable cause = e.getCause();
|
||||||
|
if (cause != null) {
|
||||||
|
sb.append(" cause: ");
|
||||||
|
formatThrowable(cause, sb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -313,7 +313,7 @@ public final class BatchControl {
|
|||||||
BatchedBeanHolder[] bsArray = beanHolderArray();
|
BatchedBeanHolder[] bsArray = beanHolderArray();
|
||||||
Arrays.sort(bsArray, depthComparator);
|
Arrays.sort(bsArray, depthComparator);
|
||||||
if (transaction.isLogSummary()) {
|
if (transaction.isLogSummary()) {
|
||||||
transaction.logSummary("BatchControl flush " + Arrays.toString(bsArray));
|
transaction.logSummary("BatchControl flush " , Arrays.toString(bsArray));
|
||||||
}
|
}
|
||||||
for (BatchedBeanHolder beanHolder : bsArray) {
|
for (BatchedBeanHolder beanHolder : bsArray) {
|
||||||
beanHolder.executeNow();
|
beanHolder.executeNow();
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public final class Binder {
|
|||||||
this.dbExpressionHandler = dbExpressionHandler;
|
this.dbExpressionHandler = dbExpressionHandler;
|
||||||
this.dataTimeZone = dataTimeZone;
|
this.dataTimeZone = dataTimeZone;
|
||||||
this.multiValueBind = multiValueBind;
|
this.multiValueBind = multiValueBind;
|
||||||
this.enableBindLog = logManager.sql().isDebug();
|
this.enableBindLog = logManager.enableBindLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -672,7 +672,7 @@ public final class DefaultPersister implements Persister {
|
|||||||
if (idList != null) {
|
if (idList != null) {
|
||||||
q.where().idIn(idList);
|
q.where().idIn(idList);
|
||||||
if (t.isLogSummary()) {
|
if (t.isLogSummary()) {
|
||||||
t.logSummary("-- DeleteById of " + descriptor.name() + " ids[" + idList + "] requires fetch of foreign key values");
|
t.logSummary("-- DeleteById of ", descriptor.name(), " ids[", idList.toString(), "] requires fetch of foreign key values");
|
||||||
}
|
}
|
||||||
List<?> beanList = server.findList(q, t);
|
List<?> beanList = server.findList(q, t);
|
||||||
deleteCascade(beanList, t, deleteMode, false);
|
deleteCascade(beanList, t, deleteMode, false);
|
||||||
@@ -681,7 +681,7 @@ public final class DefaultPersister implements Persister {
|
|||||||
} else {
|
} else {
|
||||||
q.where().idEq(id);
|
q.where().idEq(id);
|
||||||
if (t.isLogSummary()) {
|
if (t.isLogSummary()) {
|
||||||
t.logSummary("-- DeleteById of " + descriptor.name() + " id[" + id + "] requires fetch of foreign key values");
|
t.logSummary("-- DeleteById of ", descriptor.name(), " id[", String.valueOf(id), "] requires fetch of foreign key values");
|
||||||
}
|
}
|
||||||
EntityBean bean = (EntityBean) server.findOne(q, t);
|
EntityBean bean = (EntityBean) server.findOne(q, t);
|
||||||
if (bean == null) {
|
if (bean == null) {
|
||||||
@@ -741,7 +741,7 @@ public final class DefaultPersister implements Persister {
|
|||||||
for (BeanPropertyAssocMany<?> many : manys) {
|
for (BeanPropertyAssocMany<?> many : manys) {
|
||||||
SqlUpdate sqlDelete = many.deleteByParentId(id, idList);
|
SqlUpdate sqlDelete = many.deleteByParentId(id, idList);
|
||||||
if (t.isLogSummary()) {
|
if (t.isLogSummary()) {
|
||||||
t.logSummary("-- Deleting intersection table entries: " + many.fullName());
|
t.logSummary("-- Deleting intersection table entries: ", many.fullName());
|
||||||
}
|
}
|
||||||
executeSqlUpdate(sqlDelete, t);
|
executeSqlUpdate(sqlDelete, t);
|
||||||
}
|
}
|
||||||
@@ -751,9 +751,9 @@ public final class DefaultPersister implements Persister {
|
|||||||
SqlUpdate deleteById = descriptor.deleteById(id, idList, deleteMode);
|
SqlUpdate deleteById = descriptor.deleteById(id, idList, deleteMode);
|
||||||
if (t.isLogSummary()) {
|
if (t.isLogSummary()) {
|
||||||
if (idList != null) {
|
if (idList != null) {
|
||||||
t.logSummary("-- Deleting " + descriptor.name() + " Ids: " + idList);
|
t.logSummary("-- Deleting ", descriptor.name(), " Ids: ", idList.toString());
|
||||||
} else {
|
} else {
|
||||||
t.logSummary("-- Deleting " + descriptor.name() + " Id: " + id);
|
t.logSummary("-- Deleting ", descriptor.name(), " Id: ", String.valueOf(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -69,7 +69,7 @@ final class DeleteUnloadedForeignKeys {
|
|||||||
|
|
||||||
SpiTransaction t = request.transaction();
|
SpiTransaction t = request.transaction();
|
||||||
if (t.isLogSummary()) {
|
if (t.isLogSummary()) {
|
||||||
t.logSummary("-- Ebean fetching foreign key values for delete of " + descriptor.name() + " id:" + id);
|
t.logSummary("-- Ebean fetching foreign key values for delete of ", descriptor.name(), " id:", String.valueOf(id));
|
||||||
}
|
}
|
||||||
beanWithForeignKeys = (EntityBean) server.findOne(q, t);
|
beanWithForeignKeys = (EntityBean) server.findOne(q, t);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
|||||||
} catch (OptimisticLockException e) {
|
} catch (OptimisticLockException e) {
|
||||||
// add the SQL and bind values to error message
|
// add the SQL and bind values to error message
|
||||||
final String m = e.getMessage() + " sql[" + sql + "] bind[" + bindLog + "]";
|
final String m = e.getMessage() + " sql[" + sql + "] bind[" + bindLog + "]";
|
||||||
persistRequest.transaction().logSummary("OptimisticLockException:" + m);
|
persistRequest.transaction().logSummary("OptimisticLockException:", m);
|
||||||
throw new OptimisticLockException(m, null, e.getEntity());
|
throw new OptimisticLockException(m, null, e.getEntity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,15 +146,15 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
|||||||
switch (batchedStatus) {
|
switch (batchedStatus) {
|
||||||
case BATCHED_FIRST: {
|
case BATCHED_FIRST: {
|
||||||
transaction.logSql(sql);
|
transaction.logSql(sql);
|
||||||
transaction.logSql(Str.add(" -- bind(", bindLog.toString(), ")"));
|
transaction.logSql(" -- bind(", bindLog.toString(), ")");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case BATCHED: {
|
case BATCHED: {
|
||||||
transaction.logSql(Str.add(" -- bind(", bindLog.toString(), ")"));
|
transaction.logSql(" -- bind(", bindLog.toString(), ")");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
transaction.logSql(Str.add(sql, "; -- bind(", bindLog.toString(), ")"));
|
transaction.logSql(sql, "; -- bind(", bindLog.toString(), ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public final class CQueryEngine {
|
|||||||
try {
|
try {
|
||||||
int rows = query.execute();
|
int rows = query.execute();
|
||||||
if (request.logSql()) {
|
if (request.logSql()) {
|
||||||
request.logSql(Str.add(query.generatedSql(), "; --bind(", query.bindLog(), ") --micros(", query.micros() + ") --rows(", rows + ")"));
|
request.logSql(query.generatedSql(), "; --bind(", query.bindLog(), ") --micros(", query.micros() + ") --rows(", rows + ")");
|
||||||
}
|
}
|
||||||
return rows;
|
return rows;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -129,7 +129,7 @@ public final class CQueryEngine {
|
|||||||
SpiTransaction t = request.transaction();
|
SpiTransaction t = request.transaction();
|
||||||
if (t.isLogSummary()) {
|
if (t.isLogSummary()) {
|
||||||
// log the error to the transaction log
|
// log the error to the transaction log
|
||||||
t.logSummary("ERROR executing query, bindLog[" + bindLog + "] error:" + StringHelper.removeNewLines(e.getMessage()));
|
t.logSummary("ERROR executing query, bindLog[", bindLog, "] error:", StringHelper.removeNewLines(e.getMessage()));
|
||||||
}
|
}
|
||||||
// ensure 'rollback' is logged if queryOnly transaction
|
// ensure 'rollback' is logged if queryOnly transaction
|
||||||
t.connection();
|
t.connection();
|
||||||
@@ -147,7 +147,7 @@ public final class CQueryEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private <T> void logGeneratedSql(OrmQueryRequest<T> request, String sql, String bindLog, long micros) {
|
private <T> void logGeneratedSql(OrmQueryRequest<T> request, String sql, String bindLog, long micros) {
|
||||||
request.logSql(Str.add(sql, "; --bind(", bindLog, ") --micros(", micros + ")"));
|
request.logSql(sql, "; --bind(", bindLog, ") --micros(", micros + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -403,7 +403,7 @@ public final class CQueryEngine {
|
|||||||
* Log the generated SQL to the transaction log.
|
* Log the generated SQL to the transaction log.
|
||||||
*/
|
*/
|
||||||
private void logSql(CQuery<?> query) {
|
private void logSql(CQuery<?> query) {
|
||||||
query.transaction().logSql(Str.add(query.generatedSql(), "; --bind(", query.bindLog(), ") --micros(", query.micros() + ")"));
|
query.transaction().logSql(query.generatedSql(), "; --bind(", query.bindLog(), ") --micros(", String.valueOf(query.micros()), ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-2
@@ -10,8 +10,8 @@ public final class DocStoreOnlyTransaction extends JdbcTransaction {
|
|||||||
/**
|
/**
|
||||||
* Create a new DocStore only Transaction.
|
* Create a new DocStore only Transaction.
|
||||||
*/
|
*/
|
||||||
public DocStoreOnlyTransaction(String id, boolean explicit, TransactionManager manager) {
|
public DocStoreOnlyTransaction(boolean explicit, TransactionManager manager) {
|
||||||
super(id, explicit, null, manager);
|
super(explicit, null, manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-2
@@ -25,11 +25,11 @@ public final class DocStoreTransactionManager extends TransactionManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SpiTransaction createReadOnlyTransaction(Object tenantId) {
|
public SpiTransaction createReadOnlyTransaction(Object tenantId) {
|
||||||
return new DocStoreOnlyTransaction("", false, this);
|
return new DocStoreOnlyTransaction(false, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpiTransaction createTransaction(boolean explicit, Connection c) {
|
protected SpiTransaction createTransaction(boolean explicit, Connection c) {
|
||||||
return new DocStoreOnlyTransaction(nextTxnId(), explicit, this);
|
return new DocStoreOnlyTransaction(explicit, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -25,14 +25,14 @@ public class ExternalJdbcTransaction extends JdbcTransaction {
|
|||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public ExternalJdbcTransaction(Connection connection) {
|
public ExternalJdbcTransaction(Connection connection) {
|
||||||
super(null, true, connection, null);
|
super(true, connection, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct will all explicit parameters.
|
* Construct will all explicit parameters.
|
||||||
*/
|
*/
|
||||||
public ExternalJdbcTransaction(String id, boolean explicit, Connection connection, TransactionManager manager) {
|
public ExternalJdbcTransaction(boolean explicit, Connection connection, TransactionManager manager) {
|
||||||
super(id, explicit, connection, manager);
|
super(explicit, connection, manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+13
-11
@@ -33,6 +33,7 @@ final class ImplicitReadOnlyTransaction implements SpiTransaction, TxnProfileEve
|
|||||||
private static final String notExpectedMessage = "Not expected on read only transaction";
|
private static final String notExpectedMessage = "Not expected on read only transaction";
|
||||||
|
|
||||||
private final TransactionManager manager;
|
private final TransactionManager manager;
|
||||||
|
private final SpiTxnLogger logger;
|
||||||
private final boolean logSql;
|
private final boolean logSql;
|
||||||
private final boolean logSummary;
|
private final boolean logSummary;
|
||||||
|
|
||||||
@@ -61,8 +62,9 @@ final class ImplicitReadOnlyTransaction implements SpiTransaction, TxnProfileEve
|
|||||||
*/
|
*/
|
||||||
ImplicitReadOnlyTransaction(TransactionManager manager, Connection connection) {
|
ImplicitReadOnlyTransaction(TransactionManager manager, Connection connection) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.logSql = manager.isLogSql();
|
this.logger = manager.loggerReadOnly();
|
||||||
this.logSummary = manager.isLogSummary();
|
this.logSql = logger.isLogSql();
|
||||||
|
this.logSummary = logger.isLogSummary();
|
||||||
this.active = true;
|
this.active = true;
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
this.persistenceContext = new DefaultPersistenceContext();
|
this.persistenceContext = new DefaultPersistenceContext();
|
||||||
@@ -147,11 +149,6 @@ final class ImplicitReadOnlyTransaction implements SpiTransaction, TxnProfileEve
|
|||||||
public void setSkipCache(boolean skipCache) {
|
public void setSkipCache(boolean skipCache) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLogPrefix() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addBeanChange(BeanChange beanChange) {
|
public void addBeanChange(BeanChange beanChange) {
|
||||||
throw new IllegalStateException(notExpectedMessage);
|
throw new IllegalStateException(notExpectedMessage);
|
||||||
@@ -433,13 +430,18 @@ final class ImplicitReadOnlyTransaction implements SpiTransaction, TxnProfileEve
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logSql(String msg) {
|
public void logSql(String... msg) {
|
||||||
manager.log().sql().debug(msg);
|
logger.sql(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logSummary(String msg) {
|
public void logSummary(String... msg) {
|
||||||
manager.log().sum().debug(msg);
|
logger.sum(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logTxn(String... args) {
|
||||||
|
// never called
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import io.ebeaninternal.server.core.PersistDeferredRelationship;
|
|||||||
import io.ebeaninternal.server.core.PersistRequestBean;
|
import io.ebeaninternal.server.core.PersistRequestBean;
|
||||||
import io.ebeaninternal.server.persist.BatchControl;
|
import io.ebeaninternal.server.persist.BatchControl;
|
||||||
import io.ebeaninternal.server.persist.BatchedSqlException;
|
import io.ebeaninternal.server.persist.BatchedSqlException;
|
||||||
import io.ebeaninternal.server.util.Str;
|
|
||||||
import io.ebeanservice.docstore.api.DocStoreTransaction;
|
import io.ebeanservice.docstore.api.DocStoreTransaction;
|
||||||
|
|
||||||
import javax.persistence.PersistenceException;
|
import javax.persistence.PersistenceException;
|
||||||
@@ -33,8 +32,8 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
|||||||
private static final String illegalStateMessage = "Transaction is Inactive";
|
private static final String illegalStateMessage = "Transaction is Inactive";
|
||||||
|
|
||||||
final TransactionManager manager;
|
final TransactionManager manager;
|
||||||
|
private final SpiTxnLogger logger;
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String logPrefix;
|
|
||||||
private final boolean logSql;
|
private final boolean logSql;
|
||||||
private final boolean logSummary;
|
private final boolean logSummary;
|
||||||
private final boolean explicit;
|
private final boolean explicit;
|
||||||
@@ -95,17 +94,17 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
|||||||
private final long startNanos;
|
private final long startNanos;
|
||||||
private boolean autoPersistUpdates;
|
private boolean autoPersistUpdates;
|
||||||
|
|
||||||
JdbcTransaction(String id, boolean explicit, Connection connection, TransactionManager manager) {
|
JdbcTransaction(boolean explicit, Connection connection, TransactionManager manager) {
|
||||||
try {
|
try {
|
||||||
this.active = true;
|
this.active = true;
|
||||||
this.id = id;
|
|
||||||
this.logPrefix = deriveLogPrefix(id);
|
|
||||||
this.explicit = explicit;
|
this.explicit = explicit;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
this.persistenceContext = new DefaultPersistenceContext();
|
this.persistenceContext = new DefaultPersistenceContext();
|
||||||
this.startNanos = System.nanoTime();
|
this.startNanos = System.nanoTime();
|
||||||
if (manager == null) {
|
if (manager == null) {
|
||||||
|
this.logger = null;
|
||||||
|
this.id = "";
|
||||||
this.logSql = false;
|
this.logSql = false;
|
||||||
this.logSummary = false;
|
this.logSummary = false;
|
||||||
this.skipCacheAfterWrite = true;
|
this.skipCacheAfterWrite = true;
|
||||||
@@ -113,9 +112,11 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
|||||||
this.batchOnCascadeMode = false;
|
this.batchOnCascadeMode = false;
|
||||||
this.onQueryOnlyCommit = false;
|
this.onQueryOnlyCommit = false;
|
||||||
} else {
|
} else {
|
||||||
|
this.logger = manager.logger();
|
||||||
|
this.id = logger.id();
|
||||||
this.autoPersistUpdates = explicit && manager.isAutoPersistUpdates();
|
this.autoPersistUpdates = explicit && manager.isAutoPersistUpdates();
|
||||||
this.logSql = manager.isLogSql();
|
this.logSql = logger.isLogSql();
|
||||||
this.logSummary = manager.isLogSummary();
|
this.logSummary = logger.isLogSummary();
|
||||||
this.skipCacheAfterWrite = manager.isSkipCacheAfterWrite();
|
this.skipCacheAfterWrite = manager.isSkipCacheAfterWrite();
|
||||||
this.batchMode = manager.isPersistBatch();
|
this.batchMode = manager.isPersistBatch();
|
||||||
this.batchOnCascadeMode = manager.isPersistBatchOnCascade();
|
this.batchOnCascadeMode = manager.isPersistBatchOnCascade();
|
||||||
@@ -188,16 +189,7 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String deriveLogPrefix(String id) {
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("txn[");
|
|
||||||
if (id != null) {
|
|
||||||
sb.append(id);
|
|
||||||
}
|
|
||||||
sb.append("] ");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void setAutoPersistUpdates(boolean autoPersistUpdates) {
|
public final void setAutoPersistUpdates(boolean autoPersistUpdates) {
|
||||||
@@ -226,17 +218,13 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
|||||||
this.skipCache = skipCache;
|
this.skipCache = skipCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public final String getLogPrefix() {
|
|
||||||
return logPrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (active) {
|
if (active) {
|
||||||
return logPrefix;
|
return id;
|
||||||
} else {
|
} else {
|
||||||
return logPrefix + "(inactive)";
|
return id + "(inactive)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,13 +714,18 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void logSql(String msg) {
|
public final void logSql(String... msg) {
|
||||||
manager.log().sql().debug(Str.add(logPrefix, msg));
|
logger.sql(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void logSummary(String msg) {
|
public final void logSummary(String... msg) {
|
||||||
manager.log().sum().debug(Str.add(logPrefix, msg));
|
logger.sum(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logTxn(String... args) {
|
||||||
|
logger.txn(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -805,9 +798,11 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
|||||||
final void notifyCommit() {
|
final void notifyCommit() {
|
||||||
if (manager != null) {
|
if (manager != null) {
|
||||||
if (queryOnly) {
|
if (queryOnly) {
|
||||||
|
logger.notifyQueryOnly();
|
||||||
manager.notifyOfQueryOnly(this);
|
manager.notifyOfQueryOnly(this);
|
||||||
} else {
|
} else {
|
||||||
manager.notifyOfCommit(this);
|
manager.notifyOfCommit(this);
|
||||||
|
logger.notifyCommit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -966,6 +961,7 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
|||||||
manager.notifyOfQueryOnly(this);
|
manager.notifyOfQueryOnly(this);
|
||||||
} else {
|
} else {
|
||||||
manager.notifyOfRollback(this, cause);
|
manager.notifyOfRollback(this, cause);
|
||||||
|
logger.notifyRollback(cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ public final class JtaTransaction extends JdbcTransaction {
|
|||||||
/**
|
/**
|
||||||
* Create the JtaTransaction.
|
* Create the JtaTransaction.
|
||||||
*/
|
*/
|
||||||
public JtaTransaction(String id, boolean explicit, UserTransaction utx, DataSource ds, TransactionManager manager) {
|
public JtaTransaction(boolean explicit, UserTransaction utx, DataSource ds, TransactionManager manager) {
|
||||||
super(id, explicit, null, manager);
|
super(explicit, null, manager);
|
||||||
userTransaction = utx;
|
userTransaction = utx;
|
||||||
try {
|
try {
|
||||||
newTransaction = userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION;
|
newTransaction = userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION;
|
||||||
|
|||||||
+1
-2
@@ -105,8 +105,7 @@ public final class JtaTransactionManager implements ExternalTransactionManager {
|
|||||||
// This is a transaction that Ebean has not seen before.
|
// This is a transaction that Ebean has not seen before.
|
||||||
|
|
||||||
// "wrap" it in a Ebean specific JtaTransaction
|
// "wrap" it in a Ebean specific JtaTransaction
|
||||||
String txnId = String.valueOf(System.currentTimeMillis());
|
JtaTransaction newTrans = new JtaTransaction( true, ut, dataSource(), transactionManager);
|
||||||
JtaTransaction newTrans = new JtaTransaction(txnId, true, ut, dataSource(), transactionManager);
|
|
||||||
|
|
||||||
// create and register transaction listener
|
// create and register transaction listener
|
||||||
JtaTxnListener txnListener = createJtaTxnListener(newTrans);
|
JtaTxnListener txnListener = createJtaTxnListener(newTrans);
|
||||||
|
|||||||
@@ -117,10 +117,6 @@ final class NoTransaction implements SpiTransaction {
|
|||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLogPrefix() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isLogSql() {
|
public boolean isLogSql() {
|
||||||
@@ -133,12 +129,17 @@ final class NoTransaction implements SpiTransaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logSql(String msg) {
|
public void logSql(String... msg) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logSummary(String msg) {
|
public void logSummary(String... msg) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logTxn(String... args) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-10
@@ -21,7 +21,6 @@ final class SavepointTransaction extends SpiTransactionProxy {
|
|||||||
private final TransactionManager manager;
|
private final TransactionManager manager;
|
||||||
private final Savepoint savepoint;
|
private final Savepoint savepoint;
|
||||||
private final Connection connection;
|
private final Connection connection;
|
||||||
private final String logPrefix;
|
|
||||||
private final String spPrefix;
|
private final String spPrefix;
|
||||||
|
|
||||||
private boolean rollbackOnly;
|
private boolean rollbackOnly;
|
||||||
@@ -33,13 +32,12 @@ final class SavepointTransaction extends SpiTransactionProxy {
|
|||||||
this.transaction = transaction;
|
this.transaction = transaction;
|
||||||
this.connection = transaction.getInternalConnection();
|
this.connection = transaction.getInternalConnection();
|
||||||
this.savepoint = connection.setSavepoint();
|
this.savepoint = connection.setSavepoint();
|
||||||
if (manager.isTxnDebug()) {
|
if (transaction.isLogSql()) {
|
||||||
int savepointId = manager.isSupportsSavepointId() ? savepoint.getSavepointId() : 0;
|
int savepointId = manager.isSupportsSavepointId() ? savepoint.getSavepointId() : 0;
|
||||||
this.spPrefix = "sp[" + savepointId + "] ";
|
this.spPrefix = "sp[" + savepointId + "] ";
|
||||||
} else {
|
} else {
|
||||||
this.spPrefix = "sp[] ";
|
this.spPrefix = "sp[] ";
|
||||||
}
|
}
|
||||||
this.logPrefix = transaction.getLogPrefix() + spPrefix;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -51,17 +49,12 @@ final class SavepointTransaction extends SpiTransactionProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLogPrefix() {
|
public void logSql(String... msg) {
|
||||||
return logPrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logSql(String msg) {
|
|
||||||
transaction.logSql(Str.add(spPrefix, msg));
|
transaction.logSql(Str.add(spPrefix, msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logSummary(String msg) {
|
public void logSummary(String... msg) {
|
||||||
transaction.logSummary(Str.add(spPrefix, msg));
|
transaction.logSummary(Str.add(spPrefix, msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +92,7 @@ final class SavepointTransaction extends SpiTransactionProxy {
|
|||||||
connection.releaseSavepoint(savepoint);
|
connection.releaseSavepoint(savepoint);
|
||||||
state = STATE_COMMITTED;
|
state = STATE_COMMITTED;
|
||||||
manager.notifyOfCommit(this);
|
manager.notifyOfCommit(this);
|
||||||
|
transaction.logTxn(spPrefix, "commit");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new PersistenceException("Error trying to commit/release Savepoint", e);
|
throw new PersistenceException("Error trying to commit/release Savepoint", e);
|
||||||
}
|
}
|
||||||
@@ -109,6 +103,7 @@ final class SavepointTransaction extends SpiTransactionProxy {
|
|||||||
connection.rollback(savepoint);
|
connection.rollback(savepoint);
|
||||||
state = STATE_ROLLED_BACK;
|
state = STATE_ROLLED_BACK;
|
||||||
manager.notifyOfRollback(this, cause);
|
manager.notifyOfRollback(this, cause);
|
||||||
|
transaction.logTxn(spPrefix, "rollback");//TODO: Pass the cause
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new PersistenceException("Error trying to rollback Savepoint", e);
|
throw new PersistenceException("Error trying to rollback Savepoint", e);
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-74
@@ -36,7 +36,6 @@ import java.sql.SQLException;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
|
|
||||||
import static java.lang.System.Logger.Level.DEBUG;
|
import static java.lang.System.Logger.Level.DEBUG;
|
||||||
import static java.lang.System.Logger.Level.ERROR;
|
import static java.lang.System.Logger.Level.ERROR;
|
||||||
@@ -63,8 +62,6 @@ public class TransactionManager implements SpiTransactionManager {
|
|||||||
* Prefix for transaction id's (logging).
|
* Prefix for transaction id's (logging).
|
||||||
*/
|
*/
|
||||||
final String prefix;
|
final String prefix;
|
||||||
private final String externalTransPrefix;
|
|
||||||
private final AtomicLong counter = new AtomicLong(1000L);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The dataSource of connections.
|
* The dataSource of connections.
|
||||||
@@ -96,8 +93,6 @@ public class TransactionManager implements SpiTransactionManager {
|
|||||||
private final boolean skipCacheAfterWrite;
|
private final boolean skipCacheAfterWrite;
|
||||||
private final TransactionFactory transactionFactory;
|
private final TransactionFactory transactionFactory;
|
||||||
private final SpiLogManager logManager;
|
private final SpiLogManager logManager;
|
||||||
private final SpiLogger txnLogger;
|
|
||||||
private final boolean txnDebug;
|
|
||||||
private final DatabasePlatform databasePlatform;
|
private final DatabasePlatform databasePlatform;
|
||||||
private final SpiProfileHandler profileHandler;
|
private final SpiProfileHandler profileHandler;
|
||||||
private final TimedMetric txnMain;
|
private final TimedMetric txnMain;
|
||||||
@@ -115,8 +110,6 @@ public class TransactionManager implements SpiTransactionManager {
|
|||||||
public TransactionManager(TransactionManagerOptions options) {
|
public TransactionManager(TransactionManagerOptions options) {
|
||||||
this.server = options.server;
|
this.server = options.server;
|
||||||
this.logManager = options.logManager;
|
this.logManager = options.logManager;
|
||||||
this.txnLogger = logManager.txn();
|
|
||||||
this.txnDebug = txnLogger.isDebug();
|
|
||||||
this.databasePlatform = options.config.getDatabasePlatform();
|
this.databasePlatform = options.config.getDatabasePlatform();
|
||||||
this.supportsSavepointId = databasePlatform.supportsSavepointId();
|
this.supportsSavepointId = databasePlatform.supportsSavepointId();
|
||||||
this.skipCacheAfterWrite = options.config.isSkipCacheAfterWrite();
|
this.skipCacheAfterWrite = options.config.isSkipCacheAfterWrite();
|
||||||
@@ -142,7 +135,6 @@ public class TransactionManager implements SpiTransactionManager {
|
|||||||
this.profileHandler = options.profileHandler;
|
this.profileHandler = options.profileHandler;
|
||||||
this.bulkEventListenerMap = new BulkEventListenerMap(options.config.getBulkTableEventListeners());
|
this.bulkEventListenerMap = new BulkEventListenerMap(options.config.getBulkTableEventListeners());
|
||||||
this.prefix = "";
|
this.prefix = "";
|
||||||
this.externalTransPrefix = "e";
|
|
||||||
|
|
||||||
CurrentTenantProvider tenantProvider = options.config.getCurrentTenantProvider();
|
CurrentTenantProvider tenantProvider = options.config.getCurrentTenantProvider();
|
||||||
this.transactionFactory = TransactionFactoryBuilder.build(this, dataSourceSupplier, tenantProvider);
|
this.transactionFactory = TransactionFactoryBuilder.build(this, dataSourceSupplier, tenantProvider);
|
||||||
@@ -273,14 +265,7 @@ public class TransactionManager implements SpiTransactionManager {
|
|||||||
* Wrap the externally supplied Connection.
|
* Wrap the externally supplied Connection.
|
||||||
*/
|
*/
|
||||||
public SpiTransaction wrapExternalConnection(Connection c) {
|
public SpiTransaction wrapExternalConnection(Connection c) {
|
||||||
return wrapExternalConnection(externalTransPrefix + c.hashCode(), c);
|
ExternalJdbcTransaction t = new ExternalJdbcTransaction(true, c, this);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrap an externally supplied Connection with a known transaction id.
|
|
||||||
*/
|
|
||||||
private SpiTransaction wrapExternalConnection(String id, Connection c) {
|
|
||||||
ExternalJdbcTransaction t = new ExternalJdbcTransaction(id, true, c, this);
|
|
||||||
// set the default batch mode
|
// set the default batch mode
|
||||||
t.setBatchMode(persistBatch);
|
t.setBatchMode(persistBatch);
|
||||||
t.setBatchOnCascade(persistBatchOnCascade);
|
t.setBatchOnCascade(persistBatchOnCascade);
|
||||||
@@ -313,14 +298,7 @@ public class TransactionManager implements SpiTransactionManager {
|
|||||||
* Create a new transaction.
|
* Create a new transaction.
|
||||||
*/
|
*/
|
||||||
SpiTransaction createTransaction(boolean explicit, Connection c) {
|
SpiTransaction createTransaction(boolean explicit, Connection c) {
|
||||||
return new JdbcTransaction(nextTxnId(), explicit, c, this);
|
return new JdbcTransaction(explicit, c, this);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the next transaction id.
|
|
||||||
*/
|
|
||||||
String nextTxnId() {
|
|
||||||
return txnDebug ? prefix + counter.incrementAndGet() : prefix;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -328,17 +306,7 @@ public class TransactionManager implements SpiTransactionManager {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final void notifyOfRollback(SpiTransaction transaction, Throwable cause) {
|
public final void notifyOfRollback(SpiTransaction transaction, Throwable cause) {
|
||||||
try {
|
// Do nothing now
|
||||||
if (txnLogger.isDebug()) {
|
|
||||||
String msg = transaction.getLogPrefix() + "Rollback";
|
|
||||||
if (cause != null) {
|
|
||||||
msg += " error: " + formatThrowable(cause);
|
|
||||||
}
|
|
||||||
txnLogger.debug(msg);
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.log(ERROR, "Error while notifying TransactionEventListener of rollback event", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -349,38 +317,12 @@ public class TransactionManager implements SpiTransactionManager {
|
|||||||
// Nothing that interesting here
|
// Nothing that interesting here
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatThrowable(Throwable e) {
|
|
||||||
if (e == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
formatThrowable(e, sb);
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void formatThrowable(Throwable e, StringBuilder sb) {
|
|
||||||
sb.append(e.toString());
|
|
||||||
StackTraceElement[] stackTrace = e.getStackTrace();
|
|
||||||
if (stackTrace.length > 0) {
|
|
||||||
sb.append(" stack0: ");
|
|
||||||
sb.append(stackTrace[0]);
|
|
||||||
}
|
|
||||||
Throwable cause = e.getCause();
|
|
||||||
if (cause != null) {
|
|
||||||
sb.append(" cause: ");
|
|
||||||
formatThrowable(cause, sb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process a local committed transaction.
|
* Process a local committed transaction.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final void notifyOfCommit(SpiTransaction transaction) {
|
public final void notifyOfCommit(SpiTransaction transaction) {
|
||||||
try {
|
try {
|
||||||
if (txnLogger.isDebug()) {
|
|
||||||
txnLogger.debug(transaction.getLogPrefix() + "Commit");
|
|
||||||
}
|
|
||||||
PostCommitProcessing postCommit = new PostCommitProcessing(clusterManager, this, transaction);
|
PostCommitProcessing postCommit = new PostCommitProcessing(clusterManager, this, transaction);
|
||||||
postCommit.notifyLocalCache();
|
postCommit.notifyLocalCache();
|
||||||
backgroundExecutor.execute(postCommit.backgroundNotify());
|
backgroundExecutor.execute(postCommit.backgroundNotify());
|
||||||
@@ -673,25 +615,18 @@ public class TransactionManager implements SpiTransactionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public SpiTxnLogger logger() {
|
||||||
* Return true if Transaction debug is on.
|
return logManager.logger();
|
||||||
*/
|
}
|
||||||
public final boolean isTxnDebug() {
|
|
||||||
return txnDebug;
|
public SpiTxnLogger loggerReadOnly() {
|
||||||
|
return logManager.readOnlyLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final SpiLogManager log() {
|
public final SpiLogManager log() {
|
||||||
return logManager;
|
return logManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isLogSql() {
|
|
||||||
return logManager.sql().isDebug();
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean isLogSummary() {
|
|
||||||
return logManager.sum().isDebug();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Experimental - find dirty beans in the persistence context and persist them.
|
* Experimental - find dirty beans in the persistence context and persist them.
|
||||||
*/
|
*/
|
||||||
@@ -701,4 +636,5 @@ public class TransactionManager implements SpiTransactionManager {
|
|||||||
server.updateAll(dirtyBeans, transaction);
|
server.updateAll(dirtyBeans, transaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -43,4 +43,24 @@ public final class Str {
|
|||||||
return sb.append(s0).append(s1).toString();
|
return sb.append(s0).append(s1).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String add(String s0, String[] s1) {
|
||||||
|
if (s1 == null || s1.length == 0) {
|
||||||
|
return s0;
|
||||||
|
}
|
||||||
|
int len = s0.length();
|
||||||
|
for (String s : s1) {
|
||||||
|
if (s != null) {
|
||||||
|
len += s.length();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder(len);
|
||||||
|
sb.append(s0);
|
||||||
|
for (String s : s1) {
|
||||||
|
if (s != null) {
|
||||||
|
sb.append(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -34,7 +34,7 @@ public class TransactionManagerTest extends BaseTestCase {
|
|||||||
DataSource dataSource = transactionManager.dataSource();
|
DataSource dataSource = transactionManager.dataSource();
|
||||||
Connection connection = dataSource.getConnection();
|
Connection connection = dataSource.getConnection();
|
||||||
try {
|
try {
|
||||||
SpiTransaction externalTxn = new ExternalJdbcTransaction("external0", true, connection, null);
|
SpiTransaction externalTxn = new ExternalJdbcTransaction(true, connection, null);
|
||||||
|
|
||||||
// push an externally managed transaction onto scope
|
// push an externally managed transaction onto scope
|
||||||
ScopedTransaction scopedTransaction = transactionManager.externalBeginTransaction(externalTxn, TxScope.required());
|
ScopedTransaction scopedTransaction = transactionManager.externalBeginTransaction(externalTxn, TxScope.required());
|
||||||
|
|||||||
Reference in new issue
Block a user