#993 - ENH: Add flush() to EbeanServer and Model to make it more accessible than the current transaction.flushBatch()

This commit is contained in:
Rob Bygrave
2017-03-13 23:07:17 +13:00
parent 1d99a5c5a4
commit 4d82b86f81
8 changed files with 81 additions and 2 deletions
+13
View File
@@ -613,6 +613,19 @@ public interface EbeanServer {
*/
Transaction currentTransaction();
/**
* Flush the JDBC batch on the current transaction.
* <p>
* This only is useful when JDBC batch is used. Flush occurs automatically when the
* transaction commits or batch size is reached. This manually flushes the JDBC batch
* buffer.
* </p>
* <p>
* This is the same as <code>currentTransaction().flush()</code>.
* </p>
*/
void flush();
/**
* Commit the current transaction.
*/
+11
View File
@@ -190,6 +190,17 @@ public abstract class Model {
db().save(this);
}
/**
* Flush any batched changes to the database.
* <p>
* When using JDBC batch flushing occurs automatically at commit() time or when the batch size
* is reached. This provides the ability to manually flush the batch.
* </p>
*/
public void flush() {
db().flush();
}
/**
* Update this entity.
*
+8
View File
@@ -429,6 +429,14 @@ public interface Transaction extends AutoCloseable {
* <li>Transaction commit occurs</li>
* </ul>
*/
void flush() throws PersistenceException;
/**
* This is a synonym for flush() and will be deprecated.
* <p>
* flush() is preferred as it matches the JPA flush() method.
* </p>
*/
void flushBatch() throws PersistenceException;
/**
@@ -295,9 +295,14 @@ public class ScopedTransaction implements SpiTransaction {
return transaction.isBatchFlushOnQuery();
}
@Override
public void flush() throws PersistenceException {
transaction.flush();
}
@Override
public void flushBatch() throws PersistenceException {
transaction.flushBatch();
flush();
}
@Override
@@ -840,6 +840,11 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
return transactionScopeManager.get();
}
@Override
public void flush() {
currentTransaction().flush();
}
/**
* Commit the current transaction.
*/
@@ -731,13 +731,18 @@ public class JdbcTransaction implements SpiTransaction {
* </p>
*/
@Override
public void flushBatch() {
public void flush() {
if (!isActive()) {
throw new IllegalStateException(illegalStateMessage);
}
internalBatchFlush();
}
@Override
public void flushBatch() {
flush();
}
/**
* Flush the JDBC batch and execute derived relationship statements if necessary.
*/