kwatable 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +46 -0
- data/MIT-LICENSE +20 -0
- data/README.txt +4 -2
- data/bin/kwatable +4 -4
- data/examples/ex1/Makefile +40 -14
- data/examples/ex1/{example1.yaml → tabledef.yaml} +42 -11
- data/examples/ex2/Makefile +41 -14
- data/examples/ex2/{example2.yaml → tabledef.yaml} +45 -30
- data/examples/ex3/Makefile +52 -0
- data/examples/ex3/tabledef.yaml +136 -0
- data/kwatable.gemspec +11 -10
- data/lib/kwatable.rb +24 -18
- data/lib/kwatable/kwatable.schema.yaml +95 -5
- data/lib/kwatable/main.rb +331 -0
- data/lib/kwatable/manipulator.rb +320 -192
- data/lib/kwatable/messages.rb +59 -0
- data/lib/kwatable/template/ddl-mysql.eruby +202 -0
- data/lib/kwatable/{templates → template}/ddl-postgresql.eruby +71 -45
- data/lib/kwatable/{templates → template}/defaults.yaml +2 -2
- data/lib/kwatable/template/dictionary.en.yaml +70 -0
- data/lib/kwatable/template/dictionary.ja.yaml +165 -0
- data/lib/kwatable/template/dto-java.eruby +77 -0
- data/lib/kwatable/template/dto-java.sub.eruby +259 -0
- data/lib/kwatable/template/dto-ruby.eruby +63 -0
- data/lib/kwatable/template/dto-ruby.sub.eruby +213 -0
- data/lib/kwatable/template/helper/column.rb +70 -0
- data/lib/kwatable/template/helper/common.rb +151 -0
- data/lib/kwatable/template/helper/java.rb +83 -0
- data/lib/kwatable/template/helper/label.rb +90 -0
- data/lib/kwatable/template/helper/ruby.rb +36 -0
- data/lib/kwatable/template/helper/table.rb +62 -0
- data/lib/kwatable/template/hibernate.eruby +139 -0
- data/lib/kwatable/template/rails-controller.eruby +66 -0
- data/lib/kwatable/template/rails-controller.sub.eruby +114 -0
- data/lib/kwatable/template/rails-kwartz.eruby +164 -0
- data/lib/kwatable/template/rails-kwartz/_attr.plogic.eruby +56 -0
- data/lib/kwatable/template/rails-kwartz/_form.plogic.eruby +81 -0
- data/lib/kwatable/template/rails-kwartz/_link.plogic.eruby +36 -0
- data/lib/kwatable/template/rails-kwartz/edit.cfg.yaml.eruby +16 -0
- data/lib/kwatable/template/rails-kwartz/edit.html.eruby +46 -0
- data/lib/kwatable/template/rails-kwartz/edit.plogic.eruby +20 -0
- data/lib/kwatable/template/rails-kwartz/layout.html.eruby +39 -0
- data/lib/kwatable/template/rails-kwartz/layout.plogic.eruby +32 -0
- data/lib/kwatable/template/rails-kwartz/list.html.eruby +94 -0
- data/lib/kwatable/template/rails-kwartz/list.plogic.eruby +41 -0
- data/lib/kwatable/template/rails-kwartz/new.html.eruby +100 -0
- data/lib/kwatable/template/rails-kwartz/new.plogic.eruby +26 -0
- data/lib/kwatable/template/rails-kwartz/show.html.eruby +51 -0
- data/lib/kwatable/template/rails-kwartz/show.plogic.eruby +9 -0
- data/lib/kwatable/template/rails-model.eruby +35 -0
- data/lib/kwatable/template/rails-model.sub.eruby +136 -0
- data/lib/kwatable/{templates → template}/validator-ruby.eruby +18 -11
- data/lib/kwatable/util.rb +133 -0
- data/lib/kwatable/util/assert-text-equal.rb +47 -0
- data/lib/kwatable/util/assertion.rb +115 -0
- data/lib/kwatable/validator.rb +50 -0
- data/test/assert-diff.rb +1 -1
- data/test/test-ex.rb +306 -0
- data/test/test.rb +37 -127
- metadata +66 -17
- data/COPYING +0 -340
- data/ChangeLog.txt +0 -65
- data/lib/kwatable/error-msg.rb +0 -38
- data/lib/kwatable/main-program.rb +0 -216
- data/lib/kwatable/templates/ddl-mysql.eruby +0 -172
- data/lib/kwatable/templates/dto-java.eruby +0 -260
- data/lib/kwatable/templates/dto-ruby.eruby +0 -185
@@ -0,0 +1,70 @@
|
|
1
|
+
##
|
2
|
+
## $Rev: 42 $
|
3
|
+
## $Release: 0.3.0 $
|
4
|
+
## copyright(c) 2005 kuwata-lab.com all rights reserved.
|
5
|
+
##
|
6
|
+
|
7
|
+
new : New
|
8
|
+
create : Create
|
9
|
+
list : List
|
10
|
+
show : Show
|
11
|
+
read : Read
|
12
|
+
edit : Edit
|
13
|
+
modify : Modify
|
14
|
+
update : Update
|
15
|
+
destroy : Destroy
|
16
|
+
delete : Delete
|
17
|
+
|
18
|
+
new_item : New %s
|
19
|
+
create_item : Create %s
|
20
|
+
list_items : List %s
|
21
|
+
show_item : Show %s
|
22
|
+
read_item : Read %s
|
23
|
+
edit_item : Edit %s
|
24
|
+
modify_item : Modify %s
|
25
|
+
update_item : Update %s
|
26
|
+
destroy_item : Destroy %s
|
27
|
+
delete_item : Delete %s
|
28
|
+
|
29
|
+
listing_items : Listing %s
|
30
|
+
editing_item : Editing %s
|
31
|
+
modifying_item : Modifying %s
|
32
|
+
updating_item : Updating %s
|
33
|
+
showing_item : Showing %s
|
34
|
+
reading_item : Reading %s
|
35
|
+
newing_item : Newing %s
|
36
|
+
creating_item : Creating %s
|
37
|
+
destroying_item : Destroying %s
|
38
|
+
deleting_item : Deleting %s
|
39
|
+
|
40
|
+
are_you_sure : Are you sure?
|
41
|
+
invalid_session_token : Invalid session token.
|
42
|
+
|
43
|
+
xxx_was_created : %s was successfully created.
|
44
|
+
xxx_was_updated : %s was successfully updated.
|
45
|
+
xxx_was_modified : %s was successfully modified.
|
46
|
+
xxx_was_destroyed : %s was successfully destroyed.
|
47
|
+
xxx_was_deleted : %s was successfully deleted.
|
48
|
+
|
49
|
+
top : Top
|
50
|
+
home : Home
|
51
|
+
prev : Previous
|
52
|
+
next : Next
|
53
|
+
goto : Goto %s
|
54
|
+
goto_prev : Goto previous
|
55
|
+
goto_next : Goto next
|
56
|
+
prev_page : Previous page
|
57
|
+
next_page : Next page
|
58
|
+
back : Back
|
59
|
+
back_to : Back to %s
|
60
|
+
|
61
|
+
gender : Gender
|
62
|
+
gender_M : Man
|
63
|
+
gender_F : Woman
|
64
|
+
gender_m : Man
|
65
|
+
gender_f : Woman
|
66
|
+
sex : Sex
|
67
|
+
sex_M : Man
|
68
|
+
sex_F : Woman
|
69
|
+
sex_m : Man
|
70
|
+
sex_f : Woman
|
@@ -0,0 +1,165 @@
|
|
1
|
+
##
|
2
|
+
## $Rev: 42 $
|
3
|
+
## $Release: 0.3.0 $
|
4
|
+
## copyright(c) 2005 kuwata-lab.com all rights reserved.
|
5
|
+
##
|
6
|
+
|
7
|
+
new : ��������
|
8
|
+
create : ����
|
9
|
+
list : ����
|
10
|
+
show : ����
|
11
|
+
read : ����
|
12
|
+
edit : �ѹ�
|
13
|
+
modify : �ѹ�
|
14
|
+
update : �ѹ�
|
15
|
+
destroy : ���
|
16
|
+
delete : ���
|
17
|
+
|
18
|
+
new_item : %s�����
|
19
|
+
create_item : %s�����
|
20
|
+
list_items : %s�����
|
21
|
+
show_item : %s��
|
22
|
+
read_item : %s��
|
23
|
+
edit_item : %s���ѹ�
|
24
|
+
modify_item : %s���ѹ�
|
25
|
+
update_item : %s���ѹ�
|
26
|
+
destroy_item : %s����
|
27
|
+
delete_item : %s����
|
28
|
+
|
29
|
+
listing_items : %s���
|
30
|
+
editing_item : %s���Խ�
|
31
|
+
modifying_item : %s���Խ�
|
32
|
+
updating_item : %s���Խ�
|
33
|
+
showing_item : %s���
|
34
|
+
reading_item : %s���
|
35
|
+
newing_item : %s���
|
36
|
+
creating_item : %s���
|
37
|
+
destroying_item : %s��
|
38
|
+
deleting_item : %s��
|
39
|
+
|
40
|
+
are_you_sure : ��������Ǥ�����
|
41
|
+
xxx_was_created : %s����������ޤ�����
|
42
|
+
invalid_session_token : �����ʥ��å����ȡ�����Ǥ���
|
43
|
+
|
44
|
+
xxx_was_created : %s����������ޤ�����
|
45
|
+
xxx_was_updated : %s����������ޤ�����
|
46
|
+
xxx_was_modified : %s���ѹ�����ޤ�����
|
47
|
+
xxx_was_destroyed : %s���������ޤ�����
|
48
|
+
xxx_was_deleted : %s���������ޤ�����
|
49
|
+
|
50
|
+
|
51
|
+
top : �ȥå�
|
52
|
+
home : �ۡ���
|
53
|
+
prev : ��
|
54
|
+
next : ��
|
55
|
+
goto : %s��
|
56
|
+
goto_prev : ����
|
57
|
+
goto_next : ����
|
58
|
+
prev_page : ���Υڡ���
|
59
|
+
next_page : ���Υڡ���
|
60
|
+
back : ���
|
61
|
+
back_to : %s�����
|
62
|
+
|
63
|
+
###
|
64
|
+
|
65
|
+
user : �桼��
|
66
|
+
users : �桼��
|
67
|
+
user_name : �桼��̾
|
68
|
+
username : �桼��̾
|
69
|
+
group : ���롼��
|
70
|
+
groups : ���롼��
|
71
|
+
group_name : ���롼��̾
|
72
|
+
groupname : ���롼��̾
|
73
|
+
account : ���������
|
74
|
+
account_name : ���������̾
|
75
|
+
name : ̾��
|
76
|
+
password : �ѥ����
|
77
|
+
passwd : �ѥ����
|
78
|
+
desc : Ŧ��
|
79
|
+
description : Ŧ��
|
80
|
+
birth : ������
|
81
|
+
birthday : ������
|
82
|
+
mail : ���
|
83
|
+
email : Email
|
84
|
+
gender : ����
|
85
|
+
sex : ����
|
86
|
+
man : ����
|
87
|
+
men : ����
|
88
|
+
woman : ����
|
89
|
+
women : ����
|
90
|
+
gender_M : ����
|
91
|
+
gender_m : ����
|
92
|
+
gender_F : ����
|
93
|
+
gender_f : ����
|
94
|
+
adult : ����
|
95
|
+
child : �Ҷ�
|
96
|
+
children : �Ҷ�
|
97
|
+
memo : ���
|
98
|
+
note : ����
|
99
|
+
id : ID
|
100
|
+
type : ������
|
101
|
+
width : ��
|
102
|
+
height : �⤵
|
103
|
+
status : ����
|
104
|
+
created_on : ������
|
105
|
+
created_at : ��������
|
106
|
+
updated_on : ������
|
107
|
+
updated_at : ��������
|
108
|
+
modified_on : ������
|
109
|
+
modified_at : ��������
|
110
|
+
case : ������
|
111
|
+
active : ͭ��
|
112
|
+
inactive : ̵��
|
113
|
+
yes : �Ϥ�
|
114
|
+
no : ������
|
115
|
+
number : ��
|
116
|
+
num : �ֹ�
|
117
|
+
code : ������
|
118
|
+
null : �̥�
|
119
|
+
age : ǯ��
|
120
|
+
order : ��ʸ
|
121
|
+
orders : ��ʸ
|
122
|
+
sales_order : ����
|
123
|
+
sales_orders : ����
|
124
|
+
sales_order_line : ��������
|
125
|
+
sales_order_lines : ��������
|
126
|
+
purchasing_order : ȯ��
|
127
|
+
purchasing_orders : ȯ��
|
128
|
+
purchasing_order_line : ȯ������
|
129
|
+
purchasing_order_lines : ȯ������
|
130
|
+
item : ����
|
131
|
+
items: : ����
|
132
|
+
price : ����
|
133
|
+
quantity : �Ŀ�
|
134
|
+
amount : ����
|
135
|
+
total : ����
|
136
|
+
shipping : �в�
|
137
|
+
shipping_date : ���
|
138
|
+
delivery : ����
|
139
|
+
delivery_date : ������
|
140
|
+
ordered_date : ��ʸ��
|
141
|
+
ordered : ��ʸ��
|
142
|
+
booked : ��Ģ��
|
143
|
+
shipped : �вٺ�
|
144
|
+
delivered : ������
|
145
|
+
customer : �ܵ�
|
146
|
+
customers : �ܵ�
|
147
|
+
tel : ����
|
148
|
+
phone : ����
|
149
|
+
mail : ���
|
150
|
+
email : E���
|
151
|
+
e-mail : E���
|
152
|
+
addr : ����
|
153
|
+
address : ����
|
154
|
+
zipcode : ���ֹ�
|
155
|
+
zip_code : ���ֹ�
|
156
|
+
zip : ���ֹ�
|
157
|
+
country : ��
|
158
|
+
state : ��
|
159
|
+
prefecture : ��
|
160
|
+
city : ��Į¼
|
161
|
+
street : �̤�
|
162
|
+
building : ��ʪ
|
163
|
+
bldg : ��ʪ
|
164
|
+
from : ��
|
165
|
+
to : ��
|
@@ -0,0 +1,77 @@
|
|
1
|
+
<%
|
2
|
+
|
3
|
+
##
|
4
|
+
## kwatable template file for Java DTO class
|
5
|
+
##
|
6
|
+
## $Rev: 44 $
|
7
|
+
## $Release: 0.3.0 $
|
8
|
+
## copyright(c) 2005 kuwata-lab.com all rights reserved.
|
9
|
+
##
|
10
|
+
## <template-desc>generate DTO classes for Java</template-desc>
|
11
|
+
## <template-properties>
|
12
|
+
## --package=name : package name
|
13
|
+
## --parent=name : parent class
|
14
|
+
## --constructor : define constructor
|
15
|
+
## --populate : define populate method
|
16
|
+
## --collection={list|set} : collection class
|
17
|
+
## </template-properties>
|
18
|
+
##
|
19
|
+
|
20
|
+
require 'kwatable/template/helper/common'
|
21
|
+
require 'kwatable/template/helper/table'
|
22
|
+
require 'kwatable/template/helper/column'
|
23
|
+
require 'kwatable/template/helper/java'
|
24
|
+
extend Kwatable::CommonHelper
|
25
|
+
extend Kwatable::TableHelper
|
26
|
+
extend Kwatable::ColumnHelper
|
27
|
+
extend Kwatable::JavaHelper
|
28
|
+
|
29
|
+
require 'active_support/inflector'
|
30
|
+
#extend Inflector
|
31
|
+
|
32
|
+
|
33
|
+
## context check
|
34
|
+
context_var_required('@tables')
|
35
|
+
|
36
|
+
|
37
|
+
## use '_' as escape function name
|
38
|
+
alias _ escape_java_keyword
|
39
|
+
|
40
|
+
|
41
|
+
## determine java class or type from column data
|
42
|
+
alias _column_java_type column_java_type
|
43
|
+
def column_java_type(column)
|
44
|
+
#
|
45
|
+
# ... add custom code here ...
|
46
|
+
#
|
47
|
+
return _column_java_type(column)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
##
|
52
|
+
## apply template
|
53
|
+
##
|
54
|
+
@output_files = apply_subtemplate_for_each_tables(@tables) { |table|
|
55
|
+
output_filename = table_class(table) + '.java'
|
56
|
+
output_filename
|
57
|
+
}
|
58
|
+
# basename = File.basename(@template_filename)
|
59
|
+
# subtemplate_filename = basename.sub(/\.eruby\z/, '.sub.eruby')
|
60
|
+
# subtemplate_filepath = Util.find_file(subtemplate_filename, @template_pathlist)
|
61
|
+
# unless subtemplate_filepath
|
62
|
+
# raise "#{basename}: subtemplate `#{subtemplate_filename}' not found."
|
63
|
+
# end
|
64
|
+
# @output_files = []
|
65
|
+
# context = self
|
66
|
+
# encoding = @properties[:encoding] || @properties[:charset]
|
67
|
+
# each_table(@tables) do |table|
|
68
|
+
# @table = table
|
69
|
+
# output = Util.eval_template(subtemplate_filepath, context)
|
70
|
+
# output = Util.encode(output, encoding) if encoding
|
71
|
+
# outfile = @output_filename # set in subtemplate
|
72
|
+
# @output_files << [outfile, output, :create]
|
73
|
+
# end
|
74
|
+
# @table = nil
|
75
|
+
|
76
|
+
|
77
|
+
%>
|
@@ -0,0 +1,259 @@
|
|
1
|
+
<%
|
2
|
+
|
3
|
+
##
|
4
|
+
## kwatable template file for Ruby DTO class
|
5
|
+
##
|
6
|
+
## $Rev: 38 $
|
7
|
+
## $Release: 0.3.0 $
|
8
|
+
## copyright(c) 2005 kuwata-lab.com all rights reserved.
|
9
|
+
##
|
10
|
+
|
11
|
+
#
|
12
|
+
# context check
|
13
|
+
#
|
14
|
+
context_var_required('@table')
|
15
|
+
|
16
|
+
|
17
|
+
#
|
18
|
+
# output file name
|
19
|
+
#
|
20
|
+
@output_filename = table_class(@table) + ".java"
|
21
|
+
|
22
|
+
|
23
|
+
#
|
24
|
+
# class definition
|
25
|
+
#
|
26
|
+
klass = {
|
27
|
+
:name => table_class(@table),
|
28
|
+
:package => @table['package'] || @properties[:package],
|
29
|
+
:parent => @table['parent'] || @properties[:parent],
|
30
|
+
:desc => @table['desc'],
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
#
|
35
|
+
# instance variables
|
36
|
+
#
|
37
|
+
variables = []
|
38
|
+
for column in @table['columns']
|
39
|
+
hash = {
|
40
|
+
:name => column_attr(column),
|
41
|
+
:type => column['class'] || column_java_type(column),
|
42
|
+
:desc => column['desc'],
|
43
|
+
}
|
44
|
+
variables << hash
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
#
|
49
|
+
# collection class (default 'List')
|
50
|
+
#
|
51
|
+
collection_table = { 'set'=>'Set', 'list'=>'List', 'map'=>'Map',
|
52
|
+
'hash'=>'Map', 'seq'=>'List' }
|
53
|
+
collection_type = @properties[:collection] || 'list'
|
54
|
+
collection_class = collection_table[collection_type] || @properties[:collection]
|
55
|
+
|
56
|
+
|
57
|
+
#
|
58
|
+
# relations
|
59
|
+
#
|
60
|
+
relations = []
|
61
|
+
for relation in @table['relations']
|
62
|
+
kind = relation['kind']
|
63
|
+
type = table_class(relation['table'])
|
64
|
+
attr = Inflector.underscore(type)
|
65
|
+
unless kind == '1:1'
|
66
|
+
type = "#{collection_class}<#{type}>"
|
67
|
+
attr = Inflector.pluralize(attr)
|
68
|
+
end
|
69
|
+
hash = {
|
70
|
+
:kind => kind,
|
71
|
+
:type => relation['class'] || type,
|
72
|
+
:attr => relation['attr'] || attr,
|
73
|
+
}
|
74
|
+
relations << hash
|
75
|
+
end if @table['relations']
|
76
|
+
|
77
|
+
|
78
|
+
#
|
79
|
+
# import classes
|
80
|
+
#
|
81
|
+
imports = []
|
82
|
+
imports << 'java.util.Date' if variables.any? { |var| var[:type] == 'Date' }
|
83
|
+
imports << "java.util.#{collection_class}" if relations.any? { |rel| rel[:type] =~ /\A#{collection_class}<.*>\z/ }
|
84
|
+
|
85
|
+
|
86
|
+
%>
|
87
|
+
/*
|
88
|
+
* DTO for Java
|
89
|
+
* generated by kwatable with template 'dto-java.eruby'
|
90
|
+
* at <%= Time.now.to_s %>
|
91
|
+
|
92
|
+
*/
|
93
|
+
<% if klass[:package] %>
|
94
|
+
package <%= klass[:package] %>;
|
95
|
+
<% end %>
|
96
|
+
<% for class_name in imports %>
|
97
|
+
import <%= class_name %>;
|
98
|
+
<% end %>
|
99
|
+
|
100
|
+
/**
|
101
|
+
* <%= klass[:desc] %>
|
102
|
+
|
103
|
+
*/
|
104
|
+
<% extends = klass[:parent] ? ' extends ' + klass[:parent] : '' %>
|
105
|
+
public class <%= klass[:name] %><%= extends %> implements java.io.Serializable {
|
106
|
+
|
107
|
+
<%
|
108
|
+
#
|
109
|
+
# instance variables
|
110
|
+
#
|
111
|
+
%>
|
112
|
+
<% for var in variables %>
|
113
|
+
<% varname = '%-12s' % ( _(var[:name]) + ';') %>
|
114
|
+
private <%= '%-12s' % var[:type] %> <%= varname %> /* <%= var[:desc] %> */
|
115
|
+
<% end %>
|
116
|
+
|
117
|
+
<%
|
118
|
+
#
|
119
|
+
# constructor
|
120
|
+
#
|
121
|
+
argstr = variables.collect { |var| "#{var[:type]} #{_(var[:name])}" }.join(', ')
|
122
|
+
%>
|
123
|
+
<% if @properties[:constructor] %>
|
124
|
+
public <%= klass[:name] %>() {}
|
125
|
+
|
126
|
+
public <%= klass[:name] %>(<%= argstr %>) {
|
127
|
+
<% for var in variables %>
|
128
|
+
set<%= camel_case(var[:name]) %>(<%=_ var[:name] %>);
|
129
|
+
<% end %>
|
130
|
+
}
|
131
|
+
|
132
|
+
<% end %>
|
133
|
+
<%
|
134
|
+
#
|
135
|
+
# set all values with java.sql.ResultSet
|
136
|
+
#
|
137
|
+
%>
|
138
|
+
<% if @properties[:populate] %>
|
139
|
+
public void populate(java.sql.ResultSet resultset) throws java.sql.SQLException {
|
140
|
+
<% n = 0 %>
|
141
|
+
<% for var in variables %>
|
142
|
+
<% if var[:type] == 'char' %>
|
143
|
+
<% if (n += 1) == 1 %>
|
144
|
+
String val;
|
145
|
+
<% end %>
|
146
|
+
val = resultset.getString("<%= var[:name] %>");
|
147
|
+
set<%= camel_case(var[:name]) %>(val != null && val.length() > 0 ? val.charAt(0) : 0);
|
148
|
+
<% else %>
|
149
|
+
set<%= camel_case(var[:name]) %>(resultset.get<%= var[:type].capitalize %>("<%= var[:name] %>"));
|
150
|
+
<% end %>
|
151
|
+
<% end %>
|
152
|
+
}
|
153
|
+
|
154
|
+
<% end %>
|
155
|
+
<%
|
156
|
+
#
|
157
|
+
# set all properties
|
158
|
+
#
|
159
|
+
%>
|
160
|
+
<% if @properties[:populate] %>
|
161
|
+
public void populate(java.util.Map _map) {
|
162
|
+
String val = null;
|
163
|
+
<% for var in variables %>
|
164
|
+
<% getter, setter = accessors(var[:name], var[:type]) %>
|
165
|
+
if (_map.containsKey("<%= var[:name] %>")) {
|
166
|
+
val = (String)_map.get("<%= var[:name] %>");
|
167
|
+
<% case var[:type] %>
|
168
|
+
<% when 'String' %>
|
169
|
+
<%= setter %>(val);
|
170
|
+
<% when 'int' %>
|
171
|
+
<%= setter %>(Integer.parseInt(val));
|
172
|
+
<% when 'long' %>
|
173
|
+
<%= setter %>(Long.parseLong(val));
|
174
|
+
<% when 'float' %>
|
175
|
+
<%= setter %>(Float.parseFloat(val));
|
176
|
+
<% when 'double' %>
|
177
|
+
<%= setter %>(Double.parseDouble(val));
|
178
|
+
<% when 'char' %>
|
179
|
+
<%= setter %>(val.length() > 0 ? val.charAt(0) : 0);
|
180
|
+
<% when 'boolean' %>
|
181
|
+
<%= setter %>(val.length() > 0);
|
182
|
+
<% when 'Date' %>
|
183
|
+
try {
|
184
|
+
<%= setter %>(java.text.DateFormat.getDateInstance().parse(val));
|
185
|
+
} catch (java.text.ParseException ignore) {
|
186
|
+
}
|
187
|
+
<% else %>
|
188
|
+
<% raise "*** internal error: template='dto-java.eruby', var[:type]=#{var[:type].inspect}" %>
|
189
|
+
<% end %>
|
190
|
+
}
|
191
|
+
<% end %>
|
192
|
+
}
|
193
|
+
|
194
|
+
<% end %>
|
195
|
+
<%
|
196
|
+
#
|
197
|
+
# getter/setter
|
198
|
+
#
|
199
|
+
for var in variables
|
200
|
+
vartype = var[:type]
|
201
|
+
varname = var[:name]
|
202
|
+
getter, setter = accessors(varname, vartype)
|
203
|
+
%>
|
204
|
+
public <%= vartype %> <%= getter %>() { return <%=_ varname %>; }
|
205
|
+
public void <%= setter %>(<%= vartype %> <%=_ varname %>) { this.<%=_ varname %> = <%=_ varname %>; }
|
206
|
+
|
207
|
+
<% end %>
|
208
|
+
<%
|
209
|
+
#
|
210
|
+
# foreign keys
|
211
|
+
#
|
212
|
+
for column in @table['columns']
|
213
|
+
next if !column['ref']
|
214
|
+
reftype = table_class(column['ref']['table'])
|
215
|
+
refcolname = column_attr(column['ref'])
|
216
|
+
refname = column_refname(column)
|
217
|
+
varname = column_attr(column)
|
218
|
+
argname = refname # or Inflector.underscore(reftype)
|
219
|
+
if refname == varname
|
220
|
+
raise "table `#{@table['name']}': column `#{column['name']}': proper ref-name is required."
|
221
|
+
end
|
222
|
+
getter, setter = accessors(refname, reftype)
|
223
|
+
foreign_key_name = "#{column['ref']['table']['name']}.#{column['ref']['name']}"
|
224
|
+
%>
|
225
|
+
// link to <%= column['ref']['table']['name'] %> table via foreign key <%= foreign_key_name %>
|
226
|
+
|
227
|
+
private <%= reftype %> <%=_ refname %>;
|
228
|
+
public <%= reftype %> <%= getter %>() { return <%=_ refname %>; }
|
229
|
+
public void <%= setter %>(<%= reftype %> <%=_ argname %>) {
|
230
|
+
this.<%=_ refname %> = <%=_ argname %>;
|
231
|
+
set<%= camel_case(varname) %>(<%=_ argname %>.get<%= camel_case(refcolname) %>());
|
232
|
+
}
|
233
|
+
|
234
|
+
<%
|
235
|
+
#//this.#{varname} = #{argname}.get#{camel_case(refcolname)}();
|
236
|
+
end
|
237
|
+
|
238
|
+
|
239
|
+
#
|
240
|
+
# relations
|
241
|
+
#
|
242
|
+
for relation in relations
|
243
|
+
kind = relation[:kind]
|
244
|
+
type = relation[:type]
|
245
|
+
attr = relation[:attr]
|
246
|
+
getter, setter = accessors(attr, type)
|
247
|
+
arg = attr
|
248
|
+
%>
|
249
|
+
// <%= kind %> relationship
|
250
|
+
private <%= type %> <%=_ attr %>;
|
251
|
+
public <%= type %> <%= getter %>() { return <%=_ attr %>; }
|
252
|
+
public void <%= setter %>(<%= type %> <%=_ arg %>) {
|
253
|
+
this.<%=_ attr %> = <%=_ arg %>;
|
254
|
+
}
|
255
|
+
|
256
|
+
<%
|
257
|
+
end
|
258
|
+
%>
|
259
|
+
}
|