本文整理汇总了Java中javax.persistence.criteria.From类的典型用法代码示例。如果您正苦于以下问题:Java From类的具体用法?Java From怎么用?Java From使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
From类属于javax.persistence.criteria包,在下文中一共展示了From类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFieldPath
import javax.persistence.criteria.From; //导入依赖的package包/类
public FieldPath getFieldPath(From root, String fullPropertyName) {
String[] pieces = fullPropertyName.split("\\.");
List<String> associationPath = new ArrayList<String>();
List<String> basicProperties = new ArrayList<String>();
int j = 0;
for (String piece : pieces) {
checkPiece: {
if (j == 0) {
Path path = root.get(piece);
if (path instanceof PluralAttributePath) {
associationPath.add(piece);
break checkPiece;
}
}
basicProperties.add(piece);
}
j++;
}
FieldPath fieldPath = new FieldPath()
.withAssociationPath(associationPath)
.withTargetPropertyPieces(basicProperties);
return fieldPath;
}
示例2: getPath
import javax.persistence.criteria.From; //导入依赖的package包/类
private Path<?> getPath(List<String> fieldNames, Root<T> root) {
javax.persistence.criteria.Path<?> entity = root;
for (String fieldName : fieldNames) {
Path<Object> fieldAsPath = entity.get(fieldName);
if ( Collection.class.isAssignableFrom( fieldAsPath.getJavaType() ) ) {
if ( ! joinsMap.containsKey(fieldAsPath) ) {
joinsMap.put(fieldAsPath, ((From<?, ?>) entity).join(fieldName));
}
entity = joinsMap.get(fieldAsPath);
} else {
entity = entity.get(fieldName);
}
}
return entity;
}
示例3: getPath
import javax.persistence.criteria.From; //导入依赖的package包/类
/**
* Geef de Path voor de gegeven naam (kan punten bevatten om door objecten te lopen).
*
* @param base
* basis
* @param naam
* naam
* @param <T>
* attribuut type
* @return path
*/
public static <T> Path<T> getPath(final Path<?> base, final String naam) {
final Path<T> result;
final int index = naam.indexOf('.');
if (index == -1) {
result = base.get(naam);
} else {
final String part = naam.substring(0, index);
final String rest = naam.substring(index + 1);
final Path<?> partPath = base.get(part);
if (partPath.getModel() == null) {
// Dan kunnen we hier niet door, maar moeten we via een join
final Join<?, ?> join = ((From<?, ?>) base).join(part);
result = getPath(join, rest);
} else {
result = getPath(partPath, rest);
}
}
return result;
}
示例4: join
import javax.persistence.criteria.From; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Nonnull
public static <T, U> Join<T, U> join(
@Nonnull final From<?, T> from, @Nonnull final PluralAttribute<? super T, ?, U> attribute) {
Objects.requireNonNull(from, "from is null");
Objects.requireNonNull(attribute, "attribute is null");
if (attribute instanceof CollectionAttribute) {
return from.join((CollectionAttribute<T, U>) attribute);
}
if (attribute instanceof SetAttribute) {
return from.join((SetAttribute<T, U>) attribute);
}
if (attribute instanceof ListAttribute) {
return from.join((ListAttribute<T, U>) attribute);
}
if (attribute instanceof MapAttribute) {
return from.join((MapAttribute<T, ?, U>) attribute);
}
// Should never end up here.
throw new IllegalArgumentException();
}
示例5: createQueryFactory
import javax.persistence.criteria.From; //导入依赖的package包/类
@Override
protected JpaQueryFactory createQueryFactory(final EntityManager em) {
JpaCriteriaQueryFactory factory = JpaCriteriaQueryFactory.newInstance();
factory.registerComputedAttribute(TestEntity.class, ATTR_VIRTUAL_VALUE, String.class,
new JpaCriteriaExpressionFactory<From<?, TestEntity>>() {
@Override
public Expression<String> getExpression(From<?, TestEntity> parent, CriteriaQuery<?> query) {
CriteriaBuilder builder = em.getCriteriaBuilder();
Path<String> stringValue = parent.get(TestEntity.ATTR_stringValue);
return builder.upper(stringValue);
}
});
return factory;
}
示例6: toPredicate
import javax.persistence.criteria.From; //导入依赖的package包/类
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
From from = getRoot(property, root);
String field = getProperty(property);
if (values == null) {
return cb.isNull(from.get(field));
}
if (values.length == 1) {
return getPredicate(from, cb, values[0], field);
}
Predicate[] predicates = new Predicate[values.length];
for (int i = 0; i < values.length; i++) {
predicates[i] = getPredicate(root, cb, values[i], field);
}
return cb.or(predicates);
}
示例7: toPredicate
import javax.persistence.criteria.From; //导入依赖的package包/类
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
From from = getRoot(property, root);
String field = getProperty(property);
if (values == null) {
return cb.isNotNull(from.get(field));
}
if (values.length == 1) {
return getPredicate(from, cb, values[0], field);
}
Predicate[] predicates = new Predicate[values.length];
for (int i = 0; i < values.length; i++) {
predicates[i] = getPredicate(root, cb, values[i], field);
}
return cb.or(predicates);
}
示例8: buildPredicate
import javax.persistence.criteria.From; //导入依赖的package包/类
@Override
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root,
String ceilingEntity, String fullPropertyName, Path<Comparable> explicitPath,
List<Comparable> directValues) {
Path<Comparable> path;
if (explicitPath != null) {
path = explicitPath;
} else {
path = fieldPathBuilder.getPath(root, fullPropertyName, builder);
}
if (directValues.size() == 2) {
if (directValues.get(0) == null) {
return builder.lessThan(path, directValues.get(1));
} else if (directValues.get(1) == null) {
return builder.greaterThanOrEqualTo(path, directValues.get(0));
}
return builder.between(path, directValues.get(0), directValues.get(1));
} else {
// The user passed in a single date which is only down to the second granularity. The database stores things
// down to the millisecond, so we can't just do equals we have to filter dates between the date provided and
// 1000 milliseconds later than the date provided to get all records for that particular second
Date secondFromNow = new Date(((Date)directValues.get(0)).getTime() + 1000);
return builder.between(path, directValues.get(0), secondFromNow);
}
}
示例9: buildRestriction
import javax.persistence.criteria.From; //导入依赖的package包/类
/**
* This method will return a FieldPathBuilder that could be used by the caller to establish any additional Roots that
* might be necessary due to the path living inside of a polymorphic version of the ceiling entity. The Predicate
* object that {@link #buildRestriction(...)} returns is also available inside of the FieldPathBuilder object for
* the caller's use.
*
* @param builder
* @param root
* @param ceilingEntity
* @param targetPropertyName
* @param explicitPath
* @param directValues
* @param shouldConvert
* @return
*/
public Predicate buildRestriction(CriteriaBuilder builder, From root, String ceilingEntity, String targetPropertyName,
Path explicitPath, List directValues, boolean shouldConvert, CriteriaQuery criteria, List<Predicate> restrictions) {
fieldPathBuilder.setCriteria(criteria);
fieldPathBuilder.setRestrictions(restrictions);
List<Object> convertedValues = new ArrayList<Object>();
if (shouldConvert && filterValueConverter != null) {
for (Object item : directValues) {
String stringItem = (String) item;
convertedValues.add(filterValueConverter.convert(stringItem));
}
} else {
convertedValues.addAll(directValues);
}
return predicateProvider.buildPredicate(builder, fieldPathBuilder, root, ceilingEntity, targetPropertyName,
explicitPath, convertedValues);
}
示例10: getQueryRestriction
import javax.persistence.criteria.From; //导入依赖的package包/类
/**
* TODO This method may be bdata specific. Consider creating new abstract class to group all bdata related DAO. Builds a query restriction predicate for the
* specified entities as per business object data key values.
*
* @param builder the criteria builder
* @param businessObjectDataEntity the business object data entity that appears in the from clause
* @param businessObjectFormatEntity the business object format entity that appears in the from clause
* @param fileTypeEntity the file type entity that appears in the from clause
* @param businessObjectDefinitionEntity the business object definition entity that appears in the from clause
* @param businessObjectDataKey the business object data key
*
* @return the query restriction predicate
*/
protected Predicate getQueryRestriction(CriteriaBuilder builder, From<?, BusinessObjectDataEntity> businessObjectDataEntity,
From<?, BusinessObjectFormatEntity> businessObjectFormatEntity, From<?, FileTypeEntity> fileTypeEntity,
From<?, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity, BusinessObjectDataKey businessObjectDataKey)
{
// Create the standard restrictions based on the business object format key values that are part of the business object data key.
// Please note that we specify not to ignore the business object format version.
Predicate predicate = getQueryRestriction(builder, businessObjectFormatEntity, fileTypeEntity, businessObjectDefinitionEntity,
getBusinessObjectFormatKey(businessObjectDataKey), false);
// Create and append a restriction on partition values.
predicate = builder.and(predicate, getQueryRestrictionOnPartitionValues(builder, businessObjectDataEntity, businessObjectDataKey));
// If it is specified, create and append a restriction on business object data version.
if (businessObjectDataKey.getBusinessObjectDataVersion() != null)
{
predicate = builder.and(predicate,
builder.equal(businessObjectDataEntity.get(BusinessObjectDataEntity_.version), businessObjectDataKey.getBusinessObjectDataVersion()));
}
return predicate;
}
示例11: getQueryRestrictionOnPartitionValues
import javax.persistence.criteria.From; //导入依赖的package包/类
/**
* TODO This method may be bdata specific. Consider creating new abstract class to group all bdata related DAO. Builds a query restriction predicate for the
* specified business object data entity as per primary and sub-partition values in the business object data key.
*
* @param builder the criteria builder
* @param businessObjectDataEntity the business object data entity that appears in the from clause
* @param primaryPartitionValue the primary partition value of the business object data
* @param subPartitionValues the list of sub-partition values for the business object data
*
* @return the query restriction predicate
*/
protected Predicate getQueryRestrictionOnPartitionValues(CriteriaBuilder builder, From<?, BusinessObjectDataEntity> businessObjectDataEntity,
String primaryPartitionValue, List<String> subPartitionValues)
{
// Create a standard restriction on primary partition value.
Predicate predicate = builder.equal(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue), primaryPartitionValue);
// Create and add standard restrictions on sub-partition values. Please note that the subpartition value columns are nullable.
int subPartitionValuesCount = CollectionUtils.size(subPartitionValues);
for (int i = 0; i < BusinessObjectDataEntity.MAX_SUBPARTITIONS; i++)
{
predicate = builder.and(predicate, i < subPartitionValuesCount ?
builder.equal(businessObjectDataEntity.get(BUSINESS_OBJECT_DATA_SUBPARTITIONS.get(i)), subPartitionValues.get(i)) :
builder.isNull(businessObjectDataEntity.get(BUSINESS_OBJECT_DATA_SUBPARTITIONS.get(i))));
}
return predicate;
}
示例12: getQueryRestrictionOnBusinessObjectDataVersionAndStatus
import javax.persistence.criteria.From; //导入依赖的package包/类
/**
* TODO This method may be bdata specific. Consider creating new abstract class to group all bdata related DAO. Builds query restriction predicates and adds
* them to the query restriction as per specified business object data version and status. If a business object data version is specified, the business
* object data status is ignored. When both business object data version and business object data status are not specified, the sub-query restriction is not
* getting updated.
*
* @param builder the criteria builder
* @param businessObjectDataEntity the business object data entity that appears in the from clause
* @param businessObjectDataStatusEntity the business object data status entity that appears in the from clause
* @param businessObjectDataVersion the business object data version
* @param businessObjectDataStatus the business object data status. This parameter is ignored when the business object data version is specified.
*
* @return the query restriction predicate or null if both business object data version and business object data status are not specified
*/
protected Predicate getQueryRestrictionOnBusinessObjectDataVersionAndStatus(CriteriaBuilder builder,
From<?, BusinessObjectDataEntity> businessObjectDataEntity, From<?, BusinessObjectDataStatusEntity> businessObjectDataStatusEntity,
Integer businessObjectDataVersion, String businessObjectDataStatus)
{
Predicate predicate = null;
// If specified, create a standard restriction on the business object data version.
if (businessObjectDataVersion != null)
{
predicate = builder.equal(businessObjectDataEntity.get(BusinessObjectDataEntity_.version), businessObjectDataVersion);
}
// Only if a business object data version is not specified, check if we need to add a restriction on the business object data status.
else if (businessObjectDataStatus != null)
{
predicate =
builder.equal(builder.upper(businessObjectDataStatusEntity.get(BusinessObjectDataStatusEntity_.code)), businessObjectDataStatus.toUpperCase());
}
return predicate;
}
示例13: createPredicate
import javax.persistence.criteria.From; //导入依赖的package包/类
@Override
public javax.persistence.criteria.Predicate createPredicate(From<?, ?> from, CriteriaBuilder criteriaBuilder, String attributeName) {
Expression<?> expression = from.get(attributeName);
if (values.isEmpty()) {
return addNullCase ? expression.isNull() : criteriaBuilder.conjunction();
} else if (isBasicFilter()) {
return super.createPredicate(from, criteriaBuilder, attributeName);
}
javax.persistence.criteria.Predicate predicate;
if (isBooleanComparison) {
predicate = expression.in(booleanValues);
} else {
predicate = expression.as(String.class).in(values);
}
if (addNullCase) predicate = criteriaBuilder.or(predicate, expression.isNull());
return predicate;
}
示例14: fetch
import javax.persistence.criteria.From; //导入依赖的package包/类
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao
dynamicEntityDao, RecordHelper helper) throws ServiceException {
cto.getNonCountAdditionalFilterMappings().add(new FilterMapping()
.withDirectFilterValues(new EmptyFilterValues())
.withRestriction(new Restriction()
.withPredicateProvider(new PredicateProvider() {
public Predicate buildPredicate(CriteriaBuilder builder,
FieldPathBuilder fieldPathBuilder, From root,
String ceilingEntity,
String fullPropertyName, Path explicitPath,
List directValues) {
root.fetch("defaultSku", JoinType.LEFT);
root.fetch("defaultCategory", JoinType.LEFT);
return null;
}
})
));
return helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto);
}
示例15: createCompositeParamPart
import javax.persistence.criteria.From; //导入依赖的package包/类
private Predicate createCompositeParamPart(CriteriaBuilder builder, Root<ResourceTable> from, RuntimeSearchParam left, IQueryParameterType leftValue) {
Predicate retVal = null;
switch (left.getParamType()) {
case STRING: {
From<ResourceIndexedSearchParamString, ResourceIndexedSearchParamString> stringJoin = from.join("myParamsString", JoinType.INNER);
retVal = createPredicateString(leftValue, left.getName(), builder, stringJoin);
break;
}
case TOKEN: {
From<ResourceIndexedSearchParamToken, ResourceIndexedSearchParamToken> tokenJoin = from.join("myParamsToken", JoinType.INNER);
retVal = createPredicateToken(leftValue, left.getName(), builder, tokenJoin);
break;
}
case DATE: {
From<ResourceIndexedSearchParamDate, ResourceIndexedSearchParamDate> dateJoin = from.join("myParamsDate", JoinType.INNER);
retVal = createPredicateDate(builder, dateJoin, leftValue);
break;
}
}
if (retVal == null) {
throw new InvalidRequestException("Don't know how to handle composite parameter with type of " + left.getParamType());
}
return retVal;
}