#661 - ENH: Add deletePermanent(beanType, id) and deleteAllPermanent(beanType, ids) ... (basically missing API)

This commit is contained in:
Robin Bygrave
2016-04-26 21:30:52 +12:00
parent 2067568a5e
commit 03189ac92a
12 changed files with 454 additions and 20 deletions
+14
View File
@@ -728,6 +728,13 @@ public final class Ebean {
return serverMgr.getDefaultServer().delete(beanType, id);
}
/**
* Delete permanent the bean given its type and id.
*/
public static int deletePermanent(Class<?> beanType, Object id) {
return serverMgr.getDefaultServer().deletePermanent(beanType, id);
}
/**
* Delete several beans given their type and id values.
*/
@@ -735,6 +742,13 @@ public final class Ebean {
serverMgr.getDefaultServer().deleteAll(beanType, ids);
}
/**
* Delete permanent several beans given their type and id values.
*/
public static void deleteAllPermanent(Class<?> beanType, Collection<?> ids) {
serverMgr.getDefaultServer().deleteAllPermanent(beanType, ids);
}
/**
* Delete all the beans in the Collection.
*/
+21 -3
View File
@@ -1,6 +1,5 @@
package com.avaje.ebean;
import com.avaje.ebean.annotation.CacheStrategy;
import com.avaje.ebean.cache.ServerCacheManager;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.meta.MetaInfoManager;
@@ -1351,6 +1350,16 @@ public interface EbeanServer {
*/
int delete(Class<?> beanType, Object id, Transaction transaction);
/**
* Delete permanent given the bean type and id.
*/
int deletePermanent(Class<?> beanType, Object id);
/**
* Delete permanent given the bean type and id with an explicit transaction.
*/
int deletePermanent(Class<?> beanType, Object id, Transaction transaction);
/**
* Delete all the beans in the collection.
*/
@@ -1367,11 +1376,20 @@ public interface EbeanServer {
void deleteAll(Class<?> beanType, Collection<?> ids);
/**
* Delete several beans given their type and id values with an explicit
* transaction.
* Delete several beans given their type and id values with an explicit transaction.
*/
void deleteAll(Class<?> beanType, Collection<?> ids, Transaction transaction);
/**
* Delete permanent for several beans given their type and id values.
*/
void deleteAllPermanent(Class<?> beanType, Collection<?> ids);
/**
* Delete permanent for several beans given their type and id values with an explicit transaction.
*/
void deleteAllPermanent(Class<?> beanType, Collection<?> ids, Transaction transaction);
/**
* Execute a Sql Update Delete or Insert statement. This returns the number of
* rows that where updated, deleted or inserted. If is executed in batch then
@@ -1765,11 +1765,23 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
public int delete(Class<?> beanType, Object id, Transaction t) {
return delete(beanType, id, t, false);
}
public int deletePermanent(Class<?> beanType, Object id) {
return delete(beanType, id, null, true);
}
public int deletePermanent(Class<?> beanType, Object id, Transaction t) {
return delete(beanType, id, t, true);
}
private int delete(Class<?> beanType, Object id, Transaction t, boolean permanent) {
TransWrapper wrap = initTransIfRequired(t);
try {
SpiTransaction trans = wrap.transaction;
int rowCount = persister.delete(beanType, id, trans);
int rowCount = persister.delete(beanType, id, trans, permanent);
wrap.commitIfCreated();
return rowCount;
@@ -1787,11 +1799,25 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
@Override
public void deleteAll(Class<?> beanType, Collection<?> ids, Transaction t) {
deleteAll(beanType, ids, t, false);
}
@Override
public void deleteAllPermanent(Class<?> beanType, Collection<?> ids) {
deleteAll(beanType, ids, null, true);
}
@Override
public void deleteAllPermanent(Class<?> beanType, Collection<?> ids, Transaction t) {
deleteAll(beanType, ids, t, true);
}
private void deleteAll(Class<?> beanType, Collection<?> ids, Transaction t, boolean permanent) {
TransWrapper wrap = initTransIfRequired(t);
try {
SpiTransaction trans = wrap.transaction;
persister.deleteMany(beanType, ids, trans);
persister.deleteMany(beanType, ids, trans, permanent);
wrap.commitIfCreated();
} catch (RuntimeException e) {
@@ -61,7 +61,7 @@ public interface Persister {
* This will also cascade delete one level of children.
* </p>
*/
int delete(Class<?> beanType, Object id, Transaction transaction);
int delete(Class<?> beanType, Object id, Transaction transaction, boolean permanent);
/**
* Delete the bean.
@@ -71,7 +71,7 @@ public interface Persister {
/**
* Delete multiple beans given a collection of Id values.
*/
void deleteMany(Class<?> beanType, Collection<?> ids, Transaction transaction);
void deleteMany(Class<?> beanType, Collection<?> ids, Transaction transaction, boolean permanent);
/**
* Execute the Update.
@@ -559,14 +559,13 @@ public final class DefaultPersister implements Persister {
private void deleteList(List<?> beanList, Transaction t, boolean softDelete) {
for (int i = 0; i < beanList.size(); i++) {
deleteRecurse((EntityBean) beanList.get(i), t, softDelete);
//delete((EntityBean) beanList.get(i), t);
}
}
/**
* Delete by a List of Id's.
*/
public void deleteMany(Class<?> beanType, Collection<?> ids, Transaction transaction) {
public void deleteMany(Class<?> beanType, Collection<?> ids, Transaction transaction, boolean permanent) {
if (ids == null || ids.size() == 0) {
return;
@@ -580,19 +579,18 @@ public final class DefaultPersister implements Persister {
idList.add(descriptor.convertId(id));
}
delete(descriptor, null, idList, transaction, descriptor.isSoftDelete());
boolean softDelete = !permanent && descriptor.isSoftDelete();
delete(descriptor, null, idList, transaction, softDelete);
}
/**
* Delete by Id.
*/
public int delete(Class<?> beanType, Object id, Transaction transaction) {
public int delete(Class<?> beanType, Object id, Transaction transaction, boolean permanent) {
BeanDescriptor<?> descriptor = beanDescriptorManager.getBeanDescriptor(beanType);
// convert to appropriate type if required
id = descriptor.convertId(id);
return delete(descriptor, id, null, transaction, descriptor.isSoftDelete());
boolean softDelete = !permanent && descriptor.isSoftDelete();
return delete(descriptor, id, null, transaction, softDelete);
}
/**