initial add of EbeanORM spring from v2.8.1

This commit is contained in:
rbygrave
2012-09-14 01:06:56 +12:00
parent 1665b4f2fa
commit 6d8a9236f8
16 changed files with 1065 additions and 0 deletions
@@ -0,0 +1,77 @@
/**
* 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
*/
package com.avaje.ebean.springsupport;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
/**
* The Class Account.
* @since 18.05.2009
* @author E Mc Greal
*/
@Entity
public class Account {
/** The oid. */
@Id
private long oid;
/** The user. */
@OneToOne
private User user;
/**
* Gets the oid.
*
* @return the oid
*/
public long getOid() {
return oid;
}
/**
* Sets the oid.
*
* @param oid the oid to set
*/
public void setOid(long oid) {
this.oid = oid;
}
/**
* Gets the user.
*
* @return the user
*/
public User getUser() {
return user;
}
/**
* Sets the user.
*
* @param user the user to set
*/
public void setUser(User user) {
this.user = user;
}
}
@@ -0,0 +1,98 @@
/**
* 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
*/
package com.avaje.ebean.springsupport;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.logging.Logger;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
/**
* Unit test for Ebean Spring Module.
* @since 18.05.2009
* @author E Mc Greal
*/
@ContextConfiguration(locations={"/init-database.xml"})
public class EbeanSpringModuleTest extends AbstractJUnit4SpringContextTests {
/** The Constant logger. */
private final static Logger logger = Logger.getLogger(EbeanSpringModuleTest.class.getName());
/** The user service. */
@Autowired
private UserService userService;
/**
* 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 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");
}
/**
* Gets the user service.
*
* @return the userService
*/
public UserService getUserService() {
return userService;
}
/**
* Sets the user service.
*
* @param userService the userService to set
*/
public void setUserService(UserService userService) {
this.userService = userService;
}
}
@@ -0,0 +1,73 @@
/**
* 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
*/
package com.avaje.ebean.springsupport;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
/**
* The Class Role.
* @since 18.05.2009
* @author E Mc Greal
*/
@Entity
public class Role {
@Id
long oid;
@ManyToMany
private Set<User> users = new HashSet<User>();
/**
* @return the oid
*/
public long getOid() {
return oid;
}
/**
* @param oid the oid to set
*/
public void setOid(long oid) {
this.oid = oid;
}
/**
* @return the users
*/
public Set<User> getUsers() {
return users;
}
/**
* @param users the users to set
*/
public void setUsers(Set<User> users) {
this.users = users;
}
}
@@ -0,0 +1,105 @@
/**
* 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
*/
package com.avaje.ebean.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;
/**
* The Class User.
* @since 18.05.2009
* @author E Mc Greal
*/
@Entity
public class User {
@Id
long oid;
private String name;
@ManyToMany
private Set<Role> roles = new HashSet<Role>();
@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<Role> getRoles() {
return roles;
}
/**
* @param roles the roles to set
*/
public void setRoles(Set<Role> 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;
}
}
@@ -0,0 +1,31 @@
/**
* 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
*/
package com.avaje.ebean.springsupport;
/**
* The Interface UserService.
* @since 18.05.2009
* @author E Mc Greal
*/
public interface UserService {
public void save(User user);
public User find(long oid);
}
@@ -0,0 +1,74 @@
/**
* 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
*/
package com.avaje.ebean.springsupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.avaje.ebean.EbeanServer;
/**
* The Class UserServiceImpl.
*
* @since 18.05.2009
* @author E Mc Greal
*/
public class UserServiceImpl implements UserService {
/** The ebean server. */
@Autowired
private EbeanServer ebeanServer;
/* (non-Javadoc)
* @see org.spring.modules.ebean.UserService#save(org.spring.modules.ebean.User)
*/
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor=Throwable.class)
public void save(User user) {
ebeanServer.save(user);
}
@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
public User find(long oid) {
return ebeanServer.find(User.class, oid);
}
/**
* Gets the ebean server.
*
* @return the ebeanServer
*/
public EbeanServer getEbeanServer() {
return ebeanServer;
}
/**
* Sets the ebean server.
*
* @param ebeanServer the ebeanServer to set
*/
public void setEbeanServer(EbeanServer ebeanServer) {
this.ebeanServer = ebeanServer;
}
}