HHH-6132: Removed an extraneous Index parameter from the various JandexHelper.getValue methods, and modified all references to those methods accordingly

This commit is contained in:
JPAV 2011-05-24 13:02:09 -05:00
parent 7258cb98f4
commit 9b48cd993e
8 changed files with 135 additions and 170 deletions

View File

@ -53,26 +53,24 @@ public class FetchProfileBinder {
public static void bind( MetadataImpl metadata, public static void bind( MetadataImpl metadata,
Index jandex ) { Index jandex ) {
for (AnnotationInstance fetchProfile : jandex.getAnnotations(HibernateDotNames.FETCH_PROFILE)) { for (AnnotationInstance fetchProfile : jandex.getAnnotations(HibernateDotNames.FETCH_PROFILE)) {
bind(metadata, jandex, fetchProfile); bind(metadata, fetchProfile);
} }
for (AnnotationInstance fetchProfiles : jandex.getAnnotations(HibernateDotNames.FETCH_PROFILES)) { for (AnnotationInstance fetchProfiles : jandex.getAnnotations(HibernateDotNames.FETCH_PROFILES)) {
for (AnnotationInstance fetchProfile : JandexHelper.getValueAsArray(fetchProfiles, "value")) { for (AnnotationInstance fetchProfile : JandexHelper.getValueAsArray(fetchProfiles, "value")) {
bind(metadata, jandex, fetchProfile); bind(metadata, fetchProfile);
} }
} }
} }
private static void bind( MetadataImpl metadata, private static void bind( MetadataImpl metadata,
Index jandex,
AnnotationInstance fetchProfile ) { AnnotationInstance fetchProfile ) {
String name = JandexHelper.getValueAsString(jandex, fetchProfile, "name"); String name = JandexHelper.getValueAsString(fetchProfile, "name");
Set<Fetch> fetches = new HashSet<Fetch>(); Set<Fetch> fetches = new HashSet<Fetch>();
for (AnnotationInstance override : JandexHelper.getValueAsArray(fetchProfile, "fetchOverrides")) { for (AnnotationInstance override : JandexHelper.getValueAsArray(fetchProfile, "fetchOverrides")) {
FetchMode fetchMode = JandexHelper.getValueAsEnum(jandex, override, "mode", FetchMode.class); FetchMode fetchMode = JandexHelper.getValueAsEnum(override, "mode", FetchMode.class);
if (!fetchMode.equals(org.hibernate.annotations.FetchMode.JOIN)) throw new MappingException( if (!fetchMode.equals(org.hibernate.annotations.FetchMode.JOIN)) throw new MappingException("Only FetchMode.JOIN is currently supported");
"Only FetchMode.JOIN is currently supported"); fetches.add(new Fetch(JandexHelper.getValueAsString(override, "entity"), JandexHelper.getValueAsString(override,
fetches.add(new Fetch(JandexHelper.getValueAsString(jandex, override, "entity"), "association"),
JandexHelper.getValueAsString(jandex, override, "association"),
fetchMode.toString().toLowerCase())); fetchMode.toString().toLowerCase()));
} }
metadata.addFetchProfile(new FetchProfile(name, fetches)); metadata.addFetchProfile(new FetchProfile(name, fetches));

View File

@ -53,25 +53,24 @@ public class FilterDefBinder {
public static void bind( MetadataImpl metadata, public static void bind( MetadataImpl metadata,
Index jandex ) { Index jandex ) {
for (AnnotationInstance filterDef : jandex.getAnnotations(HibernateDotNames.FILTER_DEF)) { for (AnnotationInstance filterDef : jandex.getAnnotations(HibernateDotNames.FILTER_DEF)) {
bind(metadata, jandex, filterDef); bind(metadata, filterDef);
} }
for (AnnotationInstance filterDefs : jandex.getAnnotations(HibernateDotNames.FILTER_DEFS)) { for (AnnotationInstance filterDefs : jandex.getAnnotations(HibernateDotNames.FILTER_DEFS)) {
for (AnnotationInstance filterDef : JandexHelper.getValueAsArray(filterDefs, "value")) { for (AnnotationInstance filterDef : JandexHelper.getValueAsArray(filterDefs, "value")) {
bind(metadata, jandex, filterDef); bind(metadata, filterDef);
} }
} }
} }
private static void bind( MetadataImpl metadata, private static void bind( MetadataImpl metadata,
Index jandex,
AnnotationInstance filterDef ) { AnnotationInstance filterDef ) {
String name = JandexHelper.getValueAsString(jandex, filterDef, "name"); String name = JandexHelper.getValueAsString(filterDef, "name");
Map<String, Type> prms = new HashMap<String, Type>(); Map<String, Type> prms = new HashMap<String, Type>();
for (AnnotationInstance prm : JandexHelper.getValueAsArray(filterDef, "parameters")) { for (AnnotationInstance prm : JandexHelper.getValueAsArray(filterDef, "parameters")) {
prms.put(JandexHelper.getValueAsString(jandex, prm, "name"), prms.put(JandexHelper.getValueAsString(prm, "name"),
metadata.typeResolver().heuristicType(JandexHelper.getValueAsString(jandex, prm, "type"))); metadata.typeResolver().heuristicType(JandexHelper.getValueAsString(prm, "type")));
} }
metadata.addFilterDef(new FilterDefinition(name, JandexHelper.getValueAsString(jandex, filterDef, "defaultCondition"), prms)); metadata.addFilterDef(new FilterDefinition(name, JandexHelper.getValueAsString(filterDef, "defaultCondition"), prms));
LOG.debugf("Binding filter definition: %s", name); LOG.debugf("Binding filter definition: %s", name);
} }

View File

@ -53,12 +53,11 @@ public class IdGeneratorBinder {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, IdGeneratorBinder.class.getName()); private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, IdGeneratorBinder.class.getName());
private static void addStringParameter( Index index, private static void addStringParameter( AnnotationInstance annotation,
AnnotationInstance annotation,
String element, String element,
Map<String, String> parameters, Map<String, String> parameters,
String parameter ) { String parameter ) {
String string = JandexHelper.getValueAsString(index, annotation, element); String string = JandexHelper.getValueAsString(annotation, element);
if (StringHelper.isNotEmpty(string)) parameters.put(parameter, string); if (StringHelper.isNotEmpty(string)) parameters.put(parameter, string);
} }
@ -72,84 +71,81 @@ public class IdGeneratorBinder {
public static void bind( MetadataImpl metadata, public static void bind( MetadataImpl metadata,
Index jandex ) { Index jandex ) {
for (AnnotationInstance generator : jandex.getAnnotations(JPADotNames.SEQUENCE_GENERATOR)) { for (AnnotationInstance generator : jandex.getAnnotations(JPADotNames.SEQUENCE_GENERATOR)) {
bindSequenceGenerator(metadata, jandex, generator); bindSequenceGenerator(metadata, generator);
} }
for (AnnotationInstance generator : jandex.getAnnotations(JPADotNames.TABLE_GENERATOR)) { for (AnnotationInstance generator : jandex.getAnnotations(JPADotNames.TABLE_GENERATOR)) {
bindTableGenerator(metadata, jandex, generator); bindTableGenerator(metadata, generator);
} }
for (AnnotationInstance generator : jandex.getAnnotations(HibernateDotNames.GENERIC_GENERATOR)) { for (AnnotationInstance generator : jandex.getAnnotations(HibernateDotNames.GENERIC_GENERATOR)) {
bindGenericGenerator(metadata, jandex, generator); bindGenericGenerator(metadata, generator);
} }
for (AnnotationInstance generators : jandex.getAnnotations(HibernateDotNames.GENERIC_GENERATORS)) { for (AnnotationInstance generators : jandex.getAnnotations(HibernateDotNames.GENERIC_GENERATORS)) {
for (AnnotationInstance generator : JandexHelper.getValueAsArray(generators, "value")) { for (AnnotationInstance generator : JandexHelper.getValueAsArray(generators, "value")) {
bindGenericGenerator(metadata, jandex, generator); bindGenericGenerator(metadata, generator);
} }
} }
} }
private static void bindGenericGenerator( MetadataImpl metadata, private static void bindGenericGenerator( MetadataImpl metadata,
Index jandex,
AnnotationInstance generator ) { AnnotationInstance generator ) {
String name = JandexHelper.getValueAsString(jandex, generator, "name"); String name = JandexHelper.getValueAsString(generator, "name");
Map<String, String> prms = new HashMap<String, String>(); Map<String, String> prms = new HashMap<String, String>();
for (AnnotationInstance prm : JandexHelper.getValueAsArray(generator, "parameters")) { for (AnnotationInstance prm : JandexHelper.getValueAsArray(generator, "parameters")) {
prms.put(JandexHelper.getValueAsString(jandex, prm, "name"), JandexHelper.getValueAsString(jandex, prm, "value")); prms.put(JandexHelper.getValueAsString(prm, "name"), JandexHelper.getValueAsString(prm, "value"));
} }
metadata.addIdGenerator(new IdGenerator(name, JandexHelper.getValueAsString(jandex, generator, "strategy"), prms)); metadata.addIdGenerator(new IdGenerator(name, JandexHelper.getValueAsString(generator, "strategy"), prms));
LOG.tracef("Add generic generator with name: %s", name); LOG.tracef("Add generic generator with name: %s", name);
} }
private static void bindSequenceGenerator( MetadataImpl metadata, private static void bindSequenceGenerator( MetadataImpl metadata,
Index jandex,
AnnotationInstance generator ) { AnnotationInstance generator ) {
String name = JandexHelper.getValueAsString(jandex, generator, "name"); String name = JandexHelper.getValueAsString(generator, "name");
String strategy; String strategy;
Map<String, String> prms = new HashMap<String, String>(); Map<String, String> prms = new HashMap<String, String>();
addStringParameter(jandex, generator, "sequenceName", prms, SequenceStyleGenerator.SEQUENCE_PARAM); addStringParameter(generator, "sequenceName", prms, SequenceStyleGenerator.SEQUENCE_PARAM);
if (metadata.getOptions().useNewIdentifierGenerators()) { if (metadata.getOptions().useNewIdentifierGenerators()) {
strategy = SequenceStyleGenerator.class.getName(); strategy = SequenceStyleGenerator.class.getName();
addStringParameter(jandex, generator, "catalog", prms, PersistentIdentifierGenerator.CATALOG); addStringParameter(generator, "catalog", prms, PersistentIdentifierGenerator.CATALOG);
addStringParameter(jandex, generator, "schema", prms, PersistentIdentifierGenerator.SCHEMA); addStringParameter(generator, "schema", prms, PersistentIdentifierGenerator.SCHEMA);
prms.put(SequenceStyleGenerator.INCREMENT_PARAM, prms.put(SequenceStyleGenerator.INCREMENT_PARAM,
String.valueOf(JandexHelper.getValueAsInt(jandex, generator, "allocationSize"))); String.valueOf(JandexHelper.getValueAsInt(generator, "allocationSize")));
prms.put(SequenceStyleGenerator.INITIAL_PARAM, prms.put(SequenceStyleGenerator.INITIAL_PARAM,
String.valueOf(JandexHelper.getValueAsInt(jandex, generator, "initialValue"))); String.valueOf(JandexHelper.getValueAsInt(generator, "initialValue")));
} else { } else {
strategy = "seqhilo"; strategy = "seqhilo";
if (JandexHelper.getValueAsInt(jandex, generator, "initialValue") != 1) LOG.unsupportedInitialValue(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS); if (JandexHelper.getValueAsInt(generator, "initialValue") != 1) LOG.unsupportedInitialValue(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS);
prms.put(SequenceHiLoGenerator.MAX_LO, prms.put(SequenceHiLoGenerator.MAX_LO,
String.valueOf(JandexHelper.getValueAsInt(jandex, generator, "allocationSize") - 1)); String.valueOf(JandexHelper.getValueAsInt(generator, "allocationSize") - 1));
} }
metadata.addIdGenerator(new IdGenerator(name, strategy, prms)); metadata.addIdGenerator(new IdGenerator(name, strategy, prms));
LOG.tracef("Add sequence generator with name: %s", name); LOG.tracef("Add sequence generator with name: %s", name);
} }
private static void bindTableGenerator( MetadataImpl metadata, private static void bindTableGenerator( MetadataImpl metadata,
Index jandex,
AnnotationInstance generator ) { AnnotationInstance generator ) {
String name = JandexHelper.getValueAsString(jandex, generator, "name"); String name = JandexHelper.getValueAsString(generator, "name");
String strategy; String strategy;
Map<String, String> prms = new HashMap<String, String>(); Map<String, String> prms = new HashMap<String, String>();
addStringParameter(jandex, generator, "catalog", prms, PersistentIdentifierGenerator.CATALOG); addStringParameter(generator, "catalog", prms, PersistentIdentifierGenerator.CATALOG);
addStringParameter(jandex, generator, "schema", prms, PersistentIdentifierGenerator.SCHEMA); addStringParameter(generator, "schema", prms, PersistentIdentifierGenerator.SCHEMA);
if (metadata.getOptions().useNewIdentifierGenerators()) { if (metadata.getOptions().useNewIdentifierGenerators()) {
strategy = TableGenerator.class.getName(); strategy = TableGenerator.class.getName();
prms.put(TableGenerator.CONFIG_PREFER_SEGMENT_PER_ENTITY, "true"); prms.put(TableGenerator.CONFIG_PREFER_SEGMENT_PER_ENTITY, "true");
addStringParameter(jandex, generator, "table", prms, TableGenerator.TABLE_PARAM); addStringParameter(generator, "table", prms, TableGenerator.TABLE_PARAM);
addStringParameter(jandex, generator, "pkColumnName", prms, TableGenerator.SEGMENT_COLUMN_PARAM); addStringParameter(generator, "pkColumnName", prms, TableGenerator.SEGMENT_COLUMN_PARAM);
addStringParameter(jandex, generator, "pkColumnValue", prms, TableGenerator.SEGMENT_VALUE_PARAM); addStringParameter(generator, "pkColumnValue", prms, TableGenerator.SEGMENT_VALUE_PARAM);
addStringParameter(jandex, generator, "valueColumnName", prms, TableGenerator.VALUE_COLUMN_PARAM); addStringParameter(generator, "valueColumnName", prms, TableGenerator.VALUE_COLUMN_PARAM);
prms.put(TableGenerator.INCREMENT_PARAM, prms.put(TableGenerator.INCREMENT_PARAM,
String.valueOf(JandexHelper.getValueAsInt(jandex, generator, "allocationSize"))); String.valueOf(JandexHelper.getValueAsInt(generator, "allocationSize")));
prms.put(TableGenerator.INITIAL_PARAM, prms.put(TableGenerator.INITIAL_PARAM,
String.valueOf(JandexHelper.getValueAsInt(jandex, generator, "initialValue") + 1)); String.valueOf(JandexHelper.getValueAsInt(generator, "initialValue") + 1));
} else { } else {
strategy = MultipleHiLoPerTableGenerator.class.getName(); strategy = MultipleHiLoPerTableGenerator.class.getName();
addStringParameter(jandex, generator, "table", prms, MultipleHiLoPerTableGenerator.ID_TABLE); addStringParameter(generator, "table", prms, MultipleHiLoPerTableGenerator.ID_TABLE);
addStringParameter(jandex, generator, "pkColumnName", prms, MultipleHiLoPerTableGenerator.PK_COLUMN_NAME); addStringParameter(generator, "pkColumnName", prms, MultipleHiLoPerTableGenerator.PK_COLUMN_NAME);
addStringParameter(jandex, generator, "pkColumnValue", prms, MultipleHiLoPerTableGenerator.PK_VALUE_NAME); addStringParameter(generator, "pkColumnValue", prms, MultipleHiLoPerTableGenerator.PK_VALUE_NAME);
addStringParameter(jandex, generator, "valueColumnName", prms, MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME); addStringParameter(generator, "valueColumnName", prms, MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME);
prms.put(TableHiLoGenerator.MAX_LO, String.valueOf(JandexHelper.getValueAsInt(jandex, generator, "allocationSize") - 1)); prms.put(TableHiLoGenerator.MAX_LO, String.valueOf(JandexHelper.getValueAsInt(generator, "allocationSize") - 1));
} }
if (JandexHelper.getValueAsArray(generator, "uniqueConstraints").length > 0) LOG.ignoringTableGeneratorConstraints(name); if (JandexHelper.getValueAsArray(generator, "uniqueConstraints").length > 0) LOG.ignoringTableGeneratorConstraints(name);
metadata.addIdGenerator(new IdGenerator(name, strategy, prms)); metadata.addIdGenerator(new IdGenerator(name, strategy, prms));

View File

@ -66,95 +66,89 @@ public class QueryBinder {
public static void bind( MetadataImpl metadata, public static void bind( MetadataImpl metadata,
Index jandex ) { Index jandex ) {
for (AnnotationInstance query : jandex.getAnnotations(JPADotNames.NAMED_QUERY)) { for (AnnotationInstance query : jandex.getAnnotations(JPADotNames.NAMED_QUERY)) {
bindNamedQuery(metadata, jandex, query); bindNamedQuery(metadata, query);
} }
for (AnnotationInstance queries : jandex.getAnnotations(JPADotNames.NAMED_QUERIES)) { for (AnnotationInstance queries : jandex.getAnnotations(JPADotNames.NAMED_QUERIES)) {
for (AnnotationInstance query : JandexHelper.getValueAsArray(queries, "value")) { for (AnnotationInstance query : JandexHelper.getValueAsArray(queries, "value")) {
bindNamedQuery(metadata, jandex, query); bindNamedQuery(metadata, query);
} }
} }
for (AnnotationInstance query : jandex.getAnnotations(JPADotNames.NAMED_NATIVE_QUERY)) { for (AnnotationInstance query : jandex.getAnnotations(JPADotNames.NAMED_NATIVE_QUERY)) {
bindNamedNativeQuery(metadata, jandex, query); bindNamedNativeQuery(metadata, query);
} }
for (AnnotationInstance queries : jandex.getAnnotations(JPADotNames.NAMED_NATIVE_QUERIES)) { for (AnnotationInstance queries : jandex.getAnnotations(JPADotNames.NAMED_NATIVE_QUERIES)) {
for (AnnotationInstance query : JandexHelper.getValueAsArray(queries, "value")) { for (AnnotationInstance query : JandexHelper.getValueAsArray(queries, "value")) {
bindNamedNativeQuery(metadata, jandex, query); bindNamedNativeQuery(metadata, query);
} }
} }
for (AnnotationInstance query : jandex.getAnnotations(HibernateDotNames.NAMED_QUERY)) { for (AnnotationInstance query : jandex.getAnnotations(HibernateDotNames.NAMED_QUERY)) {
bindNamedQuery(metadata, jandex, query); bindNamedQuery(metadata, query);
} }
for (AnnotationInstance queries : jandex.getAnnotations(HibernateDotNames.NAMED_QUERIES)) { for (AnnotationInstance queries : jandex.getAnnotations(HibernateDotNames.NAMED_QUERIES)) {
for (AnnotationInstance query : JandexHelper.getValueAsArray(queries, "value")) { for (AnnotationInstance query : JandexHelper.getValueAsArray(queries, "value")) {
bindNamedQuery(metadata, jandex, query); bindNamedQuery(metadata, query);
} }
} }
for (AnnotationInstance query : jandex.getAnnotations(HibernateDotNames.NAMED_NATIVE_QUERY)) { for (AnnotationInstance query : jandex.getAnnotations(HibernateDotNames.NAMED_NATIVE_QUERY)) {
bindNamedNativeQuery(metadata, jandex, query); bindNamedNativeQuery(metadata, query);
} }
for (AnnotationInstance queries : jandex.getAnnotations(HibernateDotNames.NAMED_NATIVE_QUERIES)) { for (AnnotationInstance queries : jandex.getAnnotations(HibernateDotNames.NAMED_NATIVE_QUERIES)) {
for (AnnotationInstance query : JandexHelper.getValueAsArray(queries, "value")) { for (AnnotationInstance query : JandexHelper.getValueAsArray(queries, "value")) {
bindNamedNativeQuery(metadata, jandex, query); bindNamedNativeQuery(metadata, query);
} }
} }
} }
private static void bindNamedQuery( MetadataImpl metadata, private static void bindNamedQuery( MetadataImpl metadata,
Index jandex,
AnnotationInstance annotation ) { AnnotationInstance annotation ) {
String name = JandexHelper.getValueAsString(jandex, annotation, "name"); String name = JandexHelper.getValueAsString(annotation, "name");
if (StringHelper.isEmpty(name)) throw new AnnotationException( if (StringHelper.isEmpty(name)) throw new AnnotationException("A named query must have a name when used in class or package level");
"A named query must have a name when used in class or package level"); String query = JandexHelper.getValueAsString(annotation, "query");
String query = JandexHelper.getValueAsString(jandex, annotation, "query");
AnnotationInstance[] hints = JandexHelper.getValueAsArray(annotation, "hints"); AnnotationInstance[] hints = JandexHelper.getValueAsArray(annotation, "hints");
String cacheRegion = getString(jandex, hints, QueryHints.CACHE_REGION); String cacheRegion = getString(hints, QueryHints.CACHE_REGION);
if (StringHelper.isEmpty(cacheRegion)) cacheRegion = null; if (StringHelper.isEmpty(cacheRegion)) cacheRegion = null;
Integer timeout = getTimeout(jandex, hints, query); Integer timeout = getTimeout(hints, query);
if (timeout != null && timeout < 0) timeout = null; if (timeout != null && timeout < 0) timeout = null;
Integer fetchSize = getInteger(jandex, hints, QueryHints.FETCH_SIZE, name); Integer fetchSize = getInteger(hints, QueryHints.FETCH_SIZE, name);
if (fetchSize != null && fetchSize < 0) fetchSize = null; if (fetchSize != null && fetchSize < 0) fetchSize = null;
String comment = getString(jandex, hints, QueryHints.COMMENT); String comment = getString(hints, QueryHints.COMMENT);
if (StringHelper.isEmpty(comment)) comment = null; if (StringHelper.isEmpty(comment)) comment = null;
metadata.addNamedQuery(name, metadata.addNamedQuery(name,
new NamedQueryDefinition(query, getBoolean(jandex, hints, QueryHints.CACHEABLE, name), cacheRegion, new NamedQueryDefinition(query, getBoolean(hints, QueryHints.CACHEABLE, name), cacheRegion,
timeout, fetchSize, timeout, fetchSize, getFlushMode(hints, QueryHints.FLUSH_MODE, name),
getFlushMode(jandex, hints, QueryHints.FLUSH_MODE, name), getCacheMode(hints, QueryHints.CACHE_MODE, name),
getCacheMode(jandex, hints, QueryHints.CACHE_MODE, name), getBoolean(hints, QueryHints.READ_ONLY, name), comment, null));
getBoolean(jandex, hints, QueryHints.READ_ONLY, name), comment, null));
LOG.debugf("Binding named query: %s => %s", name, query); LOG.debugf("Binding named query: %s => %s", name, query);
} }
private static void bindNamedNativeQuery( MetadataImpl metadata, private static void bindNamedNativeQuery( MetadataImpl metadata,
Index jandex,
AnnotationInstance annotation ) { AnnotationInstance annotation ) {
String name = JandexHelper.getValueAsString(jandex, annotation, "name"); String name = JandexHelper.getValueAsString(annotation, "name");
if (StringHelper.isEmpty(name)) throw new AnnotationException( if (StringHelper.isEmpty(name)) throw new AnnotationException("A named native query must have a name when used in class or package level");
"A named native query must have a name when used in class or package level"); String query = JandexHelper.getValueAsString(annotation, "query");
String query = JandexHelper.getValueAsString(jandex, annotation, "query"); String resultSetMapping = JandexHelper.getValueAsString(annotation, "resultSetMapping");
String resultSetMapping = JandexHelper.getValueAsString(jandex, annotation, "resultSetMapping");
AnnotationInstance[] hints = JandexHelper.getValueAsArray(annotation, "hints"); AnnotationInstance[] hints = JandexHelper.getValueAsArray(annotation, "hints");
boolean cacheable = getBoolean(jandex, hints, "org.hibernate.cacheable", name); boolean cacheable = getBoolean(hints, "org.hibernate.cacheable", name);
String cacheRegion = getString(jandex, hints, QueryHints.CACHE_REGION); String cacheRegion = getString(hints, QueryHints.CACHE_REGION);
if (StringHelper.isEmpty(cacheRegion)) cacheRegion = null; if (StringHelper.isEmpty(cacheRegion)) cacheRegion = null;
Integer timeout = getTimeout(jandex, hints, query); Integer timeout = getTimeout(hints, query);
if (timeout != null && timeout < 0) timeout = null; if (timeout != null && timeout < 0) timeout = null;
Integer fetchSize = getInteger(jandex, hints, QueryHints.FETCH_SIZE, name); Integer fetchSize = getInteger(hints, QueryHints.FETCH_SIZE, name);
if (fetchSize != null && fetchSize < 0) fetchSize = null; if (fetchSize != null && fetchSize < 0) fetchSize = null;
FlushMode flushMode = getFlushMode(jandex, hints, QueryHints.FLUSH_MODE, name); FlushMode flushMode = getFlushMode(hints, QueryHints.FLUSH_MODE, name);
CacheMode cacheMode = getCacheMode(jandex, hints, QueryHints.CACHE_MODE, name); CacheMode cacheMode = getCacheMode(hints, QueryHints.CACHE_MODE, name);
boolean readOnly = getBoolean(jandex, hints, QueryHints.READ_ONLY, name); boolean readOnly = getBoolean(hints, QueryHints.READ_ONLY, name);
String comment = getString(jandex, hints, QueryHints.COMMENT); String comment = getString(hints, QueryHints.COMMENT);
if (StringHelper.isEmpty(comment)) comment = null; if (StringHelper.isEmpty(comment)) comment = null;
boolean callable = getBoolean(jandex, hints, QueryHints.CALLABLE, name); boolean callable = getBoolean(hints, QueryHints.CALLABLE, name);
NamedSQLQueryDefinition def; NamedSQLQueryDefinition def;
if (StringHelper.isNotEmpty(resultSetMapping)) def = new NamedSQLQueryDefinition(query, resultSetMapping, null, cacheable, if (StringHelper.isNotEmpty(resultSetMapping)) def = new NamedSQLQueryDefinition(query, resultSetMapping, null, cacheable,
cacheRegion, timeout, fetchSize, cacheRegion, timeout, fetchSize,
flushMode, cacheMode, readOnly, comment, flushMode, cacheMode, readOnly, comment,
null, callable); null, callable);
else { else {
String resultClass = JandexHelper.getValueAsString(jandex, annotation, "resultClass"); String resultClass = JandexHelper.getValueAsString(annotation, "resultClass");
if (void.class.equals(resultClass)) throw new NotYetImplementedException( if (void.class.equals(resultClass)) throw new NotYetImplementedException("Pure native scalar queries are not yet supported");
"Pure native scalar queries are not yet supported");
def = new NamedSQLQueryDefinition(query, new NativeSQLQueryRootReturn[] {new NativeSQLQueryRootReturn("alias1", def = new NamedSQLQueryDefinition(query, new NativeSQLQueryRootReturn[] {new NativeSQLQueryRootReturn("alias1",
resultClass, resultClass,
new HashMap(), new HashMap(),
@ -167,21 +161,19 @@ public class QueryBinder {
LOG.debugf("Binding named native query: %s => %s", name, query); LOG.debugf("Binding named native query: %s => %s", name, query);
} }
private static boolean getBoolean( Index jandex, private static boolean getBoolean( AnnotationInstance[] hints,
AnnotationInstance[] hints,
String element, String element,
String query ) { String query ) {
String val = getString(jandex, hints, element); String val = getString(hints, element);
if (val == null || val.equalsIgnoreCase("false")) return false; if (val == null || val.equalsIgnoreCase("false")) return false;
if (val.equalsIgnoreCase("true")) return true; if (val.equalsIgnoreCase("true")) return true;
throw new AnnotationException("Not a boolean in hint: " + query + ":" + element); throw new AnnotationException("Not a boolean in hint: " + query + ":" + element);
} }
private static CacheMode getCacheMode( Index jandex, private static CacheMode getCacheMode( AnnotationInstance[] hints,
AnnotationInstance[] hints,
String element, String element,
String query ) { String query ) {
String val = getString(jandex, hints, element); String val = getString(hints, element);
if (val == null) return null; if (val == null) return null;
if (val.equalsIgnoreCase(CacheMode.GET.toString())) return CacheMode.GET; if (val.equalsIgnoreCase(CacheMode.GET.toString())) return CacheMode.GET;
if (val.equalsIgnoreCase(CacheMode.IGNORE.toString())) return CacheMode.IGNORE; if (val.equalsIgnoreCase(CacheMode.IGNORE.toString())) return CacheMode.IGNORE;
@ -191,11 +183,10 @@ public class QueryBinder {
throw new AnnotationException("Unknown CacheMode in hint: " + query + ":" + element); throw new AnnotationException("Unknown CacheMode in hint: " + query + ":" + element);
} }
private static FlushMode getFlushMode( Index jandex, private static FlushMode getFlushMode( AnnotationInstance[] hints,
AnnotationInstance[] hints,
String element, String element,
String query ) { String query ) {
String val = getString(jandex, hints, element); String val = getString(hints, element);
if (val == null) return null; if (val == null) return null;
if (val.equalsIgnoreCase(FlushMode.ALWAYS.toString())) return FlushMode.ALWAYS; if (val.equalsIgnoreCase(FlushMode.ALWAYS.toString())) return FlushMode.ALWAYS;
else if (val.equalsIgnoreCase(FlushMode.AUTO.toString())) return FlushMode.AUTO; else if (val.equalsIgnoreCase(FlushMode.AUTO.toString())) return FlushMode.AUTO;
@ -206,11 +197,10 @@ public class QueryBinder {
} }
private static Integer getInteger( Index jandex, private static Integer getInteger( AnnotationInstance[] hints,
AnnotationInstance[] hints,
String element, String element,
String query ) { String query ) {
String val = getString(jandex, hints, element); String val = getString(hints, element);
if (val == null) return null; if (val == null) return null;
try { try {
return Integer.decode(val); return Integer.decode(val);
@ -219,22 +209,18 @@ public class QueryBinder {
} }
} }
private static String getString( Index jandex, private static String getString( AnnotationInstance[] hints,
AnnotationInstance[] hints,
String element ) { String element ) {
for (AnnotationInstance hint : hints) { for (AnnotationInstance hint : hints) {
if (element.equals(JandexHelper.getValue(jandex, hint, "name"))) return JandexHelper.getValueAsString(jandex, if (element.equals(JandexHelper.getValue(hint, "name"))) return JandexHelper.getValueAsString(hint, "value");
hint,
"value");
} }
return null; return null;
} }
private static Integer getTimeout( Index jandex, private static Integer getTimeout( AnnotationInstance[] hints,
AnnotationInstance[] hints,
String query ) { String query ) {
Integer timeout = getInteger(jandex, hints, QueryHints.TIMEOUT_JPA, query); Integer timeout = getInteger(hints, QueryHints.TIMEOUT_JPA, query);
if (timeout == null) return getInteger(jandex, hints, QueryHints.TIMEOUT_HIBERNATE, query); // timeout is already in seconds if (timeout == null) return getInteger(hints, QueryHints.TIMEOUT_HIBERNATE, query); // timeout is already in seconds
return new Integer((int)Math.round(timeout.doubleValue() / 1000.0)); // convert milliseconds to seconds return new Integer((int)Math.round(timeout.doubleValue() / 1000.0)); // convert milliseconds to seconds
} }

View File

@ -57,40 +57,37 @@ public class TableBinder {
public static void bind( MetadataImpl metadata, public static void bind( MetadataImpl metadata,
Index jandex ) { Index jandex ) {
for (AnnotationInstance tableAnnotation : jandex.getAnnotations(HibernateDotNames.TABLE)) { for (AnnotationInstance tableAnnotation : jandex.getAnnotations(HibernateDotNames.TABLE)) {
bind(metadata, jandex, tableAnnotation); bind(metadata, tableAnnotation);
} }
for (AnnotationInstance tables : jandex.getAnnotations(HibernateDotNames.TABLES)) { for (AnnotationInstance tables : jandex.getAnnotations(HibernateDotNames.TABLES)) {
for (AnnotationInstance table : JandexHelper.getValueAsArray(tables, "value")) { for (AnnotationInstance table : JandexHelper.getValueAsArray(tables, "value")) {
bind(metadata, jandex, table); bind(metadata, table);
} }
} }
} }
private static void bind( MetadataImpl metadata, private static void bind( MetadataImpl metadata,
Index jandex,
AnnotationInstance tableAnnotation ) { AnnotationInstance tableAnnotation ) {
String tableName = JandexHelper.getValueAsString(jandex, tableAnnotation, "appliesTo"); String tableName = JandexHelper.getValueAsString(tableAnnotation, "appliesTo");
ObjectName objectName = new ObjectName(tableName); ObjectName objectName = new ObjectName(tableName);
Schema schema = metadata.getDatabase().getSchema(objectName.getSchema(), objectName.getCatalog()); Schema schema = metadata.getDatabase().getSchema(objectName.getSchema(), objectName.getCatalog());
Table table = schema.getTable(objectName.getName()); Table table = schema.getTable(objectName.getName());
if (table != null) bindHibernateTableAnnotation(jandex, table, tableAnnotation); if (table != null) bindHibernateTableAnnotation(table, tableAnnotation);
} }
private static void bindHibernateTableAnnotation( Index jandex, private static void bindHibernateTableAnnotation( Table table,
Table table,
AnnotationInstance tableAnnotation ) { AnnotationInstance tableAnnotation ) {
for (AnnotationInstance indexAnnotation : JandexHelper.getValueAsArray(tableAnnotation, "indexes")) { for (AnnotationInstance indexAnnotation : JandexHelper.getValueAsArray(tableAnnotation, "indexes")) {
bindIndexAnnotation(jandex, table, indexAnnotation); bindIndexAnnotation(table, indexAnnotation);
} }
String comment = JandexHelper.getValueAsString(jandex, tableAnnotation, "comment"); String comment = JandexHelper.getValueAsString(tableAnnotation, "comment");
if (StringHelper.isNotEmpty(comment)) table.addComment(comment.trim()); if (StringHelper.isNotEmpty(comment)) table.addComment(comment.trim());
} }
private static void bindIndexAnnotation( Index jandex, private static void bindIndexAnnotation( Table table,
Table table,
AnnotationInstance indexAnnotation ) { AnnotationInstance indexAnnotation ) {
String indexName = JandexHelper.getValueAsString(jandex, indexAnnotation, "appliesTo"); String indexName = JandexHelper.getValueAsString(indexAnnotation, "appliesTo");
String[] columnNames = (String[])JandexHelper.getValue(jandex, indexAnnotation, "columnNames"); String[] columnNames = (String[])JandexHelper.getValue(indexAnnotation, "columnNames");
if (columnNames == null) { if (columnNames == null) {
LOG.noColumnsSpecifiedForIndex(indexName, table.toLoggableString()); LOG.noColumnsSpecifiedForIndex(indexName, table.toLoggableString());
return; return;

View File

@ -53,15 +53,32 @@ public class TypeDefBinder {
public static void bind( MetadataImpl metadata, public static void bind( MetadataImpl metadata,
Index jandex ) { Index jandex ) {
for (AnnotationInstance typeDef : jandex.getAnnotations(HibernateDotNames.TYPE_DEF)) { for (AnnotationInstance typeDef : jandex.getAnnotations(HibernateDotNames.TYPE_DEF)) {
bind(metadata, jandex, typeDef); bind(metadata, typeDef);
} }
for (AnnotationInstance typeDefs : jandex.getAnnotations(HibernateDotNames.TYPE_DEFS)) { for (AnnotationInstance typeDefs : jandex.getAnnotations(HibernateDotNames.TYPE_DEFS)) {
for (AnnotationInstance typeDef : JandexHelper.getValueAsArray(typeDefs, "value")) { for (AnnotationInstance typeDef : JandexHelper.getValueAsArray(typeDefs, "value")) {
bind(metadata, jandex, typeDef); bind(metadata, typeDef);
} }
} }
} }
private static void bind( MetadataImpl metadata,
AnnotationInstance typeDef ) {
String name = JandexHelper.getValueAsString(typeDef, "name");
String defaultForType = JandexHelper.getValueAsString(typeDef, "defaultForType");
String typeClass = JandexHelper.getValueAsString(typeDef, "typeClass");
boolean noName = StringHelper.isEmpty(name);
boolean noDefaultForType = defaultForType == null || defaultForType.equals(void.class.getName());
if (noName && noDefaultForType) throw new AnnotationException("Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass "
+ typeClass);
Map<String, String> prms = new HashMap<String, String>();
for (AnnotationInstance prm : JandexHelper.getValueAsArray(typeDef, "parameters")) {
prms.put(JandexHelper.getValueAsString(prm, "name"), JandexHelper.getValueAsString(prm, "value"));
}
if (!noName) bind(name, typeClass, prms, metadata);
if (!noDefaultForType) bind(defaultForType, typeClass, prms, metadata);
}
private static void bind( String name, private static void bind( String name,
String typeClass, String typeClass,
Map<String, String> prms, Map<String, String> prms,
@ -70,25 +87,6 @@ public class TypeDefBinder {
metadata.addTypeDef(name, new TypeDef(typeClass, prms)); metadata.addTypeDef(name, new TypeDef(typeClass, prms));
} }
private static void bind( MetadataImpl metadata,
Index jandex,
AnnotationInstance typeDef ) {
String name = JandexHelper.getValueAsString(jandex, typeDef, "name");
String defaultForType = JandexHelper.getValueAsString(jandex, typeDef, "defaultForType");
String typeClass = JandexHelper.getValueAsString(jandex, typeDef, "typeClass");
boolean noName = StringHelper.isEmpty(name);
boolean noDefaultForType = defaultForType == null || defaultForType.equals(void.class.getName());
if (noName && noDefaultForType) throw new AnnotationException(
"Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass "
+ typeClass);
Map<String, String> prms = new HashMap<String, String>();
for (AnnotationInstance prm : JandexHelper.getValueAsArray(typeDef, "parameters")) {
prms.put(JandexHelper.getValueAsString(jandex, prm, "name"), JandexHelper.getValueAsString(jandex, prm, "value"));
}
if (!noName) bind(name, typeClass, prms, metadata);
if (!noDefaultForType) bind(defaultForType, typeClass, prms, metadata);
}
private TypeDefBinder() { private TypeDefBinder() {
} }
} }

View File

@ -57,8 +57,7 @@ public class JandexHelper {
private static final Map<String, Object> DEFAULT_VALUES_BY_ELEMENT = new HashMap<String, Object>(); private static final Map<String, Object> DEFAULT_VALUES_BY_ELEMENT = new HashMap<String, Object>();
private static Object getDefaultValue( Index index, private static Object getDefaultValue( AnnotationInstance annotation,
AnnotationInstance annotation,
String element ) { String element ) {
String name = annotation.name().toString(); String name = annotation.name().toString();
String fqElement = name + '.' + element; String fqElement = name + '.' + element;
@ -154,22 +153,20 @@ public class JandexHelper {
* called to retrieve an enumerated value, and {@link #getValueAsArray(AnnotationInstance, String)} must be called to retrieve * called to retrieve an enumerated value, and {@link #getValueAsArray(AnnotationInstance, String)} must be called to retrieve
* an object array (other than a String array). * an object array (other than a String array).
* *
* @param index the jandex index containing the supplied annotation
* @param annotation the annotation containing the element with the supplied name * @param annotation the annotation containing the element with the supplied name
* @param element the name of the element value to be retrieve * @param element the name of the element value to be retrieve
* @return the value if not <code>null</code>, else the default value if not * @return the value if not <code>null</code>, else the default value if not
* <code>null</code>, else <code>null</code>. * <code>null</code>, else <code>null</code>.
*/ */
public static Object getValue( Index index, public static Object getValue( AnnotationInstance annotation,
AnnotationInstance annotation,
String element ) { String element ) {
AnnotationValue val = annotation.value(element); AnnotationValue val = annotation.value(element);
if (val == null) return getDefaultValue(index, annotation, element); if (val == null) return getDefaultValue(annotation, element);
return val.asNested(); return val.asNested();
} }
/** /**
* Retrieves a jandex annotation element array. Note, {@link #getValue(Index, AnnotationInstance, String)} may be * Retrieves a jandex annotation element array. Note, {@link #getValue(AnnotationInstance, String)} may be
* called to retrieve a String array (or a non-array value). * called to retrieve a String array (or a non-array value).
* *
* @param annotation the jandex annotation containing the element with the supplied name * @param annotation the jandex annotation containing the element with the supplied name
@ -187,20 +184,18 @@ public class JandexHelper {
* <code>null</code>, the default value specified in the annotation class is retrieved instead. * <code>null</code>, the default value specified in the annotation class is retrieved instead.
* *
* @param <T> an enumerated type * @param <T> an enumerated type
* @param index the jandex index containing the supplied annotation
* @param annotation the annotation containing the enumerated element with the supplied name * @param annotation the annotation containing the enumerated element with the supplied name
* @param element the name of the enumerated element value to be retrieve * @param element the name of the enumerated element value to be retrieve
* @param type the type to which to convert the value before being returned * @param type the type to which to convert the value before being returned
* @return the value converted to the supplied enumerated type if the value is not <code>null</code>, else the default value if * @return the value converted to the supplied enumerated type if the value is not <code>null</code>, else the default value if
* not <code>null</code>, else <code>null</code>. * not <code>null</code>, else <code>null</code>.
* @see #getValue(Index, AnnotationInstance, String) * @see #getValue(AnnotationInstance, String)
*/ */
public static <T extends Enum<T>> T getValueAsEnum( Index index, public static <T extends Enum<T>> T getValueAsEnum( AnnotationInstance annotation,
AnnotationInstance annotation,
String element, String element,
Class<T> type ) { Class<T> type ) {
AnnotationValue val = annotation.value(element); AnnotationValue val = annotation.value(element);
if (val == null) return (T)getDefaultValue(index, annotation, element); if (val == null) return (T)getDefaultValue(annotation, element);
return Enum.valueOf(type, val.asEnum()); return Enum.valueOf(type, val.asEnum());
} }
@ -208,17 +203,15 @@ public class JandexHelper {
* Retrieves a jandex annotation element value as an Integer. If the value is <code>null</code>, the default value specified in * Retrieves a jandex annotation element value as an Integer. If the value is <code>null</code>, the default value specified in
* the annotation class is retrieved instead. * the annotation class is retrieved instead.
* *
* @param index the jandex index containing the supplied annotation
* @param annotation the annotation containing the element with the supplied name * @param annotation the annotation containing the element with the supplied name
* @param element the name of the element value to be retrieve * @param element the name of the element value to be retrieve
* @return the value converted to an int if the value is not <code>null</code>, else the default value if not * @return the value converted to an int if the value is not <code>null</code>, else the default value if not
* <code>null</code>, else <code>0</code>. * <code>null</code>, else <code>0</code>.
*/ */
public static int getValueAsInt( Index index, public static int getValueAsInt( AnnotationInstance annotation,
AnnotationInstance annotation,
String element ) { String element ) {
AnnotationValue val = annotation.value(element); AnnotationValue val = annotation.value(element);
if (val == null) return (Integer)getDefaultValue(index, annotation, element); if (val == null) return (Integer)getDefaultValue(annotation, element);
return val.asInt(); return val.asInt();
} }
@ -226,17 +219,15 @@ public class JandexHelper {
* Retrieves a jandex annotation element value as a String. If the value is <code>null</code>, the default value specified in * Retrieves a jandex annotation element value as a String. If the value is <code>null</code>, the default value specified in
* the annotation class is retrieved instead. * the annotation class is retrieved instead.
* *
* @param index the jandex index containing the supplied annotation
* @param annotation the annotation containing the element with the supplied name * @param annotation the annotation containing the element with the supplied name
* @param element the name of the element value to be retrieve * @param element the name of the element value to be retrieve
* @return the value converted to a String if the value is not <code>null</code>, else the default value if not * @return the value converted to a String if the value is not <code>null</code>, else the default value if not
* <code>null</code>, else <code>null</code>. * <code>null</code>, else <code>null</code>.
*/ */
public static String getValueAsString( Index index, public static String getValueAsString( AnnotationInstance annotation,
AnnotationInstance annotation,
String element ) { String element ) {
AnnotationValue val = annotation.value(element); AnnotationValue val = annotation.value(element);
if (val == null) return (String)getDefaultValue(index, annotation, element); if (val == null) return (String)getDefaultValue(annotation, element);
return val.asString(); return val.asString();
} }

View File

@ -107,10 +107,10 @@ public class JandexHelperTest extends BaseUnitTestCase {
Index index = JandexHelper.indexForClass(classLoaderService, Foo.class); Index index = JandexHelper.indexForClass(classLoaderService, Foo.class);
for (AnnotationInstance query : index.getAnnotations( JPADotNames.NAMED_QUERY)) { for (AnnotationInstance query : index.getAnnotations( JPADotNames.NAMED_QUERY)) {
assertThat(JandexHelper.getValueAsEnum(index, query, "lockMode", LockModeType.class), is(LockModeType.NONE)); assertThat(JandexHelper.getValueAsEnum(query, "lockMode", LockModeType.class), is(LockModeType.NONE));
} }
for (AnnotationInstance generator : index.getAnnotations( JPADotNames.SEQUENCE_GENERATOR)) { for (AnnotationInstance generator : index.getAnnotations( JPADotNames.SEQUENCE_GENERATOR)) {
assertThat(JandexHelper.getValueAsInt(index, generator, "allocationSize"), is(50)); assertThat(JandexHelper.getValueAsInt(generator, "allocationSize"), is(50));
} }
} }
@ -123,7 +123,7 @@ public class JandexHelperTest extends BaseUnitTestCase {
Index index = JandexHelper.indexForClass(classLoaderService, Foo.class); Index index = JandexHelper.indexForClass(classLoaderService, Foo.class);
for (AnnotationInstance query : index.getAnnotations( JPADotNames.NAMED_QUERY)) { for (AnnotationInstance query : index.getAnnotations( JPADotNames.NAMED_QUERY)) {
assertThat(JandexHelper.getValueAsString(index, query, "name"), is("foo")); assertThat(JandexHelper.getValueAsString(query, "name"), is("foo"));
} }
} }
@ -136,7 +136,7 @@ public class JandexHelperTest extends BaseUnitTestCase {
Index index = JandexHelper.indexForClass(classLoaderService, Foo.class); Index index = JandexHelper.indexForClass(classLoaderService, Foo.class);
for (AnnotationInstance query : index.getAnnotations( JPADotNames.NAMED_QUERY)) { for (AnnotationInstance query : index.getAnnotations( JPADotNames.NAMED_QUERY)) {
assertThat(JandexHelper.getValueAsEnum(index, query, "lockMode", LockModeType.class), is(LockModeType.OPTIMISTIC)); assertThat(JandexHelper.getValueAsEnum(query, "lockMode", LockModeType.class), is(LockModeType.OPTIMISTIC));
} }
} }
} }