List of usage examples for org.hibernate Criteria setCacheable
public Criteria setCacheable(boolean cacheable);
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//w w w. j av a 2 s. co 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 ww w . j a v a2 s. 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; }
From source file:org.dspace.content.dao.impl.MetadataSchemaDAOImpl.java
License:BSD License
/** * Get the schema corresponding with this short name. * * @param context//from w w w. jav a 2 s .c o m * context, in case we need to read it in from DB * @param shortName * the short name for the schema * @return the metadata schema object * @throws java.sql.SQLException */ @Override public MetadataSchema find(Context context, String shortName) throws SQLException { Criteria criteria = createCriteria(context, MetadataSchema.class); criteria.add(Restrictions.eq("name", shortName)); criteria.setCacheable(true); return uniqueResult(criteria); }
From source file:org.dspace.eperson.dao.impl.Group2GroupCacheDAOImpl.java
License:BSD License
@Override public List<Group2GroupCache> findByParent(Context context, Group group) throws SQLException { Criteria criteria = createCriteria(context, Group2GroupCache.class); criteria.add(Restrictions.eq("parent.id", group.getID())); criteria.setCacheable(true); return list(criteria); }
From source file:org.dspace.eperson.dao.impl.Group2GroupCacheDAOImpl.java
License:BSD License
@Override public List<Group2GroupCache> findByChildren(Context context, Set<Group> groups) throws SQLException { Criteria criteria = createCriteria(context, Group2GroupCache.class); Disjunction orDisjunction = Restrictions.or(); for (Group group : groups) { orDisjunction.add(Restrictions.eq("child.id", group.getID())); }/*from ww w. jav a 2 s. c o m*/ criteria.add(orDisjunction); criteria.setCacheable(true); return list(criteria); }
From source file:org.dspace.eperson.dao.impl.Group2GroupCacheDAOImpl.java
License:BSD License
@Override public Group2GroupCache find(Context context, Group parent, Group child) throws SQLException { Criteria criteria = createCriteria(context, Group2GroupCache.class); criteria.add(Restrictions.eq("parent.id", parent.getID())); criteria.add(Restrictions.eq("child.id", child.getID())); criteria.setCacheable(true); return uniqueResult(criteria); }
From source file:org.faster.orm.service.hibernate.HibernateDaoSupport.java
License:Open Source License
@SuppressWarnings("rawtypes") protected List fetchPage(final DetachedCriteria criteria, final int page, final int limit, QueryOption queryOption) {/*from w w w . j av a2 s .co m*/ renderCriteria(criteria); Criteria executableCriteria = criteria.getExecutableCriteria(getSession()); if (queryOption != null) { executableCriteria.setCacheable(queryOption.isCacheEnabled()); if (cacheRegion != null) { executableCriteria.setCacheRegion(cacheRegion); } } if (page >= 1) { executableCriteria.setFirstResult((page - 1) * limit); } if (limit > 0) { executableCriteria.setMaxResults(limit); } return executableCriteria.list(); }
From source file:org.fornax.cartridges.sculptor.framework.accessimpl.jpahibernate.JpaHibFindByConditionAccessImpl.java
License:Apache License
protected void prepareCache(Criteria criteria) { if (isCache()) { criteria.setCacheable(true); criteria.setCacheRegion(getCacheRegion()); }/*from w w w . j a va 2 s . c o m*/ }
From source file:org.fosstrak.epcis.repository.capture.CaptureOperationsModule.java
License:Open Source License
/** * (changed by nkef to support MasterDataCapture. Previusly known as * "getOrInsertVocabularyElement") Inserts vocabulary into the database by * searching for already existing entries; if found, the corresponding ID is * returned. If not found, the vocabulary is extended if "insertmissingvoc" * is true; otherwise an SQLException is thrown * //from w w w . j av a 2s . c om * @param tableName * The name of the vocabulary table. * @param uri * The vocabulary adapting the URI to be inserted into the * vocabulary table. * @return The ID of an already existing vocabulary table with the given * uri. * @throws UnsupportedOperationException * If we are not allowed to insert a missing vocabulary. */ public VocabularyElement getOrEditVocabularyElement(Session session, String vocabularyType, String vocabularyElementURI, String mode) throws SAXException { boolean alterURI = false; boolean singleDelete = false; boolean wdDelete = false; Long vocabularyElementID = null; if (mode.equals("2")) { alterURI = true; } else if (mode.equals("3")) { singleDelete = true; } else if (mode.equals("4")) { wdDelete = true; } Class<?> c = vocClassMap.get(vocabularyType); Criteria c0 = session.createCriteria(c); c0.setCacheable(true); c0.add(Restrictions.eq("uri", alterURI ? vocabularyElementURI.split("#")[0] : vocabularyElementURI)); VocabularyElement ve; try { ve = (VocabularyElement) c0.uniqueResult(); } catch (ObjectNotFoundException e) { ve = null; } if (ve != null) { vocabularyElementID = ve.getId(); } if (ve == null || ((singleDelete || alterURI || wdDelete) && ve != null)) { // the uri does not yet exist: insert it if allowed. According to // the specs, some vocabulary is not allowed to be extended; this is // currently ignored here if (!insertMissingVoc) { throw new UnsupportedOperationException( "Not allowed to add new vocabulary - use existing vocabulary"); } else { // VocabularyElement subclasses should always have public // zero-arg constructor to avoid problems here if (alterURI) { ve.setUri(vocabularyElementURI.split("#")[1]); session.update(ve); session.flush(); return ve; } else if (singleDelete) { Object vocabularyElementObject = session.get(c, vocabularyElementID); if (vocabularyElementObject != null) session.delete(vocabularyElementObject); deleteVocabularyElementAttributes(session, vocabularyType, vocabularyElementID); session.flush(); return null; } else if (wdDelete) { Object vocabularyElementObject = session.get(c, vocabularyElementID); if (vocabularyElementObject != null) session.delete(vocabularyElementObject); deleteVocabularyElementAttributes(session, vocabularyType, vocabularyElementID); deleteVocabularyElementDescendants(session, vocabularyType, vocabularyElementURI); session.flush(); return null; } else { try { ve = (VocabularyElement) c.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } ve.setUri(vocabularyElementURI); session.save(ve); } session.flush(); } } return ve; }
From source file:org.fosstrak.epcis.repository.capture.CaptureOperationsModule.java
License:Open Source License
/** * (nkef) Inserts vocabulary attribute into the database by searching for * already existing entries; if found, the corresponding ID is returned. If * not found, the vocabulary is extended if "insertmissingvoc" is true; * otherwise an SQLException is thrown//from w ww. j av a2 s . c o m * * @param tableName * The name of the vocabulary table. * @param uri * The vocabulary adapting the URI to be inserted into the * vocabulary table. * @return The ID of an already existing vocabulary table with the given * uri. * @throws UnsupportedOperationException * If we are not allowed to insert a missing vocabulary. */ public VocabularyAttributeElement getOrEditVocabularyAttributeElement(Session session, String vocabularyType, Long vocabularyElementID, String vocabularyAttributeElement, String vocabularyAttributeElementValue, String mode) throws SAXException { boolean deleteAttribute = false; if (mode.equals("3")) { deleteAttribute = true; } Class<?> c = vocAttributeClassMap.get(vocabularyType); Criteria c0 = session.createCriteria(c); c0.setCacheable(true); VocabularyAttrCiD vocabularyAttrCiD = new VocabularyAttrCiD(); vocabularyAttrCiD.setAttribute(vocabularyAttributeElement); vocabularyAttrCiD.setId(vocabularyElementID); c0.add(Restrictions.idEq(vocabularyAttrCiD)); VocabularyAttributeElement vocAttributeElement = null; try { vocAttributeElement = (VocabularyAttributeElement) c0.uniqueResult(); } catch (ObjectNotFoundException e) { vocAttributeElement = null; e.printStackTrace(); } if (vocAttributeElement == null || (deleteAttribute && (vocAttributeElement != null)) || vocAttributeElement != null) { // the uri does not yet exist: insert it if allowed. According to // the specs, some vocabulary is not allowed to be extended; this is // currently ignored here if (!insertMissingVoc) { throw new UnsupportedOperationException( "Not allowed to add new vocabulary - use existing vocabulary"); } else { // VocabularyAttributeElement subclasses should always have // public zero-arg constructor to avoid problems here try { vocAttributeElement = (VocabularyAttributeElement) c.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } vocAttributeElement.setVocabularyAttrCiD(vocabularyAttrCiD); vocAttributeElement.setValue(vocabularyAttributeElementValue); if (vocAttributeElement == null) { session.save(vocAttributeElement); } else if (deleteAttribute) { Object vocabularyAttr = session.get(c, vocabularyAttrCiD); if (vocabularyAttr != null) session.delete(vocabularyAttr); session.flush(); return null; } else { session.merge(vocAttributeElement); } session.flush(); } } return vocAttributeElement; }