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

This commit is contained in:
Robin Bygrave committed 2016-04-26 21:30:52 +12:00
1 parent 2067568a5e
commit 03189ac92a
12 files changed
+454 -20

No files matched your search

@@ -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);
}
/**