org.iesc.flightws.domain.FlightDaoBase.java Source code

Java tutorial

Introduction

Here is the source code for org.iesc.flightws.domain.FlightDaoBase.java

Source

// license-header java merge-point
//
// Attention: Generated code! Do not modify by hand!
// Generated by: SpringHibernateDaoBase.vsl in andromda-spring-cartridge.
//
package org.iesc.flightws.domain;

/**
 * <p>
 * Base Spring DAO Class: is able to create, update, remove, load, and find
 * objects of type <code>org.iesc.flightws.domain.Flight</code>.
 * </p>
 *
 * @see org.iesc.flightws.domain.Flight
 */
public abstract class FlightDaoBase extends org.springframework.orm.hibernate3.support.HibernateDaoSupport
        implements org.iesc.flightws.domain.FlightDao {

    /**
     * @see org.iesc.flightws.domain.FlightDao#load(int, java.lang.Long)
     */
    public java.lang.Object load(final int transform, final java.lang.Long id) {
        if (id == null) {
            throw new IllegalArgumentException("Flight.load - 'id' can not be null");
        }
        final java.lang.Object entity = this.getHibernateTemplate().get(org.iesc.flightws.domain.FlightImpl.class,
                id);
        return transformEntity(transform, (org.iesc.flightws.domain.Flight) entity);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#load(java.lang.Long)
     */
    public org.iesc.flightws.domain.Flight load(java.lang.Long id) {
        return (org.iesc.flightws.domain.Flight) this.load(TRANSFORM_NONE, id);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#loadAll()
     */
    public java.util.Collection loadAll() {
        return this.loadAll(TRANSFORM_NONE);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#loadAll(int)
     */
    public java.util.Collection loadAll(final int transform) {
        return this.loadAll(transform, -1, -1);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#loadAll(int, int)
     */
    public java.util.Collection loadAll(final int pageNumber, final int pageSize) {
        return this.loadAll(TRANSFORM_NONE, pageNumber, pageSize);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#loadAll(int, int, int)
     */
    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.iesc.flightws.domain.FlightImpl.class);
            criteria.setCacheable(true);
            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);
        }
    }

    protected int calculateFirstResult(int pageNumber, int pageSize) {
        int firstResult = 0;
        if (pageNumber > 0) {
            firstResult = (pageNumber - 1) * pageSize;
        }
        return firstResult;
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#create(org.iesc.flightws.domain.Flight)
     */
    public org.iesc.flightws.domain.Flight create(org.iesc.flightws.domain.Flight flight) {
        return (org.iesc.flightws.domain.Flight) this.create(TRANSFORM_NONE, flight);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#create(int transform, org.iesc.flightws.domain.Flight)
     */
    public java.lang.Object create(final int transform, final org.iesc.flightws.domain.Flight flight) {
        if (flight == null) {
            throw new IllegalArgumentException("Flight.create - 'flight' can not be null");
        }
        this.getHibernateTemplate().save(flight);
        return this.transformEntity(transform, flight);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#create(java.util.Collection)
     */
    public java.util.Collection create(final java.util.Collection entities) {
        return create(TRANSFORM_NONE, entities);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#create(int, java.util.Collection)
     */
    public java.util.Collection create(final int transform, final java.util.Collection entities) {
        if (entities == null) {
            throw new IllegalArgumentException("Flight.create - 'entities' can not be null");
        }
        this.getHibernateTemplate().execute(new org.springframework.orm.hibernate3.HibernateCallback() {
            public java.lang.Object doInHibernate(org.hibernate.Session session)
                    throws org.hibernate.HibernateException {
                for (java.util.Iterator entityIterator = entities.iterator(); entityIterator.hasNext();) {
                    create(transform, (org.iesc.flightws.domain.Flight) entityIterator.next());
                }
                return null;
            }
        }, true);
        return entities;
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#create(java.lang.String)
     */
    public org.iesc.flightws.domain.Flight create(java.lang.String code) {
        return (org.iesc.flightws.domain.Flight) this.create(TRANSFORM_NONE, code);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#create(int, java.lang.String)
     */
    public java.lang.Object create(final int transform, java.lang.String code) {
        org.iesc.flightws.domain.Flight entity = new org.iesc.flightws.domain.FlightImpl();
        entity.setCode(code);
        return this.create(transform, entity);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#create(java.lang.String, org.iesc.flightws.domain.City, org.iesc.flightws.domain.City)
     */
    public org.iesc.flightws.domain.Flight create(java.lang.String code,
            org.iesc.flightws.domain.City departureCity, org.iesc.flightws.domain.City destinationCity) {
        return (org.iesc.flightws.domain.Flight) this.create(TRANSFORM_NONE, code, departureCity, destinationCity);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#create(int, java.lang.String, org.iesc.flightws.domain.City, org.iesc.flightws.domain.City)
     */
    public java.lang.Object create(final int transform, java.lang.String code,
            org.iesc.flightws.domain.City departureCity, org.iesc.flightws.domain.City destinationCity) {
        org.iesc.flightws.domain.Flight entity = new org.iesc.flightws.domain.FlightImpl();
        entity.setCode(code);
        entity.setDepartureCity(departureCity);
        entity.setDestinationCity(destinationCity);
        return this.create(transform, entity);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#update(org.iesc.flightws.domain.Flight)
     */
    public void update(org.iesc.flightws.domain.Flight flight) {
        if (flight == null) {
            throw new IllegalArgumentException("Flight.update - 'flight' can not be null");
        }
        this.getHibernateTemplate().update(flight);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#update(java.util.Collection)
     */
    public void update(final java.util.Collection entities) {
        if (entities == null) {
            throw new IllegalArgumentException("Flight.update - 'entities' can not be null");
        }
        this.getHibernateTemplate().execute(new org.springframework.orm.hibernate3.HibernateCallback() {
            public java.lang.Object doInHibernate(org.hibernate.Session session)
                    throws org.hibernate.HibernateException {
                for (java.util.Iterator entityIterator = entities.iterator(); entityIterator.hasNext();) {
                    update((org.iesc.flightws.domain.Flight) entityIterator.next());
                }
                return null;
            }
        }, true);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#remove(org.iesc.flightws.domain.Flight)
     */
    public void remove(org.iesc.flightws.domain.Flight flight) {
        if (flight == null) {
            throw new IllegalArgumentException("Flight.remove - 'flight' can not be null");
        }
        this.getHibernateTemplate().delete(flight);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#remove(java.lang.Long)
     */
    public void remove(java.lang.Long id) {
        if (id == null) {
            throw new IllegalArgumentException("Flight.remove - 'id' can not be null");
        }
        org.iesc.flightws.domain.Flight entity = this.load(id);
        if (entity != null) {
            this.remove(entity);
        }
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#remove(java.util.Collection)
     */
    public void remove(java.util.Collection entities) {
        if (entities == null) {
            throw new IllegalArgumentException("Flight.remove - 'entities' can not be null");
        }
        this.getHibernateTemplate().deleteAll(entities);
    }

    /**
     * Allows transformation of entities into value objects
     * (or something else for that matter), when the <code>transform</code>
     * flag is set to one of the constants defined in <code>org.iesc.flightws.domain.FlightDao</code>, please note
     * that the {@link #TRANSFORM_NONE} constant denotes no transformation, so the entity itself
     * will be returned.
     * <p>
     * This method will return instances of these types:
     * <ul>
     *   <li>{@link org.iesc.flightws.domain.Flight} - {@link #TRANSFORM_NONE}</li>
     *   <li>{@link org.iesc.flightws.vo.FlightVO} - {@link TRANSFORM_FLIGHTVO}</li>
     * </ul>
     *
     * If the integer argument value is unknown {@link #TRANSFORM_NONE} is assumed.
     *
     * @param transform one of the constants declared in {@link org.iesc.flightws.domain.FlightDao}
     * @param entity an entity that was found
     * @return the transformed entity (i.e. new value object, etc)
     * @see #transformEntities(int,java.util.Collection)
     */
    protected java.lang.Object transformEntity(final int transform, final org.iesc.flightws.domain.Flight entity) {
        java.lang.Object target = null;
        if (entity != null) {
            switch (transform) {
            case TRANSFORM_FLIGHTVO:
                target = toFlightVO(entity);
                break;
            case TRANSFORM_NONE: // fall-through
            default:
                target = entity;
            }
        }
        return target;
    }

    /**
     * Transforms a collection of entities using the
     * {@link #transformEntity(int,org.iesc.flightws.domain.Flight)}
     * method. This method does not instantiate a new collection.
     * <p>
     * This method is to be used internally only.
     *
     * @param transform one of the constants declared in <code>org.iesc.flightws.domain.FlightDao</code>
     * @param entities the collection of entities to transform
     * @see #transformEntity(int,org.iesc.flightws.domain.Flight)
     */
    protected void transformEntities(final int transform, final java.util.Collection entities) {
        switch (transform) {
        case TRANSFORM_FLIGHTVO:
            toFlightVOCollection(entities);
            break;
        case TRANSFORM_NONE: // fall-through
        default:
            // do nothing;
        }
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#toEntities(java.util.Collection)
     */
    public void toEntities(final java.util.Collection results) {
        if (results != null) {
            org.apache.commons.collections.CollectionUtils.transform(results, ENTITYTRANSFORMER);
        }
    }

    /**
     * This anonymous transformer is designed to transform report query results
     * (which result in an array of entities) to {@link org.iesc.flightws.domain.Flight}
     * using the Jakarta Commons-Collections Transformation API.
     */
    private org.apache.commons.collections.Transformer ENTITYTRANSFORMER = new org.apache.commons.collections.Transformer() {
        public java.lang.Object transform(java.lang.Object input) {
            java.lang.Object result = null;
            if (input instanceof java.lang.Object[]) {
                result = toEntity((java.lang.Object[]) input);
            } else if (input instanceof org.iesc.flightws.domain.Flight) {
                result = input;
            }
            return result;
        }
    };

    protected org.iesc.flightws.domain.Flight toEntity(java.lang.Object[] row) {
        org.iesc.flightws.domain.Flight target = null;
        if (row != null) {
            final int numberOfObjects = row.length;
            for (int ctr = 0; ctr < numberOfObjects; ctr++) {
                final java.lang.Object object = row[ctr];
                if (object instanceof org.iesc.flightws.domain.Flight) {
                    target = (org.iesc.flightws.domain.Flight) object;
                    break;
                }
            }
        }
        return target;
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#toFlightVOCollection(java.util.Collection)
     */
    public final void toFlightVOCollection(java.util.Collection entities) {
        if (entities != null) {
            org.apache.commons.collections.CollectionUtils.transform(entities, FLIGHTVO_TRANSFORMER);
        }
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#toFlightVOArray(java.util.Collection)
     */
    public final org.iesc.flightws.vo.FlightVO[] toFlightVOArray(java.util.Collection entities) {
        org.iesc.flightws.vo.FlightVO[] result = null;
        if (entities != null) {
            final java.util.Collection collection = new java.util.ArrayList(entities);
            this.toFlightVOCollection(collection);
            result = (org.iesc.flightws.vo.FlightVO[]) collection.toArray(new org.iesc.flightws.vo.FlightVO[0]);
        }
        return result;
    }

    /**
     * Default implementation for transforming the results of a report query into a value object. This
     * implementation exists for convenience reasons only. It needs only be overridden in the
     * {@link FlightDaoImpl} class if you intend to use reporting queries.
     * @see org.iesc.flightws.domain.FlightDao#toFlightVO(org.iesc.flightws.domain.Flight)
     */
    protected org.iesc.flightws.vo.FlightVO toFlightVO(java.lang.Object[] row) {
        return this.toFlightVO(this.toEntity(row));
    }

    /**
     * This anonymous transformer is designed to transform entities or report query results
     * (which result in an array of objects) to {@link org.iesc.flightws.vo.FlightVO}
     * using the Jakarta Commons-Collections Transformation API.
     */
    private org.apache.commons.collections.Transformer FLIGHTVO_TRANSFORMER = new org.apache.commons.collections.Transformer() {
        public java.lang.Object transform(java.lang.Object input) {
            java.lang.Object result = null;
            if (input instanceof org.iesc.flightws.domain.Flight) {
                result = toFlightVO((org.iesc.flightws.domain.Flight) input);
            } else if (input instanceof java.lang.Object[]) {
                result = toFlightVO((java.lang.Object[]) input);
            }
            return result;
        }
    };

    /**
     * @see org.iesc.flightws.domain.FlightDao#flightVOToEntityCollection(java.util.Collection)
     */
    public final void flightVOToEntityCollection(java.util.Collection instances) {
        if (instances != null) {
            for (final java.util.Iterator iterator = instances.iterator(); iterator.hasNext();) {
                // - remove an objects that are null or not of the correct instance
                if (!(iterator.next() instanceof org.iesc.flightws.vo.FlightVO)) {
                    iterator.remove();
                }
            }
            org.apache.commons.collections.CollectionUtils.transform(instances, FlightVOToEntityTransformer);
        }
    }

    private final org.apache.commons.collections.Transformer FlightVOToEntityTransformer = new org.apache.commons.collections.Transformer() {
        public java.lang.Object transform(java.lang.Object input) {
            return flightVOToEntity((org.iesc.flightws.vo.FlightVO) input);
        }
    };

    /**
     * @see org.iesc.flightws.domain.FlightDao#toFlightVO(org.iesc.flightws.domain.Flight, org.iesc.flightws.vo.FlightVO)
     */
    public void toFlightVO(org.iesc.flightws.domain.Flight source, org.iesc.flightws.vo.FlightVO target) {
        target.setId(source.getId());
        target.setCode(source.getCode());
        // No conversion for target.destinationCity (can't convert source.getDestinationCity():org.iesc.flightws.domain.City to org.iesc.flightws.vo.CityVO)
        // No conversion for target.departureCity (can't convert source.getDepartureCity():org.iesc.flightws.domain.City to org.iesc.flightws.vo.CityVO)
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#toFlightVO(org.iesc.flightws.domain.Flight)
     */
    public org.iesc.flightws.vo.FlightVO toFlightVO(final org.iesc.flightws.domain.Flight entity) {
        org.iesc.flightws.vo.FlightVO target = null;
        if (entity != null) {
            target = new org.iesc.flightws.vo.FlightVO();
            this.toFlightVO(entity, target);
        }
        return target;
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#flightVOToEntity(org.iesc.flightws.vo.FlightVO, org.iesc.flightws.domain.Flight)
     */
    public void flightVOToEntity(org.iesc.flightws.vo.FlightVO source, org.iesc.flightws.domain.Flight target,
            boolean copyIfNull) {
        if (copyIfNull || source.getCode() != null) {
            target.setCode(source.getCode());
        }
    }

    /**
     * Gets the current <code>principal</code> if one has been set,
     * otherwise returns <code>null</code>.
     *
     * @return the current principal
     */
    protected java.security.Principal getPrincipal() {
        return org.iesc.flightws.PrincipalStore.get();
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#search(int, int, int, org.iesc.flightws.Search)
     */
    public org.iesc.flightws.PaginationResult search(final int transform, final int pageNumber, final int pageSize,
            final org.iesc.flightws.Search search) {
        try {
            search.setPageNumber(pageNumber);
            search.setPageSize(pageSize);
            final org.iesc.flightws.PropertySearch propertySearch = new org.iesc.flightws.PropertySearch(
                    this.getSession(false), org.iesc.flightws.domain.FlightImpl.class, search);
            final java.util.List results = propertySearch.executeAsList();
            this.transformEntities(transform, results);
            return new org.iesc.flightws.PaginationResult(results.toArray(new java.lang.Object[0]),
                    propertySearch.getTotalCount());
        } catch (org.hibernate.HibernateException ex) {
            throw super.convertHibernateAccessException(ex);
        }
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#search(int, int, org.iesc.flightws.Search)
     */
    public org.iesc.flightws.PaginationResult search(final int pageNumber, final int pageSize,
            final org.iesc.flightws.Search search) {
        return this.search(TRANSFORM_NONE, pageNumber, pageSize, search);
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#search(int, org.iesc.flightws.Search)
     */
    public java.util.Set search(final int transform, final org.iesc.flightws.Search search) {
        try {
            final org.iesc.flightws.PropertySearch propertySearch = new org.iesc.flightws.PropertySearch(
                    this.getSession(false), org.iesc.flightws.domain.FlightImpl.class, search);
            final java.util.Set results = propertySearch.executeAsSet();
            this.transformEntities(transform, results);
            return results;
        } catch (org.hibernate.HibernateException ex) {
            throw super.convertHibernateAccessException(ex);
        }
    }

    /**
     * @see org.iesc.flightws.domain.FlightDao#search(org.iesc.flightws.Search)
     */
    public java.util.Set search(final org.iesc.flightws.Search search) {
        return this.search(TRANSFORM_NONE, search);
    }

    // spring-hibernate-dao-base merge-point
}