From 9b48cd993e0aa810efa50fcf0cf8148d213f0a34 Mon Sep 17 00:00:00 2001 From: JPAV Date: Tue, 24 May 2011 13:02:09 -0500 Subject: [PATCH] HHH-6132: Removed an extraneous Index parameter from the various JandexHelper.getValue methods, and modified all references to those methods accordingly --- .../global/FetchProfileBinder.java | 16 ++- .../annotations/global/FilterDefBinder.java | 13 +-- .../annotations/global/IdGeneratorBinder.java | 66 +++++------ .../annotations/global/QueryBinder.java | 108 ++++++++---------- .../annotations/global/TableBinder.java | 23 ++-- .../annotations/global/TypeDefBinder.java | 40 +++---- .../source/annotations/util/JandexHelper.java | 31 ++--- .../annotations/util/JandexHelperTest.java | 8 +- 8 files changed, 135 insertions(+), 170 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/FetchProfileBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/FetchProfileBinder.java index 8e6681d169..e0f4d1f55c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/FetchProfileBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/FetchProfileBinder.java @@ -53,26 +53,24 @@ public class FetchProfileBinder { public static void bind( MetadataImpl metadata, Index jandex ) { 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 fetchProfile : JandexHelper.getValueAsArray(fetchProfiles, "value")) { - bind(metadata, jandex, fetchProfile); + bind(metadata, fetchProfile); } } } private static void bind( MetadataImpl metadata, - Index jandex, AnnotationInstance fetchProfile ) { - String name = JandexHelper.getValueAsString(jandex, fetchProfile, "name"); + String name = JandexHelper.getValueAsString(fetchProfile, "name"); Set fetches = new HashSet(); for (AnnotationInstance override : JandexHelper.getValueAsArray(fetchProfile, "fetchOverrides")) { - FetchMode fetchMode = JandexHelper.getValueAsEnum(jandex, override, "mode", FetchMode.class); - if (!fetchMode.equals(org.hibernate.annotations.FetchMode.JOIN)) throw new MappingException( - "Only FetchMode.JOIN is currently supported"); - fetches.add(new Fetch(JandexHelper.getValueAsString(jandex, override, "entity"), - JandexHelper.getValueAsString(jandex, override, "association"), + FetchMode fetchMode = JandexHelper.getValueAsEnum(override, "mode", FetchMode.class); + if (!fetchMode.equals(org.hibernate.annotations.FetchMode.JOIN)) throw new MappingException("Only FetchMode.JOIN is currently supported"); + fetches.add(new Fetch(JandexHelper.getValueAsString(override, "entity"), JandexHelper.getValueAsString(override, + "association"), fetchMode.toString().toLowerCase())); } metadata.addFetchProfile(new FetchProfile(name, fetches)); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/FilterDefBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/FilterDefBinder.java index d95801292e..8062d87afd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/FilterDefBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/FilterDefBinder.java @@ -53,25 +53,24 @@ public class FilterDefBinder { public static void bind( MetadataImpl metadata, Index jandex ) { 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 filterDef : JandexHelper.getValueAsArray(filterDefs, "value")) { - bind(metadata, jandex, filterDef); + bind(metadata, filterDef); } } } private static void bind( MetadataImpl metadata, - Index jandex, AnnotationInstance filterDef ) { - String name = JandexHelper.getValueAsString(jandex, filterDef, "name"); + String name = JandexHelper.getValueAsString(filterDef, "name"); Map prms = new HashMap(); for (AnnotationInstance prm : JandexHelper.getValueAsArray(filterDef, "parameters")) { - prms.put(JandexHelper.getValueAsString(jandex, prm, "name"), - metadata.typeResolver().heuristicType(JandexHelper.getValueAsString(jandex, prm, "type"))); + prms.put(JandexHelper.getValueAsString(prm, "name"), + 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); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/IdGeneratorBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/IdGeneratorBinder.java index 6ce3fb2e9e..78cecf97a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/IdGeneratorBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/IdGeneratorBinder.java @@ -53,12 +53,11 @@ public class IdGeneratorBinder { private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, IdGeneratorBinder.class.getName()); - private static void addStringParameter( Index index, - AnnotationInstance annotation, + private static void addStringParameter( AnnotationInstance annotation, String element, Map parameters, String parameter ) { - String string = JandexHelper.getValueAsString(index, annotation, element); + String string = JandexHelper.getValueAsString(annotation, element); if (StringHelper.isNotEmpty(string)) parameters.put(parameter, string); } @@ -72,84 +71,81 @@ public class IdGeneratorBinder { public static void bind( MetadataImpl metadata, Index jandex ) { for (AnnotationInstance generator : jandex.getAnnotations(JPADotNames.SEQUENCE_GENERATOR)) { - bindSequenceGenerator(metadata, jandex, generator); + bindSequenceGenerator(metadata, generator); } for (AnnotationInstance generator : jandex.getAnnotations(JPADotNames.TABLE_GENERATOR)) { - bindTableGenerator(metadata, jandex, generator); + bindTableGenerator(metadata, 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 generator : JandexHelper.getValueAsArray(generators, "value")) { - bindGenericGenerator(metadata, jandex, generator); + bindGenericGenerator(metadata, generator); } } } private static void bindGenericGenerator( MetadataImpl metadata, - Index jandex, AnnotationInstance generator ) { - String name = JandexHelper.getValueAsString(jandex, generator, "name"); + String name = JandexHelper.getValueAsString(generator, "name"); Map prms = new HashMap(); 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); } private static void bindSequenceGenerator( MetadataImpl metadata, - Index jandex, AnnotationInstance generator ) { - String name = JandexHelper.getValueAsString(jandex, generator, "name"); + String name = JandexHelper.getValueAsString(generator, "name"); String strategy; Map prms = new HashMap(); - addStringParameter(jandex, generator, "sequenceName", prms, SequenceStyleGenerator.SEQUENCE_PARAM); + addStringParameter(generator, "sequenceName", prms, SequenceStyleGenerator.SEQUENCE_PARAM); if (metadata.getOptions().useNewIdentifierGenerators()) { strategy = SequenceStyleGenerator.class.getName(); - addStringParameter(jandex, generator, "catalog", prms, PersistentIdentifierGenerator.CATALOG); - addStringParameter(jandex, generator, "schema", prms, PersistentIdentifierGenerator.SCHEMA); + addStringParameter(generator, "catalog", prms, PersistentIdentifierGenerator.CATALOG); + addStringParameter(generator, "schema", prms, PersistentIdentifierGenerator.SCHEMA); prms.put(SequenceStyleGenerator.INCREMENT_PARAM, - String.valueOf(JandexHelper.getValueAsInt(jandex, generator, "allocationSize"))); + String.valueOf(JandexHelper.getValueAsInt(generator, "allocationSize"))); prms.put(SequenceStyleGenerator.INITIAL_PARAM, - String.valueOf(JandexHelper.getValueAsInt(jandex, generator, "initialValue"))); + String.valueOf(JandexHelper.getValueAsInt(generator, "initialValue"))); } else { 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, - String.valueOf(JandexHelper.getValueAsInt(jandex, generator, "allocationSize") - 1)); + String.valueOf(JandexHelper.getValueAsInt(generator, "allocationSize") - 1)); } metadata.addIdGenerator(new IdGenerator(name, strategy, prms)); LOG.tracef("Add sequence generator with name: %s", name); } private static void bindTableGenerator( MetadataImpl metadata, - Index jandex, AnnotationInstance generator ) { - String name = JandexHelper.getValueAsString(jandex, generator, "name"); + String name = JandexHelper.getValueAsString(generator, "name"); String strategy; Map prms = new HashMap(); - addStringParameter(jandex, generator, "catalog", prms, PersistentIdentifierGenerator.CATALOG); - addStringParameter(jandex, generator, "schema", prms, PersistentIdentifierGenerator.SCHEMA); + addStringParameter(generator, "catalog", prms, PersistentIdentifierGenerator.CATALOG); + addStringParameter(generator, "schema", prms, PersistentIdentifierGenerator.SCHEMA); if (metadata.getOptions().useNewIdentifierGenerators()) { strategy = TableGenerator.class.getName(); prms.put(TableGenerator.CONFIG_PREFER_SEGMENT_PER_ENTITY, "true"); - addStringParameter(jandex, generator, "table", prms, TableGenerator.TABLE_PARAM); - addStringParameter(jandex, generator, "pkColumnName", prms, TableGenerator.SEGMENT_COLUMN_PARAM); - addStringParameter(jandex, generator, "pkColumnValue", prms, TableGenerator.SEGMENT_VALUE_PARAM); - addStringParameter(jandex, generator, "valueColumnName", prms, TableGenerator.VALUE_COLUMN_PARAM); + addStringParameter(generator, "table", prms, TableGenerator.TABLE_PARAM); + addStringParameter(generator, "pkColumnName", prms, TableGenerator.SEGMENT_COLUMN_PARAM); + addStringParameter(generator, "pkColumnValue", prms, TableGenerator.SEGMENT_VALUE_PARAM); + addStringParameter(generator, "valueColumnName", prms, TableGenerator.VALUE_COLUMN_PARAM); prms.put(TableGenerator.INCREMENT_PARAM, - String.valueOf(JandexHelper.getValueAsInt(jandex, generator, "allocationSize"))); + String.valueOf(JandexHelper.getValueAsInt(generator, "allocationSize"))); prms.put(TableGenerator.INITIAL_PARAM, - String.valueOf(JandexHelper.getValueAsInt(jandex, generator, "initialValue") + 1)); + String.valueOf(JandexHelper.getValueAsInt(generator, "initialValue") + 1)); } else { strategy = MultipleHiLoPerTableGenerator.class.getName(); - addStringParameter(jandex, generator, "table", prms, MultipleHiLoPerTableGenerator.ID_TABLE); - addStringParameter(jandex, generator, "pkColumnName", prms, MultipleHiLoPerTableGenerator.PK_COLUMN_NAME); - addStringParameter(jandex, generator, "pkColumnValue", prms, MultipleHiLoPerTableGenerator.PK_VALUE_NAME); - addStringParameter(jandex, generator, "valueColumnName", prms, MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME); - prms.put(TableHiLoGenerator.MAX_LO, String.valueOf(JandexHelper.getValueAsInt(jandex, generator, "allocationSize") - 1)); + addStringParameter(generator, "table", prms, MultipleHiLoPerTableGenerator.ID_TABLE); + addStringParameter(generator, "pkColumnName", prms, MultipleHiLoPerTableGenerator.PK_COLUMN_NAME); + addStringParameter(generator, "pkColumnValue", prms, MultipleHiLoPerTableGenerator.PK_VALUE_NAME); + addStringParameter(generator, "valueColumnName", prms, MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME); + prms.put(TableHiLoGenerator.MAX_LO, String.valueOf(JandexHelper.getValueAsInt(generator, "allocationSize") - 1)); } if (JandexHelper.getValueAsArray(generator, "uniqueConstraints").length > 0) LOG.ignoringTableGeneratorConstraints(name); metadata.addIdGenerator(new IdGenerator(name, strategy, prms)); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/QueryBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/QueryBinder.java index a3b6636177..e72b9a04d7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/QueryBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/QueryBinder.java @@ -66,95 +66,89 @@ public class QueryBinder { public static void bind( MetadataImpl metadata, Index jandex ) { 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 query : JandexHelper.getValueAsArray(queries, "value")) { - bindNamedQuery(metadata, jandex, query); + bindNamedQuery(metadata, 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 query : JandexHelper.getValueAsArray(queries, "value")) { - bindNamedNativeQuery(metadata, jandex, query); + bindNamedNativeQuery(metadata, 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 query : JandexHelper.getValueAsArray(queries, "value")) { - bindNamedQuery(metadata, jandex, query); + bindNamedQuery(metadata, 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 query : JandexHelper.getValueAsArray(queries, "value")) { - bindNamedNativeQuery(metadata, jandex, query); + bindNamedNativeQuery(metadata, query); } } } private static void bindNamedQuery( MetadataImpl metadata, - Index jandex, AnnotationInstance annotation ) { - String name = JandexHelper.getValueAsString(jandex, annotation, "name"); - if (StringHelper.isEmpty(name)) throw new AnnotationException( - "A named query must have a name when used in class or package level"); - String query = JandexHelper.getValueAsString(jandex, annotation, "query"); + String name = JandexHelper.getValueAsString(annotation, "name"); + if (StringHelper.isEmpty(name)) throw new AnnotationException("A named query must have a name when used in class or package level"); + String query = JandexHelper.getValueAsString(annotation, "query"); 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; - Integer timeout = getTimeout(jandex, hints, query); + Integer timeout = getTimeout(hints, query); 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; - String comment = getString(jandex, hints, QueryHints.COMMENT); + String comment = getString(hints, QueryHints.COMMENT); if (StringHelper.isEmpty(comment)) comment = null; metadata.addNamedQuery(name, - new NamedQueryDefinition(query, getBoolean(jandex, hints, QueryHints.CACHEABLE, name), cacheRegion, - timeout, fetchSize, - getFlushMode(jandex, hints, QueryHints.FLUSH_MODE, name), - getCacheMode(jandex, hints, QueryHints.CACHE_MODE, name), - getBoolean(jandex, hints, QueryHints.READ_ONLY, name), comment, null)); + new NamedQueryDefinition(query, getBoolean(hints, QueryHints.CACHEABLE, name), cacheRegion, + timeout, fetchSize, getFlushMode(hints, QueryHints.FLUSH_MODE, name), + getCacheMode(hints, QueryHints.CACHE_MODE, name), + getBoolean(hints, QueryHints.READ_ONLY, name), comment, null)); LOG.debugf("Binding named query: %s => %s", name, query); } private static void bindNamedNativeQuery( MetadataImpl metadata, - Index jandex, AnnotationInstance annotation ) { - String name = JandexHelper.getValueAsString(jandex, annotation, "name"); - if (StringHelper.isEmpty(name)) throw new AnnotationException( - "A named native query must have a name when used in class or package level"); - String query = JandexHelper.getValueAsString(jandex, annotation, "query"); - String resultSetMapping = JandexHelper.getValueAsString(jandex, annotation, "resultSetMapping"); + String name = JandexHelper.getValueAsString(annotation, "name"); + if (StringHelper.isEmpty(name)) throw new AnnotationException("A named native query must have a name when used in class or package level"); + String query = JandexHelper.getValueAsString(annotation, "query"); + String resultSetMapping = JandexHelper.getValueAsString(annotation, "resultSetMapping"); AnnotationInstance[] hints = JandexHelper.getValueAsArray(annotation, "hints"); - boolean cacheable = getBoolean(jandex, hints, "org.hibernate.cacheable", name); - String cacheRegion = getString(jandex, hints, QueryHints.CACHE_REGION); + boolean cacheable = getBoolean(hints, "org.hibernate.cacheable", name); + String cacheRegion = getString(hints, QueryHints.CACHE_REGION); if (StringHelper.isEmpty(cacheRegion)) cacheRegion = null; - Integer timeout = getTimeout(jandex, hints, query); + Integer timeout = getTimeout(hints, query); 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; - FlushMode flushMode = getFlushMode(jandex, hints, QueryHints.FLUSH_MODE, name); - CacheMode cacheMode = getCacheMode(jandex, hints, QueryHints.CACHE_MODE, name); - boolean readOnly = getBoolean(jandex, hints, QueryHints.READ_ONLY, name); - String comment = getString(jandex, hints, QueryHints.COMMENT); + FlushMode flushMode = getFlushMode(hints, QueryHints.FLUSH_MODE, name); + CacheMode cacheMode = getCacheMode(hints, QueryHints.CACHE_MODE, name); + boolean readOnly = getBoolean(hints, QueryHints.READ_ONLY, name); + String comment = getString(hints, QueryHints.COMMENT); if (StringHelper.isEmpty(comment)) comment = null; - boolean callable = getBoolean(jandex, hints, QueryHints.CALLABLE, name); + boolean callable = getBoolean(hints, QueryHints.CALLABLE, name); NamedSQLQueryDefinition def; if (StringHelper.isNotEmpty(resultSetMapping)) def = new NamedSQLQueryDefinition(query, resultSetMapping, null, cacheable, cacheRegion, timeout, fetchSize, flushMode, cacheMode, readOnly, comment, null, callable); else { - String resultClass = JandexHelper.getValueAsString(jandex, annotation, "resultClass"); - if (void.class.equals(resultClass)) throw new NotYetImplementedException( - "Pure native scalar queries are not yet supported"); + String resultClass = JandexHelper.getValueAsString(annotation, "resultClass"); + if (void.class.equals(resultClass)) throw new NotYetImplementedException("Pure native scalar queries are not yet supported"); def = new NamedSQLQueryDefinition(query, new NativeSQLQueryRootReturn[] {new NativeSQLQueryRootReturn("alias1", resultClass, new HashMap(), @@ -167,21 +161,19 @@ public class QueryBinder { LOG.debugf("Binding named native query: %s => %s", name, query); } - private static boolean getBoolean( Index jandex, - AnnotationInstance[] hints, + private static boolean getBoolean( AnnotationInstance[] hints, String element, String query ) { - String val = getString(jandex, hints, element); + String val = getString(hints, element); if (val == null || val.equalsIgnoreCase("false")) return false; if (val.equalsIgnoreCase("true")) return true; throw new AnnotationException("Not a boolean in hint: " + query + ":" + element); } - private static CacheMode getCacheMode( Index jandex, - AnnotationInstance[] hints, + private static CacheMode getCacheMode( AnnotationInstance[] hints, String element, String query ) { - String val = getString(jandex, hints, element); + String val = getString(hints, element); if (val == null) return null; if (val.equalsIgnoreCase(CacheMode.GET.toString())) return CacheMode.GET; 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); } - private static FlushMode getFlushMode( Index jandex, - AnnotationInstance[] hints, + private static FlushMode getFlushMode( AnnotationInstance[] hints, String element, String query ) { - String val = getString(jandex, hints, element); + String val = getString(hints, element); if (val == null) return null; if (val.equalsIgnoreCase(FlushMode.ALWAYS.toString())) return FlushMode.ALWAYS; else if (val.equalsIgnoreCase(FlushMode.AUTO.toString())) return FlushMode.AUTO; @@ -206,11 +197,10 @@ public class QueryBinder { } - private static Integer getInteger( Index jandex, - AnnotationInstance[] hints, + private static Integer getInteger( AnnotationInstance[] hints, String element, String query ) { - String val = getString(jandex, hints, element); + String val = getString(hints, element); if (val == null) return null; try { return Integer.decode(val); @@ -219,22 +209,18 @@ public class QueryBinder { } } - private static String getString( Index jandex, - AnnotationInstance[] hints, + private static String getString( AnnotationInstance[] hints, String element ) { for (AnnotationInstance hint : hints) { - if (element.equals(JandexHelper.getValue(jandex, hint, "name"))) return JandexHelper.getValueAsString(jandex, - hint, - "value"); + if (element.equals(JandexHelper.getValue(hint, "name"))) return JandexHelper.getValueAsString(hint, "value"); } return null; } - private static Integer getTimeout( Index jandex, - AnnotationInstance[] hints, + private static Integer getTimeout( AnnotationInstance[] hints, String query ) { - Integer timeout = getInteger(jandex, hints, QueryHints.TIMEOUT_JPA, query); - if (timeout == null) return getInteger(jandex, hints, QueryHints.TIMEOUT_HIBERNATE, query); // timeout is already in seconds + Integer timeout = getInteger(hints, QueryHints.TIMEOUT_JPA, query); + 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 } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/TableBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/TableBinder.java index d009eee9a0..8639f243ab 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/TableBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/TableBinder.java @@ -57,40 +57,37 @@ public class TableBinder { public static void bind( MetadataImpl metadata, Index jandex ) { for (AnnotationInstance tableAnnotation : jandex.getAnnotations(HibernateDotNames.TABLE)) { - bind(metadata, jandex, tableAnnotation); + bind(metadata, tableAnnotation); } for (AnnotationInstance tables : jandex.getAnnotations(HibernateDotNames.TABLES)) { for (AnnotationInstance table : JandexHelper.getValueAsArray(tables, "value")) { - bind(metadata, jandex, table); + bind(metadata, table); } } } private static void bind( MetadataImpl metadata, - Index jandex, AnnotationInstance tableAnnotation ) { - String tableName = JandexHelper.getValueAsString(jandex, tableAnnotation, "appliesTo"); + String tableName = JandexHelper.getValueAsString(tableAnnotation, "appliesTo"); ObjectName objectName = new ObjectName(tableName); Schema schema = metadata.getDatabase().getSchema(objectName.getSchema(), objectName.getCatalog()); 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, - Table table, + private static void bindHibernateTableAnnotation( Table table, AnnotationInstance tableAnnotation ) { 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()); } - private static void bindIndexAnnotation( Index jandex, - Table table, + private static void bindIndexAnnotation( Table table, AnnotationInstance indexAnnotation ) { - String indexName = JandexHelper.getValueAsString(jandex, indexAnnotation, "appliesTo"); - String[] columnNames = (String[])JandexHelper.getValue(jandex, indexAnnotation, "columnNames"); + String indexName = JandexHelper.getValueAsString(indexAnnotation, "appliesTo"); + String[] columnNames = (String[])JandexHelper.getValue(indexAnnotation, "columnNames"); if (columnNames == null) { LOG.noColumnsSpecifiedForIndex(indexName, table.toLoggableString()); return; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/TypeDefBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/TypeDefBinder.java index f53fe497e4..70121230d0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/TypeDefBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/TypeDefBinder.java @@ -53,15 +53,32 @@ public class TypeDefBinder { public static void bind( MetadataImpl metadata, Index jandex ) { 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 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 prms = new HashMap(); + 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, String typeClass, Map prms, @@ -70,25 +87,6 @@ public class TypeDefBinder { 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 prms = new HashMap(); - 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() { } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/util/JandexHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/util/JandexHelper.java index 452f3c65f8..deb24dcde5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/util/JandexHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/util/JandexHelper.java @@ -57,8 +57,7 @@ public class JandexHelper { private static final Map DEFAULT_VALUES_BY_ELEMENT = new HashMap(); - private static Object getDefaultValue( Index index, - AnnotationInstance annotation, + private static Object getDefaultValue( AnnotationInstance annotation, String element ) { String name = annotation.name().toString(); 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 * 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 element the name of the element value to be retrieve * @return the value if not null, else the default value if not * null, else null. */ - public static Object getValue( Index index, - AnnotationInstance annotation, + public static Object getValue( AnnotationInstance annotation, String element ) { AnnotationValue val = annotation.value(element); - if (val == null) return getDefaultValue(index, annotation, element); + if (val == null) return getDefaultValue(annotation, element); 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). * * @param annotation the jandex annotation containing the element with the supplied name @@ -187,20 +184,18 @@ public class JandexHelper { * null, the default value specified in the annotation class is retrieved instead. * * @param 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 element the name of the enumerated element value to be retrieve * @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 null, else the default value if * not null, else null. - * @see #getValue(Index, AnnotationInstance, String) + * @see #getValue(AnnotationInstance, String) */ - public static > T getValueAsEnum( Index index, - AnnotationInstance annotation, + public static > T getValueAsEnum( AnnotationInstance annotation, String element, Class type ) { 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()); } @@ -208,17 +203,15 @@ public class JandexHelper { * Retrieves a jandex annotation element value as an Integer. If the value is null, the default value specified in * 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 element the name of the element value to be retrieve * @return the value converted to an int if the value is not null, else the default value if not * null, else 0. */ - public static int getValueAsInt( Index index, - AnnotationInstance annotation, + public static int getValueAsInt( AnnotationInstance annotation, String 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(); } @@ -226,17 +219,15 @@ public class JandexHelper { * Retrieves a jandex annotation element value as a String. If the value is null, the default value specified in * 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 element the name of the element value to be retrieve * @return the value converted to a String if the value is not null, else the default value if not * null, else null. */ - public static String getValueAsString( Index index, - AnnotationInstance annotation, + public static String getValueAsString( AnnotationInstance annotation, String 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(); } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/util/JandexHelperTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/util/JandexHelperTest.java index 90378a102d..ba455ec27f 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/util/JandexHelperTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/util/JandexHelperTest.java @@ -107,10 +107,10 @@ public class JandexHelperTest extends BaseUnitTestCase { Index index = JandexHelper.indexForClass(classLoaderService, Foo.class); 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)) { - 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); 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); 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)); } } }