All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.robe.hibernate.conf.RobeHibernateNamingStrategy Maven / Gradle / Ivy

There is a newer version: 0.5.0.0-1039
Show newest version
package io.robe.hibernate.conf;

import org.hibernate.cfg.DefaultNamingStrategy;

/**
 * Custom named strategy for table names
 * read from robe.yml -hibernate.prefix
 */
public class RobeHibernateNamingStrategy extends DefaultNamingStrategy {
    private static final long serialVersionUID = 1L;
    private String prefix;

    public RobeHibernateNamingStrategy(String prefix) {
        this.prefix = prefix;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    @Override
    public String classToTableName(final String className) {
        return this.addPrefix(super.classToTableName(className));
    }

    @Override
    public String collectionTableName(final String ownerEntity,
                                      final String ownerEntityTable, final String associatedEntity,
                                      final String associatedEntityTable, final String propertyName) {
        return this.addPrefix(super.collectionTableName(ownerEntity,
                ownerEntityTable, associatedEntity, associatedEntityTable,
                propertyName));
    }

    @Override
    public String logicalCollectionTableName(final String tableName,
                                             final String ownerEntityTable, final String associatedEntityTable,
                                             final String propertyName) {
        return this.addPrefix(super.logicalCollectionTableName(tableName,
                ownerEntityTable, associatedEntityTable, propertyName));
    }

    private String addPrefix(final String composedTableName) {
        return this.prefix + composedTableName;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy