Hibernate SVN: r10360 - branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-08-28 18:29:54 -0400 (Mon, 28 Aug 2006)
New Revision: 10360
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/Mappings.java
Log:
get rid of the private variables: too painful in Annotations
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/Mappings.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/Mappings.java 2006-08-28 21:40:46 UTC (rev 10359)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/Mappings.java 2006-08-28 22:29:54 UTC (rev 10360)
@@ -35,28 +35,28 @@
private static final Log log = LogFactory.getLog(Mappings.class);
- private final Map classes;
- private final Map collections;
- private final Map tables;
- private final Map queries;
- private final Map sqlqueries;
+ protected final Map classes;
+ protected final Map collections;
+ protected final Map tables;
+ protected final Map queries;
+ protected final Map sqlqueries;
protected final Map resultSetMappings;
- private final Map typeDefs;
- private final List secondPasses;
- private final Map imports;
- private String schemaName;
- private String catalogName;
- private String defaultCascade;
- private String defaultPackage;
- private String defaultAccess;
- private boolean autoImport;
- private boolean defaultLazy;
- private final List propertyReferences;
- private final NamingStrategy namingStrategy;
- private final Map filterDefinitions;
- private final List auxiliaryDatabaseObjects;
+ protected final Map typeDefs;
+ protected final List secondPasses;
+ protected final Map imports;
+ protected String schemaName;
+ protected String catalogName;
+ protected String defaultCascade;
+ protected String defaultPackage;
+ protected String defaultAccess;
+ protected boolean autoImport;
+ protected boolean defaultLazy;
+ protected final List propertyReferences;
+ protected final NamingStrategy namingStrategy;
+ protected final Map filterDefinitions;
+ protected final List auxiliaryDatabaseObjects;
- private final Map extendsQueue;
+ protected final Map extendsQueue;
// private final List extendsQueue;
/**
17 years, 8 months
Hibernate SVN: r10359 - trunk/HibernateExt/metadata/src/java/org/hibernate/validator
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-08-28 17:40:46 -0400 (Mon, 28 Aug 2006)
New Revision: 10359
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java
Log:
ANN-426 unefficient but fix the leaking concern, WeakRefs might be an alternative?
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java 2006-08-28 19:55:58 UTC (rev 10358)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java 2006-08-28 21:40:46 UTC (rev 10359)
@@ -55,7 +55,6 @@
private static final String DEFAULT_VALIDATOR_MESSAGE = "org.hibernate.validator.resources.DefaultValidatorMessages";
private static final String VALIDATOR_MESSAGE = "ValidatorMessages";
private static final Set<Class> INDEXABLE_CLASS = new HashSet<Class>();
- private static final ReflectionManager reflectionManager = new JavaXFactory();
static {
INDEXABLE_CLASS.add( Integer.class );
@@ -71,6 +70,7 @@
private transient ResourceBundle messageBundle;
private transient ResourceBundle defaultMessageBundle;
private transient boolean isUserProvidedResourceBundle;
+ private transient ReflectionManager reflectionManager = new JavaXFactory();
private final transient Map<XClass, ClassValidator> childClassValidators;
private transient List<Validator> beanValidators;
@@ -607,6 +607,7 @@
if ( rb == null ) rb = getDefaultResourceBundle();
this.messageBundle = rb;
this.defaultMessageBundle = ResourceBundle.getBundle( DEFAULT_VALIDATOR_MESSAGE );
+ reflectionManager = new JavaXFactory();
initValidator( reflectionManager.toXClass( beanClass ), new HashMap<XClass, ClassValidator>(), this.messageBundle );
}
}
17 years, 8 months
Hibernate SVN: r10358 - in trunk/HibernateExt/tools/src: java/org/hibernate/tool/ant java/org/hibernate/tool/hbm2x test/org/hibernate/tool/hbm2x
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-08-28 15:55:58 -0400 (Mon, 28 Aug 2006)
New Revision: 10358
Modified:
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/GenericExporterTask.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/AbstractExporter.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Exporter.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java
Log:
HBX-737 instantiate exporterclass directly instead of relaying through exporter
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/GenericExporterTask.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/GenericExporterTask.java 2006-08-28 19:37:54 UTC (rev 10357)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/GenericExporterTask.java 2006-08-28 19:55:58 UTC (rev 10358)
@@ -4,8 +4,10 @@
*/
package org.hibernate.tool.ant;
+import org.apache.tools.ant.BuildException;
import org.hibernate.tool.hbm2x.Exporter;
import org.hibernate.tool.hbm2x.GenericExporter;
+import org.hibernate.util.ReflectHelper;
/**
* @author max
@@ -21,6 +23,10 @@
String exporterClass;
String filePattern;
+ /**
+ * The FilePattern defines the pattern used to generate files.
+ * @param filePattern
+ */
public void setFilePattern(String filePattern) {
this.filePattern = filePattern;
}
@@ -33,8 +39,21 @@
this.exporterClass = exporterClass;
}
- protected Exporter createExporter() {
- return new GenericExporter();
+ protected Exporter createExporter() {
+ if (exporterClass == null) {
+ return new GenericExporter();
+ } else {
+ try {
+ Class theClass = ReflectHelper.classForName(exporterClass);
+ return (Exporter) theClass.newInstance();
+ } catch (ClassNotFoundException e) {
+ throw new BuildException("Could not find custom exporter class: " + exporterClass, e);
+ } catch (InstantiationException e) {
+ throw new BuildException("Could not create custom exporter class: " + exporterClass, e);
+ } catch (IllegalAccessException e) {
+ throw new BuildException("Could not access custom exporter class: " + exporterClass, e);
+ }
+ }
}
protected Exporter configureExporter(Exporter exp) {
@@ -42,15 +61,14 @@
if(exp instanceof GenericExporter) {
GenericExporter exporter = (GenericExporter) exp;
- exporter.setFilePattern(filePattern);
- exporter.setTemplateName(templateName);
- exporter.setExporterClassName(exporterClass);
+ if(filePattern!=null) exporter.setFilePattern(filePattern);
+ if(templateName!=null) exporter.setTemplateName(templateName);
}
return exp;
}
public String getName() {
- return "generic exporter" + ((exporterClass==null) ? "" : exporterClass);
+ return "generic exporter " + ((exporterClass==null) ? "" : exporterClass);
}
}
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/AbstractExporter.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/AbstractExporter.java 2006-08-28 19:37:54 UTC (rev 10357)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/AbstractExporter.java 2006-08-28 19:55:58 UTC (rev 10358)
@@ -86,6 +86,10 @@
return configuration;
}
+ /**
+ * Builds template context and performs file generation
+ * Subclasses mostly implement doStart() instead.
+ */
public void start() {
setTemplateHelper( new TemplateHelper() );
setupTemplates();
@@ -229,6 +233,7 @@
public void setProperties(Properties properties) {
this.properties = properties;
+
}
public void setArtifactCollector(ArtifactCollector collector) {
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Exporter.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Exporter.java 2006-08-28 19:37:54 UTC (rev 10357)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Exporter.java 2006-08-28 19:55:58 UTC (rev 10358)
@@ -14,20 +14,48 @@
*/
public interface Exporter {
+ /**
+ * @param cfg An Hibernate {@link org.hibernate.Configuration} or subclass instance that defines the hibernate meta model to be exported.
+ */
public void setConfiguration(Configuration cfg);
-
+
+ /**
+ * @param file basedirectory to be used for generated files.
+ */
public void setOutputDirectory(File file);
-
+
+ /**
+ * @param templatePath array of directories used sequentially to lookup templates
+ */
public void setTemplatePath(String[] templatePath);
+ /**
+ * @param templatePrefix template prefix to be used. e.g. if set to "dao/", "dao/" will be prefixed all lookups before the simple name will looked up. Used to allow seperation of templates within a templatepath.
+ */
public void setTemplatePrefix(String templatePrefix);
-
+
+ /**
+ *
+ * @param properties set of properties to be used by exporter.
+ */
public void setProperties(Properties properties);
+ /**
+ *
+ * @param collector Instance to be consulted when adding a new file.
+ */
public void setArtifactCollector(ArtifactCollector collector);
+
+ /**
+ *
+ * @return artifact collector
+ */
public ArtifactCollector getArtifactCollector();
+ /**
+ * Called when exporter should start generating its output
+ */
public void start();
}
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java 2006-08-28 19:37:54 UTC (rev 10357)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java 2006-08-28 19:55:58 UTC (rev 10358)
@@ -16,9 +16,8 @@
public class GenericExporter extends AbstractExporter {
- String templateName;
+ private String templateName;
private String filePattern;
- private String exporterClassName;
public GenericExporter(Configuration cfg, File outputdir) {
super(cfg,outputdir);
@@ -34,36 +33,11 @@
public void setTemplateName(String templateName) {
this.templateName = templateName;
}
-
- public void start() {
- if(exporterClassName!=null) {
- Exporter exporter = null;
- try {
- Class exporterClass = ReflectHelper.classForName(exporterClassName);
- exporter = (Exporter) exporterClass.newInstance();
- Properties p = getProperties();
- if(getTemplateName()!=null) p.put(ExporterSettings.PREFIX_KEY + "template_name", getTemplateName());
- if(filePattern!=null) p.put(ExporterSettings.PREFIX_KEY + "file_pattern", filePattern);
- exporter.setProperties(getProperties());
- exporter.setArtifactCollector(getArtifactCollector());
- exporter.setConfiguration(getConfiguration());
- exporter.setOutputDirectory(getOutputDirectory());
- exporter.setTemplatePath(getTemplatePaths());
- }
- catch (Exception e) {
- throw new ExporterException("Could not instantiate/configure exporter of class " + exporterClassName,e);
- }
- exporter.start();
- } else {
- super.start();
- }
- }
-
protected void doStart() {
- if(filePattern==null) throw new ExporterException("File pattern not set on GenericExporter");
- if(templateName==null) throw new ExporterException("Template pattern not set on GenericExporter");
+ if(filePattern==null) throw new ExporterException("File pattern not set on " + this.getClass());
+ if(templateName==null) throw new ExporterException("Template pattern not set on " + this.getClass());
if(filePattern.indexOf("{class-name}")>=0) {
exportClasses();
@@ -133,8 +107,5 @@
public void setFilePattern(String filePattern) {
this.filePattern = filePattern;
}
-
- public void setExporterClassName(String exporterClassName) {
- this.exporterClassName = exporterClassName;
- }
+
}
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java 2006-08-28 19:37:54 UTC (rev 10357)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java 2006-08-28 19:55:58 UTC (rev 10358)
@@ -39,7 +39,7 @@
Configuration cfg = getConfiguration();
if(c2h.isImportData(cfg) && (c2h.isNamedQueries(cfg)) && (c2h.isNamedSQLQueries(cfg)) && (c2h.isFilterDefinitions(cfg))) {
TemplateProducer producer = new TemplateProducer(getTemplateHelper(),getArtifactCollector());
- producer.produce(new HashMap(), "generalhbm.hbm.ftl", new File(getOutputDirectory(),"GeneralHbmSettings.hbm.xml"), templateName);
+ producer.produce(new HashMap(), "generalhbm.hbm.ftl", new File(getOutputDirectory(),"GeneralHbmSettings.hbm.xml"), getTemplateName());
}
}
Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java 2006-08-28 19:37:54 UTC (rev 10357)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java 2006-08-28 19:55:58 UTC (rev 10358)
@@ -122,17 +122,6 @@
assertEquals(generated.getProperty("myTool.value"), "value");
}
- public void testGenericClassExporter() {
- GenericExporter ge = new GenericExporter();
- ge.setConfiguration(getCfg());
- ge.setOutputDirectory(getOutputDir());
- ge.setProperties(new Properties());
- ge.setExporterClassName("org.hibernate.tool.hbm2x.POJOExporter");
-
- ge.start();
-
- }
-
protected String getBaseForMappings() {
return "org/hibernate/tool/hbm2x/";
}
17 years, 8 months
Hibernate SVN: r10357 - trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-08-28 15:37:54 -0400 (Mon, 28 Aug 2006)
New Revision: 10357
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
Log:
ANN-390 better exception wording
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-08-28 19:22:02 UTC (rev 10356)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-08-28 19:37:54 UTC (rev 10357)
@@ -509,7 +509,7 @@
}
catch (MappingException e) {
StringBuilder error = new StringBuilder( 80 );
- error.append( "mappedBy reference an unknown property: " )
+ error.append( "mappedBy reference an unknown target entity property: " )
.append( collType ).append( "." ).append( this.mappedBy )
.append( " in " )
.append( collection.getOwnerEntityName() )
@@ -918,7 +918,7 @@
}
catch (MappingException e) {
StringBuilder error = new StringBuilder( 80 );
- error.append( "mappedBy reference an unknown property: " )
+ error.append( "mappedBy reference an unknown target entity property: " )
.append( collType ).append( "." ).append( joinColumns[0].getMappedBy() )
.append( " in " )
.append( collValue.getOwnerEntityName() )
17 years, 8 months
Hibernate SVN: r10356 - in trunk/HibernateExt/metadata/src: java/org/hibernate/reflection/java test/org/hibernate/test/annotations/indexcoll
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-08-28 15:22:02 -0400 (Mon, 28 Aug 2006)
New Revision: 10356
Added:
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Trainee.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Training.java
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/JavaXCollectionType.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java
Log:
ANN-419 add unit test and fix bugs
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/JavaXCollectionType.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/JavaXCollectionType.java 2006-08-28 11:00:28 UTC (rev 10355)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/JavaXCollectionType.java 2006-08-28 19:22:02 UTC (rev 10356)
@@ -4,6 +4,7 @@
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Map;
+import java.util.SortedMap;
import org.hibernate.reflection.XClass;
import org.hibernate.reflection.java.generics.TypeEnvironment;
@@ -34,7 +35,9 @@
public XClass caseParameterizedType(ParameterizedType parameterizedType) {
Type[] args = parameterizedType.getActualTypeArguments();
Type componentType;
- if ( getCollectionClass().isAssignableFrom( Map.class ) ) {
+ Class<? extends Collection> collectionClass = getCollectionClass();
+ if ( collectionClass.isAssignableFrom( Map.class )
+ || collectionClass.isAssignableFrom( SortedMap.class ) ) {
componentType = args[1];
}
else {
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java 2006-08-28 11:00:28 UTC (rev 10355)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java 2006-08-28 19:22:02 UTC (rev 10356)
@@ -207,11 +207,11 @@
s = openSession();
tx = s.beginTransaction();
AlphabeticalDirectory m = new AlphabeticalDirectory();
- m.setName("M");
+ m.setName( "M" );
AlphabeticalDirectory v = new AlphabeticalDirectory();
- v.setName("V");
- s.persist(m);
- s.persist(v);
+ v.setName( "V" );
+ s.persist( m );
+ s.persist( v );
AddressBook book = new AddressBook();
book.setOwner( "Emmanuel" );
@@ -377,9 +377,9 @@
Gas o2 = new Gas();
o2.name = "oxygen";
atm.gases.put( "100%", o2 );
- atm.gasesPerKey.put(key, o2);
+ atm.gasesPerKey.put( key, o2 );
atm2.gases.put( "100%", o2 );
- atm2.gasesPerKey.put(key, o2);
+ atm2.gasesPerKey.put( key, o2 );
s.persist( key );
s.persist( atm );
s.persist( atm2 );
@@ -390,11 +390,33 @@
key = (GasKey) s.get( GasKey.class, key.getName() );
assertEquals( 1, atm.gases.size() );
assertEquals( o2.name, atm.gases.get( "100%" ).name );
- assertEquals( o2.name, atm.gasesPerKey.get(key).name );
+ assertEquals( o2.name, atm.gasesPerKey.get( key ).name );
tx.rollback();
s.close();
}
+ public void testSortedMap() {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ Training training = new Training();
+ Trainee trainee = new Trainee();
+ trainee.setName( "Jim" );
+ Trainee trainee2 = new Trainee();
+ trainee2.setName( "Emmanuel" );
+ s.persist( trainee );
+ s.persist( trainee2 );
+ training.getTrainees().put("Jim", trainee);
+ training.getTrainees().put("Emmanuel", trainee2);
+ s.persist( training );
+ s.flush();
+ s.clear();
+ training = (Training) s.get( Training.class, training.getId() );
+ assertEquals( "Emmanuel", training.getTrainees().firstKey() );
+ assertEquals( "Jim", training.getTrainees().lastKey() );
+ tx.rollback();
+ s.close();
+ }
+
public IndexedCollectionTest(String x) {
super( x );
}
@@ -417,7 +439,9 @@
Atmosphere.class,
Gas.class,
AlphabeticalDirectory.class,
- GasKey.class
+ GasKey.class,
+ Trainee.class,
+ Training.class
};
}
}
Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Trainee.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Trainee.java 2006-08-28 11:00:28 UTC (rev 10355)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Trainee.java 2006-08-28 19:22:02 UTC (rev 10356)
@@ -0,0 +1,31 @@
+//$Id: $
+package org.hibernate.test.annotations.indexcoll;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Trainee {
+ @Id @GeneratedValue private Long id;
+ private String name;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Training.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Training.java 2006-08-28 11:00:28 UTC (rev 10355)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Training.java 2006-08-28 19:22:02 UTC (rev 10356)
@@ -0,0 +1,39 @@
+//$Id: $
+package org.hibernate.test.annotations.indexcoll;
+
+import java.util.SortedMap;
+import java.util.TreeMap;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.MapKey;
+import javax.persistence.ManyToMany;
+
+import org.hibernate.annotations.Sort;
+import org.hibernate.annotations.SortType;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Training {
+ @Id @GeneratedValue private Long id;
+ @Sort(type= SortType.NATURAL)
+ @MapKey(name="name") @ManyToMany SortedMap<String, Trainee> trainees = new TreeMap<String, Trainee>();
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public SortedMap<String, Trainee> getTrainees() {
+ return trainees;
+ }
+
+ public void setTrainees(SortedMap<String, Trainee> trainees) {
+ this.trainees = trainees;
+ }
+}
17 years, 8 months
Hibernate SVN: r10355 - trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-08-28 07:00:28 -0400 (Mon, 28 Aug 2006)
New Revision: 10355
Modified:
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateHelper.java
Log:
replaced exception with warning when overwriting a property.
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateHelper.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateHelper.java 2006-08-28 04:33:01 UTC (rev 10354)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateHelper.java 2006-08-28 11:00:28 UTC (rev 10355)
@@ -148,7 +148,9 @@
log.trace("putInContext " + key + "=" + value);
if(value == null) throw new IllegalStateException("value must not be null for " + key);
Object replaced = internalPutInContext(key,value);
- if(replaced!=null) throw new IllegalStateException(replaced + " found when setting " + key);
+ if(replaced!=null) {
+ log.warn( "Overwriting " + replaced + " when setting " + key + " to " + value + ".");
+ }
}
public void removeFromContext(String key, Object expected) {
17 years, 8 months
Hibernate SVN: r10354 - in trunk/HibernateExt/metadata/src: java/org/hibernate/cfg java/org/hibernate/cfg/annotations test/org/hibernate/test/annotations/collectionelement
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-08-28 00:33:01 -0400 (Mon, 28 Aug 2006)
New Revision: 10354
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/CollectionPropertyHolder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyHolderBuilder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/ListBinder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/Boy.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/Brand.java
Log:
ANN-424 fix some column overriding bugs
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-08-25 23:28:31 UTC (rev 10353)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-08-28 04:33:01 UTC (rev 10354)
@@ -1354,7 +1354,7 @@
collectionBinder.setPropertyAccessorName( inferredData.getDefaultAccess() );
Ejb3Column[] elementColumns = null;
- PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "element" );
+ PropertyData virtualProperty = new WrappedInferredData( inferredData, "element" );
if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent(
Formula.class
) ) {
@@ -1365,7 +1365,7 @@
formulaAnn,
nullability,
propertyHolder,
- mapKeyVirtualProperty,
+ virtualProperty,
entityBinder.getSecondaryTables(),
mappings
);
@@ -1373,7 +1373,7 @@
else if ( property.isAnnotationPresent( Columns.class ) ) {
Columns anns = property.getAnnotation( Columns.class );
elementColumns = Ejb3Column.buildColumnFromAnnotation(
- anns.columns(), null, nullability, propertyHolder, mapKeyVirtualProperty,
+ anns.columns(), null, nullability, propertyHolder, virtualProperty,
entityBinder.getSecondaryTables(), mappings
);
}
@@ -1383,7 +1383,7 @@
null,
nullability,
propertyHolder,
- mapKeyVirtualProperty,
+ virtualProperty,
entityBinder.getSecondaryTables(),
mappings
);
@@ -1392,7 +1392,7 @@
org.hibernate.annotations.MapKey hibMapKeyAnn = property.getAnnotation(
org.hibernate.annotations.MapKey.class
);
- mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
+ PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
Ejb3Column[] mapColumns = Ejb3Column.buildColumnFromAnnotation(
hibMapKeyAnn != null && hibMapKeyAnn.columns().length > 0 ? hibMapKeyAnn.columns() : null,
null,
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/CollectionPropertyHolder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/CollectionPropertyHolder.java 2006-08-25 23:28:31 UTC (rev 10353)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/CollectionPropertyHolder.java 2006-08-28 04:33:01 UTC (rev 10354)
@@ -21,9 +21,9 @@
public CollectionPropertyHolder(
Collection collection, String path, XClass clazzToProcess, XProperty property,
- ExtendedMappings mappings
+ PropertyHolder parentPropertyHolder, ExtendedMappings mappings
) {
- super( path, null, clazzToProcess, mappings );
+ super( path, parentPropertyHolder, clazzToProcess, mappings );
this.collection = collection;
setCurrentProperty( property );
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyHolderBuilder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyHolderBuilder.java 2006-08-25 23:28:31 UTC (rev 10353)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyHolderBuilder.java 2006-08-28 04:33:01 UTC (rev 10354)
@@ -50,9 +50,9 @@
*/
public static PropertyHolder buildPropertyHolder(
Collection collection, String path, XClass clazzToProcess, XProperty property,
- ExtendedMappings mappings
+ PropertyHolder parentPropertyHolder, ExtendedMappings mappings
) {
- return new CollectionPropertyHolder( collection, path, clazzToProcess, property, mappings );
+ return new CollectionPropertyHolder( collection, path, clazzToProcess, property, parentPropertyHolder, mappings );
}
/**
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-08-25 23:28:31 UTC (rev 10353)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-08-28 04:33:01 UTC (rev 10354)
@@ -548,7 +548,7 @@
isEmbedded, collType,
ignoreNotFound, unique,
cascadeDeleteEnabled,
- associationTableBinder, property, hqlOrderBy, mappings
+ associationTableBinder, property, propertyHolder, hqlOrderBy, mappings
);
return false;
}
@@ -863,7 +863,8 @@
String collType,
boolean ignoreNotFound, boolean unique,
boolean cascadeDeleteEnabled,
- TableBinder associationTableBinder, XProperty property, String hqlOrderBy, ExtendedMappings mappings
+ TableBinder associationTableBinder, XProperty property, PropertyHolder parentPropertyHolder,
+ String hqlOrderBy, ExtendedMappings mappings
) throws MappingException {
PersistentClass collectionEntity = (PersistentClass) persistentClasses.get( collType );
@@ -1017,7 +1018,7 @@
collValue,
collValue.getRole(), // + ".element",
elementClass,
- property, mappings
+ property, parentPropertyHolder, mappings
);
//force in case of attribute override
boolean attributeOverride = property.isAnnotationPresent( AttributeOverride.class )
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/ListBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/ListBinder.java 2006-08-25 23:28:31 UTC (rev 10353)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/ListBinder.java 2006-08-28 04:33:01 UTC (rev 10354)
@@ -77,7 +77,7 @@
this.collection,
StringHelper.qualify( this.collection.getRole(), "key" ),
(XClass) null,
- (XProperty) null, mappings
+ (XProperty) null, propertyHolder, mappings
);
List list = (List) this.collection;
if ( ! list.isOneToMany() ) indexColumn.forceNotNull();
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-08-25 23:28:31 UTC (rev 10353)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-08-28 04:33:01 UTC (rev 10354)
@@ -155,7 +155,7 @@
mapValue,
StringHelper.qualify( mapValue.getRole(), "mapkey" ),
elementClass,
- property, mappings
+ property, propertyHolder, mappings
);
//force in case of attribute override
boolean attributeOverride = property.isAnnotationPresent( AttributeOverride.class )
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/Boy.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/Boy.java 2006-08-25 23:28:31 UTC (rev 10353)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/Boy.java 2006-08-28 04:33:01 UTC (rev 10354)
@@ -26,7 +26,8 @@
@Entity
@AttributeOverrides({
@AttributeOverride( name="characters.element", column = @Column(name="character") ),
- @AttributeOverride( name="scorePerNickName.element", column = @Column(name="fld_score") )}
+ @AttributeOverride( name="scorePerNickName.element", column = @Column(name="fld_score") ),
+ @AttributeOverride( name="favoriteToys.element.brand.surname", column = @Column(name = "fld_surname"))}
)
public class Boy {
private Integer id;
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/Brand.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/Brand.java 2006-08-25 23:28:31 UTC (rev 10353)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/Brand.java 2006-08-28 04:33:01 UTC (rev 10354)
@@ -9,6 +9,7 @@
@Embeddable
public class Brand {
private String name;
+ private String surname;
public String getName() {
return name;
@@ -18,6 +19,14 @@
this.name = name;
}
+ public String getSurname() {
+ return surname;
+ }
+
+ public void setSurname(String surname) {
+ this.surname = surname;
+ }
+
public boolean equals(Object o) {
if ( this == o ) return true;
if ( o == null || getClass() != o.getClass() ) return false;
17 years, 8 months
Hibernate SVN: r10353 - in trunk/HibernateExt/metadata/src: java/org/hibernate/cfg/annotations test/org/hibernate/test/annotations/onetomany
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-08-25 19:28:31 -0400 (Fri, 25 Aug 2006)
New Revision: 10353
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/City.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Street.java
Log:
ANN-284 can @OrderBy property made of formula
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-08-25 23:22:53 UTC (rev 10352)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-08-25 23:28:31 UTC (rev 10353)
@@ -25,16 +25,16 @@
import org.hibernate.annotations.AccessType;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CollectionId;
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.Fetch;
+import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.OrderBy;
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.SortType;
import org.hibernate.annotations.Where;
-import org.hibernate.annotations.CollectionId;
-import org.hibernate.annotations.ForeignKey;
import org.hibernate.cfg.AnnotatedClassType;
import org.hibernate.cfg.AnnotationBinder;
import org.hibernate.cfg.BinderHelper;
@@ -53,14 +53,15 @@
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.DependantValue;
+import org.hibernate.mapping.IdGenerator;
import org.hibernate.mapping.Join;
import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.ManyToOne;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
+import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table;
-import org.hibernate.mapping.IdGenerator;
import org.hibernate.reflection.XAnnotatedElement;
import org.hibernate.reflection.XClass;
import org.hibernate.reflection.XProperty;
@@ -655,8 +656,8 @@
//order by id
Iterator it = associatedClass.getIdentifier().getColumnIterator();
while ( it.hasNext() ) {
- Column col = (Column) it.next();
- orderByBuffer.append( col.getName() ).append( " asc" ).append( ", " );
+ Selectable col = (Selectable) it.next();
+ orderByBuffer.append( col.getText() ).append( " asc" ).append( ", " );
}
}
else {
@@ -710,8 +711,8 @@
Iterator propertyColumns = p.getColumnIterator();
while ( propertyColumns.hasNext() ) {
- Column column = (Column) propertyColumns.next();
- orderByBuffer.append( column.getName() )
+ Selectable column = (Selectable) propertyColumns.next();
+ orderByBuffer.append( column.getText() )
.append( " " )
.append( ordering.get( index ) )
.append( ", " );
@@ -784,8 +785,8 @@
Iterator propertyColumns = p.getColumnIterator();
while ( propertyColumns.hasNext() ) {
- Column column = (Column) propertyColumns.next();
- orderByBuffer.append( column.getName() )
+ Selectable column = (Selectable) propertyColumns.next();
+ orderByBuffer.append( column.getText() )
.append( " " )
.append( ordering.get( index ) )
.append( ", " );
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/City.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/City.java 2006-08-25 23:22:53 UTC (rev 10352)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/City.java 2006-08-25 23:28:31 UTC (rev 10353)
@@ -41,7 +41,7 @@
}
@OneToMany(mappedBy = "city")
- @OrderBy("streetName, id")
+ @OrderBy("streetNameCopy, streetName, id")
public synchronized List<Street> getStreets() {
return streets;
}
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java 2006-08-25 23:22:53 UTC (rev 10352)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java 2006-08-25 23:28:31 UTC (rev 10353)
@@ -49,7 +49,7 @@
s.close();
}
- public void testListWithBagSemantic() throws Exception {
+ public void testListWithBagSemanticAndOrderBy() throws Exception {
Session s;
Transaction tx;
s = openSession();
@@ -74,6 +74,7 @@
tx.commit();
s.clear();
tx = s.beginTransaction();
+ //testing @OrderBy with explicit values including Formula
paris = (City) s.get( City.class, paris.getId() );
assertEquals( 3, paris.getStreets().size() );
assertEquals( chmpsElysees.getStreetName(), paris.getStreets().get( 0 ).getStreetName() );
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Street.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Street.java 2006-08-25 23:22:53 UTC (rev 10352)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetomany/Street.java 2006-08-25 23:28:31 UTC (rev 10353)
@@ -5,7 +5,10 @@
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
+import javax.persistence.Column;
+import org.hibernate.annotations.Formula;
+
/**
* @author Emmanuel Bernard
*/
@@ -13,6 +16,7 @@
public class Street {
private Integer id;
private String streetName;
+ private String streetNameCopy;
private City city;
@Id
@@ -25,6 +29,7 @@
this.id = id;
}
+ @Column(name="STREET_NAME")
public String getStreetName() {
return streetName;
}
@@ -33,6 +38,15 @@
this.streetName = streetName;
}
+ @Formula("STREET_NAME")
+ public String getStreetNameCopy() {
+ return streetNameCopy;
+ }
+
+ public void setStreetNameCopy(String streetNameCopy) {
+ this.streetNameCopy = streetNameCopy;
+ }
+
@ManyToOne
public City getCity() {
return city;
17 years, 8 months
Hibernate SVN: r10352 - trunk/HibernateExt/metadata/src/java/org/hibernate/validator
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-08-25 19:22:53 -0400 (Fri, 25 Aug 2006)
New Revision: 10352
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java
Log:
adjust to findPropertyByName
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java 2006-08-25 22:19:53 UTC (rev 10351)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java 2006-08-25 23:22:53 UTC (rev 10352)
@@ -567,7 +567,9 @@
if ( validator instanceof PropertyConstraint ) {
try {
Property property = BinderHelper.findPropertyByName(persistentClass, propertyName);
- ( (PropertyConstraint) validator ).apply( property );
+ if (property != null) {
+ ( (PropertyConstraint) validator ).apply( property );
+ }
}
catch (MappingException pnfe) {
//do nothing
17 years, 8 months
Hibernate SVN: r10351 - trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-08-25 18:19:53 -0400 (Fri, 25 Aug 2006)
New Revision: 10351
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java
Log:
ANN-397 better exception report
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java 2006-08-25 22:15:17 UTC (rev 10350)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java 2006-08-25 22:19:53 UTC (rev 10351)
@@ -254,6 +254,7 @@
if ( columns.length != referencedEntity.getIdentifier().getColumnSpan() ) {
throw new AnnotationException(
"A Foreign key refering " + referencedEntity.getEntityName()
+ + " from " + associatedClass.getEntityName()
+ " has the wrong number of column. should be " + referencedEntity.getIdentifier()
.getColumnSpan()
);
17 years, 8 months