本文整理汇总了Java中javax.persistence.metamodel.SingularAttribute类的典型用法代码示例。如果您正苦于以下问题:Java SingularAttribute类的具体用法?Java SingularAttribute怎么用?Java SingularAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SingularAttribute类属于javax.persistence.metamodel包,在下文中一共展示了SingularAttribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: containsRelation
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
public static boolean containsRelation(Object expr) {
if (expr instanceof Join) {
return true;
} else if (expr instanceof SingularAttribute) {
SingularAttribute<?, ?> attr = (SingularAttribute<?, ?>) expr;
return attr.isAssociation();
} else if (expr instanceof Path) {
Path<?> attrPath = (Path<?>) expr;
Bindable<?> model = attrPath.getModel();
Path<?> parent = attrPath.getParentPath();
return containsRelation(parent) || containsRelation(model);
} else {
// we may can do better here...
return false;
}
}
示例2: getReferenceColumnNamesMapForReferenceAttribute
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
private Map<String, String> getReferenceColumnNamesMapForReferenceAttribute(SingularAttribute<?, ?> attribute, ManagedType<?> targetEntity) {
List<String> idAttributeNames = targetEntity.getSingularAttributes().stream()
.filter(this::isIdAttribute)
.map(this::getSingularAttributeColumnName)
.collect(Collectors.toList());
JoinColumns joinColumnsAnnotation =
((AnnotatedElement) attribute.getJavaMember()).getAnnotation(JoinColumns.class);
JoinColumn joinColumnAnnotation =
((AnnotatedElement) attribute.getJavaMember()).getAnnotation(JoinColumn.class);
JoinColumn[] joinColumns = joinColumnsAnnotation != null ? joinColumnsAnnotation.value() :
joinColumnAnnotation != null ? new JoinColumn[]{joinColumnAnnotation} : null;
Map<String, String> referenceColumnNamesMap;
if (joinColumns != null) {
referenceColumnNamesMap = Arrays.stream(joinColumns)
.collect(Collectors.toMap(JoinColumn::name, joinColumn ->
joinColumn.referencedColumnName().length() > 0 ? joinColumn.referencedColumnName() :
idAttributeNames.get(0)));
} else {
referenceColumnNamesMap = idAttributeNames.stream()
.collect(Collectors.toMap(idAttributeName -> attribute.getName().toUpperCase() + "_"
+ idAttributeName, idAttributeName -> idAttributeName));
}
return referenceColumnNamesMap;
}
示例3: getIdFieldNames
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
public static Set<String> getIdFieldNames(Metamodel metamodel, String entityName) {
Set<String> ids = entityIdMap.get(entityName);
if(ids == null) {
ids = new HashSet<>();
for(EntityType<?> et : metamodel.getEntities()) {
if(et.getJavaType().getName().equals(entityName)) {
if(et.hasSingleIdAttribute()) {
ids.add(et.getId(et.getIdType().getJavaType()).getName());
} else {
for(SingularAttribute<?, ?> idAttribute : et.getIdClassAttributes()) {
ids.add(idAttribute.getName());
}
}
}
}
}
if(ids.size() == 0) {
ids.add("id");
}
return ids;
}
示例4: LinqImpl
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public LinqImpl(Class<?> domainClass, Class<?> resultClass, EntityManager entityManager) {
super(domainClass, entityManager);
if (Tuple.class.isAssignableFrom(resultClass)) {
criteria = cb.createTupleQuery();
root = criteria.from(domainClass);
} else if (Map.class.isAssignableFrom(resultClass)) {
criteria = cb.createQuery(Object[].class);
root = criteria.from(domainClass);
resultTransformer = Transformers.ALIAS_TO_MAP;
Set<?> attrs = em.getMetamodel().entity(domainClass).getDeclaredSingularAttributes();
String[] selections = new String[attrs.size()];
int i = 0;
for (Object attr : attrs) {
selections[i] = ((SingularAttribute)attr).getName();
i++;
}
select(selections);
} else {
criteria = cb.createQuery(resultClass);
root = criteria.from(domainClass);
}
this.resultClass = resultClass;
}
示例5: getJpaHeaders
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
/**
* Return JPA managed properties.
*
* @param <T>
* Bean type.
* @param beanType
* the bean type.
* @return the headers built from given type.
*/
public <T> String[] getJpaHeaders(final Class<T> beanType) {
// Build descriptor list respecting the declaration order
final OrderedFieldCallback fieldCallBack = new OrderedFieldCallback();
ReflectionUtils.doWithFields(beanType, fieldCallBack);
final List<String> orderedDescriptors = fieldCallBack.descriptorsOrdered;
// Now filter the properties
final List<String> descriptorsFiltered = new ArrayList<>();
final ManagedType<T> managedType = transactionManager.getEntityManagerFactory().getMetamodel().managedType(beanType);
for (final String propertyDescriptor : orderedDescriptors) {
for (final Attribute<?, ?> attribute : managedType.getAttributes()) {
// Match only basic attributes
if (attribute instanceof SingularAttribute<?, ?> && propertyDescriptor.equals(attribute.getName())) {
descriptorsFiltered.add(attribute.getName());
break;
}
}
}
// Initialize the CSV reader
return descriptorsFiltered.toArray(new String[descriptorsFiltered.size()]);
}
示例6: createSetterInvoker
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
public static <T, U> BiConsumer<T, U> createSetterInvoker(
@Nonnull final SingularAttribute<? super T, U> attribute) {
Objects.requireNonNull(attribute);
final Class<?> declaringClass = attribute.getDeclaringType().getJavaType();
final String setterName = getSetterName(attribute.getName());
final Method setterMethod = BeanUtils.findDeclaredMethod(declaringClass, setterName, attribute.getJavaType());
if (setterMethod == null) {
throw new IllegalStateException(String.format(
"Class %s does not declare method named '%s'",
declaringClass.getName(),
setterName));
}
setterMethod.setAccessible(true);
return (object, value) -> {
try {
setterMethod.invoke(object, value);
} catch (final IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
};
}
示例7: testGetObservationFieldMetadataForSingleSpecies_forState
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
private void testGetObservationFieldMetadataForSingleSpecies_forState(
final SingularAttribute<ObservationContextSensitiveFields, Required> fieldAttribute,
final Required stateRequirement,
final ObservedGameState expectedStateValue) {
final GameSpecies species = newGameSpecies();
final ObservationContextSensitiveFields ctxFields =
newObservationContextSensitiveFields(species, Required.NO, Required.VOLUNTARY);
CriteriaUtils.createSetterInvoker(fieldAttribute).accept(ctxFields, stateRequirement);
persistInCurrentlyOpenTransaction();
final ContextSensitiveFieldSetDTO ctxFieldsDTO =
invokeServiceAndGetContextSensitiveFieldSetDTO(species, ctxFields.getObservationType());
assertEquals(stateRequirement, ctxFieldsDTO.getState());
assertEquals(EnumSet.of(HEALTHY, ILL, expectedStateValue), ctxFieldsDTO.getAllowedStates());
}
示例8: getSelectedType
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
private Class<?> getSelectedType(Path entityPath, Set<TypeDefinition> typeDefinitions) {
if (entityPath.isKeyPath()) {
TypeDefinition typeDefinition = typeForAlias(entityPath.getRootAlias())
.withMetamodel(metamodel)
.filter(typeDefinitions);
MapAttribute<?, ?, ?> mapAttribute = (MapAttribute<?, ?, ?>)attributeForPath(typeDefinition.getJoinPath())
.withMetamodel(metamodel)
.filter(typeDefinitions);
Class<?> keyType = mapAttribute.getKeyJavaType();
if (!entityPath.hasSubpath()) {
return keyType;
}
return attributeForPath(new Path(entityPath.getSubpath()))
.withMetamodel(metamodel)
.withRootType(keyType)
.filter()
.getJavaType();
} else if (entityPath.hasSubpath()) {
SingularAttribute<?, ?> attribute = (SingularAttribute<?, ?>)attributeForPath(entityPath)
.withMetamodel(metamodel)
.filter(typeDefinitions);
return attribute.getType().getJavaType();
} else {
return typeForAlias(entityPath.getRootAlias()).withMetamodel(metamodel).filter(typeDefinitions).getType();
}
}
示例9: visit
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
public boolean visit(JpqlPath node, Set<TypeDefinition> typeDefinitions) {
Alias alias = new Alias(node.jjtGetChild(0).getValue());
Class<?> type = getType(alias, typeDefinitions);
for (int i = 1; i < node.jjtGetNumChildren(); i++) {
ManagedType<?> managedType = forModel(metamodel).filter(type);
String attributeName = node.jjtGetChild(i).getValue();
Attribute<?, ?> attribute = managedType.getAttribute(attributeName);
if (attribute instanceof SingularAttribute
&& ((SingularAttribute<?, ?>)attribute).getType().getPersistenceType() == PersistenceType.BASIC
&& i < node.jjtGetNumChildren() - 1) {
String error = "Cannot navigate through simple property "
+ attributeName + " in class " + type.getName();
throw new PersistenceException(error);
}
type = attribute.getJavaType();
}
return false;
}
示例10: filter
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
public Attribute<?, ?> filter() {
Type<?> type = forModel(metamodel).filter(rootType);
Attribute<?, ?> result = null;
for (int i = 1; i < pathElements.length; i++) {
if (!(type instanceof ManagedType)) {
throw new PersistenceException("Cannot navigate through simple property "
+ pathElements[i] + " of type " + type.getJavaType());
}
result = ((ManagedType<?>)type).getAttribute(pathElements[i]);
if (result.isCollection()) {
type = ((PluralAttribute<?, ?, ?>)result).getElementType();
} else {
type = ((SingularAttribute<?, ?>)result).getType();
}
}
return result;
}
示例11: byExampleOnXToOne
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
/**
* Invoke byExample method for each not null x-to-one association when their pk is not set. This allows you to search entities based on an associated
* entity's properties value.
*/
@SuppressWarnings("unchecked")
public <T extends Identifiable<?>, M2O extends Identifiable<?>> List<Predicate> byExampleOnXToOne(ManagedType<T> mt, Root<T> mtPath, final T mtValue,
SearchParameters sp, CriteriaBuilder builder) {
List<Predicate> predicates = newArrayList();
for (SingularAttribute<? super T, ?> attr : mt.getSingularAttributes()) {
if (attr.getPersistentAttributeType() == MANY_TO_ONE || attr.getPersistentAttributeType() == ONE_TO_ONE) { //
M2O m2oValue = (M2O) getValue(mtValue, mt.getAttribute(attr.getName()));
if (m2oValue != null && !m2oValue.isIdSet()) {
Class<M2O> m2oType = (Class<M2O>) attr.getBindableJavaType();
ManagedType<M2O> m2oMt = em.getMetamodel().entity(m2oType);
Path<M2O> m2oPath = (Path<M2O>) mtPath.get(attr);
predicates.addAll(byExample(m2oMt, m2oPath, m2oValue, sp, builder));
}
}
}
return predicates;
}
示例12: sum
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
@Override
public <S> S sum(Class<S> resultClass, Specification<E> spec, LockModeType lockMode, List<SingularAttribute<E, ? extends Number>> properties) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<S> query = builder.createQuery(resultClass);
Root<E> root = query.from(getDomainClass());
List<Selection<?>> selectionList = Lists.newArrayList();
for (SingularAttribute<E, ? extends Number> property : properties) {
selectionList.add(builder.sum(root.get(property)));
}
return aggregate(builder, query, root, spec, selectionList, lockMode);
}
示例13: sum
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
public <S> S sum(Class<S> resultClass, Specification<E> spec,
SingularAttribute<E, ? extends Number>... properties) {
return getRepository().sum(resultClass, spec, properties);
}
示例14: getSingularAttributeColumnName
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
private String getSingularAttributeColumnName(SingularAttribute attribute) {
Column columnAnnotation = ((AnnotatedElement) attribute.getJavaMember()).getAnnotation(Column.class);
if (columnAnnotation != null && columnAnnotation.name().length() > 0) {
return columnAnnotation.name().toUpperCase();
} else {
return attribute.getName().toUpperCase();
}
}
示例15: getCanonicalDataTypeName
import javax.persistence.metamodel.SingularAttribute; //导入依赖的package包/类
@Override
public String getCanonicalDataTypeName(schemacrawler.schema.Column column) {
SingularAttribute singularAttribute;
if (column.isPartOfForeignKey()) {
Optional<ForeignKeyColumnReference> foreignKeyColumnReferenceOptional = column.getParent().getForeignKeys().stream()
.flatMap(foreignKeyColumnReferences -> foreignKeyColumnReferences.getColumnReferences().stream())
.filter(foreignKeyColumnReference -> foreignKeyColumnReference.getForeignKeyColumn().getName().equals(column.getName()))
.findFirst();
if (foreignKeyColumnReferenceOptional.isPresent()) {
ForeignKeyColumnReference ref = foreignKeyColumnReferenceOptional.get();
SingularAttribute targetSingularAttribute =
singularAttributesByColumnName.get(new QualifiedColumnName(ref.getPrimaryKeyColumn().getParent().getName(), ref.getPrimaryKeyColumn().getName()));
if (targetSingularAttribute != null) {
return targetSingularAttribute.getJavaType().getCanonicalName();
} else {
LOG.warn("Could not find target singular attribute for column " + column.getParent().getName() + "." + column.getName());
return fallbackDataTypeProvider.getCanonicalDataTypeName(column);
}
} else {
return fallbackDataTypeProvider.getCanonicalDataTypeName(column);
}
} else {
singularAttribute =
singularAttributesByColumnName.get(new QualifiedColumnName(column.getParent().getName(), column.getName()));
if (singularAttribute != null) {
return singularAttribute.getJavaType().getCanonicalName();
} else {
return fallbackDataTypeProvider.getCanonicalDataTypeName(column);
}
}
}