-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathddlToJava.html
More file actions
111 lines (89 loc) · 3.2 KB
/
ddlToJava.html
File metadata and controls
111 lines (89 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>ddlToJava</title>
<link rel="stylesheet" href="less.css">
<script type="text/javascript" src="//cdn.jsdelivr.net/json2/0.2/json2.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="polyfill.js"></script>
<script type="text/javascript">
function camelCase(v) {
v = v.toLowerCase();
return v.replace(/_([a-z])/g, function (match) {
return match.substring(1).toUpperCase();
});
}
function generate(sql) {
var arrayResult = [];
var arrayLine = sql.split("\n");
arrayLine.forEach(function (v, i) {
v = camelCase(v.trim().toLowerCase());
if (0 <= v.indexOf("create table")) {
v = v.replace('create table', '').trim();
v = v[0].toUpperCase() + v.substring(1);
v = v.replace(/\(/g, "{");
v = v.replace(/\)/g, "}");
arrayResult.push("public class " + v);
} else if (0 <= v.search(/ (nvarchar|varchar|nchar|char|nclob|clob)/)) {
v = v.replace(/ (nvarchar|varchar|nchar|char|nclob|clob)(.*)/, function (match) {
return "; // " + match.toUpperCase();
});
arrayResult.push(" public String " + v + ";");
} else if (0 <= v.search(/ (number|int)/)) {
v = v.replace(/ (number|int)(.*)/, function (match) {
return "; // " + match.toUpperCase();
});
arrayResult.push(" public int " + v + ";");
} else if (0 <= v.search(/ (datetime|date)/)) {
v = v.replace(/ (datetime|date)(.*)/, function (match) {
return "; // " + match.toUpperCase();
});
arrayResult.push(" public Date " + v + ";");
} else {
v = v.replace(/\(/g, "{");
v = v.replace(/\)/g, "}");
arrayResult.push(v);
}
});
return arrayResult.join("\n");
}
$(function () {
$('.src').keyup(function () {
$('.dstJava').val('');
$('.dstJava').val(generate($(this).val()));
}).scroll(function () {
$('.src').scrollTop
}).keyup();
});
</script>
</head>
<body class="ddlToJava">
<div class="wrap">
<h1>nativebinary - ddlToJava</h1>
<h4>
<a href="https://nativebinary.github.io/json-util/">jsonPrettier</a> |
<a href="https://nativebinary.github.io/json-util/jsonToJava.html">jsonToJava</a> |
<a href="https://nativebinary.github.io/json-util/ddlToJava.html">ddlToJava</a> |
<a href="https://nativebinary.github.io/json-util/generatePassword.html">generatePassword</a> |
<a href="https://nativebinary.github.io/json-util/mybatisBind.html">mybatisBind</a> |
</h4>
<table style="height: 100%; width: 100%;">
<tr>
<td width="50%">
<textarea class="src">
CREATE TABLE TABLE_NAME_UNDER_SCORE (
AAA_BBB VARCHAR2(1) NOT NULL,
CCC_DDD_EEE NUMBER(3) NULL
);
</textarea>
</td>
<td width="50%">
<textarea class="dstJava"></textarea>
</td>
</tr>
</table>
</div>
</body>
</html>