use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.
the class AbstractJPQLQueryHelperTest method test_ResultType_61.
@Test
public final void test_ResultType_61() throws Exception {
// SELECT e.salary / 1000D n From Employee e
IQuery namedQuery = namedQuery("Employee", "employee.resultVariable3");
AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
IType type = helper.getResultType();
assertNotNull("The type of e.salary / 1000D n as n should have been found", type);
assertEquals("The wrong type for e.salary / 1000D n as n was retrieved", getType(namedQuery, Double.class), type);
}
use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.
the class JavaTypeRepository method getEnumType.
@Override
public IType getEnumType(String enumTypeName) {
// Get the position of the last dot so we can remove the constant
int lastDotIndex = enumTypeName.lastIndexOf(".");
if (lastDotIndex == -1) {
return null;
}
// Retrieve the fully qualified enum type name
String typeName = enumTypeName.substring(0, lastDotIndex);
// Attempt to load the enum type
IType type = loadTypeImp(typeName);
return type.isEnum() ? type : null;
}
use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.
the class JavaTypeDeclaration method buildTypeDeclaration.
protected JavaTypeDeclaration buildTypeDeclaration(Object genericType) {
// <T1, ..., Tn>
if (genericType instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) genericType;
return buildTypeDeclaration(parameterizedType.getRawType());
}
// <T>
if (genericType instanceof TypeVariable) {
TypeVariable<?> typeVariable = (TypeVariable<?>) genericType;
for (Type type : typeVariable.getBounds()) {
return buildTypeDeclaration(type);
}
return buildTypeDeclaration(Object.class);
}
// ?
if (genericType instanceof WildcardType) {
WildcardType wildcardType = (WildcardType) genericType;
for (Type type : wildcardType.getUpperBounds()) {
return buildTypeDeclaration(type);
}
return buildTypeDeclaration(Object.class);
}
// T[]
if (genericType instanceof GenericArrayType) {
GenericArrayType genericArrayType = (GenericArrayType) genericType;
String arrayTypeName = buildArrayTypeName(genericArrayType.toString());
IType arrayType = typeRepository.getType(arrayTypeName);
return new JavaTypeDeclaration(typeRepository, arrayType, genericArrayType.getGenericComponentType(), true);
}
return buildTypeDeclaration((Class<?>) genericType);
}
use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.
the class AbstractMapping method calculateMappingType.
/**
* Calculates the type of the mapping represented by this external form.
*
* @param annotations The {@link Annotation Annotations} that are present on the member
* @return The mapping type, which is one of the constants defined in
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IMappingType IMappingType} when the provider is generic JPA
*/
protected int calculateMappingType(Annotation[] annotations) {
if (hasAnnotation(annotations, ElementCollection.class)) {
return ELEMENT_COLLECTION;
}
if (hasAnnotation(annotations, Embedded.class)) {
return EMBEDDED;
}
if (hasAnnotation(annotations, EmbeddedId.class)) {
return EMBEDDED_ID;
}
if (hasAnnotation(annotations, Id.class)) {
return ID;
}
if (hasAnnotation(annotations, ManyToMany.class)) {
return MANY_TO_MANY;
}
if (hasAnnotation(annotations, ManyToOne.class)) {
return MANY_TO_ONE;
}
if (hasAnnotation(annotations, OneToMany.class)) {
return ONE_TO_MANY;
}
if (hasAnnotation(annotations, OneToOne.class)) {
return ONE_TO_ONE;
}
if (hasAnnotation(annotations, Transient.class)) {
return TRANSIENT;
}
if (hasAnnotation(annotations, Version.class)) {
return VERSION;
}
// Default
IType type = getType();
TypeHelper typeHelper = getTypeRepository().getTypeHelper();
// M:M
if (typeHelper.isCollectionType(type) || typeHelper.isMapType(type)) {
return ONE_TO_MANY;
}
// 1:1
if (parent.getProvider().getEntity(type) != null) {
return ONE_TO_ONE;
}
// Embedded
if (parent.getProvider().getEmbeddable(type) != null) {
return EMBEDDED;
}
// Basic
return BASIC;
}
use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.
the class JavaConstructor method buildTypeDeclaration.
protected ITypeDeclaration buildTypeDeclaration(Class<?> javaType, Type genericType) {
ITypeRepository typeRepository = getTypeRepository();
IType type = typeRepository.getType(javaType);
return new JavaTypeDeclaration(typeRepository, type, genericType, javaType.isArray());
}
Aggregations