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

com.github.nomou.mybatis.builder.spi.TableNamingStrategy Maven / Gradle / Ivy

There is a newer version: 1.0.0-BETA-20210819
Show newest version
package com.github.nomou.mybatis.builder.spi;

import freework.util.StringUtils2;

public interface TableNamingStrategy {
    /**
     * 默认表名称策略.
     */
    TableNamingStrategy DEFAULT = new TableNamingStrategy() {
        private static final String DAO = "Dao";
        private static final String MAPPER = "Mapper";
        private static final String REPOSITORY = "Repository";

        @Override
        public String getTableName(final Class mapperInterface, final Class domainClass) {
            String domainName = null;
            if (null != domainClass) {
                domainName = domainClass.getSimpleName();
            } else {
                final String mapperName = mapperInterface.getSimpleName();
                if (mapperName.endsWith(MAPPER)) {
                    domainName = mapperName.substring(0, mapperName.length() - MAPPER.length());
                } else if (mapperName.endsWith(DAO)) {
                    domainName = mapperName.substring(0, mapperName.length() - DAO.length());
                } else if (mapperName.endsWith(REPOSITORY)) {
                    domainName = mapperName.substring(0, mapperName.length() - REPOSITORY.length());
                }
            }
            if (null == domainName || domainName.isEmpty()) {
                throw new IllegalStateException(mapperInterface.getCanonicalName() + ": Cannot detect database table name");
            }
            return StringUtils2.camelCaseToUnderscore(domainName, false);
        }
    };

    String getTableName(final Class mapperInterface, final Class domainClass);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy