use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.
the class EclipseLinkJPQLQueryHelperTest2_4 method test_ResultType_FromSubquery_1.
@Test
public void test_ResultType_FromSubquery_1() throws Exception {
// Select e3.salary from Employee e, (Select count(e2), e2.department from Employee e2 group by e2.department) e3 where e.department = e3.department
IQuery namedQuery = namedQuery("Employee", "employee.fromSubquery2");
AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
IType type = helper.getResultType();
assertNotNull("The result type should have been found", type);
assertEquals("The result type was not calculated correctly", getType(namedQuery, Object.class), type);
}
use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.
the class AbstractJPQLQueryHelper method getParameterType.
/**
* Retrieves, if it can be determined, the type of the given input parameter with the given name.
* The type will be guessed based on its location within expression.
* <p>
* Note: Both named and positional input parameter can be used.
*
* @param parameterName The name of the input parameter to retrieve its type, which needs to be
* prepended by ':' or '?'
* @return Either the closest type of the input parameter or <code>null</code> if the type
* couldn't be determined
*/
public IType getParameterType(String parameterName) {
// Retrieve the input parameter's qualifier (':' or '?')
char character = parameterName.length() > 0 ? parameterName.charAt(0) : '\0';
// Does not begin with either ':' or '?'
if ((character != ':') && (character != '?')) {
return getTypeHelper().objectType();
}
// Find the InputParameters with the given parameter name
Collection<InputParameter> inputParameters = getQueryContext().findInputParameters(parameterName);
// No InputParameter was found
if (inputParameters.isEmpty()) {
return getTypeHelper().objectType();
}
// Now find the closest type for each location
TreeSet<IType> types = new TreeSet<>(buildNumericTypeComparator());
for (InputParameter inputParameter : inputParameters) {
IType type = queryContext.getParameterType(inputParameter);
// The first :name cannot be used to calculate the type
if (type.isResolvable()) {
types.add(type);
}
}
return types.isEmpty() ? getTypeHelper().objectType() : types.first();
}
use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.
the class TypeHelper method convertPrimitive.
/**
* Converts the given {@link IType}, if it's representing a primitive type, into the class of the
* same type.
*
* @param type Type to possibly convert from the primitive into the class
* @return The given {@link IType} if it's not a primitive type otherwise the primitive type will
* have been converted into the class of that primitive
*/
public IType convertPrimitive(IType type) {
// byte
IType newType = toByteType(type);
if (newType != type) {
return newType;
}
// short
newType = toShortType(type);
if (newType != type) {
return newType;
}
// int
newType = toIntegerType(type);
if (newType != type) {
return newType;
}
// long
newType = longType(type);
if (newType != type) {
return newType;
}
// float
newType = toFloatType(type);
if (newType != type) {
return newType;
}
// double
newType = toDoubleType(type);
if (newType != type) {
return newType;
}
// boolean
newType = toBooleanType(type);
if (newType != type) {
return newType;
}
return type;
}
use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.
the class AbstractContentAssistVisitor method visitEnumConstant.
protected void visitEnumConstant(AbstractPathExpression expression) {
int position = queryPosition.getPosition(expression);
String text = expression.toActualText();
int lastDotIndex = text.lastIndexOf(DOT);
// Check to see if an enum constant can be used at the expression's location
if (isEnumAllowed(expression)) {
boolean enumConstant = false;
// The position is after the last dot, check for enum constants
if (position > lastDotIndex) {
// Retrieve the enum type if the path up to the last dot is a fully qualified enum type
String enumType = expression.toParsedText().substring(0, lastDotIndex);
IType type = queryContext.getType(enumType);
// The path expression before the last dot is an enum type
if (type.isResolvable() && type.isEnum()) {
enumConstant = true;
// Now retrieve the portion of the enum constant based on the cursor position
String word = text.substring(lastDotIndex + 1, position);
// Add the enum constants and filter them based on what's already proposed
addEnumConstants(type, word);
}
}
// Enum type
if (!enumConstant) {
// Now retrieve the portion of the enum constant based on the cursor position
text = text.substring(0, position);
// Set the possible starting of a fully qualified enum type
proposals.setClassNamePrefix(text, ClassType.ENUM);
}
}
}
use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.
the class ContentAssistTest method retrieveMappingNames.
protected final Iterable<String> retrieveMappingNames(Class<?> persistentType, MappingType mappingType, Class<?> allowedType) throws Exception {
IManagedType managedType = getPersistenceUnit().getManagedType(persistentType.getName());
if (managedType == null) {
return Collections.emptyList();
}
List<String> names = new ArrayList<>();
IType type = (allowedType != null) ? getPersistenceUnit().getTypeRepository().getType(allowedType) : null;
for (IMapping mapping : managedType.mappings()) {
if (mappingType.isValid(mapping) && ((type == null) || mapping.getType().isAssignableTo(type))) {
names.add(mapping.getName());
} else // Allow incomplete path
if (mappingType == MappingType.SINGLE_VALUED_OBJECT_FIELD) {
if (mapping.isRelationship() && !mapping.isCollection()) {
names.add(mapping.getName());
}
}
}
return names;
}
Aggregations