本文整理了Java中org.hibernate.criterion.Restrictions.isNull
方法的一些代码示例,展示了Restrictions.isNull
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Restrictions.isNull
方法的具体详情如下:
包路径:org.hibernate.criterion.Restrictions
类名称:Restrictions
方法名:isNull
[英]Apply an "is null" constraint to the named property
[中]对命名属性应用“is null”约束
代码示例来源:origin: hibernate/hibernate-orm
/**
* Apply an "equal" constraint to the named property. If the value
* is null, instead apply "is null".
*
* @param propertyName The name of the property
* @param value The value to use in comparison
*
* @return The Criterion
*
* @see #eq
* @see #isNull
*/
public static Criterion eqOrIsNull(String propertyName, Object value) {
return value == null
? isNull( propertyName )
: eq( propertyName, value );
}
代码示例来源:origin: hibernate/hibernate-orm
/**
* Creates a NULL restriction
*
* @return The restriction
*
* @see Restrictions#isNull(String)
*/
public Criterion isNull() {
return Restrictions.isNull( getPropertyName() );
}
代码示例来源:origin: kaaproject/kaa
private Criterion buildEqIdCriterion(String reference, String id) {
Criterion criterion;
if (isBlank(id)) {
criterion = Restrictions.isNull(reference);
} else {
criterion = Restrictions.eq(reference, ModelUtils.getLongId(id));
}
return criterion;
}
}
代码示例来源:origin: kaaproject/kaa
private Criterion buildSearchCriterion(String fqn, String tenantId, String applicationId) {
List<Criterion> searchCriterions = new ArrayList<>();
searchCriterions.add(Restrictions.eq(CTL_SCHEMA_META_INFO_FQN, fqn));
if (isNotBlank(tenantId)) {
searchCriterions.add(Restrictions.eq(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS,
Long.valueOf(tenantId)));
} else {
searchCriterions.add(Restrictions.isNull(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS));
}
if (isNotBlank(applicationId)) {
searchCriterions.add(Restrictions.eq(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS,
Long.valueOf(applicationId)));
} else {
searchCriterions.add(Restrictions.isNull(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS));
}
return Restrictions.and(searchCriterions.toArray(new Criterion[searchCriterions.size()]));
}
代码示例来源:origin: kaaproject/kaa
private Criterion buildScopeCriterion(String tenantId, String applicationId) {
if (isBlank(tenantId)) {
// SYSTEM - tenantId=null && appId=null
return Restrictions.and(Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID),
Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID));
} else {
if (isBlank(applicationId)) {
// TENANT - (tenantId=id or tenantId=null) && appId=null
return Restrictions.and(Restrictions.or(
Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID, Long.valueOf(tenantId)),
Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID)
),
Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID));
} else {
// APPLICATION - (tenantId=id or tenantId=null) && (appId=id or appId=null)
return Restrictions.and(Restrictions.or(
Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID, Long.valueOf(tenantId)),
Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID)
),
Restrictions.or(
Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID,
Long.valueOf(applicationId)),
Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID)));
}
}
}
代码示例来源:origin: kaaproject/kaa
CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID,
Long.valueOf(tenantId))
: Restrictions.isNull(
CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID),
applicationId != null
CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID,
Long.valueOf(applicationId))
: Restrictions.isNull(
CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID)));
代码示例来源:origin: kaaproject/kaa
@Override
public List<Topic> findVacantTopicsByGroupId(String appId, String groupId) {
List<Topic> topics = Collections.emptyList();
LOG.debug("Searching vacant topics for endpoint group with id [{}] and application id [{}]",
groupId, appId);
if (isNotBlank(groupId)) {
topics = findListByCriterionWithAlias(ENDPOINT_GROUPS_PROPERTY, ENDPOINT_GROUP_ALIAS,
JoinType.LEFT_OUTER_JOIN,
and(eq(APPLICATION_REFERENCE, Long.valueOf(appId)), or(
ne(ENDPOINT_GROUP_REFERENCE, Long.valueOf(groupId)),
isNull(ENDPOINT_GROUP_REFERENCE))));
}
if (LOG.isTraceEnabled()) {
LOG.trace("[{},{}] Search result: {}.", groupId, appId, Arrays.toString(topics.toArray()));
} else {
LOG.debug("[{},{}] Search result: {}.", groupId, appId, topics.size());
}
return topics;
}
代码示例来源:origin: kaaproject/kaa
@Override
public List<CtlSchemaMetaInfo> findOthersByFqnAndTenantId(
String fqn, String tenantId, String excludingId) {
LOG.debug("Searching other ctl schema meta infos by fqn [{}], "
+ "tenant id [{}] and excluding id [{}]", fqn, tenantId, excludingId);
List<CtlSchemaMetaInfo> availableSchemas = findListByCriterion(
Restrictions.and(Restrictions.ne(ID_PROPERTY, Long.valueOf(excludingId)),
Restrictions.eq(CTL_SCHEMA_META_INFO_FQN, fqn),
Restrictions.or(
Restrictions.eq(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS, Long.valueOf(tenantId)),
Restrictions.isNull(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS))));
if (LOG.isTraceEnabled()) {
LOG.trace("[{}][{}][{}] Search result: [{}].", fqn, tenantId, excludingId,
Arrays.toString(availableSchemas.toArray()));
} else {
LOG.debug("[{}][{}][{}] Search result: [{}].", fqn, tenantId, excludingId,
availableSchemas.size());
}
return availableSchemas;
}
代码示例来源:origin: kaaproject/kaa
private Criterion buildExludingSearchCriterion(
String fqn, String excludingTenantId, String excludingApplicationId) {
List<Criterion> searchCriterions = new ArrayList<>();
if (isNotBlank(excludingTenantId)) {
searchCriterions.add(Restrictions.isNull(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS));
if (isNotBlank(excludingApplicationId)) {
searchCriterions.add(Restrictions.and(
Restrictions.eq(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS, Long.valueOf(excludingTenantId)),
Restrictions.isNull(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS)));
} else {
searchCriterions.add(Restrictions.and(
Restrictions.eq(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS, Long.valueOf(excludingTenantId)),
Restrictions.isNotNull(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS)));
}
} else {
searchCriterions.add(Restrictions.isNotNull(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS));
}
return Restrictions.and(Restrictions.eq(CTL_SCHEMA_META_INFO_FQN, fqn),
Restrictions.or(searchCriterions.toArray(new Criterion[searchCriterions.size()])));
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<Offer> readOffersByAutomaticDeliveryType() {
//TODO change this to a JPA criteria
Criteria criteria = ((HibernateEntityManager) em).getSession().createCriteria(OfferImpl.class);
Date myDate = getCurrentDateAfterFactoringInDateResolution();
Calendar c = Calendar.getInstance();
c.setTime(myDate);
c.add(Calendar.DATE, +1);
criteria.add(Restrictions.lt("startDate", c.getTime()));
c = Calendar.getInstance();
c.setTime(myDate);
c.add(Calendar.DATE, -1);
criteria.add(Restrictions.or(Restrictions.isNull("endDate"), Restrictions.gt("endDate", c.getTime())));
criteria.add(Restrictions.or(Restrictions.eq("archiveStatus.archived", 'N'),
Restrictions.isNull("archiveStatus.archived")));
criteria.add(Restrictions.eq("automaticallyAdded", true));
criteria.setCacheable(true);
criteria.setCacheRegion("query.Offer");
return criteria.list();
}
代码示例来源:origin: kaaproject/kaa
CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID,
Long.valueOf(tenantId))
: Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID),
applicationId != null
? Restrictions.eq(
CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID,
Long.valueOf(applicationId))
: Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID))
).addOrder(Order.asc(CTL_SCHEMA_VERSION));
代码示例来源:origin: kaaproject/kaa
CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID,
Long.valueOf(tenantId))
: Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID),
applicationId != null
? Restrictions.eq(
CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID,
Long.valueOf(applicationId))
: Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID))
).addOrder(Order.desc(CTL_SCHEMA_VERSION))
.setMaxResults(FIRST);
代码示例来源:origin: gocd/gocd
public MaterialInstance findMaterialInstance(Material material) {
String cacheKey = materialKey(material);
MaterialInstance materialInstance = (MaterialInstance) goCache.get(cacheKey);
if (materialInstance == null) {
synchronized (cacheKey) {
materialInstance = (MaterialInstance) goCache.get(cacheKey);
if (materialInstance == null) {
DetachedCriteria hibernateCriteria = DetachedCriteria.forClass(material.getInstanceType());
for (Map.Entry<String, Object> property : material.getSqlCriteria().entrySet()) {
if (!property.getKey().equals(AbstractMaterial.SQL_CRITERIA_TYPE)) {//type is polymorphic mapping discriminator
if (property.getValue() == null) {
hibernateCriteria.add(isNull(property.getKey()));
} else {
hibernateCriteria.add(eq(property.getKey(), property.getValue()));
}
}
}
materialInstance = (MaterialInstance) firstResult(hibernateCriteria);
if (materialInstance != null) {
goCache.put(cacheKey, materialInstance);
}
}
}
}
return materialInstance;//TODO: clone me, caller may mutate
}
代码示例来源:origin: gocd/gocd
public MaterialInstance findMaterialInstance(MaterialConfig materialConfig) {
String cacheKey = materialKey(materialConfig.getFingerprint());
MaterialInstance materialInstance = (MaterialInstance) goCache.get(cacheKey);
if (materialInstance == null) {
synchronized (cacheKey) {
materialInstance = (MaterialInstance) goCache.get(cacheKey);
if (materialInstance == null) {
DetachedCriteria hibernateCriteria = DetachedCriteria.forClass(materialConfigConverter.getInstanceType(materialConfig));
for (Map.Entry<String, Object> property : materialConfig.getSqlCriteria().entrySet()) {
if (!property.getKey().equals(AbstractMaterial.SQL_CRITERIA_TYPE)) { //type is polymorphic mapping discriminator
if (property.getValue() == null) {
hibernateCriteria.add(isNull(property.getKey()));
} else {
hibernateCriteria.add(eq(property.getKey(), property.getValue()));
}
}
}
materialInstance = (MaterialInstance) firstResult(hibernateCriteria);
if (materialInstance != null) {
goCache.put(cacheKey, materialInstance);
}
}
}
}
return materialInstance;//TODO: clone me, caller may mutate
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testEnablingJoinFetchProfileAgainstSelfReferentialAssociation() {
Session s = openSession();
s.beginTransaction();
s.enableFetchProfile( Employee.FETCH_PROFILE_TREE );
s.createCriteria( Employee.class )
.add( Restrictions.isNull( "manager" ) )
.list();
s.getTransaction().commit();
s.close();
}
}
代码示例来源:origin: hibernate/hibernate-orm
subCriteria.add(
Restrictions.or(
Restrictions.isNull( "articleId" ), // Allow null
Restrictions.eq( "articleId", "1000" )
代码示例来源:origin: hibernate/hibernate-orm
rootCriteria.add(
Restrictions.or(
Restrictions.isNull( "ol.articleId" ), // Allow null
Restrictions.eq( "ol.articleId", "1000" )
代码示例来源:origin: hibernate/hibernate-orm
@TestForIssue(jiraKey = "HHH-4838")
@Test
public void testNaturalKeyLookupWithConstraint() {
Session s = openSession();
Transaction newTx = s.getTransaction();
newTx.begin();
A a1 = new A();
a1.setName( "name1" );
s.persist( a1 );
newTx.commit();
newTx = s.beginTransaction();
getCriteria( s ).add( Restrictions.isNull( "singleD" ) ).uniqueResult(); // put query-result into cache
A a2 = new A();
a2.setName( "xxxxxx" );
s.persist( a2 );
newTx.commit(); // Invalidates space A in UpdateTimeStamps region
newTx = s.beginTransaction();
Assert.assertTrue( s.getSessionFactory().getStatistics().isStatisticsEnabled() );
s.getSessionFactory().getStatistics().clear();
// should not produce a hit in StandardQuery cache region because there is a constraint
getCriteria( s ).add( Restrictions.isNull( "singleD" ) ).uniqueResult();
Assert.assertEquals( 0, s.getSessionFactory().getStatistics().getQueryCacheHitCount() );
s.createQuery( "delete from A" ).executeUpdate();
newTx.commit();
// Shutting down the application
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
subCriteria.add(
Restrictions.or(
Restrictions.isNull( "ol.articleId" ), // Allow null
Restrictions.eq( "ol.articleId", "1000" )
代码示例来源:origin: hibernate/hibernate-orm
"ol", JoinFragment.LEFT_OUTER_JOIN,
Restrictions.or(
Restrictions.isNull( "ol.articleId" ), // Allow null
Restrictions.eq( "ol.articleId", "1000" )
内容来源于网络,如有侵权,请联系作者删除!