package orm;import java.math.BigDecimal;
import java.util.List;
import java.util.logging.Level;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;/**
* Facade for entity Userinfo.
*
* @see orm.Userinfo
* @author MyEclipse Persistence Tools
*/
@Stateless
public class UserinfoFacade {
// property constants
public static final String USERNAME = "username"; @PersistenceContext
private EntityManager entityManager; /**
* Perform an initial save of a previously unsaved Userinfo entity. All
* subsequent persist actions of this entity should use the #update()
* method.
*
* @param entity
* Userinfo entity to persist
* @throws RuntimeException
* when the operation fails
*/
public void save(Userinfo entity) {
LogUtil.log("saving Userinfo instance", Level.INFO, null);
try {
entityManager.persist(entity);
LogUtil.log("save successful", Level.INFO, null);
} catch (RuntimeException re) {
LogUtil.log("save failed", Level.SEVERE, re);
throw re;
}
} /**
* Delete a persistent Userinfo entity.
*
* @param entity
* Userinfo entity to delete
* @throws RuntimeException
* when the operation fails
*/
public void delete(Userinfo entity) {
LogUtil.log("deleting Userinfo instance", Level.INFO, null);
try {
entity = entityManager.getReference(Userinfo.class, entity.getId());
entityManager.remove(entity);
LogUtil.log("delete successful", Level.INFO, null);
} catch (RuntimeException re) {
LogUtil.log("delete failed", Level.SEVERE, re);
throw re;
}
} /**
* Persist a previously saved Userinfo entity and return it or a copy of it
* to the sender. A copy of the Userinfo entity parameter is returned when
* the JPA persistence mechanism has not previously been tracking the
* updated entity.
*
* @param entity
* Userinfo entity to update
* @return Userinfo the persisted Userinfo entity instance, may not be the
* same
* @throws RuntimeException
* if the operation fails
*/
public Userinfo update(Userinfo entity) {
LogUtil.log("updating Userinfo instance", Level.INFO, null);
try {
Userinfo result = entityManager.merge(entity);
LogUtil.log("update successful", Level.INFO, null);
return result;
} catch (RuntimeException re) {
LogUtil.log("update failed", Level.SEVERE, re);
throw re;
}
} public Userinfo findById(BigDecimal id) {
LogUtil.log("finding Userinfo instance with id: " + id, Level.INFO,
null);
try {
Userinfo instance = entityManager.find(Userinfo.class, id);
return instance;
} catch (RuntimeException re) {
LogUtil.log("find failed", Level.SEVERE, re);
throw re;
}
} /**
* Find all Userinfo entities with a specific property value.
*
* @param propertyName
* the name of the Userinfo property to query
* @param value
* the property value to match
* @param rowStartIdxAndCount
* Optional int varargs. rowStartIdxAndCount[0] specifies the the
* row index in the query result-set to begin collecting the
* results. rowStartIdxAndCount[1] specifies the the maximum
* number of results to return.
* @return List<Userinfo> found by query
*/
@SuppressWarnings("unchecked")
public List<Userinfo> findByProperty(String propertyName,
final Object value, final int... rowStartIdxAndCount) {
LogUtil.log("finding Userinfo instance with property: " + propertyName
+ ", value: " + value, Level.INFO, null);
try {
final String queryString = "select model from Userinfo model where model."
+ propertyName + "= :propertyValue";
Query query = entityManager.createQuery(queryString);
query.setParameter("propertyValue", value);
if (rowStartIdxAndCount != null && rowStartIdxAndCount.length > 0) {
int rowStartIdx = Math.max(0, rowStartIdxAndCount[0]);
if (rowStartIdx > 0) {
query.setFirstResult(rowStartIdx);
} if (rowStartIdxAndCount.length > 1) {
int rowCount = Math.max(0, rowStartIdxAndCount[1]);
if (rowCount > 0) {
query.setMaxResults(rowCount);
}
}
}
return query.getResultList();
} catch (RuntimeException re) {
LogUtil.log("find by property name failed", Level.SEVERE, re);
throw re;
}
} public List<Userinfo> findByUsername(Object username,
int... rowStartIdxAndCount) {
return findByProperty(USERNAME, username, rowStartIdxAndCount);
} /**
* Find all Userinfo entities.
*
* @param rowStartIdxAndCount
* Optional int varargs. rowStartIdxAndCount[0] specifies the the
* row index in the query result-set to begin collecting the
* results. rowStartIdxAndCount[1] specifies the the maximum
* count of results to return.
* @return List<Userinfo> all Userinfo entities
*/
@SuppressWarnings("unchecked")
public List<Userinfo> findAll(final int... rowStartIdxAndCount) {
LogUtil.log("finding all Userinfo instances", Level.INFO, null);
try {
final String queryString = "select model from Userinfo model";
Query query = entityManager.createQuery(queryString);
if (rowStartIdxAndCount != null && rowStartIdxAndCount.length > 0) {
int rowStartIdx = Math.max(0, rowStartIdxAndCount[0]);
if (rowStartIdx > 0) {
query.setFirstResult(rowStartIdx);
} if (rowStartIdxAndCount.length > 1) {
int rowCount = Math.max(0, rowStartIdxAndCount[1]);
if (rowCount > 0) {
query.setMaxResults(rowCount);
}
}
}
return query.getResultList();
} catch (RuntimeException re) {
LogUtil.log("find all failed", Level.SEVERE, re);
throw re;
}
}}上面是用MYECLIPSE逆向的代码,,一个类似“DAO”类,没有任何的业务逻辑就是CURD,,但书上讲EJB3暴露的应该是服务层,,这二种情况是相反的啊,,MYECLIPSE的设计者应该知道EJB是什么,并且暴露出什么,,请前辈指点!
import java.util.List;
import java.util.logging.Level;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;/**
* Facade for entity Userinfo.
*
* @see orm.Userinfo
* @author MyEclipse Persistence Tools
*/
@Stateless
public class UserinfoFacade {
// property constants
public static final String USERNAME = "username"; @PersistenceContext
private EntityManager entityManager; /**
* Perform an initial save of a previously unsaved Userinfo entity. All
* subsequent persist actions of this entity should use the #update()
* method.
*
* @param entity
* Userinfo entity to persist
* @throws RuntimeException
* when the operation fails
*/
public void save(Userinfo entity) {
LogUtil.log("saving Userinfo instance", Level.INFO, null);
try {
entityManager.persist(entity);
LogUtil.log("save successful", Level.INFO, null);
} catch (RuntimeException re) {
LogUtil.log("save failed", Level.SEVERE, re);
throw re;
}
} /**
* Delete a persistent Userinfo entity.
*
* @param entity
* Userinfo entity to delete
* @throws RuntimeException
* when the operation fails
*/
public void delete(Userinfo entity) {
LogUtil.log("deleting Userinfo instance", Level.INFO, null);
try {
entity = entityManager.getReference(Userinfo.class, entity.getId());
entityManager.remove(entity);
LogUtil.log("delete successful", Level.INFO, null);
} catch (RuntimeException re) {
LogUtil.log("delete failed", Level.SEVERE, re);
throw re;
}
} /**
* Persist a previously saved Userinfo entity and return it or a copy of it
* to the sender. A copy of the Userinfo entity parameter is returned when
* the JPA persistence mechanism has not previously been tracking the
* updated entity.
*
* @param entity
* Userinfo entity to update
* @return Userinfo the persisted Userinfo entity instance, may not be the
* same
* @throws RuntimeException
* if the operation fails
*/
public Userinfo update(Userinfo entity) {
LogUtil.log("updating Userinfo instance", Level.INFO, null);
try {
Userinfo result = entityManager.merge(entity);
LogUtil.log("update successful", Level.INFO, null);
return result;
} catch (RuntimeException re) {
LogUtil.log("update failed", Level.SEVERE, re);
throw re;
}
} public Userinfo findById(BigDecimal id) {
LogUtil.log("finding Userinfo instance with id: " + id, Level.INFO,
null);
try {
Userinfo instance = entityManager.find(Userinfo.class, id);
return instance;
} catch (RuntimeException re) {
LogUtil.log("find failed", Level.SEVERE, re);
throw re;
}
} /**
* Find all Userinfo entities with a specific property value.
*
* @param propertyName
* the name of the Userinfo property to query
* @param value
* the property value to match
* @param rowStartIdxAndCount
* Optional int varargs. rowStartIdxAndCount[0] specifies the the
* row index in the query result-set to begin collecting the
* results. rowStartIdxAndCount[1] specifies the the maximum
* number of results to return.
* @return List<Userinfo> found by query
*/
@SuppressWarnings("unchecked")
public List<Userinfo> findByProperty(String propertyName,
final Object value, final int... rowStartIdxAndCount) {
LogUtil.log("finding Userinfo instance with property: " + propertyName
+ ", value: " + value, Level.INFO, null);
try {
final String queryString = "select model from Userinfo model where model."
+ propertyName + "= :propertyValue";
Query query = entityManager.createQuery(queryString);
query.setParameter("propertyValue", value);
if (rowStartIdxAndCount != null && rowStartIdxAndCount.length > 0) {
int rowStartIdx = Math.max(0, rowStartIdxAndCount[0]);
if (rowStartIdx > 0) {
query.setFirstResult(rowStartIdx);
} if (rowStartIdxAndCount.length > 1) {
int rowCount = Math.max(0, rowStartIdxAndCount[1]);
if (rowCount > 0) {
query.setMaxResults(rowCount);
}
}
}
return query.getResultList();
} catch (RuntimeException re) {
LogUtil.log("find by property name failed", Level.SEVERE, re);
throw re;
}
} public List<Userinfo> findByUsername(Object username,
int... rowStartIdxAndCount) {
return findByProperty(USERNAME, username, rowStartIdxAndCount);
} /**
* Find all Userinfo entities.
*
* @param rowStartIdxAndCount
* Optional int varargs. rowStartIdxAndCount[0] specifies the the
* row index in the query result-set to begin collecting the
* results. rowStartIdxAndCount[1] specifies the the maximum
* count of results to return.
* @return List<Userinfo> all Userinfo entities
*/
@SuppressWarnings("unchecked")
public List<Userinfo> findAll(final int... rowStartIdxAndCount) {
LogUtil.log("finding all Userinfo instances", Level.INFO, null);
try {
final String queryString = "select model from Userinfo model";
Query query = entityManager.createQuery(queryString);
if (rowStartIdxAndCount != null && rowStartIdxAndCount.length > 0) {
int rowStartIdx = Math.max(0, rowStartIdxAndCount[0]);
if (rowStartIdx > 0) {
query.setFirstResult(rowStartIdx);
} if (rowStartIdxAndCount.length > 1) {
int rowCount = Math.max(0, rowStartIdxAndCount[1]);
if (rowCount > 0) {
query.setMaxResults(rowCount);
}
}
}
return query.getResultList();
} catch (RuntimeException re) {
LogUtil.log("find all failed", Level.SEVERE, re);
throw re;
}
}}上面是用MYECLIPSE逆向的代码,,一个类似“DAO”类,没有任何的业务逻辑就是CURD,,但书上讲EJB3暴露的应该是服务层,,这二种情况是相反的啊,,MYECLIPSE的设计者应该知道EJB是什么,并且暴露出什么,,请前辈指点!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货