Skip to content

Commit ad29942

Browse files
author
synapticloop
committed
added in postgres and cockroach database variants
1 parent 8621704 commit ad29942

File tree

111 files changed

+17578
-31
lines changed

Some content is hidden

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

111 files changed

+17578
-31
lines changed

build.all.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
4+
./gradlew assemble pTML -b build.gradle
5+
./gradlew -b build.h2zero.cockroach.gradle h2zero
6+
./gradlew -b build.h2zero.mysql.gradle h2zero
7+
./gradlew -b build.h2zero.postgresql.gradle h2zero
8+
9+

build.cockroach.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
./gradlew assemble pTML -b build.gradle
4+
./gradlew -b build.h2zero.cockroach.gradle h2zero
5+

build.h2zero.cockroach.gradle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
jcenter()
5+
mavenLocal()
6+
maven {
7+
url "https://plugins.gradle.org/"
8+
}
9+
}
10+
11+
dependencies {
12+
classpath 'synapticloop:h2zero:4.2.7'
13+
// classpath 'synapticloop:h2zero-extension-taglibs:1.0.0'
14+
}
15+
}
16+
17+
plugins {
18+
id 'java'
19+
id 'eclipse'
20+
}
21+
22+
apply plugin: 'synapticloop.h2zero'
23+
24+
repositories {
25+
mavenLocal()
26+
mavenCentral()
27+
jcenter()
28+
}
29+
30+
h2zero {
31+
inFile = 'src/test/resources/sample-include-cockroach.h2zero'
32+
outDir = '.'
33+
verbose = 'false'
34+
}

build.h2zero.postgresql.gradle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
jcenter()
5+
mavenLocal()
6+
maven {
7+
url "https://plugins.gradle.org/"
8+
}
9+
}
10+
11+
dependencies {
12+
classpath 'synapticloop:h2zero:4.2.7'
13+
// classpath 'synapticloop:h2zero-extension-taglibs:1.0.0'
14+
}
15+
}
16+
17+
plugins {
18+
id 'java'
19+
id 'eclipse'
20+
}
21+
22+
apply plugin: 'synapticloop.h2zero'
23+
24+
repositories {
25+
mavenLocal()
26+
mavenCentral()
27+
jcenter()
28+
}
29+
30+
h2zero {
31+
inFile = 'src/test/resources/sample-include-postgresql.h2zero'
32+
outDir = '.'
33+
verbose = 'false'
34+
}

build.postgresql.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
./gradlew assemble pTML -b build.gradle
4+
./gradlew -b build.h2zero.postgresql.gradle h2zero
5+

src/main/java/synapticloop/h2zero/H2ZeroParser.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import synapticloop.h2zero.validator.field.FieldNotNullLengthValidator;
6565
import synapticloop.h2zero.validator.field.FieldPopulateForeignKeyValidator;
6666
import synapticloop.h2zero.validator.field.FieldPopulatePrimaryKeyValidator;
67+
import synapticloop.h2zero.validator.field.FieldPrimaryKeyTypeValidator;
6768
import synapticloop.h2zero.validator.field.SQLite3FieldBlobValidator;
6869
import synapticloop.h2zero.validator.field.SQLite3FieldClobValidator;
6970
import synapticloop.h2zero.validator.field.SQLite3FieldPrimaryKeyValidator;
@@ -81,6 +82,8 @@
8182
import synapticloop.h2zero.validator.inserter.InserterKeyValidator;
8283
import synapticloop.h2zero.validator.inserter.InserterNameValidator;
8384
import synapticloop.h2zero.validator.inserter.InserterQueryParameterNameValidator;
85+
import synapticloop.h2zero.validator.options.OptionsDatabaseDefaultValidator;
86+
import synapticloop.h2zero.validator.options.OptionsDatabaseTypeValidator;
8487
import synapticloop.h2zero.validator.question.QuestionInternalNameValidator;
8588
import synapticloop.h2zero.validator.question.QuestionJsonUniqueKeyExistsValidator;
8689
import synapticloop.h2zero.validator.question.QuestionKeyValidator;
@@ -119,6 +122,8 @@ public class H2ZeroParser {
119122
static {
120123
// options
121124
validators.add(new OptionsGeneratorsValidator());
125+
validators.add(new OptionsDatabaseDefaultValidator());
126+
validators.add(new OptionsDatabaseTypeValidator());
122127

123128
// overall validators
124129
validators.add(new UniqueTableViewNameValidator());
@@ -142,6 +147,7 @@ public class H2ZeroParser {
142147
validators.add(new FieldNameDuplicateValidator());
143148
validators.add(new FieldIgnoredKeysValidator());
144149
validators.add(new FieldNotNullLengthValidator());
150+
validators.add(new FieldPrimaryKeyTypeValidator());
145151

146152
validators.add(new SQLite3FieldBlobValidator());
147153
validators.add(new SQLite3FieldClobValidator());
@@ -205,6 +211,7 @@ public class H2ZeroParser {
205211
validators.add(new ConstantDeleterValidator());
206212
validators.add(new ConstantInserterValidator());
207213
validators.add(new ConstantUpdaterValidator());
214+
208215
}
209216

210217
private static Map<String, BaseValidator> validatorMap = new HashMap<>();

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ public static void setBigint(PreparedStatement preparedStatement, int parameterI
196196
}
197197
}
198198

199+
/**
200+
* Set a BIGSERIAL datatype to a prepared statement with the value of the passed
201+
* in Long, or the correct SQL null type if null
202+
*
203+
* @param preparedStatement The prepared statement
204+
* @param parameterIndex the index of the parameter
205+
* @param value the value to be set
206+
*
207+
* @throws SQLException if something went horribly wrong
208+
*/
209+
public static void setBigserial(PreparedStatement preparedStatement, int parameterIndex, Long value) throws SQLException {
210+
setBigint(preparedStatement, parameterIndex, value);
211+
}
212+
199213
/**
200214
* Set a VARCHAR datatype to a prepared statement with the value of the passed
201215
* in String, or the correct SQL null type if null
@@ -250,6 +264,52 @@ public static void setInt(PreparedStatement preparedStatement, int parameterInde
250264
}
251265
}
252266

267+
/**
268+
* Set a SMALLINT datatype to a prepared statement with the value of the passed
269+
* in Integer, or the correct SQL null type if null
270+
*
271+
* @param preparedStatement The prepared statement
272+
* @param parameterIndex the index of the parameter
273+
* @param value the value to be set
274+
*
275+
* @throws SQLException if something went horribly wrong
276+
*/
277+
public static void setSmallint(PreparedStatement preparedStatement, int parameterIndex, Integer value) throws SQLException {
278+
if(null == value) {
279+
preparedStatement.setNull(parameterIndex, Types.SMALLINT);
280+
} else {
281+
preparedStatement.setInt(parameterIndex, value);
282+
}
283+
}
284+
285+
/**
286+
* Set a SMALLSERIAL datatype to a prepared statement with the value of the passed
287+
* in Integer, or the correct SQL null type if null
288+
*
289+
* @param preparedStatement The prepared statement
290+
* @param parameterIndex the index of the parameter
291+
* @param value the value to be set
292+
*
293+
* @throws SQLException if something went horribly wrong
294+
*/
295+
public static void setSmallserial(PreparedStatement preparedStatement, int parameterIndex, Integer value) throws SQLException {
296+
setSmallint(preparedStatement, parameterIndex, value);
297+
}
298+
299+
/**
300+
* Set a SERIAL datatype to a prepared statement with the value of the passed
301+
* in Integer, or the correct SQL null type if null
302+
*
303+
* @param preparedStatement The prepared statement
304+
* @param parameterIndex the index of the parameter
305+
* @param value the value to be set
306+
*
307+
* @throws SQLException if something went horribly wrong
308+
*/
309+
public static void setSerial(PreparedStatement preparedStatement, int parameterIndex, Integer value) throws SQLException {
310+
setInt(preparedStatement, parameterIndex, value);
311+
}
312+
253313
/**
254314
* Set a DATETIME datatype to a prepared statement with the value of the passed
255315
* in datetime or the correct SQL null type if null
@@ -364,6 +424,20 @@ public static void setFloat(PreparedStatement preparedStatement, int parameterIn
364424
}
365425
}
366426

427+
/**
428+
* Set a NUMERIC datatype to a prepared statement with the value of the passed
429+
* in float, or the correct SQL null type if null
430+
*
431+
* @param preparedStatement The prepared statement
432+
* @param parameterIndex the index of the parameter
433+
* @param value the value to be set
434+
*
435+
* @throws SQLException if something went horribly wrong
436+
*/
437+
public static void setNumeric(PreparedStatement preparedStatement, int parameterIndex, Float value) throws SQLException {
438+
setFloat(preparedStatement, parameterIndex, value);
439+
}
440+
367441
/**
368442
* Set a TINYINT datatype to a prepared statement with the value of the passed
369443
* in boolean, or the correct SQL null type if null
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package synapticloop.h2zero.base.manager.postgresql;
2+
3+
/*
4+
* Copyright (c) 2012-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+
import synapticloop.h2zero.base.manager.BaseConnectionManager;
21+
22+
public class ConnectionManager extends BaseConnectionManager {
23+
24+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package synapticloop.h2zero.base.model.postgresql;
2+
3+
/*
4+
* Copyright (c) 2018 - 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+
import java.sql.Connection;
21+
import java.sql.SQLException;
22+
23+
import synapticloop.h2zero.base.manager.mysql.ConnectionManager;
24+
25+
public abstract class ModelBase extends synapticloop.h2zero.base.model.ModelBase {
26+
27+
@Override
28+
protected Connection getConnection() throws SQLException {
29+
return(ConnectionManager.getConnection());
30+
}
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package synapticloop.h2zero.base.validator;
2+
3+
import synapticloop.h2zero.base.validator.bean.ValidationBean;
4+
import synapticloop.h2zero.base.validator.bean.ValidationFieldBean;
5+
6+
/*
7+
* Copyright (c) 2013-2020 synapticloop.
8+
* All rights reserved.
9+
*
10+
* This source code and any derived binaries are covered by the terms and
11+
* conditions of the Licence agreement ("the Licence"). You may not use this
12+
* source code or any derived binaries except in compliance with the Licence.
13+
* A copy of the Licence is available in the file named LICENCE shipped with
14+
* this source code or binaries.
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the Licence is distributed on an "AS IS" BASIS, WITHOUT
18+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
19+
* Licence for the specific language governing permissions and limitations
20+
* under the Licence.
21+
*/
22+
23+
24+
public class NumericValidator extends ValidatorBase {
25+
26+
public NumericValidator(String nmField, String value, int minLength, int maxLength, boolean allowNull) {
27+
super(nmField, value, minLength, maxLength, allowNull, false);
28+
}
29+
}

0 commit comments

Comments
 (0)