Example usage for org.hibernate.criterion Restrictions and

List of usage examples for org.hibernate.criterion Restrictions and

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions and.

Prototype

public static LogicalExpression and(Criterion lhs, Criterion rhs) 

Source Link

Document

Return the conjuction of two expressions

Usage

From source file:org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateQuery.java

License:Apache License

@Override
public Query and(Criterion a, Criterion b) {
    AbstractHibernateCriterionAdapter aa = createHibernateCriterionAdapter(getEntity(), a, alias);
    AbstractHibernateCriterionAdapter ab = createHibernateCriterionAdapter(getEntity(), a, alias);
    addToCriteria(Restrictions.and(aa.toHibernateCriterion(this), ab.toHibernateCriterion(this)));
    return this;
}

From source file:org.dspace.authorize.dao.impl.ResourcePolicyDAOImpl.java

License:BSD License

@Override
public List<ResourcePolicy> findByDsoAndType(Context context, DSpaceObject dso, String type)
        throws SQLException {
    Criteria criteria = createCriteria(context, ResourcePolicy.class);
    criteria.add(Restrictions.and(Restrictions.eq("dSpaceObject", dso), Restrictions.eq("rptype", type)));
    return list(criteria);
}

From source file:org.dspace.authorize.dao.impl.ResourcePolicyDAOImpl.java

License:BSD License

@Override
public List<ResourcePolicy> findByDSoAndAction(Context context, DSpaceObject dso, int actionId)
        throws SQLException {
    Criteria criteria = createCriteria(context, ResourcePolicy.class);
    criteria.add(Restrictions.and(Restrictions.eq("dSpaceObject", dso), Restrictions.eq("actionId", actionId)));
    return list(criteria);
}

From source file:org.dspace.checker.dao.impl.MostRecentChecksumDAOImpl.java

License:BSD License

@Override
public MostRecentChecksum getOldestRecord(Context context, Date lessThanDate) throws SQLException {
    //                "select bitstream_id  "
    //                + "from most_recent_checksum "
    //                + "where to_be_processed = true "
    //                + "and last_process_start_date < ? "
    //                + "order by date_trunc('milliseconds', last_process_end_date), "
    //                + "bitstream_id " + "ASC LIMIT 1";
    Criteria criteria = createCriteria(context, MostRecentChecksum.class);
    criteria.add(Restrictions.and(Restrictions.eq("toBeProcessed", true),
            Restrictions.lt("processStartDate", lessThanDate)));
    criteria.addOrder(Order.asc("processEndDate")).addOrder(Order.asc("bitstream.id"));
    criteria.setMaxResults(1);/*from   ww w  .ja  v  a2s  .c o  m*/
    return singleResult(criteria);
}

From source file:org.dspace.content.dao.impl.BitstreamDAOImpl.java

License:BSD License

@Override
public List<Bitstream> findDuplicateInternalIdentifier(Context context, Bitstream bitstream)
        throws SQLException {
    Criteria criteria = createCriteria(context, Bitstream.class);
    criteria.add(Restrictions.and(Restrictions.eq("internalId", bitstream.getInternalId()),
            Restrictions.not(Restrictions.eq("id", bitstream.getID()))));

    return list(criteria);
}

From source file:org.dspace.content.dao.impl.BitstreamFormatDAOImpl.java

License:BSD License

/**
 * Find a bitstream format by its (unique) MIME type.
 * If more than one bitstream format has the same MIME type, the
 * one returned is unpredictable.//from w  w w . j  a  va2 s. c  o  m
 *
 * @param context
 *            DSpace context object
 * @param mimeType
 *            MIME type value
 *
 * @return the corresponding bitstream format, or <code>null</code> if
 *         there's no bitstream format with the given MIMEtype.
 * @throws java.sql.SQLException
 */
@Override
public BitstreamFormat findByMIMEType(Context context, String mimeType, boolean includeInternal)
        throws SQLException {
    // NOTE: Avoid internal formats since e.g. "License" also has
    // a MIMEtype of text/plain.
    Criteria criteria = createCriteria(context, BitstreamFormat.class);
    criteria.add(Restrictions.and(Restrictions.eq("internal", includeInternal),
            Restrictions.like("mimetype", mimeType)));

    return singleResult(criteria);
}

From source file:org.dspace.content.dao.impl.BitstreamFormatDAOImpl.java

License:BSD License

@Override
public List<BitstreamFormat> findNonInternal(Context context) throws SQLException {
    Criteria criteria = createCriteria(context, BitstreamFormat.class);
    criteria.add(Restrictions.and(Restrictions.eq("internal", false),
            Restrictions.not(Restrictions.like("shortDescription", "Unknown"))));
    criteria.addOrder(Order.desc("supportLevel")).addOrder(Order.asc("shortDescription"));

    return list(criteria);

}

From source file:org.dspace.content.dao.impl.MetadataFieldDAOImpl.java

License:BSD License

@Override
public List<MetadataField> findFieldsByElementNameUnqualified(Context context, String metadataSchema,
        String element) throws SQLException {
    Criteria criteria = createCriteria(context, MetadataField.class);
    criteria.createAlias("metadataSchema", "s").add(
            Restrictions.and(Restrictions.eq("s.name", metadataSchema), Restrictions.eq("element", element)));
    criteria.setCacheable(true);//  w  w  w  .  j  a  va 2s.  c  o  m

    return list(criteria);
}

From source file:org.dspace.content.dao.impl.MetadataSchemaDAOImpl.java

License:BSD License

/**
 * Return true if and only if the passed name appears within the allowed
 * number of times in the current schema.
 *
 * @param context DSpace context//from   w  w  w  . j a va2 s  . c  o  m
 * @param namespace namespace URI to match
 * @return true of false
 * @throws java.sql.SQLException
 */
@Override
public boolean uniqueNamespace(Context context, int metadataSchemaId, String namespace) throws SQLException {
    Criteria criteria = createCriteria(context, MetadataSchema.class);
    criteria.add(Restrictions.and(Restrictions.not(Restrictions.eq("id", metadataSchemaId)),
            Restrictions.eq("namespace", namespace)));
    criteria.setCacheable(true);

    return uniqueResult(criteria) == null;
}

From source file:org.dspace.content.dao.impl.MetadataSchemaDAOImpl.java

License:BSD License

/**
 * Return true if and only if the passed name is unique.
 *
 * @param context DSpace context//from   www . jav a2s  . c o m
 * @param name  short name of schema
 * @return true of false
 * @throws java.sql.SQLException
 */
@Override
public boolean uniqueShortName(Context context, int metadataSchemaId, String name) throws SQLException {
    Criteria criteria = createCriteria(context, MetadataSchema.class);
    criteria.add(Restrictions.and(Restrictions.not(Restrictions.eq("id", metadataSchemaId)),
            Restrictions.eq("name", name)));
    criteria.setCacheable(true);

    return uniqueResult(criteria) == null;
}