001package com.avaje.ebean.config; 002 003import com.avaje.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 031 * the database platform 032 */ 033 void setDatabasePlatform(DatabasePlatform databasePlatform); 034 035 /** 036 * Returns the table name for a given Class. 037 * <p> 038 * This method is always called and should take into account @Table 039 * annotations etc. This means you can choose to override the settings defined 040 * by @Table if you wish. 041 * </p> 042 * 043 * @param beanClass 044 * the bean class 045 * 046 * @return the table name for the entity class 047 */ 048 TableName getTableName(Class<?> beanClass); 049 050 /** 051 * Returns the ManyToMany join table name (aka the intersection table). 052 * 053 * @param lhsTable 054 * the left hand side bean table 055 * @param rhsTable 056 * the right hand side bean table 057 * 058 * @return the many to many join table name 059 */ 060 TableName getM2MJoinTableName(TableName lhsTable, TableName rhsTable); 061 062 /** 063 * Return the column name given the property name. 064 * 065 * @return the column name for a given property 066 */ 067 String getColumnFromProperty(Class<?> beanClass, String propertyName); 068 069 /** 070 * Return the property name from the column name. 071 * <p> 072 * This is used to help mapping of raw SQL queries onto bean properties. 073 * </p> 074 * 075 * @param beanClass 076 * the bean class 077 * @param dbColumnName 078 * the db column name 079 * 080 * @return the property name from the column name 081 */ 082 String getPropertyFromColumn(Class<?> beanClass, String dbColumnName); 083 084 /** 085 * Return the sequence name given the table name (for DB's that use sequences). 086 * <p> 087 * Typically you might append "_seq" to the table name as an example. 088 * </p> 089 * 090 * @param tableName 091 * the table name 092 * 093 * @return the sequence name 094 */ 095 String getSequenceName(String tableName, String pkColumn); 096 097 /** 098 * Return true if a prefix should be used building a foreign key name. 099 * <p> 100 * This by default is true and this works well when the primary key column 101 * names are simply "id". In this case a prefix (such as "order" and 102 * "customer" etc) is added to the foreign key column producing "order_id" and 103 * "customer_id". 104 * </p> 105 * <p> 106 * This should return false when your primary key columns are the same as the 107 * foreign key columns. For example, when the primary key columns are 108 * "order_id", "cust_id" etc ... and they are the same as the foreign key 109 * column names. 110 * </p> 111 */ 112 boolean isUseForeignKeyPrefix(); 113 114 /** 115 * Load setting from properties. 116 */ 117 void loadFromProperties(PropertiesWrapper properties); 118 119}