net.java.ao.schema.UnderscoreTableNameConverter 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.Objects;
import static net.java.ao.Common.convertSimpleClassName;
import static net.java.ao.schema.UnderScoreUtils.camelCaseToUnderScore;
/**
* Imposes an underscore word-separation convention on table
* names. This will convert entity names in the following way:
*
*
*
* Entity Name
* Table Name
*
*
*
* Person
* person
*
*
*
* LicenseRegistration
* license_registration
*
*
*
* Volume4
* volume_4
*
*
*
* Company
* company
*
*
*
* This converter allows for both all-lowercase and all-uppercase
* table name conventions. For example, depending on the configuration,
* LicenseRegistration
may convert to "LICENSE_REGISTRATION".
*
* This converter, coupled with {@link PluralizedTableNameConverter} is
* all that is required to emulate the ActiveRecord table name conversion.
*/
public final class UnderscoreTableNameConverter extends CanonicalClassNameTableNameConverter {
private final Case tableNameCase;
public UnderscoreTableNameConverter(Case tableNameCase) {
this.tableNameCase = Objects.requireNonNull(tableNameCase, "tableNameCase can't be null");
}
@Override
protected String getName(String entityClassCanonicalName) {
return tableNameCase.apply(camelCaseToUnderScore(convertSimpleClassName(entityClassCanonicalName)));
}
}