[#1692] Replace Factory.executeInsert(), Factory.executeUpdate() and

similar methods with more succinct variants - Added missing parts for
executeDelete()
This commit is contained in:
Lukas Eder 2012-08-17 14:51:30 +02:00
parent 165f5218a2
commit 53e234af71
4 changed files with 103 additions and 30 deletions

View File

@ -227,7 +227,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658,
assertEquals("Fritz", author.getValue(TAuthor_FIRST_NAME()));
assertEquals("Kästner", author.getValue(TAuthor_LAST_NAME()));
create().executeDelete(TAuthor(), TAuthor_LAST_NAME().equal("Kästner"));
create().executeDelete(author);
assertEquals(null, create().fetchOne(TAuthor(), TAuthor_FIRST_NAME().equal("Erich")));
}
@ -692,7 +692,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658,
testStoreWithOptimisticLock0(TBook(), TBook_ID(), TBook_TITLE());
// Avoid referential integrity problems for subsequent test
create().executeDelete(TBook());
create().delete(TBook()).execute();
testStoreWithOptimisticLock0(TAuthor(), TAuthor_ID(), TAuthor_LAST_NAME());
}

View File

@ -1149,7 +1149,7 @@ public interface FactoryOperations extends Configuration {
/**
* Update a table
* <code><pre>UPDATE [table] SET [modified values in record] </pre></code>
* <code><pre>UPDATE [table] SET [modified values in record] WHERE [record is supplied record] </pre></code>
*
* @return The number of updated records
* @throws DataAccessException if something went wrong executing the query
@ -1168,12 +1168,36 @@ public interface FactoryOperations extends Configuration {
<R extends TableRecord<R>, T> int executeUpdate(R record, Condition condition) throws DataAccessException;
/**
* Delete records from a table <code><pre>DELETE FROM [table]</pre></code>
* Delete a record from a table
* <code><pre>DELETE FROM [table] WHERE [record is supplied record]</pre></code>
*
* @return The number of deleted records
* @throws DataAccessException if something went wrong executing the query
*/
@Support
<R extends UpdatableRecord<R>> int executeDelete(R record) throws DataAccessException;
/**
* Delete a record from a table
* <code><pre>DELETE FROM [table] WHERE [condition]</pre></code>
*
* @return The number of deleted records
* @throws DataAccessException if something went wrong executing the query
*/
@Support
<R extends TableRecord<R>, T> int executeDelete(R record, Condition condition) throws DataAccessException;
/**
* Delete records from a table <code><pre>DELETE FROM [table]</pre></code>
*
* @return The number of deleted records
* @throws DataAccessException if something went wrong executing the query
* @deprecated - 2.5.0 [#1692] - The semantics of
* {@link #executeDelete(TableRecord, Condition)} has changed.
* This method here is no longer necessary.
*/
@Deprecated
@Support
<R extends TableRecord<R>> int executeDelete(Table<R> table) throws DataAccessException;
/**
@ -1181,8 +1205,12 @@ public interface FactoryOperations extends Configuration {
* <code><pre>DELETE FROM [table] WHERE [condition]</pre></code>
*
* @return The number of deleted records
* @throws DataAccessException if something went wrong executing the query
* @throws DataAccessException if something went wrong executing the query.
* @deprecated - 2.5.0 [#1692] - The semantics of
* {@link #executeDelete(TableRecord, Condition)} has changed.
* This method here is no longer necessary.
*/
@Deprecated
@Support
<R extends TableRecord<R>, T> int executeDelete(Table<R> table, Condition condition) throws DataAccessException;
@ -1191,7 +1219,11 @@ public interface FactoryOperations extends Configuration {
*
* @return The number of deleted records
* @throws DataAccessException if something went wrong executing the query
* @deprecated - 2.5.0 [#1692] - The semantics of
* {@link #executeDelete(TableRecord, Condition)} has changed.
* This method here is no longer necessary.
*/
@Deprecated
@Support
<R extends TableRecord<R>> int executeDeleteOne(Table<R> table) throws DataAccessException;
@ -1201,7 +1233,11 @@ public interface FactoryOperations extends Configuration {
*
* @return The number of deleted records
* @throws DataAccessException if something went wrong executing the query
* @deprecated - 2.5.0 [#1692] - The semantics of
* {@link #executeDelete(TableRecord, Condition)} has changed.
* This method here is no longer necessary.
*/
@Deprecated
@Support
<R extends TableRecord<R>, T> int executeDeleteOne(Table<R> table, Condition condition) throws DataAccessException;

View File

@ -6167,6 +6167,27 @@ public class Factory implements FactoryOperations {
* {@inheritDoc}
*/
@Override
public final <R extends UpdatableRecord<R>> int executeDelete(R record) {
DeleteQuery<R> delete = deleteQuery(record.getTable());
Util.addConditions(delete, record, record.getTable().getMainKey().getFieldsArray());
return delete.execute();
}
/**
* {@inheritDoc}
*/
@Override
public final <R extends TableRecord<R>, T> int executeDelete(R record, Condition condition) {
DeleteQuery<R> delete = deleteQuery(record.getTable());
delete.addConditions(condition);
return delete.execute();
}
/**
* {@inheritDoc}
*/
@Override
@Deprecated
public final <R extends TableRecord<R>> int executeDelete(Table<R> table) {
return executeDelete(table, trueCondition());
}
@ -6175,8 +6196,9 @@ public class Factory implements FactoryOperations {
* {@inheritDoc}
*/
@Override
@Deprecated
public final <R extends TableRecord<R>, T> int executeDelete(Table<R> table, Condition condition)
{
throws DataAccessException{
DeleteQuery<R> delete = deleteQuery(table);
delete.addConditions(condition);
return delete.execute();
@ -6186,6 +6208,7 @@ public class Factory implements FactoryOperations {
* {@inheritDoc}
*/
@Override
@Deprecated
public final <R extends TableRecord<R>> int executeDeleteOne(Table<R> table) {
return executeDeleteOne(table, trueCondition());
}
@ -6194,6 +6217,7 @@ public class Factory implements FactoryOperations {
* {@inheritDoc}
*/
@Override
@Deprecated
public final <R extends TableRecord<R>, T> int executeDeleteOne(Table<R> table, Condition condition) {
DeleteQuery<R> delete = deleteQuery(table);
delete.addConditions(condition);

View File

@ -423,17 +423,17 @@ public final class FactoryProxy implements FactoryOperations {
}
@Override
public final Cursor<Record> fetchLazy(String sql) throws DataAccessException {
public final Cursor<Record> fetchLazy(String sql) {
return getDelegate().fetchLazy(sql);
}
@Override
public final Cursor<Record> fetchLazy(String sql, Object... bindings) throws DataAccessException {
public final Cursor<Record> fetchLazy(String sql, Object... bindings) {
return getDelegate().fetchLazy(sql, bindings);
}
@Override
public final Cursor<Record> fetchLazy(String sql, QueryPart... parts) throws DataAccessException {
public final Cursor<Record> fetchLazy(String sql, QueryPart... parts) {
return getDelegate().fetchLazy(sql, parts);
}
@ -468,27 +468,27 @@ public final class FactoryProxy implements FactoryOperations {
}
@Override
public final int execute(String sql) throws DataAccessException {
public final int execute(String sql) {
return getDelegate().execute(sql);
}
@Override
public final int execute(String sql, Object... bindings) throws DataAccessException {
public final int execute(String sql, Object... bindings) {
return getDelegate().execute(sql, bindings);
}
@Override
public final int execute(String sql, QueryPart... parts) throws DataAccessException {
public final int execute(String sql, QueryPart... parts) {
return getDelegate().execute(sql, parts);
}
@Override
public final ResultQuery<Record> resultQuery(String sql) throws DataAccessException {
public final ResultQuery<Record> resultQuery(String sql) {
return getDelegate().resultQuery(sql);
}
@Override
public final ResultQuery<Record> resultQuery(String sql, Object... bindings) throws DataAccessException {
public final ResultQuery<Record> resultQuery(String sql, Object... bindings) {
return getDelegate().resultQuery(sql, bindings);
}
@ -554,7 +554,7 @@ public final class FactoryProxy implements FactoryOperations {
}
@Override
public final <R extends TableRecord<R>> int executeInsert(R record) throws DataAccessException {
public final <R extends TableRecord<R>> int executeInsert(R record) {
return getDelegate().executeInsert(record);
}
@ -583,93 +583,106 @@ public final class FactoryProxy implements FactoryOperations {
}
@Override
public final <R extends UpdatableRecord<R>> int executeUpdate(R record) throws DataAccessException {
public final <R extends UpdatableRecord<R>> int executeUpdate(R record) {
return getDelegate().executeUpdate(record);
}
@Override
public final <R extends TableRecord<R>, T> int executeUpdate(R record, Condition condition)
throws DataAccessException {
public final <R extends TableRecord<R>, T> int executeUpdate(R record, Condition condition) {
return getDelegate().executeUpdate(record, condition);
}
@Override
public final <R extends UpdatableRecord<R>> int executeDelete(R record) {
return getDelegate().executeDelete(record);
}
@Override
public final <R extends TableRecord<R>, T> int executeDelete(R record, Condition condition) {
return getDelegate().executeDelete(record, condition);
}
@Override
@Deprecated
public final <R extends TableRecord<R>> int executeDelete(Table<R> table) {
return getDelegate().executeDelete(table);
}
@Override
@Deprecated
public final <R extends TableRecord<R>, T> int executeDelete(Table<R> table, Condition condition) {
return getDelegate().executeDelete(table, condition);
}
@Override
@Deprecated
public final <R extends TableRecord<R>> int executeDeleteOne(Table<R> table) {
return getDelegate().executeDeleteOne(table);
}
@Override
@Deprecated
public final <R extends TableRecord<R>, T> int executeDeleteOne(Table<R> table, Condition condition) {
return getDelegate().executeDeleteOne(table, condition);
}
@Override
public final int getTransactionIsolation() throws DataAccessException {
public final int getTransactionIsolation() {
return getDelegate().getTransactionIsolation();
}
@Override
public final void setTransactionIsolation(int level) throws DataAccessException {
public final void setTransactionIsolation(int level) {
getDelegate().setTransactionIsolation(level);
}
@Override
public final int getHoldability() throws DataAccessException {
public final int getHoldability() {
return getDelegate().getHoldability();
}
@Override
public final void setHoldability(int holdability) throws DataAccessException {
public final void setHoldability(int holdability) {
getDelegate().setHoldability(holdability);
}
@Override
public final boolean getAutoCommit() throws DataAccessException {
public final boolean getAutoCommit() {
return getDelegate().getAutoCommit();
}
@Override
public final void setAutoCommit(boolean autoCommit) throws DataAccessException {
public final void setAutoCommit(boolean autoCommit) {
getDelegate().setAutoCommit(autoCommit);
}
@Override
public final void releaseSavepoint(Savepoint savepoint) throws DataAccessException {
public final void releaseSavepoint(Savepoint savepoint) {
getDelegate().releaseSavepoint(savepoint);
}
@Override
public final Savepoint setSavepoint(String name) throws DataAccessException {
public final Savepoint setSavepoint(String name) {
return getDelegate().setSavepoint(name);
}
@Override
public final Savepoint setSavepoint() throws DataAccessException {
public final Savepoint setSavepoint() {
return getDelegate().setSavepoint();
}
@Override
public final void rollback(Savepoint savepoint) throws DataAccessException {
public final void rollback(Savepoint savepoint) {
getDelegate().rollback(savepoint);
}
@Override
public final void rollback() throws DataAccessException {
public final void rollback() {
getDelegate().rollback();
}
@Override
public final void commit() throws DataAccessException {
public final void commit() {
getDelegate().commit();
}