use of org.hibernate.engine.ResultSetMappingDefinition in project hibernate-orm by hibernate.
the class ResultSetMappingBinder method bind.
/**
* Build a ResultSetMappingDefinition given a containing element for the "return-XXX" elements
*
* @param resultSetMappingSource The XML data as a JAXB binding
* @param context The mapping state
* @param prefix A prefix to apply to named ResultSet mapping; this is either {@code null} for
* ResultSet mappings defined outside of any entity, or the name of the containing entity
* if defined within the context of an entity
*
* @return The ResultSet mapping descriptor
*/
public static ResultSetMappingDefinition bind(ResultSetMappingBindingDefinition resultSetMappingSource, HbmLocalMetadataBuildingContext context, String prefix) {
if (StringHelper.isEmpty(prefix)) {
throw new AssertionFailure("Passed prefix was null; perhaps you meant to call the alternate #bind form?");
}
final String resultSetName = prefix + '.' + resultSetMappingSource.getName();
final ResultSetMappingDefinition binding = new ResultSetMappingDefinition(resultSetName);
bind(resultSetMappingSource, binding, context);
return binding;
}
use of org.hibernate.engine.ResultSetMappingDefinition in project hibernate-orm by hibernate.
the class ResultSetMappingBinder method bind.
/**
* Build a ResultSetMappingDefinition given a containing element for the "return-XXX" elements.
* <p/>
* This form is used for ResultSet mappings defined outside the context of any specific entity.
* For {@code hbm.xml} this means at the root of the document. For annotations, this means at
* the package level.
*
* @param resultSetMappingSource The XML data as a JAXB binding
* @param context The mapping state
*
* @return The ResultSet mapping descriptor
*/
public static ResultSetMappingDefinition bind(ResultSetMappingBindingDefinition resultSetMappingSource, HbmLocalMetadataBuildingContext context) {
if (resultSetMappingSource.getName() == null) {
throw new MappingException("ResultSet mapping did not specify name", context.getOrigin());
}
final ResultSetMappingDefinition binding = new ResultSetMappingDefinition(resultSetMappingSource.getName());
bind(resultSetMappingSource, binding, context);
return binding;
}
use of org.hibernate.engine.ResultSetMappingDefinition in project hibernate-orm by hibernate.
the class Configuration method reset.
protected void reset() {
implicitNamingStrategy = ImplicitNamingStrategyJpaCompliantImpl.INSTANCE;
physicalNamingStrategy = PhysicalNamingStrategyStandardImpl.INSTANCE;
namedQueries = new HashMap<String, NamedQueryDefinition>();
namedSqlQueries = new HashMap<String, NamedSQLQueryDefinition>();
sqlResultSetMappings = new HashMap<String, ResultSetMappingDefinition>();
namedEntityGraphMap = new HashMap<String, NamedEntityGraphDefinition>();
namedProcedureCallMap = new HashMap<String, NamedProcedureCallDefinition>();
standardServiceRegistryBuilder = new StandardServiceRegistryBuilder(bootstrapServiceRegistry);
entityTuplizerFactory = new EntityTuplizerFactory();
interceptor = EmptyInterceptor.INSTANCE;
properties = new Properties();
properties.putAll(standardServiceRegistryBuilder.getSettings());
}
use of org.hibernate.engine.ResultSetMappingDefinition in project hibernate-orm by hibernate.
the class AbstractSharedSessionContract method resultClassChecking.
@SuppressWarnings({ "unchecked", "WeakerAccess" })
protected void resultClassChecking(Class resultType, NamedSQLQueryDefinition namedQueryDefinition) {
final NativeSQLQueryReturn[] queryReturns;
if (namedQueryDefinition.getQueryReturns() != null) {
queryReturns = namedQueryDefinition.getQueryReturns();
} else if (namedQueryDefinition.getResultSetRef() != null) {
final ResultSetMappingDefinition rsMapping = getFactory().getNamedQueryRepository().getResultSetMappingDefinition(namedQueryDefinition.getResultSetRef());
queryReturns = rsMapping.getQueryReturns();
} else {
throw new AssertionFailure("Unsupported named query model. Please report the bug in Hibernate EntityManager");
}
if (queryReturns.length > 1) {
throw new IllegalArgumentException("Cannot create TypedQuery for query with more than one return");
}
final NativeSQLQueryReturn nativeSQLQueryReturn = queryReturns[0];
if (nativeSQLQueryReturn instanceof NativeSQLQueryRootReturn) {
final Class<?> actualReturnedClass;
final String entityClassName = ((NativeSQLQueryRootReturn) nativeSQLQueryReturn).getReturnEntityName();
try {
actualReturnedClass = getFactory().getServiceRegistry().getService(ClassLoaderService.class).classForName(entityClassName);
} catch (ClassLoadingException e) {
throw new AssertionFailure("Unable to load class [" + entityClassName + "] declared on named native query [" + namedQueryDefinition.getName() + "]");
}
if (!resultType.isAssignableFrom(actualReturnedClass)) {
throw buildIncompatibleException(resultType, actualReturnedClass);
}
} else if (nativeSQLQueryReturn instanceof NativeSQLQueryConstructorReturn) {
final NativeSQLQueryConstructorReturn ctorRtn = (NativeSQLQueryConstructorReturn) nativeSQLQueryReturn;
if (!resultType.isAssignableFrom(ctorRtn.getTargetClass())) {
throw buildIncompatibleException(resultType, ctorRtn.getTargetClass());
}
} else {
log.debugf("Skiping unhandled NativeSQLQueryReturn type : " + nativeSQLQueryReturn);
}
}
use of org.hibernate.engine.ResultSetMappingDefinition in project hibernate-orm by hibernate.
the class Util method resolveResultSetMappings.
/**
* Resolve the given result set mapping names
*
* @param context The context for the resolution. See {@link ResultSetMappingResolutionContext}
* @param resultSetMappingNames The names of the result-set-mappings to resolve
*/
public static void resolveResultSetMappings(ResultSetMappingResolutionContext context, String... resultSetMappingNames) {
for (String resultSetMappingName : resultSetMappingNames) {
log.tracef("Starting attempt resolve named result-set-mapping : %s", resultSetMappingName);
final ResultSetMappingDefinition mapping = context.findResultSetMapping(resultSetMappingName);
if (mapping == null) {
throw new UnknownSqlResultSetMappingException("Unknown SqlResultSetMapping [" + resultSetMappingName + "]");
}
log.tracef("Found result-set-mapping : %s", mapping.traceLoggableFormat());
context.addQueryReturns(mapping.getQueryReturns());
final SQLQueryReturnProcessor processor = new SQLQueryReturnProcessor(mapping.getQueryReturns(), context.getSessionFactory());
final SQLQueryReturnProcessor.ResultAliasContext processResult = processor.process();
context.addQuerySpaces(processResult.collectQuerySpaces());
}
}
Aggregations