Skip to content

Commit

Permalink
HBX-2390: Create a JBoss Tools adaptation layer in Hibernate Tools
Browse files Browse the repository at this point in the history
  - Modify method 'org.hibernate.tool.orm.jbt.util.NativeConfiguration#getClassMappings()' to return an iterator of 'org.hibernate.tool.orm.jbt.wrp.DelegatingPersistentClassWrapperImpl'
  - Modify method 'org.hibernate.tool.orm.jbt.util.NativeConfiguration#getClassMapping(String) to wrap the result as 'org.hibernate.tool.orm.jbt.wrp.DelegatingPersistentClassWrapperImpl'
  - Modify method 'org.hibernate.tool.orm.jbt.util.JpaConfiguration#getClassMappings()' to return an iterator of 'org.hibernate.tool.orm.jbt.wrp.DelegatingPersistentClassWrapperImpl'
  - Modify method 'org.hibernate.tool.orm.jbt.util.JpaConfiguration#getClassMapping(String) to wrap the result as 'org.hibernate.tool.orm.jbt.wrp.DelegatingPersistentClassWrapperImpl'
  - Modify method 'org.hibernate.tool.orm.jbt.util.RevengConfiguration#getClassMappings()' to return an iterator of 'org.hibernate.tool.orm.jbt.wrp.DelegatingPersistentClassWrapperImpl'
  - Modify method 'org.hibernate.tool.orm.jbt.util.RevengConfiguration#getClassMapping(String) to wrap the result as 'org.hibernate.tool.orm.jbt.wrp.DelegatingPersistentClassWrapperImpl'
  - Modify test case 'org.hibernate.tool.orm.jbt.util.JpaConfigurationTest#testGetClassMappings()'

Signed-off-by: Koen Aers <[email protected]>
  • Loading branch information
koentsje committed Jul 3, 2023
1 parent 0b86b8e commit d6f4e51
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.tool.api.reveng.RevengStrategy;
import org.hibernate.tool.orm.jbt.wrp.DelegatingPersistentClassWrapperImpl;
import org.hibernate.tool.orm.jbt.wrp.SessionFactoryWrapper;
import org.w3c.dom.Document;
import org.xml.sax.EntityResolver;
Expand Down Expand Up @@ -120,10 +121,6 @@ public String getPersistenceUnit() {
return persistenceUnit;
}

public Iterator<PersistentClass> getClassMappings() {
return getMetadata().getEntityBindings().iterator();
}

public void setPreferBasicCompositeIds(boolean b) {
throw new RuntimeException(
"Method 'setPreferBasicCompositeIds' should not be called on instances of " +
Expand All @@ -136,8 +133,24 @@ public void setReverseEngineeringStrategy(RevengStrategy strategy) {
this.getClass().getName());
}

public Iterator<PersistentClass> getClassMappings() {
final Iterator<PersistentClass> iterator = getMetadata().getEntityBindings().iterator();
return new Iterator<PersistentClass>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public PersistentClass next() {
return new DelegatingPersistentClassWrapperImpl(iterator.next());
}

};
}

public PersistentClass getClassMapping(String name) {
return getMetadata().getEntityBinding(name);
PersistentClass pc = getMetadata().getEntityBinding(name);
return pc == null ? null : new DelegatingPersistentClassWrapperImpl(pc);
}

public Iterator<Table> getTableMappings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.tool.api.reveng.RevengStrategy;
import org.hibernate.tool.orm.jbt.wrp.DelegatingPersistentClassWrapperImpl;
import org.hibernate.tool.orm.jbt.wrp.SessionFactoryWrapper;
import org.w3c.dom.Document;
import org.xml.sax.EntityResolver;
Expand Down Expand Up @@ -90,11 +91,23 @@ public void buildMappings() {
}

public Iterator<PersistentClass> getClassMappings() {
return getMetadata().getEntityBindings().iterator();
final Iterator<PersistentClass> iterator = getMetadata().getEntityBindings().iterator();
return new Iterator<PersistentClass>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public PersistentClass next() {
return new DelegatingPersistentClassWrapperImpl(iterator.next());
}

};
}

public PersistentClass getClassMapping(String name) {
return getMetadata().getEntityBinding(name);
PersistentClass pc = getMetadata().getEntityBinding(name);
return pc == null ? null : new DelegatingPersistentClassWrapperImpl(pc);
}

public Iterator<Table> getTableMappings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.hibernate.tool.api.metadata.MetadataConstants;
import org.hibernate.tool.api.metadata.MetadataDescriptorFactory;
import org.hibernate.tool.api.reveng.RevengStrategy;
import org.hibernate.tool.orm.jbt.wrp.DelegatingPersistentClassWrapperImpl;
import org.w3c.dom.Document;
import org.xml.sax.EntityResolver;

Expand Down Expand Up @@ -52,14 +53,28 @@ public void readFromJDBC() {

public Iterator<PersistentClass> getClassMappings() {
if (metadata != null) {
return metadata.getEntityBindings().iterator();
final Iterator<PersistentClass> iterator = metadata.getEntityBindings().iterator();
return new Iterator<PersistentClass>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public PersistentClass next() {
return new DelegatingPersistentClassWrapperImpl(iterator.next());
}
};
} else {
return Collections.emptyIterator();
}
}

public PersistentClass getClassMapping(String name) {
return (metadata != null) ? metadata.getEntityBinding(name) : null;
PersistentClass pc = null;
if (metadata != null) {
pc = metadata.getEntityBinding(name);
}
return (pc != null) ? new DelegatingPersistentClassWrapperImpl(pc) : null;
}

public Iterator<Table> getTableMappings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Iterator<Property> getPropertyClosureIterator() {
public PersistentClass getSuperclass() {
return delegate.getSuperclass();
}

@Override
public Iterator<Property> getPropertyIterator() {
final Iterator<Property> iterator = delegate.getPropertyIterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.tool.internal.reveng.strategy.DefaultStrategy;
import org.hibernate.tool.orm.jbt.wrp.PersistentClassWrapper;
import org.hibernate.tool.orm.jbt.wrp.SessionFactoryWrapper;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -174,8 +175,8 @@ public void testGetClassMappings() {
Iterator<PersistentClass> classMappings = jpaConfiguration.getClassMappings();
assertNotNull(classMappings);
assertTrue(classMappings.hasNext());
PersistentClass pc = classMappings.next();
assertSame(pc.getMappedClass(), FooBar.class);
PersistentClassWrapper pc = (PersistentClassWrapper)classMappings.next();
assertSame(pc.getWrappedObject().getMappedClass(), FooBar.class);
}

@Test
Expand Down

0 comments on commit d6f4e51

Please sign in to comment.