I got it!
The mistake I made was that the package name must be part of the returned String:
import org.apache.log4j.Logger; import org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy; import org.hibernate.cfg.reveng.ReverseEngineeringStrategy; import org.hibernate.cfg.reveng.TableIdentifier;
public class MyReverseEngineering extends DelegatingReverseEngineeringStrategy {
private static Logger LOGGER = Logger.getLogger(MyReverseEngineering.class);
/** * A constructor. * * @param delegate * The fall back strategy. */ public MyReverseEngineering(ReverseEngineeringStrategy delegated) { super(delegated); }
/** * {@inheritDoc} */ @Override public String tableToClassName(TableIdentifier tableIdentifier) {
final String defaultClassName = super.tableToClassName(tableIdentifier); LOGGER.warn(defaultClassName); final String packageName = this.extractPackageName(defaultClassName); LOGGER.warn(packageName); final String className = this.defineClassName(tableIdentifier); LOGGER.warn(className); final String concatedString = packageName.concat(className); LOGGER.warn(concatedString); return concatedString; }
private String extractPackageName(String defaultClassName) { int lastIndex = defaultClassName.lastIndexOf("."); final String packageName = defaultClassName.substring(0, lastIndex + 1); return packageName; }
private String defineClassName(TableIdentifier tableIdentifier) { final boolean startsWithT = tableIdentifier.getName().startsWith("T_"); final boolean startsWitht = tableIdentifier.getName().startsWith("t_"); if (startsWithT || startsWitht) { final String firstLetter = tableIdentifier.getName().substring(2, 3).toUpperCase(); final String substring = tableIdentifier.getName().substring(3); final String tableName = firstLetter.concat(substring); return tableName; } else { return super.tableToClassName(tableIdentifier); } } }
This solutions seems to be a little bit ugly. But how can reach ReverseStrategySettings from my strategy? If somebody knows it, please tell me. Otherwise I will use my solution.
Thanks, Till
|