use of org.hibernate.boot.registry.classloading.spi.ClassLoadingException in project hibernate-orm by hibernate.
the class MultiTenantConnectionProviderInitiator method initiateService.
@Override
@SuppressWarnings({ "unchecked" })
public MultiTenantConnectionProvider initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
final MultiTenancyStrategy strategy = MultiTenancyStrategy.determineMultiTenancyStrategy(configurationValues);
if (strategy == MultiTenancyStrategy.NONE || strategy == MultiTenancyStrategy.DISCRIMINATOR) {
// nothing to do, but given the separate hierarchies have to handle this here.
return null;
}
final Object configValue = configurationValues.get(AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER);
if (configValue == null) {
// if they also specified the data source *name*, then lets assume they want
// DataSourceBasedMultiTenantConnectionProviderImpl
final Object dataSourceConfigValue = configurationValues.get(AvailableSettings.DATASOURCE);
if (dataSourceConfigValue != null && String.class.isInstance(dataSourceConfigValue)) {
return new DataSourceBasedMultiTenantConnectionProviderImpl();
}
return null;
}
if (MultiTenantConnectionProvider.class.isInstance(configValue)) {
return (MultiTenantConnectionProvider) configValue;
} else {
final Class<MultiTenantConnectionProvider> implClass;
if (Class.class.isInstance(configValue)) {
implClass = (Class) configValue;
} else {
final String className = configValue.toString();
final ClassLoaderService classLoaderService = registry.getService(ClassLoaderService.class);
try {
implClass = classLoaderService.classForName(className);
} catch (ClassLoadingException cle) {
log.warn("Unable to locate specified class [" + className + "]", cle);
throw new ServiceException("Unable to locate specified multi-tenant connection provider [" + className + "]");
}
}
try {
return implClass.newInstance();
} catch (Exception e) {
log.warn("Unable to instantiate specified class [" + implClass.getName() + "]", e);
throw new ServiceException("Unable to instantiate specified multi-tenant connection provider [" + implClass.getName() + "]");
}
}
}
use of org.hibernate.boot.registry.classloading.spi.ClassLoadingException in project hibernate-orm by hibernate.
the class DefaultIdentifierGeneratorFactory method getIdentifierGeneratorClass.
@Override
public Class getIdentifierGeneratorClass(String strategy) {
if ("hilo".equals(strategy)) {
throw new UnsupportedOperationException("Support for 'hilo' generator has been removed");
}
String resolvedStrategy = "native".equals(strategy) ? getDialect().getNativeIdentifierGeneratorStrategy() : strategy;
Class generatorClass = generatorStrategyToClassNameMap.get(resolvedStrategy);
try {
if (generatorClass == null) {
final ClassLoaderService cls = serviceRegistry.getService(ClassLoaderService.class);
generatorClass = cls.classForName(resolvedStrategy);
}
} catch (ClassLoadingException e) {
throw new MappingException(String.format("Could not interpret id generator strategy [%s]", strategy));
}
return generatorClass;
}
use of org.hibernate.boot.registry.classloading.spi.ClassLoadingException in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method bindNamedSubgraph.
private static void bindNamedSubgraph(XMLContext.Default defaults, AnnotationDescriptor ann, List<Element> subgraphNodes, ClassLoaderAccess classLoaderAccess) {
List<NamedSubgraph> annSubgraphNodes = new ArrayList<NamedSubgraph>();
for (Element subgraphNode : subgraphNodes) {
AnnotationDescriptor annSubgraphNode = new AnnotationDescriptor(NamedSubgraph.class);
copyStringAttribute(annSubgraphNode, subgraphNode, "name", true);
String clazzName = subgraphNode.attributeValue("class");
Class clazz;
try {
clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(clazzName, defaults));
} catch (ClassLoadingException e) {
throw new AnnotationException("Unable to find entity-class: " + clazzName, e);
}
annSubgraphNode.setValue("type", clazz);
bindNamedAttributeNodes(subgraphNode, annSubgraphNode);
annSubgraphNodes.add((NamedSubgraph) AnnotationFactory.create(annSubgraphNode));
}
ann.setValue("subgraphs", annSubgraphNodes.toArray(new NamedSubgraph[annSubgraphNodes.size()]));
}
use of org.hibernate.boot.registry.classloading.spi.ClassLoadingException in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildNamedStoreProcedureQueries.
public static List<NamedStoredProcedureQuery> buildNamedStoreProcedureQueries(Element element, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
if (element == null) {
return new ArrayList<NamedStoredProcedureQuery>();
}
List namedStoredProcedureElements = element.elements("named-stored-procedure-query");
List<NamedStoredProcedureQuery> namedStoredProcedureQueries = new ArrayList<NamedStoredProcedureQuery>();
for (Object obj : namedStoredProcedureElements) {
Element subElement = (Element) obj;
AnnotationDescriptor ann = new AnnotationDescriptor(NamedStoredProcedureQuery.class);
copyStringAttribute(ann, subElement, "name", true);
copyStringAttribute(ann, subElement, "procedure-name", true);
List<Element> elements = subElement.elements("parameter");
List<StoredProcedureParameter> storedProcedureParameters = new ArrayList<StoredProcedureParameter>();
for (Element parameterElement : elements) {
AnnotationDescriptor parameterDescriptor = new AnnotationDescriptor(StoredProcedureParameter.class);
copyStringAttribute(parameterDescriptor, parameterElement, "name", false);
String modeValue = parameterElement.attributeValue("mode");
if (modeValue == null) {
parameterDescriptor.setValue("mode", ParameterMode.IN);
} else {
parameterDescriptor.setValue("mode", ParameterMode.valueOf(modeValue.toUpperCase(Locale.ROOT)));
}
String clazzName = parameterElement.attributeValue("class");
Class clazz;
try {
clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(clazzName, defaults));
} catch (ClassLoadingException e) {
throw new AnnotationException("Unable to find entity-class: " + clazzName, e);
}
parameterDescriptor.setValue("type", clazz);
storedProcedureParameters.add((StoredProcedureParameter) AnnotationFactory.create(parameterDescriptor));
}
ann.setValue("parameters", storedProcedureParameters.toArray(new StoredProcedureParameter[storedProcedureParameters.size()]));
elements = subElement.elements("result-class");
List<Class> returnClasses = new ArrayList<Class>();
for (Element classElement : elements) {
String clazzName = classElement.getTextTrim();
Class clazz;
try {
clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(clazzName, defaults));
} catch (ClassLoadingException e) {
throw new AnnotationException("Unable to find entity-class: " + clazzName, e);
}
returnClasses.add(clazz);
}
ann.setValue("resultClasses", returnClasses.toArray(new Class[returnClasses.size()]));
elements = subElement.elements("result-set-mapping");
List<String> resultSetMappings = new ArrayList<String>();
for (Element resultSetMappingElement : elements) {
resultSetMappings.add(resultSetMappingElement.getTextTrim());
}
ann.setValue("resultSetMappings", resultSetMappings.toArray(new String[resultSetMappings.size()]));
elements = subElement.elements("hint");
buildQueryHints(elements, ann);
namedStoredProcedureQueries.add((NamedStoredProcedureQuery) AnnotationFactory.create(ann));
}
return namedStoredProcedureQueries;
}
use of org.hibernate.boot.registry.classloading.spi.ClassLoadingException in project hibernate-orm by hibernate.
the class SelectParser method token.
public void token(String token, QueryTranslatorImpl q) throws QueryException {
String lctoken = token.toLowerCase(Locale.ROOT);
if (first) {
first = false;
if ("distinct".equals(lctoken)) {
q.setDistinct(true);
return;
} else if ("all".equals(lctoken)) {
q.setDistinct(false);
return;
}
}
if (afterNew) {
afterNew = false;
try {
holderClass = q.getFactory().getServiceRegistry().getService(ClassLoaderService.class).classForName(QuerySplitter.getImportedClass(token, q.getFactory()));
} catch (ClassLoadingException e) {
throw new QueryException(e);
}
if (holderClass == null) {
throw new QueryException("class not found: " + token);
}
q.setHolderClass(holderClass);
insideNew = true;
} else if (token.equals(",")) {
if (!aggregate && ready) {
throw new QueryException("alias or expression expected in SELECT");
}
q.appendScalarSelectToken(", ");
ready = true;
} else if ("new".equals(lctoken)) {
afterNew = true;
ready = false;
} else if ("(".equals(token)) {
if (insideNew && !aggregate && !ready) {
//opening paren in new Foo ( ... )
ready = true;
} else if (aggregate) {
q.appendScalarSelectToken(token);
} else {
throw new QueryException("aggregate function expected beforeQuery ( in SELECT");
}
ready = true;
} else if (")".equals(token)) {
if (insideNew && !aggregate && !ready) {
//if we are inside a new Result(), but not inside a nested function
insideNew = false;
} else if (aggregate && ready) {
q.appendScalarSelectToken(token);
aggregateFuncTokenList.removeLast();
if (aggregateFuncTokenList.size() < 1) {
aggregate = false;
ready = false;
}
} else {
throw new QueryException("( expected beforeQuery ) in select");
}
} else if (COUNT_MODIFIERS.contains(lctoken)) {
if (!ready || !aggregate) {
throw new QueryException(token + " only allowed inside aggregate function in SELECT");
}
q.appendScalarSelectToken(token);
if ("*".equals(token)) {
// special case
q.addSelectScalar(getFunction("count", q).getReturnType(StandardBasicTypes.LONG, q.getFactory()));
}
} else if (getFunction(lctoken, q) != null && token.equals(q.unalias(token))) {
// the name of an SQL function
if (!ready) {
throw new QueryException(", expected beforeQuery aggregate function in SELECT: " + token);
}
aggregate = true;
aggregateAddSelectScalar = true;
aggregateFuncTokenList.add(lctoken);
ready = false;
q.appendScalarSelectToken(token);
if (!aggregateHasArgs(lctoken, q)) {
q.addSelectScalar(aggregateType(aggregateFuncTokenList, null, q));
if (!aggregateFuncNoArgsHasParenthesis(lctoken, q)) {
aggregateFuncTokenList.removeLast();
if (aggregateFuncTokenList.size() < 1) {
aggregate = false;
ready = false;
} else {
ready = true;
}
}
}
} else if (aggregate) {
boolean constantToken = false;
if (!ready) {
throw new QueryException("( expected afterQuery aggregate function in SELECT");
}
try {
ParserHelper.parse(aggregatePathExpressionParser, q.unalias(token), ParserHelper.PATH_SEPARATORS, q);
} catch (QueryException qex) {
constantToken = true;
}
if (constantToken) {
q.appendScalarSelectToken(token);
} else {
if (aggregatePathExpressionParser.isCollectionValued()) {
q.addCollection(aggregatePathExpressionParser.getCollectionName(), aggregatePathExpressionParser.getCollectionRole());
}
q.appendScalarSelectToken(aggregatePathExpressionParser.getWhereColumn());
if (aggregateAddSelectScalar) {
q.addSelectScalar(aggregateType(aggregateFuncTokenList, aggregatePathExpressionParser.getWhereColumnType(), q));
aggregateAddSelectScalar = false;
}
aggregatePathExpressionParser.addAssociation(q);
}
} else {
if (!ready) {
throw new QueryException(", expected in SELECT");
}
ParserHelper.parse(pathExpressionParser, q.unalias(token), ParserHelper.PATH_SEPARATORS, q);
if (pathExpressionParser.isCollectionValued()) {
q.addCollection(pathExpressionParser.getCollectionName(), pathExpressionParser.getCollectionRole());
} else if (pathExpressionParser.getWhereColumnType().isEntityType()) {
q.addSelectClass(pathExpressionParser.getSelectName());
}
q.appendScalarSelectTokens(pathExpressionParser.getWhereColumns());
q.addSelectScalar(pathExpressionParser.getWhereColumnType());
pathExpressionParser.addAssociation(q);
ready = false;
}
}
Aggregations