Hibernate SVN: r15016 - search/trunk/src/java/org/hibernate/search/cfg.
by hibernate-commits@lists.jboss.org
Author: navssurtani
Date: 2008-08-05 06:26:27 -0400 (Tue, 05 Aug 2008)
New Revision: 15016
Modified:
search/trunk/src/java/org/hibernate/search/cfg/SearchConfiguration.java
Log:
Got rid of todo in SeachConfiguration which said TODO: It should be iterable as the return type for getClassMappings() returns an Iterator.
Modified: search/trunk/src/java/org/hibernate/search/cfg/SearchConfiguration.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/cfg/SearchConfiguration.java 2008-08-03 16:04:47 UTC (rev 15015)
+++ search/trunk/src/java/org/hibernate/search/cfg/SearchConfiguration.java 2008-08-05 10:26:27 UTC (rev 15016)
@@ -21,9 +21,8 @@
/**
* Returns a {@link java.lang.Class} from a String parameter.
- * TODO: should it be Iteratable
* @param name
- * @return java.lang.Class
+ * @return An iterator of Classes.
*/
Class<?> getClassMapping(String name);
16 years, 4 months
Hibernate SVN: r15015 - in branches/Branch_3_2/HibernateExt/tools: src/java/org/hibernate/cfg and 6 other directories.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2008-08-03 12:04:47 -0400 (Sun, 03 Aug 2008)
New Revision: 15015
Added:
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/one-to-one.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Address.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/OneToOneTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Person.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/PersonAddressOneToOnePrimaryKey.hbm.xml
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OneToOneTest.java
Modified:
branches/Branch_3_2/HibernateExt/tools/
branches/Branch_3_2/HibernateExt/tools/build.xml
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/JDBCBinder.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DefaultReverseEngineeringStrategy.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DelegatingReverseEngineeringStrategy.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringSettings.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringStrategy.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/Version.java
branches/Branch_3_2/HibernateExt/tools/src/testsupport/NoopReverseEngineeringStrategy.java
Log:
HBX-524 one-to-one reveng
(primary-key constrained bidirectional, no JPA support nor reveng.xml support yet)
Property changes on: branches/Branch_3_2/HibernateExt/tools
___________________________________________________________________
Name: svn:ignore
- build
target
hbm2xoutput
eclipsebuild
cfg2hbmoutput
reverseoutput
test_output
.settings
.classpath
.project
test.lck
test.log
test.properties
test.script
cloverout
clover_coverage.db*
toolstestoutput
+ build
target
hbm2xoutput
eclipsebuild
cfg2hbmoutput
reverseoutput
test_output
.settings
.classpath
.project
test.lck
test.log
test.properties
test.script
cloverout
clover_coverage.db*
toolstestoutput
testdb
Modified: branches/Branch_3_2/HibernateExt/tools/build.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/build.xml 2008-08-01 17:10:49 UTC (rev 15014)
+++ branches/Branch_3_2/HibernateExt/tools/build.xml 2008-08-03 16:04:47 UTC (rev 15015)
@@ -7,7 +7,7 @@
<!-- Name of project and version, used to create filenames -->
<property name="Name" value="Hibernate Tools"/>
<property name="name" value="hibernate-tools"/>
- <property name="version" value="3.2.2.CR1"/>
+ <property name="version" value="3.2.2.GA"/>
<property name="javadoc.packagenames" value="org.hibernate.tool"/>
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/JDBCBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/JDBCBinder.java 2008-08-01 17:10:49 UTC (rev 15014)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/JDBCBinder.java 2008-08-03 16:04:47 UTC (rev 15015)
@@ -13,6 +13,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import org.apache.commons.logging.Log;
@@ -36,6 +37,7 @@
import org.hibernate.mapping.ForeignKey;
import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.ManyToOne;
+import org.hibernate.mapping.OneToOne;
import org.hibernate.mapping.MetaAttribute;
import org.hibernate.mapping.OneToMany;
import org.hibernate.mapping.PersistentClass;
@@ -44,6 +46,7 @@
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.Value;
+import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.Type;
import org.hibernate.type.TypeFactory;
import org.hibernate.util.JoinedIterator;
@@ -169,16 +172,53 @@
Set processed = new HashSet();
- bindPrimaryKeyToProperties(table, rc, processed, mapping, collector);
+
+ PrimaryKeyInfo pki = bindPrimaryKeyToProperties(table, rc, processed, mapping, collector);
bindColumnsToVersioning(table, rc, processed, mapping);
bindOutgoingForeignKeys(table, rc, processed);
bindColumnsToProperties(table, rc, processed, mapping);
List incomingForeignKeys = (List) manyToOneCandidates.get( rc.getEntityName() );
bindIncomingForeignKeys(rc, processed, incomingForeignKeys, mapping);
+ updatePrimaryKey(rc, pki);
+
}
}
+
+ private void updatePrimaryKey(RootClass rc, PrimaryKeyInfo pki) {
+ SimpleValue idValue = (SimpleValue) rc.getIdentifierProperty().getValue();
+ Properties defaultStrategyProperties = new Properties();
+ Property constrainedOneToOne = getConstrainedOneToOne(rc);
+ if(constrainedOneToOne!=null) {
+ if(pki.suggestedStrategy==null) {
+ idValue.setIdentifierGeneratorStrategy("foreign");
+ }
+
+ if(pki.suggestedProperties==null) {
+ defaultStrategyProperties.setProperty("property", constrainedOneToOne.getName());
+ idValue.setIdentifierGeneratorProperties(defaultStrategyProperties);
+ }
+ }
+
+
+
+ }
+
+ private Property getConstrainedOneToOne(RootClass rc) {
+ Iterator propertyClosureIterator = rc.getPropertyClosureIterator();
+ while (propertyClosureIterator.hasNext()) {
+ Property property = (Property) propertyClosureIterator.next();
+ if(property.getValue() instanceof OneToOne) {
+ OneToOne oto = (OneToOne) property.getValue();
+ if(oto.isConstrained()) {
+ return property;
+ }
+ }
+ }
+ return null;
+ }
+
private Map safeMeta(Map map) {
if(map==null) {
return new HashMap();
@@ -200,8 +240,10 @@
TableIdentifier.create(foreignKey.getReferencedTable() ),
foreignKey.getReferencedColumns())) {
log.debug("Rev.eng excluded one-to-many for foreignkey " + foreignKey.getName());
- } else {
-
+ } else if (revengStrategy.isOneToOne(foreignKey)){
+ Property property = bindOneToOne(rc, foreignKey.getTable(), foreignKey, processed, false);
+ rc.addProperty(property);
+ } else {
Property property = bindOneToMany(rc, foreignKey, processed, mapping);
rc.addProperty(property);
}
@@ -209,6 +251,41 @@
}
}
+
+ private Property bindOneToOne(PersistentClass rc, Table targetTable,
+ ForeignKey fk, Set processedColumns, boolean constrained) {
+
+
+ OneToOne value = new OneToOne(targetTable, rc);
+ value.setReferencedEntityName(revengStrategy
+ .tableToClassName(TableIdentifier.create(targetTable)));
+
+ boolean isUnique = isUniqueReference(fk);
+ String propertyName =
+ revengStrategy.foreignKeyToEntityName(fk.getName(),
+ TableIdentifier.create(fk.getReferencedTable()), fk
+ .getReferencedColumns(), TableIdentifier
+ .create(targetTable), fk.getColumns(), isUnique);
+
+ Iterator columns = fk.getColumnIterator();
+ while (columns.hasNext()) {
+ Column fkcolumn = (Column) columns.next();
+ checkColumn(fkcolumn);
+ value.addColumn(fkcolumn);
+ processedColumns.add(fkcolumn);
+ }
+
+ value.setFetchMode(FetchMode.SELECT);
+
+ value.setConstrained(constrained);
+ value.setForeignKeyType( constrained ?
+ ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT :
+ ForeignKeyDirection.FOREIGN_KEY_TO_PARENT );
+
+ return makeProperty(TableIdentifier.create(targetTable), propertyName, value,
+ true, true, value.getFetchMode() != FetchMode.JOIN, null, null);
+ }
+
/**
* @param table
* @param fk
@@ -399,9 +476,18 @@
return true;
}
- private void bindPrimaryKeyToProperties(Table table, RootClass rc, Set processed, Mapping mapping, DatabaseCollector collector) {
+ static private class PrimaryKeyInfo {
+
+ String suggestedStrategy = null;
+ Properties suggestedProperties = null;
+ }
+
+
+ private PrimaryKeyInfo bindPrimaryKeyToProperties(Table table, RootClass rc, Set processed, Mapping mapping, DatabaseCollector collector) {
SimpleValue id = null;
String idPropertyname = null;
+
+ PrimaryKeyInfo pki = new PrimaryKeyInfo();
List keyColumns = null;
if (table.getPrimaryKey()!=null) {
@@ -419,13 +505,12 @@
final TableIdentifier tableIdentifier = TableIdentifier.create(table);
- String tableIdentifierStrategyName;
+ String tableIdentifierStrategyName = "assigned";
boolean naturalId;
if (keyColumns.size()>1) {
log.debug("id strategy for " + rc.getEntityName() + " since it has a multiple column primary key");
- tableIdentifierStrategyName = "assigned";
naturalId = true;
id = handleCompositeKey(rc, processed, keyColumns, mapping);
@@ -435,8 +520,8 @@
}
}
else {
- tableIdentifierStrategyName = "assigned";
- String suggestedStrategy = revengStrategy.getTableIdentifierStrategyName(tableIdentifier);
+ pki.suggestedStrategy = revengStrategy.getTableIdentifierStrategyName(tableIdentifier);
+ String suggestedStrategy = pki.suggestedStrategy;
if(suggestedStrategy==null) {
suggestedStrategy = collector.getSuggestedIdentifierStrategy( tableIdentifier.getCatalog(), tableIdentifier.getSchema(), tableIdentifier.getName() );
if(suggestedStrategy==null) {
@@ -461,16 +546,17 @@
processed.add(pkc);
}
id.setIdentifierGeneratorStrategy(tableIdentifierStrategyName);
- id.setIdentifierGeneratorProperties(revengStrategy.getTableIdentifierProperties(tableIdentifier));
+ pki.suggestedProperties = revengStrategy.getTableIdentifierProperties(tableIdentifier);
+ id.setIdentifierGeneratorProperties(pki.suggestedProperties);
if(naturalId) {
id.setNullValue("undefined");
}
-
Property property = makeProperty(tableIdentifier, makeUnique(rc,idPropertyname), id, true, true, false, null, null);
rc.setIdentifierProperty(property);
rc.setIdentifier(id);
+ return pki;
}
/**
@@ -498,7 +584,10 @@
foreignKey.getReferencedColumns())) {
// TODO: if many-to-one is excluded should the column be marked as processed so it won't show up at all ?
log.debug("Rev.eng excluded many-to-one for foreignkey " + foreignKey.getName());
- } else {
+ } else if (revengStrategy.isOneToOne(foreignKey)){
+ Property property = bindOneToOne(rc, foreignKey.getReferencedTable(), foreignKey, processedColumns, true);
+ rc.addProperty(property);
+ } else {
boolean isUnique = isUniqueReference(foreignKey);
String propertyName = revengStrategy.foreignKeyToEntityName(
foreignKey.getName(),
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DefaultReverseEngineeringStrategy.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DefaultReverseEngineeringStrategy.java 2008-08-01 17:10:49 UTC (rev 15014)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DefaultReverseEngineeringStrategy.java 2008-08-03 16:04:47 UTC (rev 15015)
@@ -229,6 +229,30 @@
this.settings = settings;
}
+ public boolean isOneToOne(ForeignKey foreignKey) {
+ if(settings.getDetectOneToOne()) {
+ List fkColumns = foreignKey.getColumns();
+ List pkForeignTableColumns = null;
+
+ if (foreignKey.getTable().hasPrimaryKey())
+ pkForeignTableColumns = foreignKey.getTable().getPrimaryKey().getColumns();
+
+ boolean equals =
+ fkColumns != null && pkForeignTableColumns != null
+ && fkColumns.size() == pkForeignTableColumns.size();
+
+ Iterator columns = foreignKey.getColumnIterator();
+ while (equals && columns.hasNext()) {
+ Column fkColumn = (Column) columns.next();
+ equals = equals && pkForeignTableColumns.contains(fkColumn);
+ }
+
+ return equals;
+ } else {
+ return false;
+ }
+ }
+
public boolean isManyToManyTable(Table table) {
if(settings.getDetectManyToMany()) {
Iterator foreignKeyIterator = table.getForeignKeyIterator();
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DelegatingReverseEngineeringStrategy.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DelegatingReverseEngineeringStrategy.java 2008-08-01 17:10:49 UTC (rev 15014)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DelegatingReverseEngineeringStrategy.java 2008-08-03 16:04:47 UTC (rev 15015)
@@ -121,7 +121,12 @@
public boolean isManyToManyTable(Table table) {
return delegate==null?true:delegate.isManyToManyTable( table );
}
+
+ public boolean isOneToOne(ForeignKey foreignKey) {
+ return delegate==null?true:delegate.isOneToOne( foreignKey );
+ }
+
public String foreignKeyToManyToManyName(ForeignKey fromKey, TableIdentifier middleTable, ForeignKey toKey, boolean uniqueReference) {
return delegate==null?null:delegate.foreignKeyToManyToManyName( fromKey, middleTable, toKey, uniqueReference );
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringSettings.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringSettings.java 2008-08-01 17:10:49 UTC (rev 15014)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringSettings.java 2008-08-03 16:04:47 UTC (rev 15015)
@@ -10,6 +10,8 @@
private boolean createCollectionForForeignKey = true;
private boolean createManyToOneForForeignKey = true;
private boolean detectManyToMany = true;
+ private boolean detectOneToOne = true;
+
public ReverseEngineeringSettings(ReverseEngineeringStrategy rootStrategy) {
this.rootStrategy = rootStrategy;
@@ -72,9 +74,15 @@
return detectManyToMany;
}
+ public boolean getDetectOneToOne() {
+ return detectOneToOne;
+ }
+
/** return the top/root strategy. Allows a lower strategy to ask another question. Be aware of possible recursive loops; e.g. do not call the root.tableToClassName in tableToClassName of a custom reversengineeringstrategy. */
public ReverseEngineeringStrategy getRootStrategy() {
return rootStrategy;
}
+
+
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringStrategy.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringStrategy.java 2008-08-01 17:10:49 UTC (rev 15014)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringStrategy.java 2008-08-03 16:04:47 UTC (rev 15015)
@@ -182,6 +182,8 @@
*/
public String foreignKeyToManyToManyName(ForeignKey fromKey, TableIdentifier middleTable, ForeignKey toKey, boolean uniqueReference);
+ public boolean isOneToOne(ForeignKey foreignKey);
+
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/Version.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/Version.java 2008-08-01 17:10:49 UTC (rev 15014)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/Version.java 2008-08-03 16:04:47 UTC (rev 15015)
@@ -5,7 +5,7 @@
final public class Version {
- public static final String VERSION = "3.2.2.CR1";
+ public static final String VERSION = "3.2.2.GA";
private static final Version instance = new Version();
Added: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/one-to-one.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/one-to-one.hbm.ftl (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/one-to-one.hbm.ftl 2008-08-03 16:04:47 UTC (rev 15015)
@@ -0,0 +1,21 @@
+ <one-to-one
+ name="${property.name}"
+ class="${c2j.getJavaTypeName(property, false)}"
+<#if !property.basicPropertyAccessor>
+ access="${property.propertyAccessorName}"
+</#if>
+<#if property.cascade != "none">
+ cascade="${property.cascade}"
+</#if>
+<#if property.value.constrained>
+ constrained="true"
+</#if>
+
+<#if property.value.hasFormula()>
+<#assign formula = c2h.getFormulaForProperty(property)>
+<#if formula>
+ formula="${formula.text}"
+</#if>
+</#if>
+ >
+ </one-to-one>
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Address.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Address.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Address.java 2008-08-03 16:04:47 UTC (rev 15015)
@@ -0,0 +1,8 @@
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+public class Address {
+
+ int id;
+
+ Person person;
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/OneToOneTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/OneToOneTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/OneToOneTest.java 2008-08-03 16:04:47 UTC (rev 15015)
@@ -0,0 +1,120 @@
+//$Id$
+
+/*
+ * Tests for generating the HBM documents from the Configuration data structure.
+ * The generated XML document will be validated and queried to make sure the
+ * basic structure is correct in each test.
+ */
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.io.File;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.XPath;
+import org.dom4j.io.SAXReader;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.tool.NonReflectiveTestCase;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.hbm2x.HibernateMappingExporter;
+import org.hibernate.util.DTDEntityResolver;
+
+public class OneToOneTest extends NonReflectiveTestCase {
+
+ private Exporter hbmexporter;
+
+ public OneToOneTest(String name) {
+ super( name );
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ hbmexporter = new HibernateMappingExporter(getCfg(), getOutputDir() );
+ hbmexporter.start();
+ }
+
+ public void testAllFilesExistence() {
+
+ assertFalse(new File(getOutputDir().getAbsolutePath() + "/GeneralHbmSettings.hbm.xml").exists() );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Person.hbm.xml") );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Address.hbm.xml") );
+ }
+
+ public void testArtifactCollection() {
+
+ assertEquals(2,hbmexporter.getArtifactCollector().getFileCount("hbm.xml"));
+
+ }
+
+ public void testReadable() {
+ Configuration cfg = new Configuration();
+
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Person.hbm.xml"));
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Address.hbm.xml"));
+
+ cfg.buildMappings();
+
+ }
+
+ public void testOneToOne() throws DocumentException {
+ Document document = getXMLDocument(getBaseForMappings() + "Person.hbm.xml");
+
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/one-to-one");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one-to-one element", 1, list.size());
+ Element node = (Element) list.get(0);
+ assertEquals(node.attribute( "name" ).getText(),"address");
+ assertEquals(node.attribute( "constrained" ).getText(),"false");
+
+ document = getXMLDocument(getBaseForMappings() + "Address.hbm.xml");
+
+ xpath = DocumentHelper.createXPath("//hibernate-mapping/class/one-to-one");
+ list = xpath.selectNodes(document);
+ assertEquals("Expected to get one set element", 1, list.size());
+ node = (Element) list.get(0);
+ assertEquals(node.attribute( "name" ).getText(),"person");
+ assertEquals(node.attribute( "constrained" ).getText(),"true");
+
+
+ }
+
+ private Document getXMLDocument(String location) throws DocumentException {
+ File outputXml = new File(getOutputDir(), location);
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = this.getSAXReader();
+
+ Document document = xmlReader.read(outputXml);
+ return document;
+ }
+
+
+ private SAXReader getSAXReader() {
+ SAXReader xmlReader = new SAXReader();
+ xmlReader.setEntityResolver(new DTDEntityResolver() );
+ xmlReader.setValidation(true);
+ return xmlReader;
+ }
+
+ protected String getBaseForMappings() {
+ return "org/hibernate/tool/hbm2x/hbm2hbmxml/";
+ }
+
+ protected String[] getMappings() {
+ return new String[] {
+ "PersonAddressOneToOnePrimaryKey.hbm.xml"
+ };
+ }
+
+ public static Test suite() {
+ return new TestSuite(OneToOneTest.class);
+ }
+
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Person.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Person.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Person.java 2008-08-03 16:04:47 UTC (rev 15015)
@@ -0,0 +1,8 @@
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+public class Person {
+
+ int id;
+
+ Address address;
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/PersonAddressOneToOnePrimaryKey.hbm.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/PersonAddressOneToOnePrimaryKey.hbm.xml (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/PersonAddressOneToOnePrimaryKey.hbm.xml 2008-08-03 16:04:47 UTC (rev 15015)
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping
+ package="org.hibernate.tool.hbm2x.hbm2hbmxml">
+<class name="Person">
+ <id name="id" column="personId">
+ <generator class="native"/>
+ </id>
+ <one-to-one name="address"/>
+</class>
+
+<class name="Address">
+ <id name="id" column="personId">
+ <generator class="foreign">
+ <param name="property">person</param>
+ </generator>
+ </id>
+ <one-to-one name="person"
+ constrained="true"/>
+</class>
+</hibernate-mapping>
\ No newline at end of file
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OneToOneTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OneToOneTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OneToOneTest.java 2008-08-03 16:04:47 UTC (rev 15015)
@@ -0,0 +1,223 @@
+/*
+ * Created on 2004-12-01
+ *
+ */
+package org.hibernate.tool.test.jdbc2cfg;
+
+import java.io.File;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.MappingException;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.JDBCMetaDataConfiguration;
+import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy;
+import org.hibernate.cfg.reveng.ReverseEngineeringSettings;
+import org.hibernate.mapping.OneToOne;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.SimpleValue;
+import org.hibernate.tool.JDBCMetaDataBinderTestCase;
+import org.hibernate.tool.hbm2x.HibernateMappingExporter;
+
+/**
+ * @author max
+ *
+ */
+public class OneToOneTest extends JDBCMetaDataBinderTestCase {
+
+ public static Test suite() {
+ return new TestSuite(OneToOneTest.class);
+ }
+
+ private JDBCMetaDataConfiguration localCfg;
+
+ protected void configure(JDBCMetaDataConfiguration configuration) {
+ super.configure( configuration );
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ localCfg = new JDBCMetaDataConfiguration();
+
+ DefaultReverseEngineeringStrategy c = new DefaultReverseEngineeringStrategy();
+
+ localCfg.setReverseEngineeringStrategy(c);
+ localCfg.readFromJDBC();
+ }
+ protected void tearDown() throws Exception {
+ localCfg = null;
+
+ super.tearDown();
+ }
+
+ public void testOneToOneSingleColumnBiDirectional() {
+
+ PersistentClass person = localCfg.getClassMapping("Person");
+
+ Property addressProperty = person.getProperty("addressPerson");
+ assertNotNull(addressProperty);
+
+ assertTrue(addressProperty.getValue() instanceof OneToOne);
+
+ OneToOne oto = (OneToOne) addressProperty.getValue();
+
+ assertEquals(oto.getColumnSpan(),1);
+ assertEquals("Person", oto.getEntityName());
+ assertEquals("AddressPerson", oto.getReferencedEntityName());
+
+
+ assertEquals(2, person.getPropertyClosureSpan());
+ assertEquals("personId", person.getIdentifierProperty().getName());
+ assertFalse(oto.isConstrained());
+
+ PersistentClass addressPerson = localCfg.getClassMapping("AddressPerson");
+
+
+ Property personProperty = addressPerson.getProperty("person");
+ assertNotNull(personProperty);
+
+ assertTrue(personProperty.getValue() instanceof OneToOne);
+
+ oto = (OneToOne) personProperty.getValue();
+
+ assertTrue(oto.isConstrained());
+ assertEquals(oto.getColumnSpan(),1);
+ assertEquals("AddressPerson", oto.getEntityName());
+ assertEquals("Person", oto.getReferencedEntityName());
+
+ assertEquals(2, addressPerson.getPropertyClosureSpan());
+ assertEquals("addressId", addressPerson.getIdentifierProperty().getName());
+
+ }
+
+ public void testAddressWithForeignKeyGeneration() {
+
+ PersistentClass address = localCfg.getClassMapping("AddressPerson");
+
+ assertEquals("foreign", ((SimpleValue)address.getIdentifier()).getIdentifierGeneratorStrategy());
+ }
+
+ public void testOneToOneMultiColumnBiDirectional() {
+
+ PersistentClass person = localCfg.getClassMapping("MultiPerson");
+
+ Property addressProperty = person.getProperty("addressMultiPerson");
+ assertNotNull(addressProperty);
+
+ assertTrue(addressProperty.getValue() instanceof OneToOne);
+
+ OneToOne oto = (OneToOne) addressProperty.getValue();
+
+ assertEquals(oto.getColumnSpan(),2);
+ assertEquals("MultiPerson", oto.getEntityName());
+ assertEquals("AddressMultiPerson", oto.getReferencedEntityName());
+ assertFalse(oto.isConstrained());
+
+ assertEquals(2, person.getPropertyClosureSpan());
+ assertEquals("compositeid gives generic id name", "id", person.getIdentifierProperty().getName());
+
+ PersistentClass addressPerson = localCfg.getClassMapping("AddressMultiPerson");
+
+
+ Property personProperty = addressPerson.getProperty("multiPerson");
+ assertNotNull(personProperty);
+
+ assertTrue(personProperty.getValue() instanceof OneToOne);
+
+ oto = (OneToOne) personProperty.getValue();
+
+ assertEquals(oto.getColumnSpan(),2);
+ assertEquals("AddressMultiPerson", oto.getEntityName());
+ assertEquals("MultiPerson", oto.getReferencedEntityName());
+
+ assertEquals(2, addressPerson.getPropertyClosureSpan());
+ assertEquals("compositeid gives generic id name","id", addressPerson.getIdentifierProperty().getName());
+ assertTrue(oto.isConstrained());
+ }
+
+
+ public void xtestNoCreation() {
+
+ assertNull("No middle class should be generated.", cfg.getClassMapping( "WorksOn" ));
+
+ assertNotNull("Should create worksontext since one of the foreign keys is not part of pk", cfg.getClassMapping( "WorksOnContext" ));
+
+ PersistentClass projectClass = cfg.getClassMapping("Project");
+ assertNotNull( projectClass );
+
+ PersistentClass employeeClass = cfg.getClassMapping("Employee");
+ assertNotNull( employeeClass );
+
+ assertPropertyNotExist( projectClass, "worksOns" );
+ assertPropertyNotExist( employeeClass, "worksOns" );
+
+ Property property = employeeClass.getProperty( "projects" );
+ assertNotNull( property);
+ assertNotNull( projectClass.getProperty( "employees" ));
+
+ }
+
+ public void testBuildMappings() {
+
+ localCfg.buildMappings();
+ }
+
+ public void testGenerateAndReadable() {
+
+ cfg.buildMappings();
+
+ HibernateMappingExporter hme = new HibernateMappingExporter(cfg, getOutputDir());
+ hme.start();
+
+ assertFileAndExists( new File(getOutputDir(), "Person.hbm.xml") );
+ assertFileAndExists( new File(getOutputDir(), "AddressPerson.hbm.xml") );
+ assertFileAndExists( new File(getOutputDir(), "AddressMultiPerson.hbm.xml") );
+ assertFileAndExists( new File(getOutputDir(), "MultiPerson.hbm.xml") );
+
+ assertEquals(4, getOutputDir().listFiles().length);
+
+ Configuration configuration = new Configuration()
+ .addFile( new File(getOutputDir(), "Person.hbm.xml") )
+ .addFile( new File(getOutputDir(), "AddressPerson.hbm.xml") )
+ .addFile( new File(getOutputDir(), "AddressMultiPerson.hbm.xml"))
+ .addFile( new File(getOutputDir(), "MultiPerson.hbm.xml"));
+
+ configuration.buildMappings();
+
+ }
+
+
+ private void assertPropertyNotExist(PersistentClass projectClass, String prop) {
+ try {
+ projectClass.getProperty(prop);
+ fail("property " + prop + " should not exist on " + projectClass);
+ } catch(MappingException e) {
+ // expected
+ }
+ }
+
+ protected String[] getCreateSQL() {
+ return new String[] {
+ "create table PERSON ( person_id integer not null, name varchar(50), primary key (person_id) )",
+ "create table ADDRESS_PERSON ( address_id integer not null, name varchar(50), primary key (address_id), constraint address_person foreign key (address_id) references PERSON)",
+ "create table MULTI_PERSON ( person_id integer not null, person_compid integer not null, name varchar(50), primary key (person_id, person_compid) )",
+ "create table ADDRESS_MULTI_PERSON ( address_id integer not null, address_compid integer not null, name varchar(50), primary key (address_id, address_compid), constraint address_multi_person foreign key (address_id, address_compid) references MULTI_PERSON)",
+ };
+ }
+
+ protected String[] getDropSQL() {
+ return new String[] {
+ "drop table ADDRESS_PERSON",
+ "drop table PERSON",
+ "drop table ADDRESS_MULTI_PERSON",
+ "drop table MULTI_PERSON",
+
+
+ };
+ }
+
+}
Modified: branches/Branch_3_2/HibernateExt/tools/src/testsupport/NoopReverseEngineeringStrategy.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/testsupport/NoopReverseEngineeringStrategy.java 2008-08-01 17:10:49 UTC (rev 15014)
+++ branches/Branch_3_2/HibernateExt/tools/src/testsupport/NoopReverseEngineeringStrategy.java 2008-08-03 16:04:47 UTC (rev 15015)
@@ -162,4 +162,9 @@
// TODO Auto-generated method stub
return null;
}
+
+ public boolean isOneToOne(ForeignKey foreignKey) {
+ // TODO Auto-generated method stub
+ return false;
+ }
}
16 years, 4 months
Hibernate SVN: r15014 - in search/trunk/src: test/org/hibernate/search/test/configuration and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2008-08-01 13:10:49 -0400 (Fri, 01 Aug 2008)
New Revision: 15014
Modified:
search/trunk/src/java/org/hibernate/search/backend/configuration/MaskedProperty.java
search/trunk/src/test/org/hibernate/search/test/configuration/MaskedPropertiesTest.java
Log:
additional fixes for HSEARCH-241: recursive listing, inclusion of fallback properties in lists, synchronization, isEmpty().
Modified: search/trunk/src/java/org/hibernate/search/backend/configuration/MaskedProperty.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/configuration/MaskedProperty.java 2008-08-01 12:23:25 UTC (rev 15013)
+++ search/trunk/src/java/org/hibernate/search/backend/configuration/MaskedProperty.java 2008-08-01 17:10:49 UTC (rev 15014)
@@ -10,15 +10,13 @@
import java.io.PrintWriter;
import java.io.Serializable;
import java.util.Collection;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.InvalidPropertiesFormatException;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
+import java.util.TreeSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,7 +25,7 @@
* A wrapper to Properties, to restrict the availability of
* values to only those which have a key beginning with some
* masking String.
- * Supported methods to enumerate the lsit of properties are:
+ * Supported methods to enumerate the list of properties are:
* - propertyNames()
* - keySet()
* - keys()
@@ -44,7 +42,7 @@
private final Properties masked;
private final Properties fallBack;
private final String radix;
- private transient List<String> propertyNames;
+ private transient Set<Object> propertyNames;
/**
* Provides a view to the provided Properties hiding
@@ -143,37 +141,33 @@
@Override
public Enumeration<?> propertyNames() {
initPropertyNames();
- return new PropertyNameEnumeration();
+ return Collections.enumeration( propertyNames );
}
- private void initPropertyNames() {
+ private synchronized void initPropertyNames() {
if ( propertyNames != null) return;
- propertyNames = new ArrayList<String>();
- List<String> maskedProperties = new ArrayList<String>();
+ Set<Object> maskedProperties = new TreeSet<Object>();
//we use keys to be safe and avoid CCE for non String key entries
- Enumeration maskedNames = masked.keys();
+ Enumeration<?> maskedNames = masked.propertyNames();
while ( maskedNames.hasMoreElements() ) {
Object key = maskedNames.nextElement();
if ( String.class.isInstance( key ) ) {
String maskedProperty = (String) key;
if ( maskedProperty.startsWith( radix ) ) {
- maskedProperties.add(maskedProperty);
- propertyNames.add(maskedProperty.substring( radix.length(), maskedProperty.length() ) );
+ maskedProperties.add(maskedProperty.substring( radix.length(), maskedProperty.length() ) );
}
}
}
if (fallBack != null) {
- Enumeration fallbackKeys = fallBack.keys();
- while ( fallbackKeys.hasMoreElements() ) {
- Object key = fallbackKeys.nextElement();
+ Enumeration<?> fallBackNames = fallBack.propertyNames();
+ while ( fallBackNames.hasMoreElements() ) {
+ Object key = fallBackNames.nextElement();
if ( String.class.isInstance( key ) ) {
- String fallbackProperty = (String) key;
- if ( ! maskedProperties.contains( fallbackProperty )) {
- propertyNames.add(fallbackProperty);
- }
+ maskedProperties.add( (String) key );
}
}
}
+ propertyNames = Collections.unmodifiableSet( maskedProperties );
}
/**
@@ -276,12 +270,8 @@
@Override
public boolean isEmpty() {
- if ( fallBack==null ) {
- return masked.isEmpty();
- }
- else {
- return masked.isEmpty() && fallBack.isEmpty();
- }
+ initPropertyNames();
+ return propertyNames.isEmpty();
}
/**
@@ -290,13 +280,13 @@
@Override
public Enumeration<Object> keys() {
initPropertyNames();
- return new PropertyNameEnumeration();
+ return Collections.enumeration( propertyNames );
}
@Override
public Set<Object> keySet() {
initPropertyNames();
- return new HashSet<Object>(propertyNames);
+ return propertyNames;
}
/**
@@ -393,16 +383,4 @@
aOutputStream.defaultWriteObject();
}
- private class PropertyNameEnumeration implements Enumeration<Object> {
- private int index = -1;
-
- public boolean hasMoreElements() {
- return index + 1 < propertyNames.size();
- }
-
- public Object nextElement() {
- index++;
- return propertyNames.get( index );
- }
- }
}
Modified: search/trunk/src/test/org/hibernate/search/test/configuration/MaskedPropertiesTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/configuration/MaskedPropertiesTest.java 2008-08-01 12:23:25 UTC (rev 15013)
+++ search/trunk/src/test/org/hibernate/search/test/configuration/MaskedPropertiesTest.java 2008-08-01 17:10:49 UTC (rev 15014)
@@ -59,4 +59,30 @@
assertEquals( "value", theCopy.getProperty( "key" ) );
}
+ public void testListingKeys() {
+ Properties defaultProp = new Properties();
+ defaultProp.put( "some.inherited.prop", "to test standard Properties fallback behaviour" );
+ Properties rootProp = new Properties( defaultProp );
+ rootProp.put( "some.long.dotted.prop1", "hello!" );
+ rootProp.put( "hidden.long.dotted.prop2", "hello again" );
+ Properties fallbackProp = new Properties();
+ fallbackProp.put( "default.long.dotted.prop3", "hello!" );
+ Properties masked = new MaskedProperty( rootProp, "some", fallbackProp );
+
+ assertTrue( masked.keySet().contains( "long.dotted.prop1" ) );
+ assertTrue( masked.keySet().contains( "default.long.dotted.prop3" ) );
+ assertTrue( masked.keySet().contains( "inherited.prop" ) );
+ assertFalse( masked.keySet().contains( "hidden.long.dotted.prop2" ) );
+ assertFalse( masked.keySet().contains( "long.dotted.prop2" ) );
+
+ Properties maskedAgain = new MaskedProperty( masked, "long.dotted", masked ); //falling back to same instance for **
+ assertTrue( maskedAgain.keySet().contains( "prop1" ) );
+ assertTrue( maskedAgain.keySet().contains( "long.dotted.prop1" ) ); //**: prop 1 should be visible in both ways
+ assertTrue( maskedAgain.keySet().contains( "default.long.dotted.prop3" ) );
+
+ Properties maskingAll = new MaskedProperty( masked, "secured" );
+ assertTrue( maskingAll.keySet().isEmpty() );
+ assertTrue( maskingAll.isEmpty() );
+ }
+
}
16 years, 4 months
Hibernate SVN: r15013 - in entitymanager/tags/3.4.0.CR2: src/test/org/hibernate/ejb/test/instrument and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-08-01 08:23:25 -0400 (Fri, 01 Aug 2008)
New Revision: 15013
Modified:
entitymanager/tags/3.4.0.CR2/changelog.txt
entitymanager/tags/3.4.0.CR2/ivy.xml
entitymanager/tags/3.4.0.CR2/pom.xml
entitymanager/tags/3.4.0.CR2/readme.txt
entitymanager/tags/3.4.0.CR2/src/test/org/hibernate/ejb/test/instrument/InstrumentedClassLoader.java
entitymanager/tags/3.4.0.CR2/src/test/org/hibernate/ejb/test/instrument/InterceptFieldClassFileTransformerTest.java
Log:
Synced with core rlease 3.3.0.CR2.
Updated test for byte code enhancement due to the fact that javassist is now default provider.
Modified: entitymanager/tags/3.4.0.CR2/changelog.txt
===================================================================
--- entitymanager/tags/3.4.0.CR2/changelog.txt 2008-08-01 12:17:53 UTC (rev 15012)
+++ entitymanager/tags/3.4.0.CR2/changelog.txt 2008-08-01 12:23:25 UTC (rev 15013)
@@ -1,7 +1,7 @@
Hibernate EntityManager Changelog
==================================
-3.4.0.CR2 (29-07-2008)
+3.4.0.CR2 (01-08-2008)
----------------------
** Bug
Modified: entitymanager/tags/3.4.0.CR2/ivy.xml
===================================================================
--- entitymanager/tags/3.4.0.CR2/ivy.xml 2008-08-01 12:17:53 UTC (rev 15012)
+++ entitymanager/tags/3.4.0.CR2/ivy.xml 2008-08-01 12:23:25 UTC (rev 15013)
@@ -16,7 +16,7 @@
<dependency name="ejb3-persistence" rev="1.0.2.GA" conf="default->default"/>
<dependency name="commons-annotations" rev="3.1.0.CR2" conf="default->default"/>
<dependency name="annotations" rev="3.4.0.CR2" conf="default->default"/>
- <dependency org="org.hibernate" name="hibernate-core" rev="3.3.0.CR1" conf="default->default"/>
+ <dependency org="org.hibernate" name="hibernate-core" rev="3.3.0.CR2" conf="default->default"/>
<dependency org="dom4j" name="dom4j" rev="1.6.1" conf="default->default"/>
<dependency org="javax.transaction" name="jta" rev="1.1" conf="default->default"/>
<dependency org="javassist" name="javassist" rev="3.4.GA" conf="default->default"/>
Modified: entitymanager/tags/3.4.0.CR2/pom.xml
===================================================================
--- entitymanager/tags/3.4.0.CR2/pom.xml 2008-08-01 12:17:53 UTC (rev 15012)
+++ entitymanager/tags/3.4.0.CR2/pom.xml 2008-08-01 12:23:25 UTC (rev 15013)
@@ -39,7 +39,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
- <version>3.3.0.CR1</version>
+ <version>3.3.0.CR2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Modified: entitymanager/tags/3.4.0.CR2/readme.txt
===================================================================
--- entitymanager/tags/3.4.0.CR2/readme.txt 2008-08-01 12:17:53 UTC (rev 15012)
+++ entitymanager/tags/3.4.0.CR2/readme.txt 2008-08-01 12:23:25 UTC (rev 15013)
@@ -1,6 +1,6 @@
Hibernate EntityManager
==================================================
-Version: 3.4.0.CR2, 29.07.2008
+Version: 3.4.0.CR2, 01.08.2008
THIS RELEASE OF HIBERNATE ENTITYMANAGER REQUIRES HIBERNATE CORE 3.3 (and above)
Modified: entitymanager/tags/3.4.0.CR2/src/test/org/hibernate/ejb/test/instrument/InstrumentedClassLoader.java
===================================================================
--- entitymanager/tags/3.4.0.CR2/src/test/org/hibernate/ejb/test/instrument/InstrumentedClassLoader.java 2008-08-01 12:17:53 UTC (rev 15012)
+++ entitymanager/tags/3.4.0.CR2/src/test/org/hibernate/ejb/test/instrument/InstrumentedClassLoader.java 2008-08-01 12:23:25 UTC (rev 15013)
@@ -20,7 +20,7 @@
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
- if ( "java.lang.Object".equals( name ) ) return getParent().loadClass( name );
+ if ( name != null && name.startsWith( "java.lang." ) ) return getParent().loadClass( name );
Class c = findLoadedClass( name );
if ( c != null ) return c;
InputStream is = this.getResourceAsStream( name.replace( ".", "/" ) + ".class" );
Modified: entitymanager/tags/3.4.0.CR2/src/test/org/hibernate/ejb/test/instrument/InterceptFieldClassFileTransformerTest.java
===================================================================
--- entitymanager/tags/3.4.0.CR2/src/test/org/hibernate/ejb/test/instrument/InterceptFieldClassFileTransformerTest.java 2008-08-01 12:17:53 UTC (rev 15012)
+++ entitymanager/tags/3.4.0.CR2/src/test/org/hibernate/ejb/test/instrument/InterceptFieldClassFileTransformerTest.java 2008-08-01 12:23:25 UTC (rev 15013)
@@ -1,6 +1,7 @@
//$Id$
package org.hibernate.ejb.test.instrument;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -8,17 +9,34 @@
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public class InterceptFieldClassFileTransformerTest extends TestCase {
+ /**
+ * Tests that class file enhancement works.
+ *
+ * @throws Exception in case the test fails.
+ */
public void testEnhancement() throws Exception {
List<String> entities = new ArrayList<String>();
entities.add( "org.hibernate.ejb.test.instrument.Simple" );
+
+ // sanity check that the class is unmodified and does not contain getFieldHandler()
+ try {
+ org.hibernate.ejb.test.instrument.Simple.class.getDeclaredMethod( "getFieldHandler" );
+ fail();
+ } catch ( NoSuchMethodException nsme ) {
+ // success
+ }
+
+ // use custom class loader which enhances the class
InstrumentedClassLoader cl = new InstrumentedClassLoader( Thread.currentThread().getContextClassLoader() );
cl.setEntities( entities );
- Class interceptedFieldEnabled = cl.loadClass( "net.sf.cglib.transform.impl.InterceptFieldEnabled" );
Class clazz = cl.loadClass( entities.get( 0 ) );
- //clazz = cl.loadClass( "org.hibernate.ejb.test.instrument.Simple" );
- assertTrue( interceptedFieldEnabled.isAssignableFrom( clazz ) );
- clazz.getName();
+
+ // javassist is our default byte code enhancer. Enhancing will eg add the method getFieldHandler()
+ // see org.hibernate.bytecode.javassist.FieldTransformer
+ Method method = clazz.getDeclaredMethod( "getFieldHandler" );
+ assertNotNull( method );
}
}
16 years, 4 months
Hibernate SVN: r15012 - in entitymanager/trunk: src/test/org/hibernate/ejb/test/instrument and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-08-01 08:17:53 -0400 (Fri, 01 Aug 2008)
New Revision: 15012
Modified:
entitymanager/trunk/
entitymanager/trunk/changelog.txt
entitymanager/trunk/ivy.xml
entitymanager/trunk/pom.xml
entitymanager/trunk/readme.txt
entitymanager/trunk/src/test/org/hibernate/ejb/test/instrument/InstrumentedClassLoader.java
entitymanager/trunk/src/test/org/hibernate/ejb/test/instrument/InterceptFieldClassFileTransformerTest.java
Log:
Synced with core rlease 3.3.0.CR2.
Updated test for byte code enhancement due to the fact that javassist is now default provider.
Property changes on: entitymanager/trunk
___________________________________________________________________
Name: svn:ignore
+ .*
target
build
test_output
Modified: entitymanager/trunk/changelog.txt
===================================================================
--- entitymanager/trunk/changelog.txt 2008-08-01 09:32:46 UTC (rev 15011)
+++ entitymanager/trunk/changelog.txt 2008-08-01 12:17:53 UTC (rev 15012)
@@ -1,7 +1,7 @@
Hibernate EntityManager Changelog
==================================
-3.4.0.CR2 (29-07-2008)
+3.4.0.CR2 (01-08-2008)
----------------------
** Bug
Modified: entitymanager/trunk/ivy.xml
===================================================================
--- entitymanager/trunk/ivy.xml 2008-08-01 09:32:46 UTC (rev 15011)
+++ entitymanager/trunk/ivy.xml 2008-08-01 12:17:53 UTC (rev 15012)
@@ -16,7 +16,7 @@
<dependency name="ejb3-persistence" rev="1.0.2.GA" conf="default->default"/>
<dependency name="commons-annotations" rev="3.1.0.CR2" conf="default->default"/>
<dependency name="annotations" rev="3.4.0.CR2" conf="default->default"/>
- <dependency org="org.hibernate" name="hibernate-core" rev="3.3.0.CR1" conf="default->default"/>
+ <dependency org="org.hibernate" name="hibernate-core" rev="3.3.0.CR2" conf="default->default"/>
<dependency org="dom4j" name="dom4j" rev="1.6.1" conf="default->default"/>
<dependency org="javax.transaction" name="jta" rev="1.1" conf="default->default"/>
<dependency org="javassist" name="javassist" rev="3.4.GA" conf="default->default"/>
Modified: entitymanager/trunk/pom.xml
===================================================================
--- entitymanager/trunk/pom.xml 2008-08-01 09:32:46 UTC (rev 15011)
+++ entitymanager/trunk/pom.xml 2008-08-01 12:17:53 UTC (rev 15012)
@@ -39,7 +39,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
- <version>3.3.0.CR1</version>
+ <version>3.3.0.CR2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Modified: entitymanager/trunk/readme.txt
===================================================================
--- entitymanager/trunk/readme.txt 2008-08-01 09:32:46 UTC (rev 15011)
+++ entitymanager/trunk/readme.txt 2008-08-01 12:17:53 UTC (rev 15012)
@@ -1,6 +1,6 @@
Hibernate EntityManager
==================================================
-Version: 3.4.0.CR2, 29.07.2008
+Version: 3.4.0.CR2, 01.08.2008
THIS RELEASE OF HIBERNATE ENTITYMANAGER REQUIRES HIBERNATE CORE 3.3 (and above)
Modified: entitymanager/trunk/src/test/org/hibernate/ejb/test/instrument/InstrumentedClassLoader.java
===================================================================
--- entitymanager/trunk/src/test/org/hibernate/ejb/test/instrument/InstrumentedClassLoader.java 2008-08-01 09:32:46 UTC (rev 15011)
+++ entitymanager/trunk/src/test/org/hibernate/ejb/test/instrument/InstrumentedClassLoader.java 2008-08-01 12:17:53 UTC (rev 15012)
@@ -20,7 +20,7 @@
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
- if ( "java.lang.Object".equals( name ) ) return getParent().loadClass( name );
+ if ( name != null && name.startsWith( "java.lang." ) ) return getParent().loadClass( name );
Class c = findLoadedClass( name );
if ( c != null ) return c;
InputStream is = this.getResourceAsStream( name.replace( ".", "/" ) + ".class" );
Modified: entitymanager/trunk/src/test/org/hibernate/ejb/test/instrument/InterceptFieldClassFileTransformerTest.java
===================================================================
--- entitymanager/trunk/src/test/org/hibernate/ejb/test/instrument/InterceptFieldClassFileTransformerTest.java 2008-08-01 09:32:46 UTC (rev 15011)
+++ entitymanager/trunk/src/test/org/hibernate/ejb/test/instrument/InterceptFieldClassFileTransformerTest.java 2008-08-01 12:17:53 UTC (rev 15012)
@@ -1,6 +1,7 @@
//$Id$
package org.hibernate.ejb.test.instrument;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -8,17 +9,34 @@
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public class InterceptFieldClassFileTransformerTest extends TestCase {
+ /**
+ * Tests that class file enhancement works.
+ *
+ * @throws Exception in case the test fails.
+ */
public void testEnhancement() throws Exception {
List<String> entities = new ArrayList<String>();
entities.add( "org.hibernate.ejb.test.instrument.Simple" );
+
+ // sanity check that the class is unmodified and does not contain getFieldHandler()
+ try {
+ org.hibernate.ejb.test.instrument.Simple.class.getDeclaredMethod( "getFieldHandler" );
+ fail();
+ } catch ( NoSuchMethodException nsme ) {
+ // success
+ }
+
+ // use custom class loader which enhances the class
InstrumentedClassLoader cl = new InstrumentedClassLoader( Thread.currentThread().getContextClassLoader() );
cl.setEntities( entities );
- Class interceptedFieldEnabled = cl.loadClass( "net.sf.cglib.transform.impl.InterceptFieldEnabled" );
Class clazz = cl.loadClass( entities.get( 0 ) );
- //clazz = cl.loadClass( "org.hibernate.ejb.test.instrument.Simple" );
- assertTrue( interceptedFieldEnabled.isAssignableFrom( clazz ) );
- clazz.getName();
+
+ // javassist is our default byte code enhancer. Enhancing will eg add the method getFieldHandler()
+ // see org.hibernate.bytecode.javassist.FieldTransformer
+ Method method = clazz.getDeclaredMethod( "getFieldHandler" );
+ assertNotNull( method );
}
}
16 years, 4 months
Hibernate SVN: r15011 - annotations/trunk.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-08-01 05:32:46 -0400 (Fri, 01 Aug 2008)
New Revision: 15011
Modified:
annotations/trunk/changelog.txt
Log:
Updated release date.
Modified: annotations/trunk/changelog.txt
===================================================================
--- annotations/trunk/changelog.txt 2008-08-01 09:30:41 UTC (rev 15010)
+++ annotations/trunk/changelog.txt 2008-08-01 09:32:46 UTC (rev 15011)
@@ -1,7 +1,7 @@
Hibernate Annotations Changelog
===============================
-3.4.0.CR2 (29-07-2008)
+3.4.0.CR2 (01-08-2008)
----------------------
** Bug
16 years, 4 months
Hibernate SVN: r15010 - annotations/tags/3.4.0.CR2.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-08-01 05:30:41 -0400 (Fri, 01 Aug 2008)
New Revision: 15010
Modified:
annotations/tags/3.4.0.CR2/changelog.txt
Log:
Updated release date.
Modified: annotations/tags/3.4.0.CR2/changelog.txt
===================================================================
--- annotations/tags/3.4.0.CR2/changelog.txt 2008-08-01 08:45:34 UTC (rev 15009)
+++ annotations/tags/3.4.0.CR2/changelog.txt 2008-08-01 09:30:41 UTC (rev 15010)
@@ -1,7 +1,7 @@
Hibernate Annotations Changelog
===============================
-3.4.0.CR2 (29-07-2008)
+3.4.0.CR2 (01-08-2008)
----------------------
** Bug
16 years, 4 months
Hibernate SVN: r15009 - annotations/tags/3.4.0.CR2.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-08-01 04:45:34 -0400 (Fri, 01 Aug 2008)
New Revision: 15009
Modified:
annotations/tags/3.4.0.CR2/readme.txt
Log:
Updated release date.
Modified: annotations/tags/3.4.0.CR2/readme.txt
===================================================================
--- annotations/tags/3.4.0.CR2/readme.txt 2008-08-01 08:45:05 UTC (rev 15008)
+++ annotations/tags/3.4.0.CR2/readme.txt 2008-08-01 08:45:34 UTC (rev 15009)
@@ -1,6 +1,6 @@
Hibernate Annotations
==================================================
-Version: 3.4.0.CR2, 29.07.2008
+Version: 3.4.0.CR2, 01.08.2008
THIS RELEASE OF HIBERNATE ANNOTATIONS REQUIRES HIBERNATE CORE 3.3 (and above)
16 years, 4 months
Hibernate SVN: r15008 - annotations/trunk.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-08-01 04:45:05 -0400 (Fri, 01 Aug 2008)
New Revision: 15008
Modified:
annotations/trunk/readme.txt
Log:
Updated release date.
Modified: annotations/trunk/readme.txt
===================================================================
--- annotations/trunk/readme.txt 2008-08-01 08:15:25 UTC (rev 15007)
+++ annotations/trunk/readme.txt 2008-08-01 08:45:05 UTC (rev 15008)
@@ -1,6 +1,6 @@
Hibernate Annotations
==================================================
-Version: 3.4.0.CR2, 29.07.2008
+Version: 3.4.0.CR2, 01.08.2008
THIS RELEASE OF HIBERNATE ANNOTATIONS REQUIRES HIBERNATE CORE 3.3 (and above)
16 years, 4 months
Hibernate SVN: r15007 - in annotations/tags/3.4.0.CR2: doc/reference/en/modules and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-08-01 04:15:25 -0400 (Fri, 01 Aug 2008)
New Revision: 15007
Modified:
annotations/tags/3.4.0.CR2/doc/reference/en/modules/setup.xml
annotations/tags/3.4.0.CR2/ivy.xml
annotations/tags/3.4.0.CR2/pom.xml
annotations/tags/3.4.0.CR2/src/java/org/hibernate/cfg/AnnotationConfiguration.java
annotations/tags/3.4.0.CR2/src/java/org/hibernate/cfg/search/HibernateSearchEventListenerRegister.java
Log:
Synced with core release 3.3.0.CR2
Switched to javassist as byecode provider for the tests.
Modified: annotations/tags/3.4.0.CR2/doc/reference/en/modules/setup.xml
===================================================================
--- annotations/tags/3.4.0.CR2/doc/reference/en/modules/setup.xml 2008-08-01 08:14:23 UTC (rev 15006)
+++ annotations/tags/3.4.0.CR2/doc/reference/en/modules/setup.xml 2008-08-01 08:15:25 UTC (rev 15007)
@@ -18,7 +18,7 @@
</listitem>
<listitem>
- <para>This release is known to work on Hibernate Core 3.3.CR1</para>
+ <para>This release is known to work on Hibernate Core 3.3.0.CR2</para>
</listitem>
<listitem>
Modified: annotations/tags/3.4.0.CR2/ivy.xml
===================================================================
--- annotations/tags/3.4.0.CR2/ivy.xml 2008-08-01 08:14:23 UTC (rev 15006)
+++ annotations/tags/3.4.0.CR2/ivy.xml 2008-08-01 08:15:25 UTC (rev 15007)
@@ -15,7 +15,7 @@
<!-- compile time dependencies -->
<dependency name="ejb3-persistence" rev="1.0.2.GA" conf="default->default"/>
<dependency name="commons-annotations" rev="3.1.0.CR2" conf="default->default"/>
- <dependency org="org.hibernate" name="hibernate-core" rev="3.3.0.CR1" conf="default->default"/>
+ <dependency org="org.hibernate" name="hibernate-core" rev="3.3.0.CR2" conf="default->default"/>
<dependency org="dom4j" name="dom4j" rev="1.6.1" conf="default->default"/>
<dependency org="org.slf4j" name="slf4j-api" rev="1.4.2" conf="default->default"/>
@@ -25,7 +25,7 @@
<dependency org="commons-collections" name="commons-collections" rev="3.1" conf="test->default"/>
<!-- test deps -->
- <dependency org="cglib" name="cglib" rev="2.1_3" conf="test->default"/>
+ <dependency org="javassist" name="javassist" rev="3.4.GA" conf="test->default"/>
<dependency org="asm" name="asm" rev="1.5.3" conf="test->default"/>
<dependency org="asm" name="asm-attrs" rev="1.5.3" conf="test->default"/>
<dependency org="javax.transaction" name="jta" rev="1.1" conf="test->default"/>
Modified: annotations/tags/3.4.0.CR2/pom.xml
===================================================================
--- annotations/tags/3.4.0.CR2/pom.xml 2008-08-01 08:14:23 UTC (rev 15006)
+++ annotations/tags/3.4.0.CR2/pom.xml 2008-08-01 08:15:25 UTC (rev 15007)
@@ -35,7 +35,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
- <version>3.3.0.CR1</version>
+ <version>3.3.0.CR2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Modified: annotations/tags/3.4.0.CR2/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- annotations/tags/3.4.0.CR2/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2008-08-01 08:14:23 UTC (rev 15006)
+++ annotations/tags/3.4.0.CR2/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2008-08-01 08:15:25 UTC (rev 15007)
@@ -61,14 +61,13 @@
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
-@SuppressWarnings({"unchecked", "serial"})
public class AnnotationConfiguration extends Configuration {
private Logger log = LoggerFactory.getLogger( AnnotationConfiguration.class );
/**
* Class name of the class needed to enable Search.
*/
- private static final String SEARCH_STARTUP_CLASS = "org.hibernate.search.cfg.EventListenerRegister";
+ private static final String SEARCH_STARTUP_CLASS = "org.hibernate.search.event.EventListenerRegister";
/**
* Method to call to enable Search.
@@ -360,9 +359,8 @@
try {
Class classValidator = ReflectHelper.classForName( "org.hibernate.validator.ClassValidator", this.getClass() );
Class messageInterpolator = ReflectHelper.classForName( "org.hibernate.validator.MessageInterpolator", this.getClass() );
- validatorCtr = classValidator.getDeclaredConstructor( new Class[] {
+ validatorCtr = classValidator.getDeclaredConstructor(
Class.class, ResourceBundle.class, messageInterpolator, Map.class, ReflectionManager.class
- }
);
applyMethod = classValidator.getMethod( "apply", PersistentClass.class );
}
@@ -827,9 +825,7 @@
if ( !present ) {
int length = listeners.length + 1;
PreInsertEventListener[] newListeners = new PreInsertEventListener[length];
- for (int i = 0; i < length - 1; i++) {
- newListeners[i] = listeners[i];
- }
+ System.arraycopy( listeners, 0, newListeners, 0, length - 1 );
newListeners[length - 1] = (PreInsertEventListener) validateEventListener;
getEventListeners().setPreInsertEventListeners( newListeners );
}
@@ -853,9 +849,7 @@
if ( !present ) {
int length = listeners.length + 1;
PreUpdateEventListener[] newListeners = new PreUpdateEventListener[length];
- for (int i = 0; i < length - 1; i++) {
- newListeners[i] = listeners[i];
- }
+ System.arraycopy( listeners, 0, newListeners, 0, length - 1 );
newListeners[length - 1] = (PreUpdateEventListener) validateEventListener;
getEventListeners().setPreUpdateEventListeners( newListeners );
}
@@ -879,7 +873,7 @@
*/
private void enableHibernateSearch() {
// load the bootstrap class
- Class searchStartupClass = null;
+ Class searchStartupClass;
try {
searchStartupClass = ReflectHelper.classForName(SEARCH_STARTUP_CLASS, AnnotationConfiguration.class);
} catch ( ClassNotFoundException e ) {
Modified: annotations/tags/3.4.0.CR2/src/java/org/hibernate/cfg/search/HibernateSearchEventListenerRegister.java
===================================================================
--- annotations/tags/3.4.0.CR2/src/java/org/hibernate/cfg/search/HibernateSearchEventListenerRegister.java 2008-08-01 08:14:23 UTC (rev 15006)
+++ annotations/tags/3.4.0.CR2/src/java/org/hibernate/cfg/search/HibernateSearchEventListenerRegister.java 2008-08-01 08:15:25 UTC (rev 15007)
@@ -18,7 +18,7 @@
/**
* Helper methods initializing Hibernate Search event listeners.
*
- * @deprecated as of release 3.4.0.CR2, replaced by Hibernate Search's {@link org.hibernate.search.cfg.EventListenerBoostrap}
+ * @deprecated as of release 3.4.0.CR2, replaced by Hibernate Search's {@link org.hibernate.search.cfg.EventListenerRegister}
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
@@ -199,23 +199,20 @@
*
* @return An event listener instance in case the jar was available.
*/
- @SuppressWarnings("unchecked")
- private static Class attemptToLoadSearchEventListener() {
+ private static Class<?> attemptToLoadSearchEventListener() {
Class searchEventListenerClass = null;
try {
searchEventListenerClass = ReflectHelper.classForName(
FULL_TEXT_INDEX_EVENT_LISTENER_CLASS,
HibernateSearchEventListenerRegister.class);
} catch (ClassNotFoundException e) {
- log
- .debug("Search not present in classpath, ignoring event listener registration.");
+ log.debug("Search not present in classpath, ignoring event listener registration.");
}
return searchEventListenerClass;
}
- @SuppressWarnings("unchecked")
- private static Object instantiateEventListener(Class clazz) {
- Object searchEventListener = null;
+ private static Object instantiateEventListener(Class<?> clazz) {
+ Object searchEventListener;
try {
searchEventListener = clazz.newInstance();
} catch (Exception e) {
16 years, 4 months