当前位置: 首页>>代码示例>>Java>>正文


Java SingularAttribute类代码示例

本文整理汇总了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;
	}
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:17,代码来源:QueryUtil.java

示例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;
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:26,代码来源:JpaMetamodelRedGProvider.java

示例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;
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:22,代码来源:EntityConstraintAnalyzer.java

示例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;
}
 
开发者ID:muxiangqiu,项目名称:linq,代码行数:25,代码来源:LinqImpl.java

示例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()]);
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:32,代码来源:CsvForJpa.java

示例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);
        }
    };
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:27,代码来源:CriteriaUtils.java

示例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());
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:20,代码来源:ObservationFieldsMetadataServiceTest.java

示例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();
    }
}
 
开发者ID:ArneLimburg,项目名称:jpasecurity,代码行数:27,代码来源:EntityFilter.java

示例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;
}
 
开发者ID:ArneLimburg,项目名称:jpasecurity,代码行数:19,代码来源:MappingEvaluator.java

示例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;
}
 
开发者ID:ArneLimburg,项目名称:jpasecurity,代码行数:18,代码来源:TypeDefinition.java

示例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;
}
 
开发者ID:ddRPB,项目名称:rpb,代码行数:22,代码来源:ByExampleUtil.java

示例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);
}
 
开发者ID:onsoul,项目名称:os,代码行数:12,代码来源:GenericRepositoryImpl.java

示例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);
}
 
开发者ID:onsoul,项目名称:os,代码行数:8,代码来源:GenericService.java

示例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();
	}
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:9,代码来源:JpaMetamodelRedGProvider.java

示例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);
		}
	}
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:33,代码来源:JpaMetamodelRedGProvider.java


注:本文中的javax.persistence.metamodel.SingularAttribute类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。