domaframework / doma-gen Goto Github PK
View Code? Open in Web Editor NEW[deprecated] A code generation tool for Doma
Home Page: https://doma-gen.readthedocs.io/
License: Apache License 2.0
[deprecated] A code generation tool for Doma
Home Page: https://doma-gen.readthedocs.io/
License: Apache License 2.0
一点質問させてください。
domagenで作ったjavaクラスでカラムがNotNullのプロパティに対して、
@NotNullをつけたいと考えています。
そこで質問です。
entity.ftl内でcolumnmetaのnullableの値を参照できれば実現可能と考えているのですが
可能でしょうか。
https://github.com/domaframework/doma-gen/blob/master/src/main/java/org/seasar/doma/extension/gen/ColumnMeta.java
EntityPropertyDescにはColumnMetaの情報を持っていないようだったので
やり方がわからず(そもそもできるのかがわからず)質問させていただいた次第です。
https://github.com/domaframework/doma-gen/blob/master/src/main/java/org/seasar/doma/extension/gen/EntityPropertyDesc.java
作成されるEntityのフィルドはDBの定義により出力されると思いますが、Enumに対応するように出力可能でしょうか?
※後entityConfigにsuperclassNameを指定したらエラーになります。
参考になるページなどあるでしょうか?
configurations {
domaGenRuntime
}
repositories {
mavenCentral()
maven {url 'https://oss.sonatype.org/content/repositories/snapshots/'}
}
dependencies {
domaGenRuntime 'org.seasar.doma:doma-gen:2.18.0'
domaGenRuntime 'org.mariadb.jdbc:mariadb-java-client:2.1.2'
}
task gen << {
ant.taskdef(resource: 'domagentask.properties',
classpath: configurations.domaGenRuntime.asPath)
ant.gen(url: 'jdbc:mariadb://xxx:3306/test',dialectName:"mysql",driverClassName:"org.mariadb.jdbc.Driver", user: 'test', password: 'test',templatePrimaryDir: "src/domaTemplate") {
entityConfig(
superclassName:'samples.domain.DomaEntity'
,packageName:'samples.domain.entity',originalStatesPropertyName:"original",useListener:true
,listenerSuperclassName:'samples.domain.entity.DomaEntityListener'
,overwrite: true
)
daoConfig(packageName:'samples.dao',suffix:"DaoGen" ,overwrite:true)
sqlConfig()
}
}
EntityのpackageNameを4階層以上指定した場合、生成したDaoクラスには、Entityクラスのimport宣言はなくなります。
例:
task gen << {
ant.taskdef(resource: 'domagentask.properties',
classpath: configurations.domaGenRuntime.asPath)
ant.gen(url: 'jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=UTF-8&useSSL=false', user: 'username', password: 'password') {
entityConfig(packageName: 'jp.co.abc.entity',useListener: false)
daoConfig(packageName: 'jp.co.abc.dao')
sqlConfig()
}
}
MYSQL V5.7.xの場合、以下のテーブルに対してAUTO_INCREMENT カラムに@GeneratedValueが付かない。
・DDL
CREATE TABLE TEST
(
ID
INT NOT NULL AUTO_INCREMENT COMMENT 'ID',
DELETE_FLG
BIT DEFAULT 0 NOT NULL COMMENT '削除フラグ',
VERSION
INT DEFAULT 1 NOT NULL COMMENT 'バージョン',
PRIMARY KEY (ID
, DELETE_FLG
)
);
・作成されたEntity
public class Test {
/** ID */
@Id
@Column(name = "ID")
Integer id;
・・・・・
schemaNameオプションを指定しても、指定していないスキーマに属するテーブル情報が出力されてしまいます。
また、showSchemaName: trueを指定しても、出力されるエンティティクラスにスキーマ名が記載されていません。
スキーマ情報が取れていない(?)のかなと思います。
gradlewからの実行です。
java 1.8
mysql 5.7
Gradle 5.3
dependencies {
domaGenRuntime 'org.seasar.doma:doma-gen:2.19.3'
domaGenRuntime 'mysql:mysql-connector-java:8.0.13'
}
def basePackage = 'aaaaaaaaaaaaaaaaa'
def resourceDir = 'aaaaaaaaaaaaaaaaa'
task domaGen doLast {
ant.taskdef(resource: 'domagentask.properties', classpath: configurations.domaGenRuntime.asPath)
ant.gen(
dialectName: "mysql"
, driverClassName: "com.mysql.cj.jdbc.Driver"
, schemaName : "xxxx"
, url: "jdbc:mysql://127.0.0.1:3306/xxxx?useSSL=false&useUnicode=true&characterEncoding=utf8&nullNamePatternMatchesAll=true"
, user: "root"
, password: ""
, templatePrimaryDir: "${resourceDir}/config/doma/templates"
, ignoredTableNamePattern: "(sys_config") {
entityConfig(
overwrite: "true"
, packageName: "${basePackage}.entity"
, useListener: "false"
, useAccessor: false
, entityPropertyClassNamesFile: "${resourceDir}/config/domagen/entityPropertyClassNameFile.properties"
, showSchemaName: true
)
daoConfig(
overwrite: "false"
, packageName: "${basePackage}.repository"
)
sqlConfig(
overwrite: "false"
)
}
}
この場合「xxxx」以外のスキーマ「yyyy」「zzzz」のエンティティ・リポジトリクラスが出力されます
デフォルト値は false
とすべき。
Dao はデフォルトメソッドで実装を持つ場合がある。
誤って上書きすることを防ぐためにデフォルト値は false
とする。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.