net.java.ao.schema.TransformsTableNameConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of activeobjects-core Show documentation
Show all versions of activeobjects-core Show documentation
This is the core library for Active Objects. It is generic and can be embedded in any environment.
As such it is generic and won't contain all connection pooling, etc.
package net.java.ao.schema;
import java.util.List;
import java.util.Objects;
import static net.java.ao.Common.convertSimpleClassName;
abstract class TransformsTableNameConverter extends CanonicalClassNameTableNameConverter {
private List transforms;
private CanonicalClassNameTableNameConverter delegateTableNameConverter;
TransformsTableNameConverter(List transforms, CanonicalClassNameTableNameConverter delegateTableNameConverter) {
this.transforms = Objects.requireNonNull(transforms, "transforms can't be null");
this.delegateTableNameConverter = Objects.requireNonNull(delegateTableNameConverter, "delegateTableNameConverter can't be null");
}
@Override
protected final String getName(String entityClassCanonicalName) {
return delegateTableNameConverter.getName(transform(entityClassCanonicalName));
}
private String transform(String entityClassCanonicalName) {
for (Transform transform : transforms) {
if (transform.accept(entityClassCanonicalName)) {
return transform.apply(entityClassCanonicalName);
}
}
return entityClassCanonicalName;
}
static interface Transform {
boolean accept(String entityClassCanonicalName);
String apply(String entityClassCanonicalName);
}
final static class ClassNameTableNameConverter extends CanonicalClassNameTableNameConverter {
@Override
protected String getName(String entityClassCanonicalName) {
return convertSimpleClassName(entityClassCanonicalName);
}
}
}