/** * Example license header for Java files * * http://andromda.sourceforge.net/ */ // // Attention: Generated code! Do not modify by hand! hibernate4=true hibernateVersion=4 // Generated by hibernate/SpringHibernateDaoBase.vsl in andromda-spring-cartridge on 09/18/2014 17:02:25-0400. Do not modify by hand!. // package org.andromda.test.7; /** *

* Base Spring DAO Class: is able to create, update, remove, load, and find * objects of type org.andromda.test.7.Person. *

* * @see org.andromda.test.7.Person */ @org.springframework.stereotype.Repository public abstract class PersonDaoBase implements org.andromda.test.7.PersonDao { /** * For backwards compatibility with HibernateDao method * @deprecated Use LogFactory.getLog on each subclass, for the correct class name * Apache commons logging logger used by all subclasses */ @Deprecated protected org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(PersonDaoBase.class); @javax.annotation.Resource private org.hibernate.SessionFactory sessionFactory; /** * @param sessionFactoryIn */ public void setSessionFactory(org.hibernate.SessionFactory sessionFactoryIn) { this.sessionFactory = sessionFactoryIn; } /** * @return SessionFactory */ protected org.hibernate.SessionFactory getSessionFactory() { return this.sessionFactory; } /** * @return currentSession */ protected org.hibernate.Session getSession() { return this.sessionFactory.getCurrentSession(); } /** * For backwards compatibility with HibernateDao method * @deprecated Use this.sessionFactory.getCurrentSession() instead * @param ignore boolean - always create new session if needed * @return currentSession */ @Deprecated protected org.hibernate.Session getSession(boolean ignore) { return this.getSession(); } /** * {@inheritDoc} */ @Override public Object get(final int transform, final java.lang.Long id) { if (id == null) { throw new IllegalArgumentException( "Person.get - 'id' can not be null"); } final Object entity = this.sessionFactory.getCurrentSession().get(org.andromda.test.7.PersonImpl.class, id); return transformEntity(transform, (org.andromda.test.7.Person)entity); } /** * {@inheritDoc} */ @Override public org.andromda.test.7.Person get(java.lang.Long id) { return (org.andromda.test.7.Person)this.get(TRANSFORM_NONE, id); } /** * {@inheritDoc} */ @Override public Object load(final int transform, final java.lang.Long id) { if (id == null) { throw new IllegalArgumentException( "Person.load - 'id' can not be null"); } final Object entity = this.sessionFactory.getCurrentSession().get(org.andromda.test.7.PersonImpl.class, id); return transformEntity(transform, (org.andromda.test.7.Person)entity); } /** * {@inheritDoc} */ @Override public org.andromda.test.7.Person load(java.lang.Long id) { return (org.andromda.test.7.Person)this.load(TRANSFORM_NONE, id); } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.Collection loadAll() { return (java.util.Collection) this.loadAll(org.andromda.test.7.PersonDao.TRANSFORM_NONE); } /** * {@inheritDoc} */ @Override public java.util.Collection loadAll(final int transform) { return this.loadAll(transform, -1, -1); } /** * {@inheritDoc} */ @Override public java.util.Collection loadAll(final int pageNumber, final int pageSize) { return this.loadAll(org.andromda.test.7.PersonDao.TRANSFORM_NONE, pageNumber, pageSize); } /** * {@inheritDoc} */ @Override public java.util.Collection loadAll(final int transform, final int pageNumber, final int pageSize) { final org.hibernate.Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(org.andromda.test.7.PersonImpl.class); if (pageNumber > 0 && pageSize > 0) { criteria.setFirstResult(this.calculateFirstResult(pageNumber, pageSize)); criteria.setMaxResults(pageSize); } final java.util.Collection results = criteria.list(); this.transformEntities(transform, results); return results; } /** * firstResult = (pageNumber - 1) * pageSize * @param pageNumber * @param pageSize * @return firstResult */ protected int calculateFirstResult(int pageNumber, int pageSize) { int firstResult = 0; if (pageNumber > 0) { firstResult = (pageNumber - 1) * pageSize; } return firstResult; } /** * prePersist event - This method is called before creating the entity * @param person org.andromda.test.7.Person */ protected void _prePersist(final org.andromda.test.7.Person person) { // Abstract method - your implementation goes in the descendant } /** * postPersist event - This method is called after creating the entity * @param person org.andromda.test.7.Person */ protected void _postPersist(final org.andromda.test.7.Person person) { // Abstract method - your implementation goes in the descendant } /** * preUpdate event - This method is called before updating the entity * @param person org.andromda.test.7.Person */ protected void _preUpdate(final org.andromda.test.7.Person person) { // Abstract method - your implementation goes in the descendant } /** * postUpdate event - This method is called after updating the entity * @param person org.andromda.test.7.Person */ protected void _postUpdate(final org.andromda.test.7.Person person) { // Abstract method - your implementation goes in the descendant } /** * preRemove event - This method is called before deleting the entity * @param person org.andromda.test.7.Person */ protected void _preRemove(final org.andromda.test.7.Person person) { // Abstract method - your implementation goes in the descendant } /** * postRemove event - This method is called after deleting the entity * @param person org.andromda.test.7.Person */ protected void _postRemove(final org.andromda.test.7.Person person) { // Abstract method - your implementation goes in the descendant } /** * {@inheritDoc} */ @Override public org.andromda.test.7.Person create(org.andromda.test.7.Person person) { return (org.andromda.test.7.Person)this.create(org.andromda.test.7.PersonDao.TRANSFORM_NONE, person); } /** * {@inheritDoc} */ @Override public Object create(final int transform, final org.andromda.test.7.Person person) { if (person == null) { throw new IllegalArgumentException( "Person.create - 'person' can not be null"); } //prePersist event _prePersist(person); this.sessionFactory.getCurrentSession().save(person); //postPersist event _postPersist(person); return this.transformEntity(transform, person); } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.Collection create(final java.util.Collection entities) { return (java.util.Collection) create(org.andromda.test.7.PersonDao.TRANSFORM_NONE, entities); } /** * {@inheritDoc} */ @Override public java.util.Collection create(final int transform, final java.util.Collection entities) { if (entities == null) { throw new IllegalArgumentException( "Person.create - 'entities' can not be null"); } java.util.Collection transformed = new java.util.ArrayList(); for (org.andromda.test.7.Person entity : entities) { transformed.add(create(transform, entity)); } return transformed; } /** * {@inheritDoc} */ @Override public org.andromda.test.7.Person create( java.lang.String name, java.util.Date birthDate) { return (org.andromda.test.7.Person)this.create(org.andromda.test.7.PersonDao.TRANSFORM_NONE, name, birthDate); } /** * {@inheritDoc} */ @Override public Object create( final int transform, java.lang.String name, java.util.Date birthDate) { org.andromda.test.7.Person entity = new org.andromda.test.7.PersonImpl(); entity.setName(name); entity.setBirthDate(birthDate); return this.create(transform, entity); } /** * {@inheritDoc} */ @Override public void update(org.andromda.test.7.Person person) { if (person == null) { throw new IllegalArgumentException( "Person.update - 'person' can not be null"); } //preUpdate event _preUpdate(person); this.sessionFactory.getCurrentSession().update(person); //postUpdate event _postUpdate(person); } /** * {@inheritDoc} */ @Override public void update(final java.util.Collection entities) { if (entities == null) { throw new IllegalArgumentException( "Person.update - 'entities' can not be null"); } for (org.andromda.test.7.Person entity : entities) { update(entity); } } /** * {@inheritDoc} */ @Override public void remove(org.andromda.test.7.Person person) { if (person == null) { throw new IllegalArgumentException( "Person.remove - 'person' can not be null"); } //preRemove event _preRemove(person); this.sessionFactory.getCurrentSession().delete(person); //postRemove event _postRemove(person); } /** * {@inheritDoc} */ @Override public void remove(java.lang.Long id) { if (id == null) { throw new IllegalArgumentException( "Person.remove - 'id' can not be null"); } org.andromda.test.7.Person entity = this.get(id); if (entity != null) { this.remove(entity); } } /** * {@inheritDoc} */ @Override public void remove(java.util.Collection entities) { if (entities == null) { throw new IllegalArgumentException( "Person.remove - 'entities' can not be null"); } for (org.andromda.test.7.Person entity : entities) { //preRemove event _preRemove(entity); this.sessionFactory.getCurrentSession().delete(entity); //postRemove event _postRemove(entity); } } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.List findAll() { return (java.util.List)this.findAll(org.andromda.test.7.PersonDao.TRANSFORM_NONE); } /** * {@inheritDoc} */ @Override public java.util.List findAll(final int transform) { return this.findAll(transform, -1, -1); } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.List findAll(final String queryString) { return (java.util.List)this.findAll(org.andromda.test.7.PersonDao.TRANSFORM_NONE, queryString); } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.List findAll(final int pageNumber, final int pageSize) { return (java.util.List) this.findAll(org.andromda.test.7.PersonDao.TRANSFORM_NONE, pageNumber, pageSize); } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.List findAll(final String queryString, final int pageNumber, final int pageSize) { return (java.util.List) this.findAll(org.andromda.test.7.PersonDao.TRANSFORM_NONE, queryString, pageNumber, pageSize); } /** * {@inheritDoc} */ @Override public java.util.List findAll(final int transform, final String queryString) { return this.findAll(transform, queryString, -1, -1); } /** * {@inheritDoc} */ @Override public java.util.List findAll(final int transform, final int pageNumber, final int pageSize) { return this.findAll(transform, "from org.andromda.test.7.PersonImpl as person", pageNumber, pageSize); } /** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public java.util.List findAll(final int transform, final String queryString, int pageNumber, int pageSize) { org.hibernate.Query queryObject = this.sessionFactory.getCurrentSession().createQuery(queryString); if (pageNumber > 0 && pageSize > 0) { queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize)); queryObject.setMaxResults(pageSize); } java.util.List results = queryObject.list(); transformEntities(transform, results); return results; } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.List findByName(java.lang.String name) { return (java.util.List)this.findByName(org.andromda.test.7.PersonDao.TRANSFORM_NONE, name); } /** * {@inheritDoc} */ @Override public java.util.List findByName(final int transform, final java.lang.String name) { return this.findByName(transform, -1, -1, name); } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.List findByName(final String queryString, final java.lang.String name) { return (java.util.List)this.findByName(org.andromda.test.7.PersonDao.TRANSFORM_NONE, queryString, name); } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.List findByName(final int pageNumber, final int pageSize, final java.lang.String name) { return (java.util.List) this.findByName(org.andromda.test.7.PersonDao.TRANSFORM_NONE, pageNumber, pageSize, name); } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.List findByName(final String queryString, final int pageNumber, final int pageSize, final java.lang.String name) { return (java.util.List) this.findByName(org.andromda.test.7.PersonDao.TRANSFORM_NONE, queryString, pageNumber, pageSize, name); } /** * {@inheritDoc} */ @Override public java.util.List findByName(final int transform, final String queryString, final java.lang.String name) { return this.findByName(transform, queryString, -1, -1, name); } /** * {@inheritDoc} */ @Override public java.util.List findByName(final int transform, final int pageNumber, final int pageSize, final java.lang.String name) { return this.findByName(transform, "from org.andromda.test.7.PersonImpl as person where person.name = :name", pageNumber, pageSize, name); } /** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public java.util.List findByName(final int transform, final String queryString, int pageNumber, int pageSize, final java.lang.String name) { org.hibernate.Query queryObject = this.sessionFactory.getCurrentSession().createQuery(queryString); queryObject.setParameter("name", name); if (pageNumber > 0 && pageSize > 0) { queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize)); queryObject.setMaxResults(pageSize); } java.util.List results = queryObject.list(); transformEntities(transform, results); return results; } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.List findByNameOrBirthDate(java.lang.String name, java.util.Date birthDate) { return (java.util.List)this.findByNameOrBirthDate(org.andromda.test.7.PersonDao.TRANSFORM_NONE, name, birthDate); } /** * {@inheritDoc} */ @Override public java.util.List findByNameOrBirthDate(final int transform, final java.lang.String name, final java.util.Date birthDate) { return this.findByNameOrBirthDate(transform, -1, -1, name, birthDate); } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.List findByNameOrBirthDate(final String queryString, final java.lang.String name, final java.util.Date birthDate) { return (java.util.List)this.findByNameOrBirthDate(org.andromda.test.7.PersonDao.TRANSFORM_NONE, queryString, name, birthDate); } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.List findByNameOrBirthDate(final int pageNumber, final int pageSize, final java.lang.String name, final java.util.Date birthDate) { return (java.util.List) this.findByNameOrBirthDate(org.andromda.test.7.PersonDao.TRANSFORM_NONE, pageNumber, pageSize, name, birthDate); } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.List findByNameOrBirthDate(final String queryString, final int pageNumber, final int pageSize, final java.lang.String name, final java.util.Date birthDate) { return (java.util.List) this.findByNameOrBirthDate(org.andromda.test.7.PersonDao.TRANSFORM_NONE, queryString, pageNumber, pageSize, name, birthDate); } /** * {@inheritDoc} */ @Override public java.util.List findByNameOrBirthDate(final int transform, final String queryString, final java.lang.String name, final java.util.Date birthDate) { return this.findByNameOrBirthDate(transform, queryString, -1, -1, name, birthDate); } /** * {@inheritDoc} */ @Override public java.util.List findByNameOrBirthDate(final int transform, final int pageNumber, final int pageSize, final java.lang.String name, final java.util.Date birthDate) { return this.findByNameOrBirthDate(transform, "from org.andromda.test.7.PersonImpl as person where person.name = :name and person.birthDate = :birthDate", pageNumber, pageSize, name, birthDate); } /** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public java.util.List findByNameOrBirthDate(final int transform, final String queryString, int pageNumber, int pageSize, final java.lang.String name, final java.util.Date birthDate) { org.hibernate.Query queryObject = this.sessionFactory.getCurrentSession().createQuery(queryString); queryObject.setParameter("name", name); queryObject.setParameter("birthDate", birthDate); if (pageNumber > 0 && pageSize > 0) { queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize)); queryObject.setMaxResults(pageSize); } java.util.List results = queryObject.list(); transformEntities(transform, results); return results; } /** * Allows transformation of entities into value objects * (or something else for that matter), when the transform * flag is set to one of the constants defined in org.andromda.test.7.PersonDao, please note * that the {@link #TRANSFORM_NONE} constant denotes no transformation, so the entity itself * will be returned. * * If the integer argument value is unknown {@link #TRANSFORM_NONE} is assumed. * * @param transform one of the constants declared in {@link org.andromda.test.7.PersonDao} * @param entity an entity that was found * @return the transformed entity (i.e. new value object, etc) * @see org.andromda.test.7.PersonDao#transformEntity(int, org.andromda.test.7.Person) */ @Override public Object transformEntity(final int transform, final org.andromda.test.7.Person entity) { Object target = null; if (entity != null) { switch (transform) { case org.andromda.test.7.PersonDao.TRANSFORM_NONE : // fall-through default: target = entity; } } return target; } /** * {@inheritDoc} */ @Override public void transformEntities(final int transform, final java.util.Collection entities) { switch (transform) { case org.andromda.test.7.PersonDao.TRANSFORM_NONE : // fall-through default: // do nothing; } } /** * @see org.andromda.test.7.PersonDao#toEntities(java.util.Collection) */ @Override public void toEntities(final java.util.Collection results) { if (results != null) { org.apache.commons.collections.CollectionUtils.transform(results, this.ENTITYTRANSFORMER); } } /** * This anonymous transformer is designed to transform report query results * (which result in an array of entities) to {@link org.andromda.test.7.Person} * using the Jakarta Commons-Collections Transformation API. */ private org.apache.commons.collections.Transformer ENTITYTRANSFORMER = new org.apache.commons.collections.Transformer() { @Override public Object transform(Object input) { Object result = null; if (input instanceof Object[]) { final Object[] rows = (Object[])input; result = toEntity(rows); } else if (input instanceof org.andromda.test.7.Person) { result = input; } return result; } }; /** * @param row * @return org.andromda.test.7.Person */ protected org.andromda.test.7.Person toEntity(Object[] row) { org.andromda.test.7.Person target = null; if (row != null) { final int numberOfObjects = row.length; for (int ctr = 0; ctr < numberOfObjects; ctr++) { final Object object = row[ctr]; if (object instanceof org.andromda.test.7.Person) { target = (org.andromda.test.7.Person)object; break; } } } return target; } /** * Gets the current principal if one has been set, * otherwise returns null. * * @return the current principal */ protected java.security.Principal getPrincipal() { return org.andromda.spring.PrincipalStore.get(); } /** * {@inheritDoc} */ @Override public org.andromda.spring.PaginationResult search(final int transform, final int pageNumber, final int pageSize, final org.andromda.spring.Search search) { search.setPageNumber(pageNumber); search.setPageSize(pageSize); final org.andromda.spring.PropertySearch propertySearch = new org.andromda.spring.PropertySearch( this.sessionFactory.getCurrentSession(), org.andromda.test.7.PersonImpl.class, search); final java.util.List results = propertySearch.executeAsList(); this.transformEntities(transform, results); return new org.andromda.spring.PaginationResult(results.toArray(new Object[results.size()]), propertySearch.getTotalCount()); } /** * {@inheritDoc} */ @Override public org.andromda.spring.PaginationResult search(final int pageNumber, final int pageSize, final org.andromda.spring.Search search) { return this.search(org.andromda.test.7.PersonDao.TRANSFORM_NONE, pageNumber, pageSize, search); } /** * {@inheritDoc} */ @Override public java.util.Collection search(final int transform, final org.andromda.spring.Search search) { final org.andromda.spring.PropertySearch propertySearch = new org.andromda.spring.PropertySearch( this.sessionFactory.getCurrentSession(), org.andromda.test.7.PersonImpl.class, search); final java.util.Collection results = propertySearch.executeAsList(); this.transformEntities(transform, results); return results; } /** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public java.util.Collection search(final org.andromda.spring.Search search) { return (java.util.Collection) this.search(org.andromda.test.7.PersonDao.TRANSFORM_NONE, search); } /** * Executes and returns the given Hibernate queryObject as a {@link org.andromda.spring.PaginationResult} instance. * @param queryObject * @param transform * @param pageNumber * @param pageSize * @return org.andromda.spring.PaginationResult */ @SuppressWarnings({ "unchecked" }) protected org.andromda.spring.PaginationResult getPaginationResult( final org.hibernate.Query queryObject, final int transform, int pageNumber, int pageSize) { final org.hibernate.ScrollableResults scrollableResults = queryObject.scroll(); scrollableResults.last(); int totalCount = scrollableResults.getRowNumber(); totalCount = totalCount >= 0 ? totalCount + 1 : 0; if (pageNumber > 0 && pageSize > 0) { queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize)); queryObject.setMaxResults(pageSize); } // Unchecked transformation because Set object is reused, cannot be strongly typed. @SuppressWarnings("rawtypes") java.util.Collection results = new java.util.ArrayList(queryObject.list()); transformEntities(transform, results); return new org.andromda.spring.PaginationResult(results.toArray(new Object[results.size()]), totalCount); } /** * {@inheritDoc} */ @Override public org.andromda.test.7.Person searchUniqueName(final java.lang.String name) { final org.andromda.spring.Search search=new org.andromda.spring.Search( new org.andromda.spring.SearchParameter[]{ new org.andromda.spring.SearchParameter("name",name,org.andromda.spring.SearchParameter.EQUAL_COMPARATOR) } ); final java.util.Collection searchResult=this.search(search); switch(searchResult.size()) { case 0: return null; case 1: return searchResult.iterator().next(); default: throw new org.hibernate.NonUniqueResultException(searchResult.size()); } } /** * {@inheritDoc} */ @Override public Object searchUniqueName(final int transform, final java.lang.String name) { final org.andromda.test.7.Person entity=this.searchUniqueName(name); if(entity == null) { return null; } return transformEntity(transform, entity); } /** * {@inheritDoc} */ @Override public org.andromda.test.7.Person searchUniqueBirthDate(final java.util.Date birthDate) { final org.andromda.spring.Search search=new org.andromda.spring.Search( new org.andromda.spring.SearchParameter[]{ new org.andromda.spring.SearchParameter("birthDate",birthDate,org.andromda.spring.SearchParameter.EQUAL_COMPARATOR) } ); final java.util.Collection searchResult=this.search(search); switch(searchResult.size()) { case 0: return null; case 1: return searchResult.iterator().next(); default: throw new org.hibernate.NonUniqueResultException(searchResult.size()); } } /** * {@inheritDoc} */ @Override public Object searchUniqueBirthDate(final int transform, final java.util.Date birthDate) { final org.andromda.test.7.Person entity=this.searchUniqueBirthDate(birthDate); if(entity == null) { return null; } return transformEntity(transform, entity); } /** * Create or Update the person instance in the persistent store. * @param person */ @Override public org.andromda.test.7.Person createOrUpdate(org.andromda.test.7.Person person) { if(person.getId() == null) { return (org.andromda.test.7.Person)this.create(TRANSFORM_NONE,person); } this.update(person); return person; } // spring-hibernate-dao-base merge-point }