本文整理了Java中org.hibernate.Criteria.setFetchSize()
方法的一些代码示例,展示了Criteria.setFetchSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Criteria.setFetchSize()
方法的具体详情如下:
包路径:org.hibernate.Criteria
类名称:Criteria
方法名:setFetchSize
[英]Set a fetch size for the underlying JDBC query.
[中]为基础JDBC查询设置获取大小。
代码示例来源:origin: spring-projects/spring-framework
/**
* Prepare the given Criteria object, applying cache settings and/or
* a transaction timeout.
* @param criteria the Criteria object to prepare
* @see #setCacheQueries
* @see #setQueryCacheRegion
*/
protected void prepareCriteria(Criteria criteria) {
if (isCacheQueries()) {
criteria.setCacheable(true);
if (getQueryCacheRegion() != null) {
criteria.setCacheRegion(getQueryCacheRegion());
}
}
if (getFetchSize() > 0) {
criteria.setFetchSize(getFetchSize());
}
if (getMaxResults() > 0) {
criteria.setMaxResults(getMaxResults());
}
ResourceHolderSupport sessionHolder =
(ResourceHolderSupport) TransactionSynchronizationManager.getResource(obtainSessionFactory());
if (sessionHolder != null && sessionHolder.hasTimeout()) {
criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
}
}
代码示例来源:origin: org.springframework/spring-orm
/**
* Prepare the given Criteria object, applying cache settings and/or
* a transaction timeout.
* @param criteria the Criteria object to prepare
* @see #setCacheQueries
* @see #setQueryCacheRegion
*/
protected void prepareCriteria(Criteria criteria) {
if (isCacheQueries()) {
criteria.setCacheable(true);
if (getQueryCacheRegion() != null) {
criteria.setCacheRegion(getQueryCacheRegion());
}
}
if (getFetchSize() > 0) {
criteria.setFetchSize(getFetchSize());
}
if (getMaxResults() > 0) {
criteria.setMaxResults(getMaxResults());
}
ResourceHolderSupport sessionHolder =
(ResourceHolderSupport) TransactionSynchronizationManager.getResource(obtainSessionFactory());
if (sessionHolder != null && sessionHolder.hasTimeout()) {
criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
}
}
代码示例来源:origin: stackoverflow.com
Criteria crit = HibernateUtil.getSession().createCriteria( persistentClass );
crit.setFirstResult(startIndex);
crit.setFetchSize(fetchSize);
crit.setCachable(true); // Enable caching of this query result
return crit.list();
代码示例来源:origin: openmrs/openmrs-core
/**
* @see org.openmrs.api.db.ConceptDAO#getPrevConcept(org.openmrs.Concept)
*/
@Override
@SuppressWarnings("unchecked")
public Concept getPrevConcept(Concept c) {
Integer i = c.getConceptId();
List<Concept> concepts = sessionFactory.getCurrentSession().createCriteria(Concept.class).add(
Restrictions.lt("conceptId", i)).addOrder(Order.desc("conceptId")).setFetchSize(1).list();
if (concepts.isEmpty()) {
return null;
}
return concepts.get(0);
}
代码示例来源:origin: com.atlassian.hibernate/hibernate.adapter
@Override
public Criteria setFetchSize(final int fetchSize) {
criteria.setFetchSize(fetchSize);
return null;
}
代码示例来源:origin: TGAC/miso-lims
@Override
public Criteria setFetchSize(int fetchSize) {
backingCriteria.setFetchSize(fetchSize);
return this;
}
代码示例来源:origin: ezbz/projectx
@Override
public Criteria setFetchSize(final int fetchSize) {
return criteria.setFetchSize(fetchSize);
}
代码示例来源:origin: openmrs/openmrs-core
ScrollableResults results = session.createCriteria(type).setFetchSize(1000).scroll(ScrollMode.FORWARD_ONLY);
int index = 0;
while (results.next()) {
代码示例来源:origin: com.silicolife.textmining/core
@SuppressWarnings("unchecked")
public List<T> findByAttributesWithPagniation(Map<String, Serializable> eqRestrictions, int index, int limit) {
Criteria c = sessionFactory.getCurrentSession().createCriteria(klass);
for (Map.Entry<String, Serializable> entry : eqRestrictions.entrySet())
c.add(Restrictions.eq(entry.getKey(), entry.getValue()));
c.setFirstResult(index);
c.setMaxResults(limit);
c.setFetchSize(limit);
return c.list();
}
代码示例来源:origin: com.silicolife.textmining/core
@Override
public List<Synonyms> findSynonymsByResourceElementWithLimit(Long resourceId, String synonym, int maxLimit) {
Session session = sessionFactory.getCurrentSession();
Criteria c = session.createCriteria(Synonyms.class, "syn");
c.createAlias("syn.resourceElements", "resourceElements");
c.createAlias("resourceElements.resources", "resources");
c.add(Restrictions.eq("resources.resoId", resourceId));
// Added By Hugo
c.add(Restrictions.eq("syn.id.synActive", true));
c.add(Restrictions.eq("resourceElements.resActive", true));
c.add(Restrictions.eq("syn.id.synSynonym", synonym));
// c.add(Restrictions.sqlRestriction("syn_synonym" + " = ? collate utf8_bin", synonym, new StringType()));
c.setMaxResults(maxLimit);
c.setFetchSize(maxLimit);
// c.setFirstResult(rowStart);
@SuppressWarnings("unchecked")
List<Synonyms> synonims = c.list();
return synonims;
}
代码示例来源:origin: com.silicolife.textmining/core
@Override
@SuppressWarnings("unchecked")
public List<Publications> findPublicationsByCorpusIdPaginated(Long corpusId, Integer paginationIndex, Integer paginationSize) {
Session session = sessionFactory.getCurrentSession();
Criteria c = session.createCriteria(Publications.class, "pub");
c.createAlias("pub.corpusHasPublicationses", "corpusHasPub");
c.setFetchMode("pub.corpusHasPublicationses", FetchMode.JOIN);
c.add(Restrictions.eq("corpusHasPub.id.chpCorpusId", corpusId));
c.setFirstResult(paginationIndex);
c.setMaxResults(paginationSize);
c.setFetchSize(paginationSize);
List<Publications> publications = c.list();
return publications;
}
代码示例来源:origin: stackoverflow.com
Criteria crit = session.createCriteria(User.class);
crit.createAlias("userLoginSession", "session", Criteria.INNER_JOIN);
crit.add(Restrictions.eq("session.token", sessionToken));
crit.setMaxResults(1);
crit.setFirstResult(0);
crit.setFetchSize(1);
代码示例来源:origin: org.picketlink.idm/picketlink-idm-hibernate
public Map<String, IdentityObjectAttribute> getAttributes(IdentityStoreInvocationContext ctx, IdentityObject identity) throws IdentityException
{
HibernateRealm realm = getRealm(getHibernateSession(ctx), ctx);
HibernateIdentityObjectType hibernateType = getHibernateIdentityObjectType(ctx, identity.getIdentityType());
Map<String, IdentityObjectAttribute> result = new HashMap<String, IdentityObjectAttribute>();
Criteria criteria = getHibernateSession(ctx).
createCriteria(HibernateIdentityObjectAttribute.class)
.setCacheable(true)
.setFetchMode("textValues", FetchMode.JOIN)
.setFetchSize(20)
.createAlias("identityObject", "io")
.add(Restrictions.eq("io.name", identity.getName()))
.add(Restrictions.eq("io.realm", realm))
.add(Restrictions.eq("io.identityType", hibernateType));
Collection<HibernateIdentityObjectAttribute> storeAttributes = (Collection<HibernateIdentityObjectAttribute>)criteria.list();
// Remap the names
for (HibernateIdentityObjectAttribute attribute : storeAttributes)
{
String name = resolveAttributeNameFromStoreMapping(identity.getIdentityType(), attribute.getName());
if (name != null)
{
result.put(name, attribute);
}
}
return result;
}
代码示例来源:origin: com.silicolife.textmining/core
@Override
@SuppressWarnings("unchecked")
public List<Publications> findPublicationsByQueryIdPaginated(Long queryId, Integer paginationIndex, Integer paginationSize, boolean asc, String sortBy) {
Session session = sessionFactory.getCurrentSession();
Criteria c = session.createCriteria(Publications.class, "pub");
c.setFetchMode("pub.queryHasPublicationses", FetchMode.JOIN);
c.createAlias("pub.queryHasPublicationses", "queriesHasPub");
c.add(Restrictions.eq("queriesHasPub.id.qhbQueryId", queryId));
//Order order = new Order(sortBy,asc);
//c.createAlias("pub."+sortBy, "sortValue");
if(!sortBy.equals("none")){
String uniqueId = PublicationFieldsEnum.valueOf(sortBy).getUniqueIdentifier();
String sortAlias = "pub."+uniqueId;
if(asc)
c.addOrder(Order.asc(sortAlias));
else
c.addOrder(Order.desc(sortAlias));
}
c.setFirstResult(paginationIndex);
c.setMaxResults(paginationSize);
c.setFetchSize(paginationSize);
List<Publications> publications = c.list();
return publications;
}
代码示例来源:origin: OneBusAway/onebusaway-application-modules
@Override
public List<BlockLocationRecord> doInHibernate(Session session)
throws HibernateException, SQLException {
Criteria c = session.createCriteria(BlockLocationRecord.class);
if (blockId != null)
c.add(Property.forName("blockId").eq(blockId));
if (tripId != null)
c.add(Property.forName("tripId").eq(tripId));
if (vehicleId != null)
c.add(Property.forName("vehicleId").eq(vehicleId));
if (serviceDate != 0)
c.add(Property.forName("serviceDate").eq(serviceDate));
if (fromTime != 0)
c.add(Property.forName("time").ge(fromTime));
if (toTime != 0)
c.add(Property.forName("time").le(toTime));
if (recordLimit != 0)
c.setFetchSize(recordLimit);
c.addOrder(Order.asc("time"));
return c.list();
}
});
代码示例来源:origin: org.onebusaway/onebusaway-transit-data-federation
@Override
public List<BlockLocationRecord> doInHibernate(Session session)
throws HibernateException, SQLException {
Criteria c = session.createCriteria(BlockLocationRecord.class);
if (blockId != null)
c.add(Property.forName("blockId").eq(blockId));
if (tripId != null)
c.add(Property.forName("tripId").eq(tripId));
if (vehicleId != null)
c.add(Property.forName("vehicleId").eq(vehicleId));
if (serviceDate != 0)
c.add(Property.forName("serviceDate").eq(serviceDate));
if (fromTime != 0)
c.add(Property.forName("time").ge(fromTime));
if (toTime != 0)
c.add(Property.forName("time").le(toTime));
if (recordLimit != 0)
c.setFetchSize(recordLimit);
c.addOrder(Order.asc("time"));
return c.list();
}
});
代码示例来源:origin: org.hibernatespatial/hibernate-spatial
public BasicFeatureReader(Class entityClass, SessionFactory sf, Geometry filterGeom, String attributeFilter) throws FinderException {
this.session = sf.openStatelessSession();
this.metadata = sf.getClassMetadata(entityClass);
String geomProp;
Criteria crit = this.session.createCriteria(entityClass);
if (filterGeom != null) {
GeometryPropertyFinder gp = new GeometryPropertyFinder();
geomProp = gp.find(this.metadata);
SpatialFilter filter = SpatialRestrictions.filter(geomProp,
filterGeom);
crit.add(filter);
}
if (attributeFilter != null) {
crit.add(Restrictions.sqlRestriction(attributeFilter));
}
// set explicit fetch size (necessary for postgresql)
crit.setFetchSize(fetchSize);
// ensure that there is no autocommit;
tx = this.session.beginTransaction();
this.results = crit.scroll(ScrollMode.FORWARD_ONLY);
}
代码示例来源:origin: hibernate/hibernate-search
.setCacheable( false )
.setFlushMode( FlushMode.MANUAL )
.setFetchSize( listIds.size() )
.setResultTransformer( CriteriaSpecification.DISTINCT_ROOT_ENTITY )
.add( Restrictions.in( idName, listIds ) );
代码示例来源:origin: org.infinispan/infinispan-cachestore-jpa
@Override
public Flowable<K> publishKeys(Predicate<? super K> filter) {
return Flowable.using(() -> {
EntityManager emStream = emf.createEntityManager();
Session session = emStream.unwrap(Session.class);
Criteria criteria = session.createCriteria(configuration.entityClass()).setProjection(Projections.id()).setReadOnly(true);
if (setFetchSizeMinInteger) {
criteria.setFetchSize(Integer.MIN_VALUE);
}
ScrollableResults results = criteria.scroll(ScrollMode.FORWARD_ONLY);
return new KeyValuePair<>(emStream, results);
}, kvp -> {
ScrollableResults results = kvp.getValue();
return Flowable.fromIterable(() -> new ScrollableResultsIterator(results, filter)
);
}, kvp -> {
try {
kvp.getValue().close();
} finally {
kvp.getKey().close();
}
});
}
代码示例来源:origin: apache/servicemix-bundles
/**
* Prepare the given Criteria object, applying cache settings and/or
* a transaction timeout.
* @param criteria the Criteria object to prepare
* @see #setCacheQueries
* @see #setQueryCacheRegion
* @see SessionFactoryUtils#applyTransactionTimeout
*/
protected void prepareCriteria(Criteria criteria) {
if (isCacheQueries()) {
criteria.setCacheable(true);
if (getQueryCacheRegion() != null) {
criteria.setCacheRegion(getQueryCacheRegion());
}
}
if (getFetchSize() > 0) {
criteria.setFetchSize(getFetchSize());
}
if (getMaxResults() > 0) {
criteria.setMaxResults(getMaxResults());
}
SessionFactoryUtils.applyTransactionTimeout(criteria, getSessionFactory());
}
内容来源于网络,如有侵权,请联系作者删除!