package com.po;
import java.util.Date;
import java.util.List;
import javax.annotation.Generated;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;
import javax.persistence.Query;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.jpa.JpaCallback;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.support.JpaDaoSupport;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition;
/**
* A data access object (DAO) providing persistence and search support for Admin
* entities. Transaction control of the save(), update() and delete() operations
* can directly support Spring container-managed transactions or they can be
* augmented to handle user-managed Spring transactions. Each of these methods
* provides additional information for how to configure it for the desired type
* of transaction control.
*
* @see com.po.Admin
* @author MyEclipse Persistence Tools
*/
public class AdminDAO extends JpaDaoSupport implements IAdminDAO {
// property constants
public static final String ANAME = "aname";
public static final String PASSWD = "passwd";
public static final String ADDRESS = "address";
/**
* Perform an initial save of a previously unsaved Admin entity. All
* subsequent persist actions of this entity should use the #update()
* method. This operation must be performed within the a database
* transaction context for the entity's data to be permanently saved to the
* persistence store, i.e., database. This method uses the
* {@link javax.persistence.EntityManager#persist(Object) EntityManager#persist}
* operation.
* <p>
* User-managed Spring transaction example:
*
* <pre>
TransactionStatus txn = txManager
.getTransaction(new DefaultTransactionDefinition());
* AdminDAO.save(entity);
* txManager.commit(txn);
* </pre>
*
* @see <a href =
* "http://www.myeclipseide.com/documentation/quickstarts/jpaspring#containermanaged">Spring
* container-managed transaction examples</a>
* @param entity
* Admin entity to persist
* @throws RuntimeException
* when the operation fails
*/
public void save(Admin entity) {
logger.info("saving Admin instance");
try {
getJpaTemplate().persist(entity);
logger.info("save successful");
} catch (RuntimeException re) {
logger.error("save failed", re);
throw re;
}
}
/**
* Delete a persistent Admin entity. This operation must be performed within
* the a database transaction context for the entity's data to be
* permanently deleted from the persistence store, i.e., database. This
* method uses the
* {@link javax.persistence.EntityManager#remove(Object) EntityManager#delete}
* operation.
* <p>
* User-managed Spring transaction example:
*
* <pre>
* TransactionStatus txn = txManager
* .getTransaction(new DefaultTransactionDefinition());
* AdminDAO.delete(entity);
* txManager.commit(txn);
* entity = null;
* </pre>
*
* @see <a href =
* "http://www.myeclipseide.com/documentation/quickstarts/jpaspring#containermanaged">Spring
* container-managed transaction examples</a>
* @param entity
* Admin entity to delete
* @throws RuntimeException
* when the operation fails
*/
public void delete(Admin entity) {
logger.info("deleting Admin instance");
try {
entity = getJpaTemplate()
.getReference(Admin.class, entity.getAid());
getJpaTemplate().remove(entity);
logger.info("delete successful");
} catch (RuntimeException re) {
logger.error("delete failed", re);
throw re;
}
}
/**
* Persist a previously saved Admin entity and return it or a copy of it to
* the sender. A copy of the Admin entity parameter is returned when the JPA
* persistence mechanism has not previously been tracking the updated
* entity. This operation must be performed within the a database
* transaction context for the entity's data to be permanently saved to the
* persistence store, i.e., database. This method uses the
* {@link javax.persistence.EntityManager#merge(Object) EntityManager#merge}
* operation.
* <p>
* User-managed Spring transaction example:
*
* <pre>
* TransactionStatus txn = txManager
* .getTransaction(new DefaultTransactionDefinition());
* entity = AdminDAO.update(entity);
* txManager.commit(txn);
* </pre>
*
* @see <a href =
* "http://www.myeclipseide.com/documentation/quickstarts/jpaspring#containermanaged">Spring
* container-managed transaction examples</a>
* @param entity
* Admin entity to update
* @returns Admin the persisted Admin entity instance, may not be the same
* @throws RuntimeException
* if the operation fails
*/
public Admin update(Admin entity) {
logger.info("updating Admin instance");
try {
Admin result = getJpaTemplate().merge(entity);
logger.info("update successful");
return result;
} catch (RuntimeException re) {
logger.error("update failed", re);
throw re;
}
}
public Admin findById(Integer id) {
logger.info("finding Admin instance with id: " + id);
try {
Admin instance = getJpaTemplate().find(Admin.class, id);
return instance;
} catch (RuntimeException re) {
logger.error("find failed", re);
throw re;
}
}
/**
* Find all Admin entities with a specific property value.
*
* @param propertyName
* the name of the Admin 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<Admin> found by query
*/
@SuppressWarnings("unchecked")
public List<Admin> findByProperty(String propertyName, final Object value,
final int... rowStartIdxAndCount) {
logger.info("finding Admin instance with property: " + propertyName
+ ", value: " + value);
try {
final String queryString = "select model from Admin model where model."
+ propertyName + "= :propertyValue";
return getJpaTemplate().executeFind(new JpaCallback() {
public Object doInJpa(EntityManager em)
throws PersistenceException {
Query query = em.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) {
logger.error("find by property name failed", re);
throw re;
}
}
public List<Admin> findByAname(Object aname, int... rowStartIdxAndCount) {
return findByProperty(ANAME, aname, rowStartIdxAndCount);
}
public List<Admin> findByPasswd(Object passwd, int... rowStartIdxAndCount) {
return findByProperty(PASSWD, passwd, rowStartIdxAndCount);
}
public List<Admin> findByAddress(Object address, int... rowStartIdxAndCount) {
return findByProperty(ADDRESS, address, rowStartIdxAndCount);
}
/**
* Find all Admin entities.
*
* @param rowStartIdxAndCoun