Skip to content

Commit

Permalink
#2124 - ENH: Add name() attribute to @DBArray, @dbjson, @DbJsonB, @DbMap
Browse files Browse the repository at this point in the history
  • Loading branch information
rbygrave committed Dec 7, 2020
1 parent d68f477 commit 7389a8b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ebean-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-annotation</artifactId>
<version>6.14-SNAPSHOT</version>
<version>6.15</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,19 +311,23 @@ private void initDbJson(DeployBeanProperty prop) {
DbMap dbMap = get(prop, DbMap.class);
if (dbMap != null) {
util.setDbMap(prop, dbMap);
setColumnName(prop, dbMap.name());
}
DbJson dbJson = get(prop, DbJson.class);
if (dbJson != null) {
util.setDbJsonType(prop, dbJson);
setColumnName(prop, dbJson.name());
} else {
DbJsonB dbJsonB = get(prop, DbJsonB.class);
if (dbJsonB != null) {
util.setDbJsonBType(prop, dbJsonB);
setColumnName(prop, dbJsonB.name());
}
}
DbArray dbArray = get(prop, DbArray.class);
if (dbArray != null) {
util.setDbArray(prop, dbArray);
setColumnName(prop, dbArray.name());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ void readEmbeddedAttributeOverrides(DeployBeanPropertyAssocOne<?> prop) {
}

void readColumn(Column columnAnn, DeployBeanProperty prop) {

if (!isEmpty(columnAnn.name())) {
prop.setDbColumn(databasePlatform.convertQuotedIdentifiers(columnAnn.name()));
}

setColumnName(prop, columnAnn.name());
prop.setDbInsertable(columnAnn.insertable());
prop.setDbUpdateable(columnAnn.updatable());
prop.setNullable(columnAnn.nullable());
Expand All @@ -125,6 +121,12 @@ void readColumn(Column columnAnn, DeployBeanProperty prop) {
}
}

protected void setColumnName(DeployBeanProperty prop, String name) {
if (!isEmpty(name)) {
prop.setDbColumn(databasePlatform.convertQuotedIdentifiers(name));
}
}

/**
* Return true if the validation groups are {@link Default} (respectively empty)
* can be applied to DDL generation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ public void updateIncludesJsonColumn_when_loadedAndNotDirtyAware() {

final List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("update ebasic_json_list set name=?, bean_set=?, bean_list=?, plain_bean=?, version=? where id=?");
assertThat(sql.get(0)).contains("update ebasic_json_list set name=?, beans=?, bean_list=?, plain_bean=?, version=? where id=?");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void update_when_dirty_SetListMap() {
List<String> sql = LoggedSqlCollector.stop();

// we don't update the phone numbers (as they are not dirty)
assertSql(sql.get(0)).contains("update ebasic_json_list set bean_set=?, bean_list=?, bean_map=?, plain_bean=?, version=? where id=? and version=?");
assertSql(sql.get(0)).contains("update ebasic_json_list set beans=?, bean_list=?, bean_map=?, plain_bean=?, version=? where id=? and version=?");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class EBasicJsonList {

String name;

@DbJson(length = 700)
@DbJson(length = 700, name = "beans")
Set<PlainBean> beanSet;

@DbJsonB
Expand Down

0 comments on commit 7389a8b

Please sign in to comment.