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   * Return the column name given the property name.
058   *
059   * @return the column name for a given property
060   */
061  String getColumnFromProperty(Class<?> beanClass, String propertyName);
062
063  /**
064   * Return the property name from the column name.
065   * <p>
066   * This is used to help mapping of raw SQL queries onto bean properties.
067   * </p>
068   *
069   * @param beanClass    the bean class
070   * @param dbColumnName the db column name
071   * @return the property name from the column name
072   */
073  String getPropertyFromColumn(Class<?> beanClass, String dbColumnName);
074
075  /**
076   * Return the sequence name given the table name (for DB's that use sequences).
077   * <p>
078   * Typically you might append "_seq" to the table name as an example.
079   * </p>
080   *
081   * @param tableName the table name
082   * @return the sequence name
083   */
084  String getSequenceName(String tableName, String pkColumn);
085
086  /**
087   * Return true if a prefix should be used building a foreign key name.
088   * <p>
089   * This by default is true and this works well when the primary key column
090   * names are simply "id". In this case a prefix (such as "order" and
091   * "customer" etc) is added to the foreign key column producing "order_id" and
092   * "customer_id".
093   * </p>
094   * <p>
095   * This should return false when your primary key columns are the same as the
096   * foreign key columns. For example, when the primary key columns are
097   * "order_id", "cust_id" etc ... and they are the same as the foreign key
098   * column names.
099   * </p>
100   */
101  boolean isUseForeignKeyPrefix();
102
103  /**
104   * Return the foreign key column given the local and foreign properties.
105   *
106   * @param prefix the local column used to prefix the fk column
107   * @param fkProperty the property name of the foreign key
108   * @return the foreign key column
109   */
110  String getForeignKey(String prefix, String fkProperty);
111
112  /**
113   * Load setting from properties.
114   */
115  void loadFromProperties(PropertiesWrapper properties);
116
117}