Class RailsNamingStrategy

  • All Implemented Interfaces:
    Serializable, org.hibernate.cfg.NamingStrategy

    public class RailsNamingStrategy
    extends Object
    implements org.hibernate.cfg.NamingStrategy, Serializable
    类似Rails的数据库表名、列名命名策略
    Author:
    chaostone
    See Also:
    the default strategy, Serialized Form
    • Constructor Detail

      • RailsNamingStrategy

        public RailsNamingStrategy()
    • Method Detail

      • classToTableName

        public String classToTableName​(String className)
        根据实体名(entityName)命名表
        Specified by:
        classToTableName in interface org.hibernate.cfg.NamingStrategy
        Parameters:
        className -
      • tableName

        public String tableName​(String tableName)
        对自动起名和使体内集合配置的表名,添加前缀
         配置好的实体表名和关联表的名字都会经过此方法。
         
        Specified by:
        tableName in interface org.hibernate.cfg.NamingStrategy
      • columnName

        public String columnName​(String columnName)
        对配置文件起好的列名,不进行处理
        Specified by:
        columnName in interface org.hibernate.cfg.NamingStrategy
      • logicalColumnName

        public String logicalColumnName​(String columnName,
                                        String propertyName)
        数据列的逻辑名
         如果有列名,不做处理,否则按照属性自动起名.
         该策略保证columnName=logicalColumnName
         
        Specified by:
        logicalColumnName in interface org.hibernate.cfg.NamingStrategy
      • propertyToColumnName

        public String propertyToColumnName​(String propertyName)
        根据属性名自动起名
         将混合大小写,带有.分割的属性描述,转换成下划线分割的名称。
         属性名字包括:简单属性、集合属性、组合属性(component.name)
         
        Specified by:
        propertyToColumnName in interface org.hibernate.cfg.NamingStrategy
        Parameters:
        propertyName -
      • joinKeyColumnName

        public String joinKeyColumnName​(String joinedColumn,
                                        String joinedTable)
        Return the argument
        Specified by:
        joinKeyColumnName in interface org.hibernate.cfg.NamingStrategy
      • foreignKeyColumnName

        public String foreignKeyColumnName​(String propertyName,
                                           String propertyEntityName,
                                           String propertyTableName,
                                           String referencedColumnName)
        Return the property name or propertyTableName
        Specified by:
        foreignKeyColumnName in interface org.hibernate.cfg.NamingStrategy
      • collectionTableName

        public String collectionTableName​(String ownerEntity,
                                          String ownerEntityTable,
                                          String associatedEntity,
                                          String associatedEntityTable,
                                          String propertyName)
        Collection Table
        Specified by:
        collectionTableName in interface org.hibernate.cfg.NamingStrategy
      • logicalCollectionTableName

        public String logicalCollectionTableName​(String tableName,
                                                 String ownerEntityTable,
                                                 String associatedEntityTable,
                                                 String propertyName)
        Returns either the table name if explicit or if there is an associated table, the concatenation of owner entity table and associated table otherwise the concatenation of owner entity table and the unqualified property name
        Specified by:
        logicalCollectionTableName in interface org.hibernate.cfg.NamingStrategy
      • logicalCollectionColumnName

        public String logicalCollectionColumnName​(String columnName,
                                                  String propertyName,
                                                  String referencedColumn)
        Return the column name if explicit or the concatenation of the property name and the referenced column
        Specified by:
        logicalCollectionColumnName in interface org.hibernate.cfg.NamingStrategy
      • setTableNamingStrategy

        public void setTableNamingStrategy​(TableNamingStrategy tableNamingStrategy)
      • addUnderscores

        protected static String addUnderscores​(String name)
      • unqualify

        protected static String unqualify​(String qualifiedName)