diff --git a/.gitignore b/.gitignore index 77344b780..2befb7af3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ .settings/ target/ logs/ +.idea/ +*.iml + diff --git a/pom.xml b/pom.xml index 20b97d276..55b07566f 100644 --- a/pom.xml +++ b/pom.xml @@ -16,8 +16,7 @@ UTF-8 - 3.0.0.RELEASE - 3.2.1 + 4.1.7.RELEASE http://www.avaje.org @@ -41,17 +40,28 @@ org.avaje.ebeanorm avaje-ebeanorm - [4,5) + [6,7) org.avaje.ebeanorm avaje-ebeanorm-agent - 3.2.1 - test + [4.5,5) + + + + org.avaje + avaje-agentloader + 2.1.2 + + org.springframework + spring-context + ${spring.framework.version} + + org.springframework spring-core @@ -106,33 +116,14 @@ org.slf4j jcl-over-slf4j - [1.6.2] + 1.7.12 - junit - junit - 4.8.2 - test - - - - org.apache.xbean - xbean-spring - 3.5 - test - - - commons-logging - commons-logging - - - - - - com.h2database - h2 - 1.2.128 + org.avaje.composite + avaje-composite-testing-ebean + 4.1 + pom test @@ -143,7 +134,7 @@ org.avaje.ebeanorm avaje-ebeanorm-mavenenhancer - ${ebean.mavenenhancer.version} + 4.5.3 main @@ -189,7 +180,7 @@ avaje-ebeanorm-mavenenhancer - [3.2.1,3.9) + [3,4) enhance diff --git a/src/test/java/com/avaje/test/springsupport/Account.java b/src/test/java/com/avaje/test/springsupport/Account.java index a527e9652..12043ed5d 100644 --- a/src/test/java/com/avaje/test/springsupport/Account.java +++ b/src/test/java/com/avaje/test/springsupport/Account.java @@ -1,18 +1,18 @@ /** * Copyright (C) 2009 the original author or authors - * + *

* This file is part of Ebean. - * + *

* Ebean is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. - * + *

* Ebean is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + *

* You should have received a copy of the GNU Lesser General Public License * along with Ebean; if not, write to the Free Software Foundation, Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -31,47 +31,27 @@ import javax.persistence.OneToOne; @Entity public class Account { - /** The oid. */ - @Id - private long oid; + /** The id. */ + @Id + private Long id; - /** The user. */ - @OneToOne - private User user; + /** The user. */ + @OneToOne + private User user; - /** - * Gets the oid. - * - * @return the oid - */ - public long getOid() { - return oid; - } + public Long getId() { + return id; + } - /** - * Sets the oid. - * - * @param oid the oid to set - */ - public void setOid(long oid) { - this.oid = oid; - } + public void setId(Long id) { + this.id = id; + } - /** - * Gets the user. - * - * @return the user - */ - public User getUser() { - return user; - } + public User getUser() { + return user; + } - /** - * Sets the user. - * - * @param user the user to set - */ - public void setUser(User user) { - this.user = user; - } + public void setUser(User user) { + this.user = user; + } } diff --git a/src/test/java/com/avaje/test/springsupport/EbeanSpringModuleTest.java b/src/test/java/com/avaje/test/springsupport/EbeanSpringModuleTest.java index 2eecfd646..54f50f495 100644 --- a/src/test/java/com/avaje/test/springsupport/EbeanSpringModuleTest.java +++ b/src/test/java/com/avaje/test/springsupport/EbeanSpringModuleTest.java @@ -1,18 +1,18 @@ /** * Copyright (C) 2009 the original author or authors - * + *

* This file is part of Ebean. - * + *

* Ebean is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. - * + *

* Ebean is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + *

* You should have received a copy of the GNU Lesser General Public License * along with Ebean; if not, write to the Free Software Foundation, Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -25,74 +25,79 @@ import static org.junit.Assert.assertTrue; import java.util.logging.Logger; import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Unit test for Ebean Spring Module. * @since 18.05.2009 * @author E Mc Greal */ -@ContextConfiguration(locations={"/init-database.xml"}) -public class EbeanSpringModuleTest extends AbstractJUnit4SpringContextTests { +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = {"/init-database.xml"}) +public class EbeanSpringModuleTest { - /** The Constant logger. */ - private final static Logger logger = Logger.getLogger(EbeanSpringModuleTest.class.getName()); + /** The Constant logger. */ + private final static Logger logger = Logger.getLogger(EbeanSpringModuleTest.class.getName()); - /** The user service. */ - @Autowired - private UserService userService; + /** The user service. */ + @Autowired + private UserService userService; - /** - * Create the test case. - */ - public EbeanSpringModuleTest(){ - super(); - } + /** + * Create the test case. + */ + public EbeanSpringModuleTest() { + super(); + } - /** - * Test app. - */ - @Test - public void testSaveUser(){ - logger.info("Saving new User..."); - User user = new User(); - user.setName("ebean"); - userService.save(user); - logger.info("Saved new User"); - } + @Test + public void testBatchInsert() { - /** - * Test app. - */ - @Test - public void testFindUser(){ - logger.info("Finding User with OID = 1 ..."); - User user = userService.find(1); + userService.batchInsert(); + } - assertNotNull(user); - assertTrue("ebean".equals(user.getName())); - logger.info("Found User with OID = 1"); - } + /** + * Test app. + */ + @Test + public void testSaveUser() { + logger.info("Saving new User..."); + User user = new User(); + user.setName("ebean"); + userService.save(user); + logger.info("Saved new User"); + } - /** - * Gets the user service. - * - * @return the userService - */ - public UserService getUserService() { - return userService; - } + /** + * Test app. + */ + @Test + public void testFindUser() { + logger.info("Finding User with OID = 1 ..."); + User user = userService.find(1); + + assertNotNull(user); + assertTrue("ebean".equals(user.getName())); + logger.info("Found User with OID = 1"); + } + + /** + * Return the user service. + */ + public UserService getUserService() { + return userService; + } - /** - * Sets the user service. - * - * @param userService the userService to set - */ - public void setUserService(UserService userService) { - this.userService = userService; - } + /** + * Sets the user service. + */ + public void setUserService(UserService userService) { + this.userService = userService; + } } diff --git a/src/test/java/com/avaje/test/springsupport/Role.java b/src/test/java/com/avaje/test/springsupport/Role.java index e6fed39d2..02381291e 100644 --- a/src/test/java/com/avaje/test/springsupport/Role.java +++ b/src/test/java/com/avaje/test/springsupport/Role.java @@ -1,18 +1,18 @@ /** * Copyright (C) 2009 the original author or authors - * + *

* This file is part of Ebean. - * + *

* Ebean is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. - * + *

* Ebean is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + *

* You should have received a copy of the GNU Lesser General Public License * along with Ebean; if not, write to the Free Software Foundation, Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -34,40 +34,28 @@ import javax.persistence.ManyToMany; */ @Entity public class Role { - @Id - long oid; - @ManyToMany - private Set users = new HashSet(); + @Id + Long id; - /** - * @return the oid - */ - public long getOid() { - return oid; - } + @ManyToMany + private Set users; - /** - * @param oid the oid to set - */ - public void setOid(long oid) { - this.oid = oid; - } + public Long getId() { + return id; + } - /** - * @return the users - */ - public Set getUsers() { - return users; - } + public void setId(Long id) { + this.id = id; + } - /** - * @param users the users to set - */ - public void setUsers(Set users) { - this.users = users; - } + public Set getUsers() { + return users; + } + public void setUsers(Set users) { + this.users = users; + } } diff --git a/src/test/java/com/avaje/test/springsupport/User.java b/src/test/java/com/avaje/test/springsupport/User.java index 430d777b7..eccf35e1a 100644 --- a/src/test/java/com/avaje/test/springsupport/User.java +++ b/src/test/java/com/avaje/test/springsupport/User.java @@ -17,16 +17,13 @@ * along with Ebean; if not, write to the Free Software Foundation, Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - package com.avaje.test.springsupport; -import java.util.HashSet; -import java.util.Set; - import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.OneToOne; +import java.util.Set; /** * The Class User. @@ -41,63 +38,39 @@ public class User { private String name; @ManyToMany - private Set roles = new HashSet(); + private Set roles; @OneToOne(mappedBy="user") private Account account; - /** - * @return the oid - */ public long getOid() { return oid; } - /** - * @param oid the oid to set - */ public void setOid(long oid) { this.oid = oid; } - /** - * @return the roles - */ public Set getRoles() { return roles; } - /** - * @param roles the roles to set - */ public void setRoles(Set roles) { this.roles = roles; } - /** - * @return the name - */ public String getName() { return name; } - /** - * @param name the name to set - */ public void setName(String name) { this.name = name; } - /** - * @return the account - */ public Account getAccount() { return account; } - /** - * @param account the account to set - */ public void setAccount(Account account) { this.account = account; } diff --git a/src/test/java/com/avaje/test/springsupport/UserService.java b/src/test/java/com/avaje/test/springsupport/UserService.java index 072824263..8da63c0ae 100644 --- a/src/test/java/com/avaje/test/springsupport/UserService.java +++ b/src/test/java/com/avaje/test/springsupport/UserService.java @@ -26,6 +26,10 @@ package com.avaje.test.springsupport; * @author E Mc Greal */ public interface UserService { - public void save(User user); - public User find(long oid); + + void save(User user); + + User find(long id); + + void batchInsert(); } diff --git a/src/test/java/com/avaje/test/springsupport/UserServiceImpl.java b/src/test/java/com/avaje/test/springsupport/UserServiceImpl.java index eab077042..8bb82c305 100644 --- a/src/test/java/com/avaje/test/springsupport/UserServiceImpl.java +++ b/src/test/java/com/avaje/test/springsupport/UserServiceImpl.java @@ -20,12 +20,17 @@ package com.avaje.test.springsupport; +import com.avaje.ebean.Transaction; +import com.avaje.ebean.config.PersistBatch; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import com.avaje.ebean.EbeanServer; +import java.util.ArrayList; +import java.util.List; + /** * The Class UserServiceImpl. * @@ -47,15 +52,35 @@ public class UserServiceImpl implements UserService { } @Transactional(readOnly = true, propagation = Propagation.REQUIRED) - public User find(long oid) { - return ebeanServer.find(User.class, oid); + public User find(long id) { + return ebeanServer.find(User.class, id); } + @Transactional(readOnly = false, propagation = Propagation.REQUIRED) + public void batchInsert(){ + + List users = new ArrayList(); + for(int i=0 ;i<5;i++){ + User user = new User(); + user.setName("user"+i); + users.add(user); + } + + System.out.println("---------before batch-------"); + + Transaction tx = ebeanServer.beginTransaction(); + tx.setBatch(PersistBatch.NONE); + tx.setBatchOnCascade(PersistBatch.ALL); + tx.setBatchSize(20); + ebeanServer.saveAll(users);// + + System.out.println("---------after batch-------"); + } + + /** - * Gets the ebean server. - * - * @return the ebeanServer + * Return the ebean server. */ public EbeanServer getEbeanServer() { return ebeanServer; @@ -63,8 +88,6 @@ public class UserServiceImpl implements UserService { /** * Sets the ebean server. - * - * @param ebeanServer the ebeanServer to set */ public void setEbeanServer(EbeanServer ebeanServer) { this.ebeanServer = ebeanServer; diff --git a/src/test/resources/init-database.xml b/src/test/resources/init-database.xml index 220ba5051..42fea58d6 100644 --- a/src/test/resources/init-database.xml +++ b/src/test/resources/init-database.xml @@ -14,11 +14,15 @@ - - - - + + + + + + + + diff --git a/src/test/resources/jndi.properties b/src/test/resources/jndi.properties deleted file mode 100644 index a954f4c9c..000000000 --- a/src/test/resources/jndi.properties +++ /dev/null @@ -1 +0,0 @@ -java.naming.factory.initial = org.apache.xbean.spring.jndi.SpringInitialContextFactory diff --git a/src/test/resources/jndi.xml b/src/test/resources/jndi.xml deleted file mode 100644 index f7af2db77..000000000 --- a/src/test/resources/jndi.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file