/** * Example license header for Java files * * http://www.andromda.org/ */ // // Attention: Generated code! Do not modify by hand! // Generated by: hibernate/SpringHibernateDaoBase.vsl in andromda-spring-cartridge. // package org.andromda.test.3; /** *

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

* * @see org.andromda.test.3.Car */ public abstract class CarDaoBase extends org.springframework.orm.hibernate3.support.HibernateDaoSupport implements org.andromda.test.3.CarDao { /** * {@inheritDoc} */ @Override public Object get(final int transform, final java.lang.Long id) { if (id == null) { throw new IllegalArgumentException( "Car.get - 'id' can not be null"); } final Object entity = this.getHibernateTemplate().get(org.andromda.test.3.CarImpl.class, id); return transformEntity(transform, (org.andromda.test.3.Car)entity); } /** * {@inheritDoc} */ @Override public org.andromda.test.3.Car get(java.lang.Long id) { return (org.andromda.test.3.Car)this.get(TRANSFORM_NONE, id); } /** * {@inheritDoc} */ @Override public Object load(final int transform, final java.lang.Long id) { if (id == null) { throw new IllegalArgumentException( "Car.load - 'id' can not be null"); } final Object entity = this.getHibernateTemplate().get(org.andromda.test.3.CarImpl.class, id); return transformEntity(transform, (org.andromda.test.3.Car)entity); } /** * {@inheritDoc} */ @Override public org.andromda.test.3.Car load(java.lang.Long id) { return (org.andromda.test.3.Car)this.load(TRANSFORM_NONE, id); } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.Collection loadAll() { return (java.util.Collection) this.loadAll(org.andromda.test.3.CarDao.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.3.CarDao.TRANSFORM_NONE, pageNumber, pageSize); } /** * {@inheritDoc} */ @Override public java.util.Collection loadAll(final int transform, final int pageNumber, final int pageSize) { try { final org.hibernate.Criteria criteria = this.getSession(false).createCriteria(org.andromda.test.3.CarImpl.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; } catch (org.hibernate.HibernateException ex) { throw super.convertHibernateAccessException(ex); } } /** * 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; } /** * {@inheritDoc} */ @Override public org.andromda.test.3.Car create(org.andromda.test.3.Car car) { return (org.andromda.test.3.Car)this.create(org.andromda.test.3.CarDao.TRANSFORM_NONE, car); } /** * {@inheritDoc} */ @Override public Object create(final int transform, final org.andromda.test.3.Car car) { if (car == null) { throw new IllegalArgumentException( "Car.create - 'car' can not be null"); } this.getHibernateTemplate().save(car); return this.transformEntity(transform, car); } /** * {@inheritDoc} */ @Override @SuppressWarnings({"unchecked"}) public java.util.Collection create(final java.util.Collection entities) { return (java.util.Collection) create(org.andromda.test.3.CarDao.TRANSFORM_NONE, entities); } /** * {@inheritDoc} */ @Override public java.util.Collection create(final int transform, final java.util.Collection entities) { if (entities == null) { throw new IllegalArgumentException( "Car.create - 'entities' can not be null"); } this.getHibernateTemplate().executeWithNativeSession( new org.springframework.orm.hibernate3.HibernateCallback() { public Object doInHibernate(org.hibernate.Session session) throws org.hibernate.HibernateException { for (org.andromda.test.3.Car entity : entities) { create(transform, entity); } return null; } }); return entities; } /** * {@inheritDoc} */ @Override public org.andromda.test.3.Car create( java.lang.String serial, java.lang.String name, java.lang.String type) { return (org.andromda.test.3.Car)this.create(org.andromda.test.3.CarDao.TRANSFORM_NONE, serial, name, type); } /** * {@inheritDoc} */ @Override public Object create( final int transform, java.lang.String serial, java.lang.String name, java.lang.String type) { org.andromda.test.3.Car entity = new org.andromda.test.3.CarImpl(); entity.setSerial(serial); entity.setName(name); entity.setType(type); return this.create(transform, entity); } /** * {@inheritDoc} */ @Override public org.andromda.test.3.Car create( java.lang.String name, org.andromda.test.3.Person owner, java.lang.String serial, java.lang.String type) { return (org.andromda.test.3.Car)this.create(org.andromda.test.3.CarDao.TRANSFORM_NONE, name, owner, serial, type); } /** * {@inheritDoc} */ @Override public Object create( final int transform, java.lang.String name, org.andromda.test.3.Person owner, java.lang.String serial, java.lang.String type) { org.andromda.test.3.Car entity = new org.andromda.test.3.CarImpl(); entity.setName(name); entity.setOwner(owner); entity.setSerial(serial); entity.setType(type); return this.create(transform, entity); } /** * {@inheritDoc} */ @Override public void update(org.andromda.test.3.Car car) { if (car == null) { throw new IllegalArgumentException( "Car.update - 'car' can not be null"); } this.getHibernateTemplate().update(car); } /** * {@inheritDoc} */ @Override public void update(final java.util.Collection entities) { if (entities == null) { throw new IllegalArgumentException( "Car.update - 'entities' can not be null"); } this.getHibernateTemplate().executeWithNativeSession( new org.springframework.orm.hibernate3.HibernateCallback() { public Object doInHibernate(org.hibernate.Session session) throws org.hibernate.HibernateException { for (org.andromda.test.3.Car entity : entities) { update(entity); } return null; } }); } /** * {@inheritDoc} */ @Override public void remove(org.andromda.test.3.Car car) { if (car == null) { throw new IllegalArgumentException( "Car.remove - 'car' can not be null"); } this.getHibernateTemplate().delete(car); } /** * {@inheritDoc} */ @Override public void remove(java.lang.Long id) { if (id == null) { throw new IllegalArgumentException( "Car.remove - 'id' can not be null"); } org.andromda.test.3.Car 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( "Car.remove - 'entities' can not be null"); } this.getHibernateTemplate().deleteAll(entities); } /** * {@inheritDoc} */ @Override public boolean allCarsAreRented() { try { return this.handleAllCarsAreRented(); } catch (Throwable th) { throw new RuntimeException( "Error performing 'org.andromda.test.3.CarDao.allCarsAreRented()' --> " + th, th); } } /** * Performs the core logic for {@link #allCarsAreRented()} * @return boolean * @throws Exception */ protected abstract boolean handleAllCarsAreRented() throws Exception; /** * 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.3.CarDao, 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.3.CarDao} * @param entity an entity that was found * @return the transformed entity (i.e. new value object, etc) * @see org.andromda.test.3.CarDao#transformEntity(int, org.andromda.test.3.Car) */ public Object transformEntity(final int transform, final org.andromda.test.3.Car entity) { Object target = null; if (entity != null) { switch (transform) { case org.andromda.test.3.CarDao.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.3.CarDao.TRANSFORM_NONE : // fall-through default: // do nothing; } } /** * @see org.andromda.test.3.CarDao#toEntities(java.util.Collection) */ 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.3.Car} * using the Jakarta Commons-Collections Transformation API. */ private org.apache.commons.collections.Transformer ENTITYTRANSFORMER = new org.apache.commons.collections.Transformer() { public Object transform(Object input) { Object result = null; if (input instanceof Object[]) { result = toEntity((Object[])input); } else if (input instanceof org.andromda.test.3.Car) { result = input; } return result; } }; /** * @param row * @return org.andromda.test.3.Car */ protected org.andromda.test.3.Car toEntity(Object[] row) { org.andromda.test.3.Car 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.3.Car) { target = (org.andromda.test.3.Car)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 @SuppressWarnings({ "unchecked" }) public org.andromda.spring.PaginationResult search(final int transform, final int pageNumber, final int pageSize, final org.andromda.spring.Search search) { try { search.setPageNumber(pageNumber); search.setPageSize(pageSize); final org.andromda.spring.PropertySearch propertySearch = new org.andromda.spring.PropertySearch( this.getSession(false), org.andromda.test.3.CarImpl.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()); } catch (org.hibernate.HibernateException ex) { throw super.convertHibernateAccessException(ex); } } /** * {@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.3.CarDao.TRANSFORM_NONE, pageNumber, pageSize, search); } /** * {@inheritDoc} */ @Override public java.util.Set search(final int transform, final org.andromda.spring.Search search) { try { final org.andromda.spring.PropertySearch propertySearch = new org.andromda.spring.PropertySearch( this.getSession(false), org.andromda.test.3.CarImpl.class, search); final java.util.Set results = propertySearch.executeAsSet(); this.transformEntities(transform, results); return results; } catch (org.hibernate.HibernateException ex) { throw super.convertHibernateAccessException(ex); } } /** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public java.util.Set search(final org.andromda.spring.Search search) { return (java.util.Set) this.search(org.andromda.test.3.CarDao.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) { try { 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. java.util.Set results = new java.util.LinkedHashSet(queryObject.list()); transformEntities(transform, results); return new org.andromda.spring.PaginationResult(results.toArray(new Object[results.size()]), totalCount); } catch (org.hibernate.HibernateException ex) { throw super.convertHibernateAccessException(ex); } } // spring-hibernate-dao-base merge-point }