本文整理汇总了Java中org.hibernate.criterion.DetachedCriteria类的典型用法代码示例。如果您正苦于以下问题:Java DetachedCriteria类的具体用法?Java DetachedCriteria怎么用?Java DetachedCriteria使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DetachedCriteria类属于org.hibernate.criterion包,在下文中一共展示了DetachedCriteria类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareItemQuery
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
@Override
public void prepareItemQuery(ItemSerializerState state)
{
final DetachedCriteria criteria = state.getItemQuery();
final ProjectionList projection = state.getItemProjection();
if( state.hasCategory(ItemSerializerService.CATEGORY_BASIC) )
{
projection.add(Projections.property("name.id"), NAME_ALIAS);
projection.add(Projections.property("description.id"), DESC_ALIAS);
}
if( state.hasCategory(ItemSerializerService.CATEGORY_METADATA) )
{
criteria.createAlias("itemXml", "itemXml");
projection.add(Projections.property("itemXml.xml"), METADATA_ALIAS);
}
}
示例2: listCriteria
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
@SuppressWarnings ("unchecked")
public List<T> listCriteria (DetachedCriteria detached, int skip, int top)
{
SessionFactory factory = getSessionFactory ();
org.hibernate.classic.Session session = factory.getCurrentSession ();
Criteria criteria = detached.getExecutableCriteria (session);
if (skip > 0)
criteria.setFirstResult (skip);
if (top > 0)
criteria.setMaxResults (top);
return criteria.list ();
}
示例3: findByCriteria
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
@Override
public List<?> findByCriteria(final DetachedCriteria criteria, final int firstResult, final int maxResults)
throws DataAccessException {
Assert.notNull(criteria, "DetachedCriteria must not be null");
return executeWithNativeSession(new HibernateCallback<List<?>>() {
@Override
@SuppressWarnings("unchecked")
public List<?> doInHibernate(Session session) throws HibernateException {
Criteria executableCriteria = criteria.getExecutableCriteria(session);
prepareCriteria(executableCriteria);
if (firstResult >= 0) {
executableCriteria.setFirstResult(firstResult);
}
if (maxResults > 0) {
executableCriteria.setMaxResults(maxResults);
}
return executableCriteria.list();
}
});
}
示例4: execute
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
private Object execute(FlowFinderCriteria flowFinderCriteria,
DetachedCriteria flowStatusCriteria, Session session,
boolean idProjection) {
Criteria criteria = flowStatusCriteria.getExecutableCriteria(session);
if (idProjection) {
criteria.setProjection(Projections.id());
}
int maxResults = flowFinderCriteria.getMaxResults();
if (maxResults != FlowFinderCriteria.DEFAULT_MAX_RESULTS) {
criteria.setMaxResults(maxResults);
}
if (flowFinderCriteria.hasMessageQuery()) {
FlowSearchCriteria flowSearchCriteria = new FlowSearchCriteria();
flowSearchCriteria.setHibernateCriteria(criteria);
flowSearchCriteria.setInboundMessageQuery(flowFinderCriteria.getInboundMessageQuery());
flowSearchCriteria.setOutboundMessageQuery(flowFinderCriteria.getOutboundMessageQuery());
return flowSearchCallback.findFlows(session, flowSearchCriteria);
} else {
return criteria.list();
}
}
示例5: createFlowsCriteria
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
private static DetachedCriteria createFlowsCriteria(FlowFinderCriteria finderCriteria) {
DetachedCriteria criteria = DetachedCriteria.forClass(Flow.class)
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.setFetchMode("parts", FetchMode.JOIN) // eager
.add(ge("creationTime", finderCriteria.getFrom()))
.addOrder(Order.desc("identifier"));
if (finderCriteria.getApplication() != null) {
// constrain query to a certain application name
criteria.add(eq("application", finderCriteria
.getApplication()));
}
if (finderCriteria.getTo() != null) {
// there's an upper limit to creationTime property
criteria.add(Restrictions
.le("creationTime", finderCriteria.getTo()));
}
return criteria;
}
示例6: createPurgeCriteria
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
private static DetachedCriteria createPurgeCriteria(FlowPurgeCriteria purgeCriteria) {
DetachedCriteria criteria = DetachedCriteria.forClass(Flow.class)
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
// purge all flows with a creation time older than time limit
.add(lt("creationTime", purgeCriteria.getTimeLimit()))
// purge oldest flows first
.addOrder(Order.asc("creationTime"));
if (purgeCriteria.getApplication() != null) {
criteria.add(eq("application", purgeCriteria.getApplication()));
}
if (purgeCriteria.getPurgeMode() == PurgeMode.CLEAN) {
// omit flows with error status
criteria.add(
or(
eq("derivedStatus", FlowStatus.CLEAN),
isNull("derivedStatus") // old flows (both CLEAN and ERROR)
)
);
}
return criteria;
}
示例7: getLast
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
@Override
public QuotePE getLast(String sigle) {
Session session = getSession();
DetachedCriteria maxDate = DetachedCriteria.forClass(QuotePE.class);
maxDate.add(Restrictions.eq("symbol", sigle));
maxDate.setProjection(Projections.max("creationDateTime"));
Criteria criteria = session.createCriteria(QuotePE.class);
criteria.add(Restrictions.eq("symbol", sigle));
criteria.add(Property.forName("creationDateTime").eq(maxDate));
QuotePE pe = (QuotePE) criteria.uniqueResult();
session.close();
return pe;
}
示例8: process
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
@Override
public RpcGetAuthorizCustomer process(CmdParams cmdParams, String ipAdress, byte[] IP) {
QLog.l().logQUser().debug("getClientAuthorization");
super.process(cmdParams, ipAdress, IP);
// Вытащим из базы предварительного кастомера
if (cmdParams.clientAuthId == null || cmdParams.clientAuthId.isEmpty()) {
return new RpcGetAuthorizCustomer(null);
}
final List<QAuthorizationCustomer> authCusts = Spring.getInstance().getHt()
.findByCriteria(
DetachedCriteria.forClass(QAuthorizationCustomer.class)
.add(Restrictions.eq("authId", cmdParams.clientAuthId).ignoreCase()));
final QAuthorizationCustomer authCust;
if (authCusts.isEmpty() || authCusts.get(0) == null || authCusts.get(0).getId() == null
|| authCusts.get(0).getName() == null) {
QLog.l().logger()
.trace("Не найден клиент по его ID = '" + cmdParams.clientAuthId + "'");
authCust = null;
} else {
authCust = authCusts.get(0);
}
return new RpcGetAuthorizCustomer(authCust);
}
示例9: deleteComponentProfileByControlId
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void deleteComponentProfileByControlId(String controlId, String name) {
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(ComponentConfig.class);
detachedCriteria.add(Restrictions.eq("controlId", controlId));
detachedCriteria.add(Restrictions.eq("name", name));
Session session = this.getSessionFactory().openSession();
try {
org.hibernate.Criteria criteria = detachedCriteria.getExecutableCriteria(session);
List<ComponentConfig> list = criteria.list();
if (list.size() > 0) {
String hql = "delete " + ComponentConfigMember.class.getName()
+ " m where m.componentConfig.id = :configId";
session.createQuery(hql).setString("configId", list.get(0).getId()).executeUpdate();
session.delete(list.get(0));
}
} finally {
session.flush();
session.close();
}
}
示例10: loadMessageTemplates
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
public void loadMessageTemplates(Page<MessageTemplate> page,Criteria criteria,String type){
IUser user=ContextHolder.getLoginUser();
if(user==null){
throw new RuntimeException("Please login first!");
}
String companyId=user.getCompanyId();
if(StringUtils.isNotEmpty(getFixedCompanyId())){
companyId=getFixedCompanyId();
}
DetachedCriteria dc=this.buildDetachedCriteria(criteria, MessageTemplate.class);
if(StringUtils.isNotEmpty(type)){
dc.add(Property.forName("type").eq(type));
}
Property p=Property.forName("companyId");
dc.add(p.eq(companyId));
this.pagingQuery(page, dc);
}
示例11: createEcrfFieldValueDetachedCriteria
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
private static DetachedCriteria createEcrfFieldValueDetachedCriteria(org.hibernate.Criteria ecrfFieldValueCriteria, org.hibernate.Criteria ecrfFieldCriteria,
org.hibernate.Criteria probandListEntryCriteria,
Long probandListEntryId, Long ecrfFieldId) {
DetachedCriteria subQuery = DetachedCriteria.forClass(ECRFFieldValueImpl.class, "ecrfFieldValue1"); // IMPL!!!!
// subQuery.setProjection(Projections.max("id"));
if (probandListEntryId == null) {
if (probandListEntryCriteria == null) {
probandListEntryCriteria = ecrfFieldValueCriteria.createCriteria("listEntry", "probandListEntry0");
}
subQuery.add(Restrictions.eqProperty("listEntry.id", probandListEntryCriteria.getAlias() + ".id"));
} else {
subQuery.add(Restrictions.eq("listEntry.id", probandListEntryId.longValue()));
}
if (ecrfFieldId == null) {
if (ecrfFieldCriteria == null) {
ecrfFieldCriteria = ecrfFieldValueCriteria.createCriteria("ecrfField", "ecrfField0");
}
subQuery.add(Restrictions.eqProperty("ecrfField.id", ecrfFieldCriteria.getAlias() + ".id"));
} else {
subQuery.add(Restrictions.eq("ecrfField.id", ecrfFieldId.longValue()));
}
return subQuery;
}
示例12: buildCriterions
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
private void buildCriterions(Collection<com.bstek.dorado.data.provider.Criterion> criterions, DetachedCriteria dc) {
for (com.bstek.dorado.data.provider.Criterion c : criterions) {
if (c instanceof SingleValueFilterCriterion) {
SingleValueFilterCriterion fc = (SingleValueFilterCriterion) c;
dc.add(this.buildCriterion(fc));
}
if (c instanceof Junction) {
Junction jun = (Junction) c;
org.hibernate.criterion.Junction junction = null;
if (jun instanceof Or) {
junction = Restrictions.disjunction();
} else if (jun instanceof And) {
junction = Restrictions.conjunction();
}
Collection<com.bstek.dorado.data.provider.Criterion> subCriterions = jun.getCriterions();
if (subCriterions != null) {
buildCriterions(subCriterions, junction);
}
dc.add(junction);
}
}
}
示例13: createEcrfFieldStatusEntryDetachedCriteria
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
private static DetachedCriteria createEcrfFieldStatusEntryDetachedCriteria(org.hibernate.Criteria ecrfFieldStatusEntryCriteria, org.hibernate.Criteria ecrfFieldCriteria,
org.hibernate.Criteria probandListEntryCriteria,
Long probandListEntryId, Long ecrfFieldId) {
DetachedCriteria subQuery = DetachedCriteria.forClass(ECRFFieldStatusEntryImpl.class, "ecrfFieldStatusEntry1"); // IMPL!!!!
// subQuery.setProjection(Projections.max("id"));
if (probandListEntryId == null) {
if (probandListEntryCriteria == null) {
probandListEntryCriteria = ecrfFieldStatusEntryCriteria.createCriteria("listEntry", "probandListEntry0");
}
subQuery.add(Restrictions.eqProperty("listEntry.id", probandListEntryCriteria.getAlias() + ".id"));
} else {
subQuery.add(Restrictions.eq("listEntry.id", probandListEntryId.longValue()));
}
if (ecrfFieldId == null) {
if (ecrfFieldCriteria == null) {
ecrfFieldCriteria = ecrfFieldStatusEntryCriteria.createCriteria("ecrfField", "ecrfField0");
}
subQuery.add(Restrictions.eqProperty("ecrfField.id", ecrfFieldCriteria.getAlias() + ".id"));
} else {
subQuery.add(Restrictions.eq("ecrfField.id", ecrfFieldId.longValue()));
}
return subQuery;
}
示例14: createEcrfFieldStatusEntryDetachedCriteriaMaxId
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
private static DetachedCriteria createEcrfFieldStatusEntryDetachedCriteriaMaxId(org.hibernate.Criteria ecrfFieldStatusEntryCriteria, org.hibernate.Criteria ecrfFieldCriteria,
org.hibernate.Criteria probandListEntryCriteria,
ECRFFieldStatusQueue queue, Long probandListEntryId, Long ecrfFieldId) {
DetachedCriteria subQuery = createEcrfFieldStatusEntryDetachedCriteria(ecrfFieldStatusEntryCriteria, ecrfFieldCriteria, probandListEntryCriteria, probandListEntryId,
ecrfFieldId);
if (queue != null) {
subQuery.add(Restrictions.eq("queue", queue));
subQuery.setProjection(Projections.max("id"));
} else {
ProjectionList proj = Projections.projectionList();
proj.add(Projections.sqlGroupProjection(
"max({alias}.id) as maxId",
"{alias}.queue",
new String[] { "maxId" },
new org.hibernate.type.Type[] { Hibernate.LONG }));
subQuery.setProjection(proj);
}
return subQuery;
}
示例15: uniqueResult
import org.hibernate.criterion.DetachedCriteria; //导入依赖的package包/类
@SuppressWarnings ("unchecked")
public T uniqueResult (DetachedCriteria criteria)
{
Criteria excrit = criteria.getExecutableCriteria(getSessionFactory().getCurrentSession());
excrit.setMaxResults(1);
List<?> res = excrit.list();
return res.isEmpty() ? null : (T) res.get(0);
}