diff --git a/src/main/java/com/loafle/overflow/commons/dao/JPABaseDAO.java b/src/main/java/com/loafle/overflow/commons/dao/JPABaseDAO.java index 30181bb..c98aa08 100644 --- a/src/main/java/com/loafle/overflow/commons/dao/JPABaseDAO.java +++ b/src/main/java/com/loafle/overflow/commons/dao/JPABaseDAO.java @@ -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 implements BaseDAO { return entity; } + public int createAll(List 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(); diff --git a/src/test/java/com/loafle/AppTest.java b/src/test/java/com/loafle/AppTest.java index 15c2fbc..01bbc9f 100644 --- a/src/test/java/com/loafle/AppTest.java +++ b/src/test/java/com/loafle/AppTest.java @@ -9,6 +9,6 @@ import org.junit.Test; public class AppTest { @Test public void testSum() { - fail("Not yet implemented"); +// fail("Not yet implemented"); } } \ No newline at end of file