Skip to content

Commit 6d003ff

Browse files
author
synapticloop
committed
added in all types for MySQL, refactored database schemas
1 parent 5cd6187 commit 6d003ff

File tree

100 files changed

+2353
-7994
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2353
-7994
lines changed

build.h2zero.mysql.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repositories {
2828
}
2929

3030
h2zero {
31-
inFile = 'src/test/resources/sample-include.h2zero'
31+
inFile = 'src/test/resources/mysql/sample-include-mysql.h2zero'
3232
outDir = '.'
3333
verbose = 'false'
3434
}

src/main/java/synapticloop/h2zero/base/manager/BaseConnectionManager.java

Lines changed: 166 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.io.Reader;
2727
import java.io.StringReader;
2828
import java.io.Writer;
29+
import java.math.BigDecimal;
2930
import java.sql.Blob;
3031
import java.sql.Clob;
3132
import java.sql.Connection;
@@ -228,6 +229,60 @@ public static void setVarchar(PreparedStatement preparedStatement, int parameter
228229
}
229230
}
230231

232+
/**
233+
* Set a CHAR datatype to a prepared statement with the value of the passed
234+
* in String, or the correct SQL null type if null
235+
*
236+
* @param preparedStatement The prepared statement
237+
* @param parameterIndex the index of the parameter
238+
* @param value the value to be set
239+
*
240+
* @throws SQLException if something went horribly wrong
241+
*/
242+
public static void setChar(PreparedStatement preparedStatement, int parameterIndex, String value) throws SQLException {
243+
if(null == value) {
244+
preparedStatement.setNull(parameterIndex, Types.CHAR);
245+
} else {
246+
preparedStatement.setString(parameterIndex, value);
247+
}
248+
}
249+
250+
/**
251+
* Set a BINARY datatype to a prepared statement with the value of the passed
252+
* in String, or the correct SQL null type if null
253+
*
254+
* @param preparedStatement The prepared statement
255+
* @param parameterIndex the index of the parameter
256+
* @param value the value to be set
257+
*
258+
* @throws SQLException if something went horribly wrong
259+
*/
260+
public static void setBinary(PreparedStatement preparedStatement, int parameterIndex, String value) throws SQLException {
261+
if(null == value) {
262+
preparedStatement.setNull(parameterIndex, Types.BINARY);
263+
} else {
264+
preparedStatement.setString(parameterIndex, value);
265+
}
266+
}
267+
268+
/**
269+
* Set a VARBINARY datatype to a prepared statement with the value of the passed
270+
* in String, or the correct SQL null type if null
271+
*
272+
* @param preparedStatement The prepared statement
273+
* @param parameterIndex the index of the parameter
274+
* @param value the value to be set
275+
*
276+
* @throws SQLException if something went horribly wrong
277+
*/
278+
public static void setVarbinary(PreparedStatement preparedStatement, int parameterIndex, String value) throws SQLException {
279+
if(null == value) {
280+
preparedStatement.setNull(parameterIndex, Types.VARBINARY);
281+
} else {
282+
preparedStatement.setString(parameterIndex, value);
283+
}
284+
}
285+
231286
/**
232287
* Set a VARCHAR datatype to a prepared statement with the value of the passed
233288
* in String, or the correct SQL null type if null
@@ -264,6 +319,24 @@ public static void setInt(PreparedStatement preparedStatement, int parameterInde
264319
}
265320
}
266321

322+
/**
323+
* Set a MEDIUMINT datatype to a prepared statement with the value of the passed
324+
* in Integer, or the correct SQL null type if null
325+
*
326+
* @param preparedStatement The prepared statement
327+
* @param parameterIndex the index of the parameter
328+
* @param value the value to be set
329+
*
330+
* @throws SQLException if something went horribly wrong
331+
*/
332+
public static void setMediumint(PreparedStatement preparedStatement, int parameterIndex, Integer value) throws SQLException {
333+
if(null == value) {
334+
preparedStatement.setNull(parameterIndex, Types.INTEGER);
335+
} else {
336+
preparedStatement.setInt(parameterIndex, value);
337+
}
338+
}
339+
267340
/**
268341
* Set a INTEGER datatype to a prepared statement with the value of the passed
269342
* in Integer, or the correct SQL null type if null
@@ -296,6 +369,24 @@ public static void setSmallint(PreparedStatement preparedStatement, int paramete
296369
}
297370
}
298371

372+
/**
373+
* Set a YEAR datatype to a prepared statement with the value of the passed
374+
* in Integer, or the correct SQL null type if null
375+
*
376+
* @param preparedStatement The prepared statement
377+
* @param parameterIndex the index of the parameter
378+
* @param value the value to be set
379+
*
380+
* @throws SQLException if something went horribly wrong
381+
*/
382+
public static void setYear(PreparedStatement preparedStatement, int parameterIndex, Integer value) throws SQLException {
383+
if(null == value) {
384+
preparedStatement.setNull(parameterIndex, Types.INTEGER);
385+
} else {
386+
preparedStatement.setInt(parameterIndex, value);
387+
}
388+
}
389+
299390
/**
300391
* Set a SMALLSERIAL datatype to a prepared statement with the value of the passed
301392
* in Integer, or the correct SQL null type if null
@@ -406,6 +497,42 @@ public static void setMediumtext(PreparedStatement preparedStatement, int parame
406497
setVarchar(preparedStatement, parameterIndex, value);
407498
}
408499

500+
/**
501+
* Set a TEXT datatype to a prepared statement with the value of the
502+
* passed in mediumtext, or the correct SQL null type if null
503+
*
504+
* @param preparedStatement The prepared statement
505+
* @param parameterIndex the index of the parameter
506+
* @param value the value to be set
507+
*
508+
* @throws SQLException if something went horribly wrong
509+
*/
510+
public static void setText(PreparedStatement preparedStatement, int parameterIndex, String value) throws SQLException {
511+
if(null == value) {
512+
preparedStatement.setNull(parameterIndex, Types.LONGVARCHAR);
513+
} else {
514+
preparedStatement.setString(parameterIndex, value);
515+
}
516+
}
517+
518+
/**
519+
* Set a TINYTEXT datatype to a prepared statement with the value of the
520+
* passed in string, or the correct SQL null type if null
521+
*
522+
* @param preparedStatement The prepared statement
523+
* @param parameterIndex the index of the parameter
524+
* @param value the value to be set
525+
*
526+
* @throws SQLException if something went horribly wrong
527+
*/
528+
public static void setTinytext(PreparedStatement preparedStatement, int parameterIndex, String value) throws SQLException {
529+
if(null == value) {
530+
preparedStatement.setNull(parameterIndex, Types.VARCHAR);
531+
} else {
532+
preparedStatement.setString(parameterIndex, value);
533+
}
534+
}
535+
409536
/**
410537
* Set a LONGTEXT datatype to a prepared statement with the value of the
411538
* passed in longtext, or the correct SQL null type if null
@@ -440,16 +567,16 @@ public static void setFloat(PreparedStatement preparedStatement, int parameterIn
440567

441568
/**
442569
* Set a NUMERIC datatype to a prepared statement with the value of the passed
443-
* in float, or the correct SQL null type if null
570+
* in BigDecimal, or the correct SQL null type if null
444571
*
445572
* @param preparedStatement The prepared statement
446573
* @param parameterIndex the index of the parameter
447574
* @param value the value to be set
448575
*
449576
* @throws SQLException if something went horribly wrong
450577
*/
451-
public static void setNumeric(PreparedStatement preparedStatement, int parameterIndex, Float value) throws SQLException {
452-
setFloat(preparedStatement, parameterIndex, value);
578+
public static void setNumeric(PreparedStatement preparedStatement, int parameterIndex, BigDecimal value) throws SQLException {
579+
setDecimal(preparedStatement, parameterIndex, value);
453580
}
454581

455582
/**
@@ -482,11 +609,22 @@ public static void setTinyint(PreparedStatement preparedStatement, int parameter
482609
* @throws SQLException if something went horribly wrong
483610
*/
484611
public static void setBoolean(PreparedStatement preparedStatement, int parameterIndex, Boolean value) throws SQLException {
485-
if(null == value) {
486-
preparedStatement.setNull(parameterIndex, Types.TINYINT);
487-
} else {
488-
preparedStatement.setBoolean(parameterIndex, value);
489-
}
612+
setTinyint(preparedStatement, parameterIndex, value);
613+
}
614+
615+
/**
616+
* Set a BOOL (or in sthis case conversion to a TINYINT) datatype to a
617+
* prepared statement with the value of the passed in boolean, or the correct
618+
* SQL null type if null
619+
*
620+
* @param preparedStatement The prepared statement
621+
* @param parameterIndex the index of the parameter
622+
* @param value the value to be set
623+
*
624+
* @throws SQLException if something went horribly wrong
625+
*/
626+
public static void setBool(PreparedStatement preparedStatement, int parameterIndex, Boolean value) throws SQLException {
627+
setTinyint(preparedStatement, parameterIndex, value);
490628
}
491629

492630
/**
@@ -517,14 +655,28 @@ public static void setDouble(PreparedStatement preparedStatement, int parameterI
517655
*
518656
* @throws SQLException if something went horribly wrong
519657
*/
520-
public static void setDecimal(PreparedStatement preparedStatement, int parameterIndex, Double value) throws SQLException {
658+
public static void setDecimal(PreparedStatement preparedStatement, int parameterIndex, BigDecimal value) throws SQLException {
521659
if(null == value) {
522660
preparedStatement.setNull(parameterIndex, Types.DECIMAL);
523661
} else {
524-
preparedStatement.setDouble(parameterIndex, value);
662+
preparedStatement.setBigDecimal(parameterIndex, value);
525663
}
526664
}
527665

666+
/**
667+
* Set a DEC datatype to a prepared statement with the value of the passed
668+
* in double, or the correct SQL null type if null
669+
*
670+
* @param preparedStatement The prepared statement
671+
* @param parameterIndex the index of the parameter
672+
* @param value the value to be set
673+
*
674+
* @throws SQLException if something went horribly wrong
675+
*/
676+
public static void setDec(PreparedStatement preparedStatement, int parameterIndex, BigDecimal value) throws SQLException {
677+
setDecimal(preparedStatement, parameterIndex, value);
678+
}
679+
528680
/**
529681
* Set a REAL datatype to a prepared statement with the value of the passed
530682
* in double, or the correct SQL null type if null
@@ -790,6 +942,10 @@ public static Short getNullableResultShort(ResultSet resultSet, int index) throw
790942
return((Short)returnPossibleNullObject(resultSet, resultSet.getShort(index)));
791943
}
792944

945+
public static BigDecimal getNullableResultBigDecimal(ResultSet resultSet, int index) throws SQLException {
946+
return((BigDecimal)returnPossibleNullObject(resultSet, resultSet.getBigDecimal(index)));
947+
}
948+
793949

794950
/**
795951
* Get the underlying combo pooled result set

src/main/java/synapticloop/h2zero/model/field/BaseField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public abstract class BaseField {
4242
public static final String PRIMARY_KEY_POSTGRESQL_BIGSERIAL = "bigserial";
4343
public static final String PRIMARY_KEY_POSTGRESQL_SERIAL = "serial";
4444
public static final String PRIMARY_KEY_POSTGRESQL_SMALLSERIAL = "smallserial";
45-
45+
4646
public static final Map<String, String> PRIMARY_KEY_POSTGRESQL_REPLACE = new HashMap<>();
4747
static {
4848
PRIMARY_KEY_POSTGRESQL_REPLACE.put("bigint", PRIMARY_KEY_POSTGRESQL_BIGSERIAL);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package synapticloop.h2zero.model.field;
2+
3+
/*
4+
* Copyright (c) 2012-2020 synapticloop.
5+
*
6+
* All rights reserved.
7+
*
8+
* This source code and any derived binaries are covered by the terms and
9+
* conditions of the Licence agreement ("the Licence"). You may not use this
10+
* source code or any derived binaries except in compliance with the Licence.
11+
* A copy of the Licence is available in the file named LICENCE shipped with
12+
* this source code or binaries.
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the Licence is distributed on an "AS IS" BASIS, WITHOUT
16+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17+
* Licence for the specific language governing permissions and limitations
18+
* under the Licence.
19+
*/
20+
21+
import org.json.JSONObject;
22+
23+
import synapticloop.h2zero.exception.H2ZeroParseException;
24+
25+
public class BinaryField extends BaseField {
26+
27+
public BinaryField(JSONObject jsonObject) throws H2ZeroParseException {
28+
super(jsonObject);
29+
}
30+
31+
public BinaryField(JSONObject jsonObject, boolean isInField) throws H2ZeroParseException {
32+
super(jsonObject, isInField);
33+
}
34+
35+
@Override
36+
public String getJavaType() {
37+
return "String";
38+
}
39+
40+
@Override
41+
public String getSqlJavaType() {
42+
return("String");
43+
}
44+
45+
@Override
46+
public String getSqlNullType() {
47+
return("BINARY");
48+
}
49+
50+
@Override
51+
public boolean getShouldEscape() {
52+
return true;
53+
}
54+
55+
@Override
56+
public boolean getIsLargeObject() {
57+
return(true);
58+
}
59+
60+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package synapticloop.h2zero.model.field;
2+
3+
/*
4+
* Copyright (c) 2013-2020 synapticloop.
5+
* All rights reserved.
6+
*
7+
* This source code and any derived binaries are covered by the terms and
8+
* conditions of the Licence agreement ("the Licence"). You may not use this
9+
* source code or any derived binaries except in compliance with the Licence.
10+
* A copy of the Licence is available in the file named LICENCE shipped with
11+
* this source code or binaries.
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the Licence is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* Licence for the specific language governing permissions and limitations
17+
* under the Licence.
18+
*/
19+
20+
21+
import org.json.JSONObject;
22+
23+
import synapticloop.h2zero.exception.H2ZeroParseException;
24+
25+
public class CharField extends BaseField {
26+
27+
public CharField(JSONObject jsonObject) throws H2ZeroParseException {
28+
super(jsonObject);
29+
}
30+
31+
public CharField(JSONObject jsonObject, boolean isInField) throws H2ZeroParseException {
32+
super(jsonObject, isInField);
33+
}
34+
35+
@Override
36+
public String getJavaType() {
37+
return("String");
38+
}
39+
40+
@Override
41+
public String getSqlJavaType() {
42+
return("String");
43+
}
44+
45+
@Override
46+
public String getSqlNullType() {
47+
return("CHAR");
48+
}
49+
50+
@Override
51+
public boolean getShouldEscape() {
52+
return false;
53+
}
54+
}

0 commit comments

Comments
 (0)