-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBX-2733: Create Interface for Cfg2HbmWrapper
- Create new test class 'org.hibernate.tool.orm.jbt.api.Cfg2HbmToolWrapperTest' - Create new interface class 'org.hibernate.tool.orm.jbt.api.Cfg2HbmToolWrapper' - Create new factory class 'org.hibernate.tool.orm.jbt.internal.factory.Cfg2HbmToolWrapperFactory' Signed-off-by: Koen Aers <koen.aers@gmail.com>
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
jbt/src/main/java/org/hibernate/tool/orm/jbt/api/Cfg2HbmToolWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.hibernate.tool.orm.jbt.api; | ||
|
||
import org.hibernate.mapping.PersistentClass; | ||
import org.hibernate.mapping.Property; | ||
import org.hibernate.mapping.SimpleValue; | ||
import org.hibernate.tool.internal.export.hbm.Cfg2HbmTool; | ||
import org.hibernate.tool.internal.export.hbm.HBMTagForValueVisitor; | ||
import org.hibernate.tool.orm.jbt.wrp.Wrapper; | ||
|
||
public interface Cfg2HbmToolWrapper extends Wrapper { | ||
|
||
default String getTag(PersistentClass pc) { | ||
return ((Cfg2HbmTool)getWrappedObject()).getTag(pc); | ||
} | ||
default String getTag(Property p) { | ||
if (p instanceof Wrapper) { | ||
p = (Property)((Wrapper)p).getWrappedObject(); | ||
} | ||
PersistentClass persistentClass = p.getPersistentClass(); | ||
if(persistentClass!=null) { | ||
Property v = persistentClass.getVersion(); | ||
if (v instanceof Wrapper) { | ||
v = (Property)((Wrapper)v).getWrappedObject(); | ||
} | ||
if(v==p) { | ||
String typeName = ((SimpleValue)p.getValue()).getTypeName(); | ||
if("timestamp".equals(typeName) || "dbtimestamp".equals(typeName)) { | ||
return "timestamp"; | ||
} else { | ||
return "version"; | ||
} | ||
} | ||
} | ||
String toolTag = (String) p.getValue().accept(HBMTagForValueVisitor.INSTANCE); | ||
if ("component".equals(toolTag) && "embedded".equals(p.getPropertyAccessorName())){ | ||
toolTag = "properties"; | ||
} | ||
return toolTag; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
jbt/src/main/java/org/hibernate/tool/orm/jbt/internal/factory/Cfg2HbmToolWrapperFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.hibernate.tool.orm.jbt.internal.factory; | ||
|
||
import org.hibernate.tool.internal.export.hbm.Cfg2HbmTool; | ||
import org.hibernate.tool.orm.jbt.api.Cfg2HbmToolWrapper; | ||
|
||
public class Cfg2HbmToolWrapperFactory { | ||
|
||
public static Cfg2HbmToolWrapper createCfg2HbmToolWrapper() { | ||
Cfg2HbmTool wrappedCfg2HbmTool = new Cfg2HbmTool(); | ||
return new Cfg2HbmToolWrapper() { | ||
@Override public Cfg2HbmTool getWrappedObject() { return wrappedCfg2HbmTool; } | ||
}; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
jbt/src/test/java/org/hibernate/tool/orm/jbt/api/Cfg2HbmToolWrapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.hibernate.tool.orm.jbt.api; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.hibernate.mapping.BasicValue; | ||
import org.hibernate.mapping.PersistentClass; | ||
import org.hibernate.mapping.Property; | ||
import org.hibernate.mapping.RootClass; | ||
import org.hibernate.tool.orm.jbt.internal.factory.Cfg2HbmToolWrapperFactory; | ||
import org.hibernate.tool.orm.jbt.util.DummyMetadataBuildingContext; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class Cfg2HbmToolWrapperTest { | ||
|
||
private Cfg2HbmToolWrapper wrapper = null; | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
wrapper = Cfg2HbmToolWrapperFactory.createCfg2HbmToolWrapper(); | ||
} | ||
|
||
@Test | ||
public void testGetTagPersistentClass() { | ||
PersistentClass persistentClass = new RootClass(DummyMetadataBuildingContext.INSTANCE); | ||
assertEquals("class", wrapper.getTag(persistentClass)); | ||
} | ||
|
||
@Test | ||
public void testGetTagProperty() throws Exception { | ||
Property property = new Property(); | ||
RootClass rc = new RootClass(DummyMetadataBuildingContext.INSTANCE); | ||
BasicValue basicValue = new BasicValue(DummyMetadataBuildingContext.INSTANCE); | ||
basicValue.setTypeName("foobar"); | ||
property.setValue(basicValue); | ||
property.setPersistentClass(rc); | ||
rc.setVersion(property); | ||
assertEquals("version", wrapper.getTag(property)); | ||
} | ||
|
||
} |