Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBX-2390: Create a JBoss Tools adaptation layer in Hibernate Tools #4277

Merged
merged 5 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
package org.hibernate.tool.orm.jbt.wrp;

import java.util.Iterator;

import org.hibernate.mapping.Join;
import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.Value;
import org.hibernate.tool.orm.jbt.util.DummyMetadataBuildingContext;

public class DelegatingPersistentClassWrapperImpl extends RootClass implements PersistentClassWrapper {

private PersistentClass delegate = null;

public DelegatingPersistentClassWrapperImpl(PersistentClass pc) {
super(DummyMetadataBuildingContext.INSTANCE);
delegate = pc;
}

@Override
public PersistentClass getWrappedObject() {
return delegate;
}

@Override
public String getEntityName() {
return delegate.getEntityName();
}

@Override
public String getClassName() {
return delegate.getClassName();
}

@Override
public Property getIdentifierProperty() {
return wrapPropertyIfNeeded(delegate.getIdentifierProperty());
}

@Override
public boolean hasIdentifierProperty() {
return delegate.hasIdentifierProperty();
}

@Override
public RootClass getRootClass() {
return delegate.getRootClass();
}

@Override
public Iterator<Property> getPropertyClosureIterator() {
return getPropertyIterator();
}

@Override
public PersistentClass getSuperclass() {
return delegate.getSuperclass();
}

@Override
public Iterator<Property> getPropertyIterator() {
final Iterator<Property> iterator = delegate.getPropertyIterator();
return new Iterator<Property>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public Property next() {
return PropertyWrapperFactory.createPropertyWrapper(iterator.next());
}

};
}

@Override
public Property getProperty(String name) {
return wrapPropertyIfNeeded(delegate.getProperty(name));
}

@Override
public Table getTable() {
return delegate.getTable();
}

@Override
public Boolean isAbstract() {
return delegate.isAbstract();
}

@Override
public Value getDiscriminator() {
return wrapValueIfNeeded(delegate.getDiscriminator());
}

@Override
public KeyValue getIdentifier() {
return (KeyValue)wrapValueIfNeeded(delegate.getIdentifier());
}

@Override
public Iterator<Join> getJoinIterator() {
return delegate.getJoinIterator();
}

@Override
public Property getVersion() {
return wrapPropertyIfNeeded(delegate.getVersion());
}

@Override
public void setClassName(String name) {
delegate.setClassName(name);
}

@Override
public void setEntityName(String name) {
delegate.setEntityName(name);
}

@Override
public void setDiscriminatorValue(String str) {
delegate.setDiscriminatorValue(str);
}

@Override
public void setAbstract(Boolean b) {
delegate.setAbstract(b);
}

@Override
public void addProperty(Property p) {
delegate.addProperty(p);
}

@Override
public void setProxyInterfaceName(String name) {
delegate.setProxyInterfaceName(name);
}

@Override
public void setLazy(boolean b) {
delegate.setLazy(b);
}

@Override
public Iterator<Subclass> getSubclassIterator() {
return delegate.getSubclassIterator();
}

@Override
public boolean isCustomDeleteCallable() {
return delegate.isCustomDeleteCallable();
}

@Override
public boolean isCustomInsertCallable() {
return delegate.isCustomInsertCallable();
}

@Override
public boolean isCustomUpdateCallable() {
return delegate.isCustomUpdateCallable();
}

@Override
public boolean isDiscriminatorInsertable() {
return delegate.isDiscriminatorInsertable();
}

@Override
public boolean isDiscriminatorValueNotNull() {
return delegate.isDiscriminatorValueNotNull();
}

@Override
public boolean isDiscriminatorValueNull() {
return delegate.isDiscriminatorValueNull();
}

@Override
public boolean isExplicitPolymorphism() {
return delegate.isExplicitPolymorphism();
}

@Override
public boolean isForceDiscriminator() {
return delegate.isForceDiscriminator();
}

@Override
public boolean isInherited() {
return delegate.isInherited();
}

@Override
public boolean isJoinedSubclass() {
return delegate.isJoinedSubclass();
}

@Override
public boolean isLazy() {
return delegate.isLazy();
}

@Override
public boolean isMutable() {
return delegate.isMutable();
}

@Override
public boolean isPolymorphic() {
return delegate.isPolymorphic();
}

@Override
public boolean isVersioned() {
return delegate.isVersioned();
}

@Override
public int getBatchSize() {
return delegate.getBatchSize();
}

@Override
public String getCacheConcurrencyStrategy() {
return delegate.getCacheConcurrencyStrategy();
}

@Override
public String getCustomSQLDelete() {
return delegate.getCustomSQLDelete();
}

@Override
public String getCustomSQLInsert() {
return delegate.getCustomSQLInsert();
}

@Override
public String getCustomSQLUpdate() {
return delegate.getCustomSQLUpdate();
}

@Override
public String getDiscriminatorValue() {
return delegate.getDiscriminatorValue();
}

@Override
public String getLoaderName() {
return delegate.getLoaderName();
}

@Override
public int getOptimisticLockMode() {
return delegate.getOptimisticLockMode();
}

@Override
public String getWhere() {
return delegate.getWhere();
}

@Override
public Table getRootTable() {
return delegate.getRootTable();
}


private static Value wrapValueIfNeeded(Value v) {
return (v != null) && !(v instanceof Wrapper) ? ValueWrapperFactory.createValueWrapper(v) : v;
}

private static Property wrapPropertyIfNeeded(Property p) {
return (p != null) && !(p instanceof Wrapper) ? PropertyWrapperFactory.createPropertyWrapper(p) : p;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,30 @@
public interface PersistentClassWrapper extends Wrapper {

default PersistentClass getWrappedObject() { return (PersistentClass)this; }
String getEntityName();
String getClassName();
default boolean isAssignableToRootClass() { return isInstanceOfRootClass(); }
default boolean isRootClass() { return getWrappedObject().getClass() == RootClassWrapperImpl.class; }
Property getIdentifierProperty();
boolean hasIdentifierProperty();
default boolean isInstanceOfRootClass() { return RootClass.class.isAssignableFrom(getWrappedObject().getClass()); }
default boolean isInstanceOfSubclass() { return Subclass.class.isAssignableFrom(getWrappedObject().getClass()); }
default boolean isInstanceOfJoinedSubclass() { return JoinedSubclass.class.isAssignableFrom(getWrappedObject().getClass()); }
default Property getProperty() { throw new RuntimeException("getProperty() is only allowed on SpecialRootClass"); }
default void setTable(Table table) { throw new RuntimeException("Method 'setTable(Table)' is not supported."); }
default void setIdentifier(KeyValue value) { throw new RuntimeException("Method 'setIdentifier(KeyValue)' can only be called on RootClass instances"); }
default void setKey(KeyValue value) { throw new RuntimeException("setKey(KeyValue) is only allowed on JoinedSubclass"); }
default boolean isInstanceOfSpecialRootClass() { return SpecialRootClass.class.isAssignableFrom(getWrappedObject().getClass()); }
default Property getParentProperty() { throw new RuntimeException("getParentProperty() is only allowed on SpecialRootClass"); }
default void setIdentifierProperty(Property property) { throw new RuntimeException("setIdentifierProperty(Property) is only allowed on RootClass instances"); }
default void setDiscriminator(Value value) { throw new RuntimeException("Method 'setDiscriminator(Value)' can only be called on RootClass instances"); }
default boolean isLazyPropertiesCacheable() { throw new RuntimeException("Method 'isLazyPropertiesCacheable()' can only be called on RootClass instances"); }

String getEntityName();
String getClassName();
Property getIdentifierProperty();
boolean hasIdentifierProperty();
PersistentClass getRootClass();
Iterator<Property> getPropertyClosureIterator();
PersistentClass getSuperclass();
Iterator<Property> getPropertyIterator();
Property getProperty(String name);
default Property getProperty() { throw new RuntimeException("getProperty() is only allowed on SpecialRootClass"); }
Table getTable();
Boolean isAbstract();
Value getDiscriminator();
Expand All @@ -43,13 +52,6 @@ public interface PersistentClassWrapper extends Wrapper {
void setDiscriminatorValue(String str);
void setAbstract(Boolean b);
void addProperty(Property p);
default void setTable(Table table) { throw new RuntimeException("Method 'setTable(Table)' is not supported."); }
default void setIdentifier(KeyValue value) { throw new RuntimeException("Method 'setIdentifier(KeyValue)' can only be called on RootClass instances"); }
default void setKey(KeyValue value) { throw new RuntimeException("setKey(KeyValue) is only allowed on JoinedSubclass"); }
default boolean isInstanceOfSpecialRootClass() { return SpecialRootClass.class.isAssignableFrom(getWrappedObject().getClass()); }
default Property getParentProperty() { throw new RuntimeException("getParentProperty() is only allowed on SpecialRootClass"); }
default void setIdentifierProperty(Property property) { throw new RuntimeException("setIdentifierProperty(Property) is only allowed on RootClass instances"); }
default void setDiscriminator(Value value) { throw new RuntimeException("Method 'setDiscriminator(Value)' can only be called on RootClass instances"); }
void setProxyInterfaceName(String name);
void setLazy(boolean b);
Iterator<Subclass> getSubclassIterator();
Expand All @@ -64,7 +66,6 @@ public interface PersistentClassWrapper extends Wrapper {
boolean isInherited();
boolean isJoinedSubclass();
boolean isLazy();
default boolean isLazyPropertiesCacheable() { throw new RuntimeException("Method 'isLazyPropertiesCacheable()' can only be called on RootClass instances"); }
boolean isMutable();
boolean isPolymorphic();
boolean isVersioned();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,19 @@
public class PersistentClassWrapperFactory {

public static PersistentClassWrapper createRootClassWrapper() {
return (PersistentClassWrapper)Proxy.newProxyInstance(
PersistentClassWrapperFactory.class.getClassLoader(),
new Class[] { PersistentClassWrapper.class },
new PersistentClassWrapperInvocationHandler(new RootClassWrapperImpl()));
return new RootClassWrapperImpl();
}

public static PersistentClassWrapper createSingleTableSubclassWrapper(PersistentClassWrapper superClassWrapper) {
return (PersistentClassWrapper)Proxy.newProxyInstance(
PersistentClassWrapperFactory.class.getClassLoader(),
new Class[] { PersistentClassWrapper.class },
new PersistentClassWrapperInvocationHandler(
new SingleTableSubclassWrapperImpl(superClassWrapper.getWrappedObject())));
return new SingleTableSubclassWrapperImpl(superClassWrapper.getWrappedObject());
}

public static PersistentClassWrapper createJoinedSubclassWrapper(PersistentClassWrapper superClassWrapper) {
return (PersistentClassWrapper)Proxy.newProxyInstance(
PersistentClassWrapperFactory.class.getClassLoader(),
new Class[] { PersistentClassWrapper.class },
new PersistentClassWrapperInvocationHandler(
new JoinedSubclassWrapperImpl(superClassWrapper.getWrappedObject())));
return new JoinedSubclassWrapperImpl(superClassWrapper.getWrappedObject());
}

public static PersistentClassWrapper createSpecialRootClassWrapper(Property property) {
return (PersistentClassWrapper)Proxy.newProxyInstance(
PersistentClassWrapperFactory.class.getClassLoader(),
new Class[] { PersistentClassWrapper.class },
new PersistentClassWrapperInvocationHandler(
new SpecialRootClassWrapperImpl(property)));
return new SpecialRootClassWrapperImpl(property);
}

public static PersistentClassWrapper createPersistentClassWrapper(PersistentClassWrapper persistentClassWrapper) {
Expand Down