mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
This commit is contained in:
@@ -41,4 +41,11 @@ public class MatchingNamingConvention extends AbstractNamingConvention {
|
||||
public String getPropertyFromColumn(Class<?> beanClass, String dbColumnName) {
|
||||
return dbColumnName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForeignKey(String prefix, String fkProperty) {
|
||||
// add fkProperty as init caps
|
||||
return prefix + fkProperty.substring(0, 1).toUpperCase() + fkProperty.substring(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -100,6 +100,15 @@ public interface NamingConvention {
|
||||
*/
|
||||
boolean isUseForeignKeyPrefix();
|
||||
|
||||
/**
|
||||
* Return the foreign key column given the local and foreign properties.
|
||||
*
|
||||
* @param prefix the local column used to prefix the fk column
|
||||
* @param fkProperty the property name of the foreign key
|
||||
* @return the foreign key column
|
||||
*/
|
||||
String getForeignKey(String prefix, String fkProperty);
|
||||
|
||||
/**
|
||||
* Load setting from properties.
|
||||
*/
|
||||
|
||||
@@ -100,6 +100,11 @@ public class UnderscoreNamingConvention extends AbstractNamingConvention {
|
||||
this.digitsCompressed = digitsCompressed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForeignKey(String prefix, String fkProperty) {
|
||||
return prefix + "_" + toUnderscoreFromCamel(fkProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert and return the string to underscore from camel case.
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import com.avaje.ebean.config.EncryptKey;
|
||||
import com.avaje.ebean.config.NamingConvention;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebeaninternal.server.cache.SpiCacheManager;
|
||||
import com.avaje.ebeaninternal.server.deploy.id.IdBinder;
|
||||
@@ -30,6 +31,11 @@ public interface BeanDescriptorMap {
|
||||
*/
|
||||
SpiCacheManager getCacheManager();
|
||||
|
||||
/**
|
||||
* Return the naming convention.
|
||||
*/
|
||||
NamingConvention getNamingConvention();
|
||||
|
||||
/**
|
||||
* Return the BeanDescriptor for a given class.
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,8 @@ public class BeanTable {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BeanTable.class);
|
||||
|
||||
private final BeanDescriptorMap owner;
|
||||
|
||||
private final Class<?> beanType;
|
||||
|
||||
/**
|
||||
@@ -34,6 +36,7 @@ public class BeanTable {
|
||||
* Create the BeanTable.
|
||||
*/
|
||||
public BeanTable(DeployBeanTable mutable, BeanDescriptorMap owner) {
|
||||
this.owner = owner;
|
||||
this.beanType = mutable.getBeanType();
|
||||
this.baseTable = InternString.intern(mutable.getBaseTable());
|
||||
this.idProperties = mutable.createIdProperties(owner);
|
||||
@@ -94,14 +97,13 @@ public class BeanTable {
|
||||
String lc = prop.getDbColumn();
|
||||
String fk = lc;
|
||||
if (foreignKeyPrefix != null) {
|
||||
fk = foreignKeyPrefix + "_" + fk;
|
||||
fk = owner.getNamingConvention().getForeignKey(foreignKeyPrefix, fk);
|
||||
}
|
||||
|
||||
if (complexKey) {
|
||||
// just to copy the column name rather than prefix with the foreignKeyPrefix.
|
||||
// I think that with complex keys this is the more common approach.
|
||||
String msg = "On table[" + baseTable + "] foreign key column [" + lc + "]";
|
||||
logger.debug(msg);
|
||||
logger.debug("On table[{}] foreign key column [{}]", baseTable, lc);
|
||||
fk = lc;
|
||||
}
|
||||
if (sqlFormulaSelect != null) {
|
||||
|
||||
Reference in New Issue
Block a user