001package io.ebean.config; 002 003import io.ebean.config.dbplatform.DatabasePlatform; 004 005/** 006 * Defines the naming convention for converting between logical property 007 * names/entity names and physical DB column names/table names. 008 * <p> 009 * The main goal of the naming convention is to reduce the amount of 010 * configuration required in the mapping (especially when mapping between column 011 * and property names). 012 * </p> 013 * <p> 014 * Note that if you do not define a NamingConvention the default one will be 015 * used and you can configure it's behaviour via properties. 016 * </p> 017 */ 018public interface NamingConvention { 019 020 /** 021 * Set the associated DatabasePlaform. 022 * <p> 023 * This is set after the DatabasePlatform has been associated. 024 * </p> 025 * <p> 026 * The purpose of this is to enable NamingConvention to be able to support 027 * database platform specific configuration. 028 * </p> 029 * 030 * @param databasePlatform the database platform 031 */ 032 void setDatabasePlatform(DatabasePlatform databasePlatform); 033 034 /** 035 * Returns the table name for a given Class. 036 * <p> 037 * This method is always called and should take into account @Table 038 * annotations etc. This means you can choose to override the settings defined 039 * by @Table if you wish. 040 * </p> 041 * 042 * @param beanClass the bean class 043 * @return the table name for the entity class 044 */ 045 TableName getTableName(Class<?> beanClass); 046 047 /** 048 * Returns the ManyToMany join table name (aka the intersection table). 049 * 050 * @param lhsTable the left hand side bean table 051 * @param rhsTable the right hand side bean table 052 * @return the many to many join table name 053 */ 054 TableName getM2MJoinTableName(TableName lhsTable, TableName rhsTable); 055 056 /** 057 * Derive a DB Column from a FK table and column. 058 */ 059 String deriveM2MColumn(String tableName, String dbColumn); 060 061 /** 062 * Return the full table name taking into account quoted identifiers. 063 */ 064 String getTableName(String catalog, String schema, String name); 065 066 /** 067 * Return the column name given the property name. 068 * 069 * @return the column name for a given property 070 */ 071 String getColumnFromProperty(Class<?> beanClass, String propertyName); 072 073 /** 074 * Return the sequence name given the table name (for DB's that use sequences). 075 * <p> 076 * Typically you might append "_seq" to the table name as an example. 077 * </p> 078 * 079 * @param tableName the table name 080 * @return the sequence name 081 */ 082 String getSequenceName(String tableName, String pkColumn); 083 084 /** 085 * Return true if a prefix should be used building a foreign key name. 086 * <p> 087 * This by default is true and this works well when the primary key column 088 * names are simply "id". In this case a prefix (such as "order" and 089 * "customer" etc) is added to the foreign key column producing "order_id" and 090 * "customer_id". 091 * </p> 092 * <p> 093 * This should return false when your primary key columns are the same as the 094 * foreign key columns. For example, when the primary key columns are 095 * "order_id", "cust_id" etc ... and they are the same as the foreign key 096 * column names. 097 * </p> 098 */ 099 boolean isUseForeignKeyPrefix(); 100 101 /** 102 * Return the foreign key column given the local and foreign properties. 103 * 104 * @param prefix the local column used to prefix the fk column 105 * @param fkProperty the property name of the foreign key 106 * @return the foreign key column 107 */ 108 String getForeignKey(String prefix, String fkProperty); 109 110 /** 111 * Load setting from properties. 112 */ 113 void loadFromProperties(PropertiesWrapper properties); 114 115}