use of io.jmix.data.persistence.DbmsFeatures in project jmix by jmix-framework.
the class JmixEclipseLinkQuery method internalSetParameter.
private TypedQuery<E> internalSetParameter(int position, Object value) {
checkState();
DbmsFeatures dbmsFeatures = dbmsSpecifics.getDbmsFeatures();
if (isNative && (value instanceof UUID) && (dbmsFeatures.getUuidTypeClassName() != null)) {
Class<?> c = ReflectionHelper.getClass(dbmsFeatures.getUuidTypeClassName());
try {
value = ReflectionHelper.newInstance(c, value);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Error setting parameter value", e);
}
} else if (value instanceof EnumClass) {
value = ((EnumClass) value).getId();
} else if (isCollectionOfEntitiesOrEnums(value)) {
value = convertToCollectionOfIds(value);
}
params.add(new Param(position, value));
return this;
}
use of io.jmix.data.persistence.DbmsFeatures in project jmix by jmix-framework.
the class JmixEclipseLinkQuery method transformQueryString.
private String transformQueryString() {
String result = replaceConstants(queryString);
result = expandMacros(result);
boolean rebuildParser = false;
QueryParser parser = queryTransformerFactory.parser(result);
String entityName = parser.getEntityName();
Class effectiveClass = extendedEntities.getEffectiveClass(entityName);
MetaClass effectiveMetaClass = metadata.getClass(effectiveClass);
String effectiveEntityName = effectiveMetaClass.getName();
if (!effectiveEntityName.equals(entityName)) {
QueryTransformer transformer = queryTransformerFactory.transformer(result);
transformer.replaceEntityName(effectiveEntityName);
result = transformer.getResult();
rebuildParser = true;
}
if (firstResult != null && firstResult > 0) {
String storeName = effectiveMetaClass.getStore().getName();
DbmsFeatures dbmsFeatures = dbmsSpecifics.getDbmsFeatures(storeName);
if (dbmsFeatures.useOrderByForPaging()) {
QueryTransformer transformer = queryTransformerFactory.transformer(result);
transformer.addOrderByIdIfNotExists(metadataTools.getPrimaryKeyName(effectiveMetaClass));
result = transformer.getResult();
rebuildParser = true;
}
}
result = replaceParams(result, parser);
if (rebuildParser) {
parser = queryTransformerFactory.parser(result);
}
String nestedEntityName = parser.getOriginalEntityName();
String nestedEntityPath = parser.getOriginalEntityPath();
if (nestedEntityName != null) {
if (parser.isCollectionOriginalEntitySelect()) {
throw new IllegalStateException(String.format("Collection attributes are not supported in select clause: %s", nestedEntityPath));
}
if (!metadataTools.isJpaEmbeddable(metadata.getClass(nestedEntityName))) {
QueryTransformer transformer = queryTransformerFactory.transformer(result);
transformer.replaceWithSelectEntityVariable("tempEntityAlias");
transformer.addFirstSelectionSource(String.format("%s tempEntityAlias", nestedEntityName));
MetaClass nestedMetaClass = metadata.getSession().getClass(nestedEntityName);
if (nestedMetaClass != null) {
addIdConditions(nestedMetaClass, nestedEntityPath, transformer);
} else {
log.info("MetaClass {} that is necessary for building JPQL query is not found", nestedMetaClass);
}
transformer.addEntityInGroupBy("tempEntityAlias");
result = transformer.getResult();
}
}
result = replaceIsNullAndIsNotNullStatements(result);
return result;
}
Aggregations