diff --git a/DaoGenerator/src-template/dao.ftl b/DaoGenerator/src-template/dao.ftl index 60f7045b1..2d2184918 100644 --- a/DaoGenerator/src-template/dao.ftl +++ b/DaoGenerator/src-template/dao.ftl @@ -135,10 +135,19 @@ as property>\"${property.columnName}\"<#if property_has_next>,);") } <#else> <#-- nullable, non-protobuff --> + <#if property.pkAutoincrement> + //PrimaryKey Autoincrement,so we do not care this property. + /** ${property.javaTypeInEntity} ${property.propertyName} = entity.get${property.propertyName?cap_first}(); + if (${property.propertyName} != null) { + stmt.bind${toBindType[property.propertyType]}(${property_index + 1}, ${property.databaseValueExpression}); + } + */ + <#else> ${property.javaTypeInEntity} ${property.propertyName} = entity.get${property.propertyName?cap_first}(); if (${property.propertyName} != null) { stmt.bind${toBindType[property.propertyType]}(${property_index + 1}, ${property.databaseValueExpression}); } + <#list entity.toOneRelations as toOne> diff --git a/DaoGenerator/src-template/entity.ftl b/DaoGenerator/src-template/entity.ftl index 0e383d847..273ea3293 100644 --- a/DaoGenerator/src-template/entity.ftl +++ b/DaoGenerator/src-template/entity.ftl @@ -101,21 +101,48 @@ ${keepFields!} // KEEP FIELDS END <#if entity.constructors> public ${entity.className}() { + <#list entity.properties as property> + <#if property.defValType> + this.${property.propertyName} = ${property.defValue}; + + } <#if entity.propertiesPk?has_content && entity.propertiesPk?size != entity.properties?size> + <#if entity.propertiesPk?has_content && entity.propertiesPk?size == 1 && entity.propertiesPk[0].pkAutoincrement> + //pass one aleady constructor. + <#else> public ${entity.className}(<#list entity.propertiesPk as -property>${property.javaType} ${property.propertyName}<#if property_has_next>, ) { -<#list entity.propertiesPk as property> - this.${property.propertyName} = ${property.propertyName}; - +property><#if !property.pkAutoincrement>${property.javaType} ${property.propertyName}<#if property_has_next>, ) { + this(); + <#list entity.propertiesPk as property> + <#if !property.pkAutoincrement>this.${property.propertyName} = ${property.propertyName}; + <#if property.defValType> + if(this.${property.propertyName}==null)this.${property.propertyName} = ${property.defValue}; + + } + +<#if entity.propertiesPk?has_content && (entity.propertiesPk?size > 0) && entity.propertiesPk[0].pkAutoincrement> + public ${entity.className}(<#list entity.properties as +property><#if !property.pkAutoincrement>${property.javaTypeInEntity} ${property.propertyName}<#if property_has_next>, ) { +<#list entity.properties as property> + <#if !property.pkAutoincrement>this.${property.propertyName} = ${property.propertyName}; + <#if property.defValType> + if(this.${property.propertyName}==null)this.${property.propertyName} = ${property.defValue}; + + + } + public ${entity.className}(<#list entity.properties as property>${property.javaTypeInEntity} ${property.propertyName}<#if property_has_next>, ) { <#list entity.properties as property> this.${property.propertyName} = ${property.propertyName}; + <#if property.defValType> + if(this.${property.propertyName}==null)this.${property.propertyName} = ${property.defValue}; + } @@ -153,6 +180,9 @@ ${property.javaDocSetter} public void set${property.propertyName?cap_first}(${property.javaTypeInEntity} ${property.propertyName}) { this.${property.propertyName} = ${property.propertyName}; + <#if property.defValType> + if(this.${property.propertyName}==null) this.${property.propertyName} = ${property.defValue}; + } diff --git a/DaoGenerator/src/de/greenrobot/daogenerator/Property.java b/DaoGenerator/src/de/greenrobot/daogenerator/Property.java index 14534df55..f2ae8e40c 100644 --- a/DaoGenerator/src/de/greenrobot/daogenerator/Property.java +++ b/DaoGenerator/src/de/greenrobot/daogenerator/Property.java @@ -26,7 +26,12 @@ public static class PropertyBuilder { public PropertyBuilder(Schema schema, Entity entity, PropertyType propertyType, String propertyName) { property = new Property(schema, entity, propertyType, propertyName); } - + public PropertyBuilder defValue(String pVal) + { + property.defValue = pVal; + property.defValType = true; + return this; + } public PropertyBuilder columnName(String columnName) { property.columnName = columnName; return this; @@ -166,6 +171,8 @@ public Property getProperty() { private final Entity entity; private PropertyType propertyType; private final String propertyName; + private boolean defValType; + private Object defValue; private String columnName; private String columnType; @@ -199,6 +206,7 @@ public Property getProperty() { private String javaType; public Property(Schema schema, Entity entity, PropertyType propertyType, String propertyName) { + defValType = false; this.schema = schema; this.entity = entity; this.propertyName = propertyName; @@ -229,7 +237,7 @@ public boolean isPrimaryKey() { return primaryKey; } - public boolean isAutoincrement() { + public boolean isPkAutoincrement() { return pkAutoincrement; } @@ -248,6 +256,14 @@ public boolean isNotNull() { public String getJavaType() { return javaType; } + public String getDefValue() + { + return (String)defValue; + } + public boolean isDefValType() + { + return defValType; + } public String getJavaTypeInEntity() { if (customTypeClassName != null) {