added
createAll
This commit is contained in:
parent
ab7e579b52
commit
809f91c195
|
@ -5,6 +5,7 @@ import javax.persistence.EntityTransaction;
|
|||
import javax.persistence.Persistence;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by insanity on 17. 5. 25.
|
||||
|
@ -41,6 +42,22 @@ public class JPABaseDAO<T> implements BaseDAO<T> {
|
|||
return entity;
|
||||
}
|
||||
|
||||
public int createAll(List<T> entityList) {
|
||||
EntityTransaction tx = this.entityManager.getTransaction();
|
||||
if (!tx.isActive()) tx.begin();
|
||||
try {
|
||||
|
||||
for(T ent : entityList) {
|
||||
this.entityManager.persist(ent);
|
||||
}
|
||||
tx.commit();
|
||||
}catch(Exception e) {
|
||||
tx.rollback();
|
||||
return 0;
|
||||
}
|
||||
return entityList.size();
|
||||
}
|
||||
|
||||
public T update(T entity) {
|
||||
EntityTransaction tx = this.entityManager.getTransaction();
|
||||
if (!tx.isActive()) tx.begin();
|
||||
|
|
|
@ -9,6 +9,6 @@ import org.junit.Test;
|
|||
public class AppTest {
|
||||
@Test
|
||||
public void testSum() {
|
||||
fail("Not yet implemented");
|
||||
// fail("Not yet implemented");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user