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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 2 deletions
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

Lines changed: 26 additions & 3 deletions
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

Lines changed: 45 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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
}

0 commit comments

Comments
 (0)