mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#326 - API Addition - saveAll(), deleteAll() etc
This commit is contained in:
@@ -559,10 +559,20 @@ public final class Ebean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated - please migrate to insertAll().
|
||||
*
|
||||
* Insert a collection of beans.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void insert(Collection<?> beans) {
|
||||
serverMgr.getDefaultServer().insert(beans);
|
||||
serverMgr.getDefaultServer().insertAll(beans);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a collection of beans.
|
||||
*/
|
||||
public static void insertAll(Collection<?> beans) {
|
||||
serverMgr.getDefaultServer().insertAll(beans);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -630,24 +640,46 @@ public final class Ebean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecate - please migrate to updateAll().
|
||||
*
|
||||
* Update the beans in the collection.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void update(Collection<?> beans) throws OptimisticLockException {
|
||||
serverMgr.getDefaultServer().update(beans);
|
||||
serverMgr.getDefaultServer().updateAll(beans);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the beans in the collection.
|
||||
*/
|
||||
public static void updateAll(Collection<?> beans) throws OptimisticLockException {
|
||||
serverMgr.getDefaultServer().updateAll(beans);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated - please change to iterate yourself and save().
|
||||
*
|
||||
* Save all the beans from an Iterator.
|
||||
*/
|
||||
@Deprecated
|
||||
public static int save(Iterator<?> iterator) throws OptimisticLockException {
|
||||
return serverMgr.getDefaultServer().save(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated - please migrate to saveAll().
|
||||
*
|
||||
* Save all the beans from a Collection.
|
||||
*/
|
||||
public static int save(Collection<?> beans) throws OptimisticLockException {
|
||||
return serverMgr.getDefaultServer().save(beans);
|
||||
return serverMgr.getDefaultServer().saveAll(beans);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all the beans from a Collection.
|
||||
*/
|
||||
public static int saveAll(Collection<?> beans) throws OptimisticLockException {
|
||||
return serverMgr.getDefaultServer().saveAll(beans);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -721,10 +753,13 @@ public final class Ebean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated - please migrate to deleteAll().
|
||||
*
|
||||
* Delete several beans given their type and id values.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void delete(Class<?> beanType, Collection<?> ids) {
|
||||
serverMgr.getDefaultServer().delete(beanType, ids);
|
||||
serverMgr.getDefaultServer().deleteAll(beanType, ids);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -737,8 +772,16 @@ public final class Ebean {
|
||||
/**
|
||||
* Delete all the beans from a Collection.
|
||||
*/
|
||||
public static int delete(Collection<?> c) throws OptimisticLockException {
|
||||
return delete(c.iterator());
|
||||
@Deprecated
|
||||
public static int delete(Collection<?> beans) throws OptimisticLockException {
|
||||
return serverMgr.getDefaultServer().deleteAll(beans);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the beans in the Collection.
|
||||
*/
|
||||
public static int deleteAll(Collection<?> beans) throws OptimisticLockException {
|
||||
return serverMgr.getDefaultServer().deleteAll(beans);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1441,8 +1484,7 @@ public final class Ebean {
|
||||
* @param deletes
|
||||
* true if rows on the table where deleted
|
||||
*/
|
||||
public static void externalModification(String tableName, boolean inserts, boolean updates,
|
||||
boolean deletes) {
|
||||
public static void externalModification(String tableName, boolean inserts, boolean updates, boolean deletes) {
|
||||
|
||||
serverMgr.getDefaultServer().externalModification(tableName, inserts, updates, deletes);
|
||||
}
|
||||
|
||||
@@ -1223,14 +1223,25 @@ public interface EbeanServer {
|
||||
void save(Object bean) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Deprecated - please change to iterate yourself and save.
|
||||
*
|
||||
* Save all the beans in the iterator.
|
||||
*/
|
||||
@Deprecated
|
||||
int save(Iterator<?> it) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Deprecated - please migrate to saveAll().
|
||||
*
|
||||
* Save all the beans in the collection.
|
||||
*/
|
||||
@Deprecated
|
||||
int save(Collection<?> beans) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Save all the beans in the collection.
|
||||
*/
|
||||
int save(Collection<?> beans) throws OptimisticLockException;
|
||||
int saveAll(Collection<?> beans) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Delete the bean.
|
||||
@@ -1242,14 +1253,25 @@ public interface EbeanServer {
|
||||
void delete(Object bean) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Deprecated - please change to iterate yourself and delete.
|
||||
*
|
||||
* Delete all the beans from an Iterator.
|
||||
*/
|
||||
@Deprecated
|
||||
int delete(Iterator<?> it) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Deprecated - please migrate to deleteAll().
|
||||
*
|
||||
* Delete all the beans in the collection.
|
||||
*/
|
||||
@Deprecated
|
||||
int delete(Collection<?> beans) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Delete all the beans in the collection.
|
||||
*/
|
||||
int delete(Collection<?> c) throws OptimisticLockException;
|
||||
int deleteAll(Collection<?> beans) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Delete the bean given its type and id.
|
||||
@@ -1262,15 +1284,45 @@ public interface EbeanServer {
|
||||
int delete(Class<?> beanType, Object id, Transaction transaction);
|
||||
|
||||
/**
|
||||
* Deprecated - please migrate to deleteAll().
|
||||
*
|
||||
* Delete several beans given their type and id values.
|
||||
*/
|
||||
@Deprecated
|
||||
void delete(Class<?> beanType, Collection<?> ids);
|
||||
|
||||
/**
|
||||
* Delete several beans given their type and id values.
|
||||
*/
|
||||
void deleteAll(Class<?> beanType, Collection<?> ids);
|
||||
|
||||
/**
|
||||
* Deprecated - please migrate to deleteAll().
|
||||
*
|
||||
* Delete several beans given their type and id values with an explicit
|
||||
* transaction.
|
||||
*/
|
||||
@Deprecated
|
||||
void delete(Class<?> beanType, Collection<?> ids, Transaction transaction);
|
||||
|
||||
/**
|
||||
* Delete several beans given their type and id values with an explicit
|
||||
* transaction.
|
||||
*/
|
||||
void delete(Class<?> beanType, Collection<?> ids, Transaction transaction);
|
||||
void deleteAll(Class<?> beanType, Collection<?> ids, Transaction transaction);
|
||||
|
||||
/**
|
||||
* Delete the bean with an explicit transaction.
|
||||
*/
|
||||
void delete(Object bean, Transaction transaction) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Deprecated - please migrate to iterate yourself and delete().
|
||||
*
|
||||
* Delete all the beans from an iterator.
|
||||
*/
|
||||
@Deprecated
|
||||
int delete(Iterator<?> it, Transaction transaction) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Execute a Sql Update Delete or Insert statement. This returns the number of
|
||||
@@ -1413,14 +1465,24 @@ public interface EbeanServer {
|
||||
void save(Object bean, Transaction transaction) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Deprecated - please change to iterate yourself and save.
|
||||
* Save all the beans in the iterator with an explicit transaction.
|
||||
*/
|
||||
@Deprecated
|
||||
int save(Iterator<?> it, Transaction transaction) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Deprecated - please migrate to saveAll().
|
||||
*
|
||||
* Save all the beans in the collection with an explicit transaction.
|
||||
*/
|
||||
@Deprecated
|
||||
int save(Collection<?> beans, Transaction transaction) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Save all the beans in the collection with an explicit transaction.
|
||||
*/
|
||||
int save(Collection<?> beans, Transaction transaction) throws OptimisticLockException;
|
||||
int saveAll(Collection<?> beans, Transaction transaction) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Marks the entity bean as dirty.
|
||||
@@ -1502,16 +1564,33 @@ public interface EbeanServer {
|
||||
void update(Object bean, Transaction transaction, boolean deleteMissingChildren) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Deprecated - please migrate to updateAll().
|
||||
*
|
||||
* Update a collection of beans. If there is no current transaction one is created and used to
|
||||
* update all the beans in the collection.
|
||||
*/
|
||||
@Deprecated
|
||||
void update(Collection<?> beans) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Update a collection of beans. If there is no current transaction one is created and used to
|
||||
* update all the beans in the collection.
|
||||
*/
|
||||
void updateAll(Collection<?> beans) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Deprecated - please migrate to updateAll().
|
||||
*
|
||||
* Update a collection of beans with an explicit transaction.
|
||||
*/
|
||||
@Deprecated
|
||||
void update(Collection<?> beans, Transaction transaction) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Update a collection of beans with an explicit transaction.
|
||||
*/
|
||||
void update(Collection<?> beans, Transaction transaction) throws OptimisticLockException;
|
||||
|
||||
void updateAll(Collection<?> beans, Transaction transaction) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Insert the bean.
|
||||
* <p>
|
||||
@@ -1528,15 +1607,32 @@ public interface EbeanServer {
|
||||
void insert(Object bean, Transaction transaction);
|
||||
|
||||
/**
|
||||
* Deprecated - please migrate to insertAll().
|
||||
*
|
||||
* Insert a collection of beans. If there is no current transaction one is created and used to
|
||||
* insert all the beans in the collection.
|
||||
*/
|
||||
@Deprecated
|
||||
void insert(Collection<?> beans);
|
||||
|
||||
/**
|
||||
* Insert a collection of beans. If there is no current transaction one is created and used to
|
||||
* insert all the beans in the collection.
|
||||
*/
|
||||
void insertAll(Collection<?> beans);
|
||||
|
||||
/**
|
||||
* Deprecated - please migrate to insertAll().
|
||||
*
|
||||
* Insert a collection of beans with an explicit transaction.
|
||||
*/
|
||||
@Deprecated
|
||||
void insert(Collection<?> beans, Transaction transaction);
|
||||
|
||||
/**
|
||||
* Insert a collection of beans with an explicit transaction.
|
||||
*/
|
||||
void insert(Collection<?> beans, Transaction transaction);
|
||||
void insertAll(Collection<?> beans, Transaction transaction);
|
||||
|
||||
/**
|
||||
* Delete the associations (from the intersection table) of a ManyToMany given
|
||||
@@ -1545,7 +1641,7 @@ public interface EbeanServer {
|
||||
* Typically these deletions occur automatically when persisting a ManyToMany
|
||||
* collection and this provides a way to invoke those deletions directly.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @return the number of associations deleted (from the intersection table).
|
||||
*/
|
||||
int deleteManyToManyAssociations(Object ownerBean, String propertyName);
|
||||
@@ -1560,7 +1656,7 @@ public interface EbeanServer {
|
||||
* Typically these deletions occur automatically when persisting a ManyToMany
|
||||
* collection and this provides a way to invoke those deletions directly.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @return the number of associations deleted (from the intersection table).
|
||||
*/
|
||||
int deleteManyToManyAssociations(Object ownerBean, String propertyName, Transaction transaction);
|
||||
@@ -1624,15 +1720,6 @@ public interface EbeanServer {
|
||||
*/
|
||||
void saveAssociation(Object ownerBean, String propertyName, Transaction transaction);
|
||||
|
||||
/**
|
||||
* Delete the bean with an explicit transaction.
|
||||
*/
|
||||
void delete(Object bean, Transaction transaction) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Delete all the beans from an iterator.
|
||||
*/
|
||||
int delete(Iterator<?> it, Transaction transaction) throws OptimisticLockException;
|
||||
|
||||
/**
|
||||
* Execute explicitly passing a transaction.
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.slf4j.LoggerFactory;
|
||||
import javax.management.InstanceAlreadyExistsException;
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
import javax.persistence.OptimisticLockException;
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -1171,7 +1172,7 @@ public final class DefaultServer implements SpiEbeanServer {
|
||||
|
||||
BeanDescriptor<T> desc = beanDescriptorManager.getBeanDescriptor(q.getBeanType());
|
||||
|
||||
T bean = desc.cacheNaturalKeyLookup(q, (SpiTransaction)t);
|
||||
T bean = desc.cacheNaturalKeyLookup(q, (SpiTransaction) t);
|
||||
if (bean != null) {
|
||||
return bean;
|
||||
}
|
||||
@@ -1503,13 +1504,23 @@ public final class DefaultServer implements SpiEbeanServer {
|
||||
* Update all beans in the collection.
|
||||
*/
|
||||
public void update(Collection<?> beans) {
|
||||
update(beans, null);
|
||||
updateAll(beans, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateAll(Collection<?> beans) throws OptimisticLockException {
|
||||
updateAll(beans, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Collection<?> beans, Transaction transaction) throws OptimisticLockException {
|
||||
updateAll(beans, transaction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all beans in the collection with an explicit transaction.
|
||||
*/
|
||||
public void update(Collection<?> beans, Transaction t) {
|
||||
public void updateAll(Collection<?> beans, Transaction t) {
|
||||
|
||||
if (beans == null || beans.isEmpty()) {
|
||||
// Nothing to update?
|
||||
@@ -1547,14 +1558,24 @@ public final class DefaultServer implements SpiEbeanServer {
|
||||
/**
|
||||
* Insert all beans in the collection.
|
||||
*/
|
||||
public void insert(Collection<?> beans) {
|
||||
insert(beans, null);
|
||||
public void insertAll(Collection<?> beans) {
|
||||
insertAll(beans, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void insert(Collection<?> beans) {
|
||||
insertAll(beans, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insert(Collection<?> beans, Transaction transaction) {
|
||||
insertAll(beans, transaction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert all beans in the collection with a transaction.
|
||||
*/
|
||||
public void insert(Collection<?> beans, Transaction t) {
|
||||
public void insertAll(Collection<?> beans, Transaction t) {
|
||||
|
||||
if (beans == null || beans.isEmpty()) {
|
||||
// Nothing to insert?
|
||||
@@ -1674,7 +1695,7 @@ public final class DefaultServer implements SpiEbeanServer {
|
||||
* number of beans that where saved.
|
||||
*/
|
||||
public int save(Iterator<?> it) {
|
||||
return save(it, null);
|
||||
return saveAllInternal(it, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1682,7 +1703,7 @@ public final class DefaultServer implements SpiEbeanServer {
|
||||
* number of beans that where saved.
|
||||
*/
|
||||
public int save(Collection<?> c) {
|
||||
return save(c.iterator(), null);
|
||||
return saveAllInternal(c.iterator(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1690,13 +1711,28 @@ public final class DefaultServer implements SpiEbeanServer {
|
||||
* number of beans that where saved.
|
||||
*/
|
||||
public int save(Collection<?> c, Transaction t) {
|
||||
return save(c.iterator(), t);
|
||||
return saveAllInternal(c.iterator(), t);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int save(Iterator<?> it, Transaction transaction) throws OptimisticLockException {
|
||||
return saveAllInternal(it, transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveAll(Collection<?> beans, Transaction transaction) throws OptimisticLockException {
|
||||
return saveAllInternal(beans.iterator(), transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveAll(Collection<?> beans) throws OptimisticLockException {
|
||||
return saveAllInternal(beans.iterator(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all beans in the iterator with an explicit transaction.
|
||||
*/
|
||||
public int save(Iterator<?> it, Transaction t) {
|
||||
public int saveAllInternal(Iterator<?> it, Transaction t) {
|
||||
|
||||
TransWrapper wrap = initTransIfRequired(t);
|
||||
try {
|
||||
@@ -1739,11 +1775,23 @@ public final class DefaultServer implements SpiEbeanServer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Class<?> beanType, Collection<?> ids) {
|
||||
delete(beanType, ids, null);
|
||||
deleteAll(beanType, ids, null);
|
||||
}
|
||||
|
||||
public void delete(Class<?> beanType, Collection<?> ids, Transaction t) {
|
||||
@Override
|
||||
public void delete(Class<?> beanType, Collection<?> ids, Transaction transaction) {
|
||||
deleteAll(beanType, ids, transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(Class<?> beanType, Collection<?> ids) {
|
||||
deleteAll(beanType, ids, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(Class<?> beanType, Collection<?> ids, Transaction t) {
|
||||
|
||||
TransWrapper wrap = initTransIfRequired(t);
|
||||
try {
|
||||
@@ -1775,21 +1823,36 @@ public final class DefaultServer implements SpiEbeanServer {
|
||||
/**
|
||||
* Delete all the beans in the iterator.
|
||||
*/
|
||||
@Override
|
||||
public int delete(Iterator<?> it) {
|
||||
return delete(it, null);
|
||||
return deleteAllInternal(it, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the beans in the collection.
|
||||
*/
|
||||
public int delete(Collection<?> c) {
|
||||
return delete(c.iterator(), null);
|
||||
@Override
|
||||
public int delete(Collection<?> beans) {
|
||||
return deleteAllInternal(beans.iterator(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Iterator<?> it, Transaction transaction) throws OptimisticLockException {
|
||||
return deleteAllInternal(it, transaction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the beans in the collection.
|
||||
*/
|
||||
@Override
|
||||
public int deleteAll(Collection<?> beans) {
|
||||
return deleteAllInternal(beans.iterator(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the beans in the iterator with an explicit transaction.
|
||||
*/
|
||||
public int delete(Iterator<?> it, Transaction t) {
|
||||
private int deleteAllInternal(Iterator<?> it, Transaction t) {
|
||||
|
||||
TransWrapper wrap = initTransIfRequired(t);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user