Skip to content

Commit fe76d73

Browse files
author
synapticloop
committed
fixed view getIsConstantsplit out generators
1 parent b2f5356 commit fe76d73

Some content is hidden

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

41 files changed

+2073
-12
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ plugins {
2121
group = 'synapticloop'
2222
archivesBaseName = 'h2zero'
2323
description = """lightweight ORM generator for mysql/sqlite, java with extensions for taglibs and routemaster"""
24-
version = '4.3.0'
24+
version = '4.4.1'
2525

2626
tasks.withType(Javadoc).all { enabled = false }
2727

build.h2zero.cockroach.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010

1111
dependencies {
12-
classpath 'synapticloop:h2zero:4.3.0'
12+
classpath 'synapticloop:h2zero:4.4.0'
1313
}
1414
}
1515

build.h2zero.mysql.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010

1111
dependencies {
12-
classpath 'synapticloop:h2zero:4.3.0'
12+
classpath 'synapticloop:h2zero:4.4.0'
1313
}
1414
}
1515

build.h2zero.postgresql.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010

1111
dependencies {
12-
classpath 'synapticloop:h2zero:4.3.0'
12+
classpath 'synapticloop:h2zero:4.4.0'
1313
}
1414
}
1515

build.h2zero.sqlite3.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010

1111
dependencies {
12-
classpath 'synapticloop:h2zero:4.3.0'
12+
classpath 'synapticloop:h2zero:4.4.0'
1313
}
1414
}
1515

build.mysql.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22

33
./gradlew assemble pTML -b build.gradle
4-
./gradlew -b build.h2zero.mysql.gradle h2zero
4+
./gradlew --stacktrace -b build.h2zero.mysql.gradle h2zero
55

src/main/java/synapticloop/h2zero/generator/JavaGenerator.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ private void generateTables(TemplarContext templarContext) throws ParseException
7777
Parser javaCreateQuestionParser = getParser("/java-create-question.templar");
7878
Parser javaCreateUpdaterParser = getParser("/java-create-updater.templar");
7979
Parser javaCreateDeleterParser = getParser("/java-create-deleter.templar");
80+
Parser javaCreateUpserterParser = getParser("/java-create-upserter.templar");
8081

8182
// the select clause bean
8283
Parser javaCreateSelectClauseBeanParser = getParser("/java-create-select-clause-bean.templar");
@@ -87,7 +88,7 @@ private void generateTables(TemplarContext templarContext) throws ParseException
8788
pathname = outFile + options.getOutputCode() + database.getPackagePath() + "/model/util/Statistics.java";
8889
renderToFile(templarContext, javaCreateModelStatisticsParser, pathname);
8990

90-
91+
9192

9293
// now for the tables
9394
List<Table> tables = database.getTables();
@@ -106,12 +107,17 @@ private void generateTables(TemplarContext templarContext) throws ParseException
106107
pathname = outFile + options.getOutputCode() + database.getPackagePath() + "/finder/" + table.getJavaClassName() + "Finder.java";
107108
renderToFile(templarContext, javaCreateFinderParser, pathname);
108109

109-
// the inserter
110110
if(!table.getIsConstant()) {
111+
// the inserter
111112
pathname = outFile + options.getOutputCode() + database.getPackagePath() + "/inserter/" + table.getJavaClassName() + "Inserter.java";
112113
renderToFile(templarContext, javaCreateInserterParser, pathname);
114+
115+
// the upserter
116+
pathname = outFile + options.getOutputCode() + database.getPackagePath() + "/upserter/" + table.getJavaClassName() + "Upserter.java";
117+
renderToFile(templarContext, javaCreateUpserterParser, pathname);
113118
}
114119

120+
115121
// the counters
116122
pathname = outFile + options.getOutputCode() + database.getPackagePath() + "/counter/" + table.getJavaClassName() + "Counter.java";
117123
renderToFile(templarContext, javaCreateCounterParser, pathname);

src/main/java/synapticloop/h2zero/model/Table.java

+26-3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class Table extends BaseSchemaObject {
6666
ALLOWABLE_KEYS.add(JSONKeyConstants.FINDERS);
6767
ALLOWABLE_KEYS.add(JSONKeyConstants.QUESTIONS);
6868
ALLOWABLE_KEYS.add(JSONKeyConstants.UPDATERS);
69+
ALLOWABLE_KEYS.add(JSONKeyConstants.UPSERTERS);
6970
ALLOWABLE_KEYS.add(JSONKeyConstants.COUNTERS);
7071
ALLOWABLE_KEYS.add(JSONKeyConstants.DELETERS);
7172
ALLOWABLE_KEYS.add(JSONKeyConstants.INSERTERS);
@@ -101,6 +102,7 @@ public class Table extends BaseSchemaObject {
101102

102103
private List<Updater> updaters = new ArrayList<>(); // a list of all of the updaters
103104
private List<Inserter> inserters = new ArrayList<>(); // a list of all of the inserters
105+
private List<Upserter> upserters = new ArrayList<>(); // a list of all of the upserters
104106
private List<Deleter> deleters = new ArrayList<>(); // a list of all of the deleters
105107
private List<Constant> constants = new ArrayList<>(); // a list of all of the constants
106108

@@ -184,6 +186,7 @@ public void populateActions() throws H2ZeroParseException {
184186
populateUpdaters(jsonObject);
185187
populateDeleters(jsonObject);
186188
populateInserters(jsonObject);
189+
populateUpserters(jsonObject);
187190
populateConstants(jsonObject);
188191
populateCounters(jsonObject);
189192
populateQuestions(jsonObject);
@@ -481,6 +484,26 @@ private void populateInserters(JSONObject jsonObject) throws H2ZeroParseExceptio
481484
jsonObject.remove(JSONKeyConstants.INSERTERS);
482485
}
483486

487+
private void populateUpserters(JSONObject jsonObject) throws H2ZeroParseException {
488+
JSONArray upserterJson = new JSONArray();
489+
try {
490+
upserterJson = jsonObject.getJSONArray(JSONKeyConstants.UPSERTERS);
491+
} catch (JSONException ojjsonex) {
492+
// do nothing - no finders is ok
493+
}
494+
495+
for (int i = 0; i < upserterJson.length(); i++) {
496+
try {
497+
JSONObject upserterObject = upserterJson.getJSONObject(i);
498+
upserters.add(new Upserter(this, upserterObject));
499+
} catch (JSONException jsonex) {
500+
throw new H2ZeroParseException("Could not parse upserters.", jsonex);
501+
}
502+
}
503+
504+
jsonObject.remove(JSONKeyConstants.UPSERTERS);
505+
}
506+
484507
private void populateConstants(JSONObject jsonObject) throws H2ZeroParseException {
485508
JSONArray constantJson = new JSONArray();
486509
try {
@@ -501,9 +524,8 @@ private void populateConstants(JSONObject jsonObject) throws H2ZeroParseExceptio
501524
jsonObject.remove(JSONKeyConstants.CONSTANTS);
502525
}
503526

504-
505-
506-
527+
528+
507529
// boring old getters and setters
508530
public String getEngine() { return(this.engine); }
509531
public String getCharset() { return(this.charset); }
@@ -513,6 +535,7 @@ private void populateConstants(JSONObject jsonObject) throws H2ZeroParseExceptio
513535

514536
public List<Updater> getUpdaters() { return(updaters); }
515537
public List<Inserter> getInserters() { return(inserters); }
538+
public List<Upserter> getUpserters() { return(upserters); }
516539
public List<Deleter> getDeleters() { return(deleters); }
517540
public List<Constant> getConstants() { return(constants); }
518541

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package synapticloop.h2zero.model;
2+
3+
/*
4+
* Copyright (c) 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+
import synapticloop.h2zero.model.util.JSONKeyConstants;
25+
import synapticloop.h2zero.util.JsonHelper;
26+
27+
public class Upserter extends BaseQueryObject {
28+
29+
/**
30+
* Create an umodel object
31+
*
32+
* @param baseSchemaObject The base schema object to attach to
33+
* @param upserterObject The JSON object that encapsulates the upserter
34+
*
35+
* @throws H2ZeroParseException If there was an error parsing the JSON upserter
36+
* object
37+
*/
38+
public Upserter(BaseSchemaObject baseSchemaObject, JSONObject upserterObject) throws H2ZeroParseException {
39+
super(baseSchemaObject, upserterObject);
40+
41+
}
42+
43+
@Override
44+
public String getType() { return("Upserter"); }
45+
}

src/main/java/synapticloop/h2zero/model/View.java

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ private void populateFields(JSONObject jsonObject) throws H2ZeroParseException {
141141
public boolean getCacheable() { return cacheable; }
142142
public boolean getCacheFindAll() { return cacheFindAll; }
143143

144+
public boolean getIsConstant() { return(false); }
145+
144146
@Override public boolean getIsTable() { return(false); }
145147
@Override public boolean getIsView() { return(true); }
146148
}

src/main/java/synapticloop/h2zero/model/util/JSONKeyConstants.java

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ private JSONKeyConstants() {}
3636
public static final String COUNTERS = "counters";
3737
public static final String DELETERS = "deleters";
3838
public static final String INSERTERS = "inserters";
39+
public static final String UPSERTERS = "upserters";
3940

4041
public static final String UPDATERS = "updaters";
4142
public static final String FIELD_UPDATERS = "fieldUpdaters";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2+
PACKAGE DECLARATION, IMPORT STATEMENTS AND CLASS DEFINITION
3+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --}
4+
5+
package {database.package}.upserter;{\n}{\n}
6+
// - - - - thoughtfully generated by synapticloop h2zero - - - - {\n}
7+
// with the use of synapticloop templar templating language{\n}
8+
// (java-create-upserter.templar){\n}{\n}
9+
10+
{import classpath:/snippet/global/finder-imports.templar}
11+
12+
13+
public class {table.javaClassName}Upserter {{{\n}
14+
15+
{set table as baseSchemaObject}
16+
17+
{import classpath:/snippet/global/java-binder-declaration.templar}
18+
19+
{set "Upserter" as classType}
20+
{set table.javaClassName as loggerClass}
21+
22+
{import classpath:/snippet/global/java-logger-declaration.templar}
23+
24+
25+
{set table as tableOrView}
26+
27+
{-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
28+
STATIC SQL STATEMENTS
29+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --}
30+
31+
{import classpath:/snippet/finder/sql-statements.templar}
32+
33+
{-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
34+
STATEMENT CACHES
35+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --}
36+
37+
{\n}{\t}private {table.javaClassName}Upserter() {{}{\n}{\n}
38+
{loop table.upserters as upserter}
39+
{set upserter as finder}
40+
{\t}public static boolean {upserter.name}({import classpath:/snippet/finder/method-parameters.templar}) {{{\n}
41+
{\t}{\t}return(false);{\n}
42+
{\t}}{\n}
43+
{\n}
44+
{endloop}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package synapticloop.sample.h2zero.cockroach.upserter;
2+
3+
// - - - - thoughtfully generated by synapticloop h2zero - - - -
4+
// with the use of synapticloop templar templating language
5+
// (java-create-upserter.templar)
6+
7+
import java.sql.Connection;
8+
import java.sql.PreparedStatement;
9+
import java.sql.ResultSet;
10+
import java.sql.SQLException;
11+
import java.math.BigDecimal;
12+
import java.util.List;
13+
import java.util.ArrayList;
14+
15+
import synapticloop.h2zero.base.exception.H2ZeroFinderException;
16+
import synapticloop.h2zero.base.manager.cockroach.ConnectionManager;
17+
import synapticloop.h2zero.util.LruCache;
18+
19+
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
23+
24+
import synapticloop.sample.h2zero.cockroach.model.util.Constants;
25+
26+
import synapticloop.sample.h2zero.cockroach.model.AllTypes;
27+
28+
public class AllTypesUpserter {
29+
// the binder is unused in code, but will generate compile problems if this
30+
// class is no longer referenced in the h2zero file. Just a nicety for
31+
// removing dead code
32+
@SuppressWarnings("unused")
33+
private static final String BINDER = Constants.ALL_TYPES_BINDER;
34+
35+
private static final Logger LOGGER = LoggerFactory.getLogger(AllTypesUpserter.class);
36+
private static final String SQL_SELECT_START = "select id_all_types, num_smallint, num_integer, num_bigint, num_decimal, num_numeric, flt_real, dbl_real, num_serial, num_smallserial, num_bigserial from all_types";
37+
private static final String SQL_BUILTIN_FIND_BY_PRIMARY_KEY = SQL_SELECT_START + " where id_all_types = ?";
38+
39+
40+
41+
private AllTypesUpserter() {}
42+
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package synapticloop.sample.h2zero.cockroach.upserter;
2+
3+
// - - - - thoughtfully generated by synapticloop h2zero - - - -
4+
// with the use of synapticloop templar templating language
5+
// (java-create-upserter.templar)
6+
7+
import java.sql.Connection;
8+
import java.sql.PreparedStatement;
9+
import java.sql.ResultSet;
10+
import java.sql.SQLException;
11+
import java.sql.Date;
12+
import java.sql.Blob;
13+
import java.math.BigDecimal;
14+
import java.util.List;
15+
import java.util.ArrayList;
16+
17+
import synapticloop.h2zero.base.exception.H2ZeroFinderException;
18+
import synapticloop.h2zero.base.manager.cockroach.ConnectionManager;
19+
import synapticloop.h2zero.util.LruCache;
20+
21+
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
25+
26+
import synapticloop.sample.h2zero.cockroach.model.util.Constants;
27+
28+
import synapticloop.sample.h2zero.cockroach.model.Pet;
29+
30+
public class PetUpserter {
31+
// the binder is unused in code, but will generate compile problems if this
32+
// class is no longer referenced in the h2zero file. Just a nicety for
33+
// removing dead code
34+
@SuppressWarnings("unused")
35+
private static final String BINDER = Constants.PET_BINDER;
36+
37+
private static final Logger LOGGER = LoggerFactory.getLogger(PetUpserter.class);
38+
private static final String SQL_SELECT_START = "select id_pet, nm_pet, num_age, flt_weight, dt_birthday, img_photo from pet";
39+
private static final String SQL_BUILTIN_FIND_BY_PRIMARY_KEY = SQL_SELECT_START + " where id_pet = ?";
40+
41+
private static final String SQL_FIND_BY_NM_PET_NUM_AGE = SQL_SELECT_START + " where nm_pet = ? and num_age = ?";
42+
43+
44+
private PetUpserter() {}
45+
46+
}

0 commit comments

Comments
 (0)