Package vn.pyco.commons.dao.criteria

Examples of vn.pyco.commons.dao.criteria.Criteria


    }

    @SuppressWarnings(value = "unchecked")
    @Override
    public final T get(I id) {
        Criteria criteria = createCriteria();
        Criterion criterion = Restrictions.eq(Identifiable.PROP_ID, id);
        criteria.add(criterion);
        if (_deletable) {
            Criterion notDeleted = Restrictions.eq(Undeletable.PROP_DELETED, new Boolean(false));
            criteria.add(notDeleted);
        }
        return (T) _entityManager.find(_clazz, id);
    }
View Full Code Here


    }

    @SuppressWarnings("unchecked")
    @Override
    public final List<T> getAll() {
        Criteria criteria = createCriteria();
        if (_deletable) {
            Criterion notDeleted = Restrictions.eq(Undeletable.PROP_DELETED, new Boolean(false));
            criteria.add(notDeleted);
        }
        return findByCriteria(criteria);
    }
View Full Code Here

     * (non-Javadoc)
     * @see vn.pyco.commons.dao.GenericDao#countAll()
     */
    @Override
    public long countAll() {
        Criteria criteria = createCriteria();
        criteria.setProjection(Projections.count(Identifiable.PROP_ID));
        if (isDeletable()) {
            Criterion notDeleted = Restrictions.eq(Undeletable.PROP_DELETED, new Boolean(false));
            criteria.add(notDeleted);
        }
        Long count = (Long) criteria.uniqueResult(_entityManager);
       
        return count;
    }
View Full Code Here

    }
   
    @SuppressWarnings("unchecked")
    @Override
    public final List<T> findByExample(T example) {
        Criteria criteria = Criteria.forClass(_clazz);
        PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(_clazz);
        for (PropertyDescriptor descriptor : descriptors) {
            String propName = descriptor.getName();
           
            if (propName.equals(Identifiable.PROP_ID)) {
                continue;
            }
            if (propName.equals(Activable.PROP_ACTIVE)) {
                continue;
            }
            if (propName.equals(Defaultable.PROP_DEFAULT)) {
                continue;
            }
            if (propName.equals(Undeletable.PROP_DELETED)) {
                // always get item is not hidden
                criteria.add(Restrictions.eq(Undeletable.PROP_DELETED, new Boolean(false)));
                continue;
            }
           
            Method method = descriptor.getReadMethod();
            if (!method.isAnnotationPresent(Column.class) && !method.isAnnotationPresent(Basic.class)) {
                continue;
            }

            Object value = null;

            try {
                method.setAccessible(true);
                value = method.invoke(example);
            } catch (IllegalArgumentException e) {
                continue;
            } catch (IllegalAccessException e) {
                continue;
            } catch (InvocationTargetException e) {
                continue;
            }

            if (value == null) {
                continue;
            }

            criteria.add(Restrictions.eq(propName, value));
        }

        if (example instanceof Inheritable) {
            if (((Inheritable) example).getParent() == null) {
                criteria.add(Restrictions.isNull(Inheritable.PROP_PARENT));
            } else {
                criteria.add(Restrictions.eq(Inheritable.PROP_PARENT, ((Inheritable) example).getParent()));
            }
        }

        return findByCriteria(criteria);
    }
View Full Code Here

    @SuppressWarnings(value = "unchecked")
    public T getObjectByCriteria(String[] names, String[] values) {
        T result = null;
        try {
            Criteria criteria = createCriteria();
            for (int i = 0; i < names.length; i++) {
                criteria.add(Restrictions.eq(names[0], values[0]));
            }
            result = (T) findUniqueByCriteria(criteria);

        } catch (NoResultException e) {
            return null;
View Full Code Here

     */
    @Override
    public User getByUsername(String username) {
        User result = null;
        try {
            Criteria criteria = createCriteria();
            criteria.add(Restrictions.eq(User.PROP_USERNAME, username));
            result = (User) findUniqueByCriteria(criteria);
           
        } catch (NoResultException e) {
            return null;
        }
View Full Code Here

     */
    @Override
    public Authority getByName(String authority) {
        Authority result = null;
        try {
            Criteria criteria = createCriteria();
            criteria.add(Restrictions.eq(Authority.PROP_AUTHORITY, authority));
            result = (Authority) findUniqueByCriteria(criteria);
           
        } catch (Exception e) {
            logger.error("Could not get authority from name=" + authority);
            return null;
View Full Code Here

                                implements PropertyTypeDao {
    @Override
    public PropertyType getPropertyTypeByName(String name) {
        PropertyType result = null;
        try {
            Criteria criteria = createCriteria();
            criteria.add(Restrictions.eq(PropertyType.PROP_NAME, name));
            result = (PropertyType) findUniqueByCriteria(criteria);

        } catch (NoResultException e) {
            return null;
        }
View Full Code Here

            return null;
        }
       
        Page result = null;
        try {
            Criteria criteria = Criteria.forClass(Page.class);
            criteria.add(Restrictions.eq(Page.PROP_PARENT, node));
            criteria.add(Restrictions.eq(Page.PROP_DEFAULT, true));
            result = (Page) findUniqueByCriteria(criteria);
        } catch (NoResultException e) {
            // no-op
        } catch (Exception e) {
            logger.error("Cound not get default page from path=" + parentPath, e);
View Full Code Here

            return null;
        }
       
        Page result = null;
        try {
            Criteria criteria = Criteria.forClass(Page.class);
            criteria.add(Restrictions.eq(Page.PROP_PARENT, node));
            criteria.setMaxResults(1);
            result = (Page) findByCriteria(criteria).get(0);
        } catch (Exception e) {
            logger.error("Cound not get first page from path=" + parentPath, e);
            result = null;
        }
View Full Code Here

TOP

Related Classes of vn.pyco.commons.dao.criteria.Criteria

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.