001package io.ebean.config;
002
003/**
004 * The JPA naming convention where column names match property names and table
005 * names match entity names.
006 * <p>
007 * The JPA specification states that the in the case of no annotations the name
008 * of the class will be take as the table name and the name of a property will
009 * be taken as the name of the column.
010 * </p>
011 *
012 * @author emcgreal
013 */
014public class MatchingNamingConvention extends AbstractNamingConvention {
015
016  /**
017   * Create with a sequence format of "{table}_seq".
018   */
019  public MatchingNamingConvention() {
020    super();
021  }
022
023  /**
024   * Instantiates with a specific format for DB sequences.
025   *
026   * @param sequenceFormat the sequence format
027   */
028  public MatchingNamingConvention(String sequenceFormat) {
029    super(sequenceFormat);
030  }
031
032  @Override
033  public String getColumnFromProperty(Class<?> beanClass, String propertyName) {
034    return quoteIdentifiers(propertyName);
035  }
036
037  @Override
038  public TableName getTableNameByConvention(Class<?> beanClass) {
039
040    return new TableName(getCatalog(), getSchema(), beanClass.getSimpleName());
041  }
042
043  @Override
044  public String getPropertyFromColumn(Class<?> beanClass, String dbColumnName) {
045    return dbColumnName;
046  }
047
048  @Override
049  public String getForeignKey(String prefix, String fkProperty) {
050    prefix = databasePlatform.unQuote(prefix);
051    fkProperty = databasePlatform.unQuote(fkProperty);
052    // add fkProperty as init caps
053    String fullName = prefix + fkProperty.substring(0, 1).toUpperCase() + fkProperty.substring(1);
054    return quoteIdentifiers(fullName);
055  }
056
057}