Skip to content

Commit

Permalink
Handle version properties for Kotlin code generation (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
nakamura-to authored Sep 12, 2020
1 parent c0745b8 commit d2b67e0
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class EntityPropertyDesc {

protected String propertyClassName;

protected String languageClassName;

protected boolean id;

protected GenerationType generationType;
Expand Down Expand Up @@ -58,6 +60,14 @@ public String getPropertyClassSimpleName() {
return ClassUtil.getSimpleName(propertyClassName);
}

public String getLanguageClassSimpleName() {
return ClassUtil.getSimpleName(languageClassName);
}

public void setLanguageClassName(String languageClassName) {
this.languageClassName = languageClassName;
}

public void setId(boolean id) {
this.id = id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ protected void handlePropertyClass(
columnMeta.getSqlType()));
className = String.class.getName();
}
propertyDesc.setPropertyClassName(className);
LanguageClass languageClass = languageClassResolver.resolve(className, columnMeta);
propertyDesc.setPropertyClassName(languageClass.getClassName());
propertyDesc.setLanguageClassName(languageClass.getClassName());
propertyDesc.setDefaultValue(languageClass.getDefaultValue());
if (columnMeta.isNullable() || "null".equals(languageClass.getDefaultValue())) {
propertyDesc.setNullable(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface ${simpleName} {
* @return the <#if entityDesc.entityPrefix??>${entityDesc.entityPrefix}</#if>${entityDesc.simpleName}<#if entityDesc.entitySuffix??>${entityDesc.entitySuffix}</#if> entity
*/
@Select
fun selectById(<#list entityDesc.idEntityPropertyDescs as property>${property.name}: ${property.propertyClassSimpleName}<#if property_has_next>, </#if></#list>): <#if entityDesc.entityPrefix??>${entityDesc.entityPrefix}</#if>${entityDesc.simpleName}<#if entityDesc.entitySuffix??>${entityDesc.entitySuffix}</#if>
fun selectById(<#list entityDesc.idEntityPropertyDescs as property>${property.name}: ${property.languageClassSimpleName}<#if property_has_next>, </#if></#list>): <#if entityDesc.entityPrefix??>${entityDesc.entityPrefix}</#if>${entityDesc.simpleName}<#if entityDesc.entitySuffix??>${entityDesc.entitySuffix}</#if>

</#if>
<#if entityDesc.idEntityPropertyDescs?size gt 0 && entityDesc.versionEntityPropertyDesc??>
Expand All @@ -39,7 +39,7 @@ interface ${simpleName} {
* @return the <#if entityDesc.entityPrefix??>${entityDesc.entityPrefix}</#if>${entityDesc.simpleName}<#if entityDesc.entitySuffix??>${entityDesc.entitySuffix}</#if> entity
*/
@Select(ensureResult = true)
fun selectByIdAndVersion(<#list entityDesc.idEntityPropertyDescs as property>${property.name}: ${property.propertyClassSimpleName}, </#list>${entityDesc.versionEntityPropertyDesc.name}: ${entityDesc.versionEntityPropertyDesc.propertyClassSimpleName}): <#if entityDesc.entityPrefix??>${entityDesc.entityPrefix}</#if>${entityDesc.simpleName}<#if entityDesc.entitySuffix??>${entityDesc.entitySuffix}</#if>
fun selectByIdAndVersion(<#list entityDesc.idEntityPropertyDescs as property>${property.name}: ${property.languageClassSimpleName}, </#list>${entityDesc.versionEntityPropertyDesc.name}: ${entityDesc.versionEntityPropertyDesc.languageClassSimpleName}): <#if entityDesc.entityPrefix??>${entityDesc.entityPrefix}</#if>${entityDesc.simpleName}<#if entityDesc.entitySuffix??>${entityDesc.entitySuffix}</#if>

</#if>
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class <#if entityPrefix??>${entityPrefix}</#if>${simpleName}<#if entitySuffix??>
<#if property.showColumnName && property.columnName??>
@Column(name = "${property.columnName}")
</#if>
var ${property.name}: ${property.propertyClassSimpleName}<#if property.nullable>?</#if> = ${property.defaultValue}
var ${property.name}: ${property.languageClassSimpleName}<#if property.nullable>?</#if> = ${property.defaultValue}
</#list>
<#if originalStatesPropertyName??>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ interface HogeDao {
@Select
fun selectById(id: Int): Hoge

/**
* @param id
* @param version
* @return the Hoge entity
*/
@Select(ensureResult = true)
fun selectByIdAndVersion(id: Int, version: Int): Hoge

/**
* @param entity
* @return affected rows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.seasar.doma.Entity
import org.seasar.doma.Id
import org.seasar.doma.Metamodel
import org.seasar.doma.Table
import org.seasar.doma.Version

/**
* COMMENT for HOGE
Expand All @@ -23,6 +24,7 @@ class Hoge {
var empName: String? = null

/** COMMENT for VERSION */
@Version
@Column(name = "VERSION")
var version: Int = -1
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.seasar.doma.Entity
import org.seasar.doma.Id
import org.seasar.doma.OriginalStates
import org.seasar.doma.Table
import org.seasar.doma.Version

/**
* COMMENT for HOGE
Expand All @@ -23,6 +24,7 @@ class Hoge {
var empName: String? = null

/** COMMENT for VERSION */
@Version
@Column(name = "VERSION")
var version: Int = -1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ interface HogeDao {
@Select
fun selectById(id: Int): Hoge

/**
* @param id
* @param version
* @return the Hoge entity
*/
@Select(ensureResult = true)
fun selectByIdAndVersion(id: Int, version: Int): Hoge

/**
* @param entity
* @return affected rows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ interface THogeDao {
@Select
fun selectById(id: Int): THoge

/**
* @param id
* @param version
* @return the THoge entity
*/
@Select(ensureResult = true)
fun selectByIdAndVersion(id: Int, version: Int): THoge

/**
* @param entity
* @return affected rows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ interface THogeEntityDao {
@Select
fun selectById(id: Int): THogeEntity

/**
* @param id
* @param version
* @return the THogeEntity entity
*/
@Select(ensureResult = true)
fun selectByIdAndVersion(id: Int, version: Int): THogeEntity

/**
* @param entity
* @return affected rows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ interface HogeEntityDao {
@Select
fun selectById(id: Int): HogeEntity

/**
* @param id
* @param version
* @return the HogeEntity entity
*/
@Select(ensureResult = true)
fun selectByIdAndVersion(id: Int, version: Int): HogeEntity

/**
* @param entity
* @return affected rows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.seasar.doma.Column
import org.seasar.doma.Entity
import org.seasar.doma.Id
import org.seasar.doma.Table
import org.seasar.doma.Version

/**
* COMMENT for HOGE
Expand All @@ -22,6 +23,7 @@ class Hoge {
var empName: String? = null

/** COMMENT for VERSION */
@Version
@Column(name = "VERSION")
var version: Int = -1
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.seasar.doma.Column
import org.seasar.doma.Entity
import org.seasar.doma.Id
import org.seasar.doma.Table
import org.seasar.doma.Version

/**
* COMMENT for HOGE
Expand All @@ -22,6 +23,7 @@ class THoge {
var empName: String? = null

/** COMMENT for VERSION */
@Version
@Column(name = "VERSION")
var version: Int = -1
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.seasar.doma.Column
import org.seasar.doma.Entity
import org.seasar.doma.Id
import org.seasar.doma.Table
import org.seasar.doma.Version

/**
* COMMENT for HOGE
Expand All @@ -22,6 +23,7 @@ class THogeEntity {
var empName: String? = null

/** COMMENT for VERSION */
@Version
@Column(name = "VERSION")
var version: Int = -1
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.seasar.doma.Column
import org.seasar.doma.Entity
import org.seasar.doma.Id
import org.seasar.doma.Table
import org.seasar.doma.Version

/**
* COMMENT for HOGE
Expand All @@ -22,6 +23,7 @@ class HogeEntity {
var empName: String? = null

/** COMMENT for VERSION */
@Version
@Column(name = "VERSION")
var version: Int = -1
}

0 comments on commit d2b67e0

Please sign in to comment.