Skip to content

Commit bde957c

Browse files
committed
fied updaters - added comments, code cleanup
1 parent 14aef93 commit bde957c

16 files changed

+363
-130
lines changed

.idea/jarRepositories.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ plugins {
55

66
id "com.github.ben-manes.versions" version "0.49.0"
77

8-
// id 'com.gradle.plugin-publish' version '0.11.0'
8+
id 'com.gradle.plugin-publish' version '1.2.1'
99
// id 'co.riiid.gradle' version '0.4.2'
1010

1111
id 'synapticloop.copyrightr' version '1.3.1'
12-
// id 'synapticloop.documentr' version '3.1.0'
1312

1413
}
1514

@@ -87,13 +86,6 @@ test {
8786
maxParallelForks = 1
8887
}
8988

90-
//shadowJar {
91-
// configurations = [project.configurations.shadowRuntime]
92-
//}
93-
//
94-
//build.finalizedBy(project.tasks.shadowJar)
95-
96-
9789
publishing {
9890
publications {
9991
mavenJava(MavenPublication) {
@@ -106,20 +98,23 @@ publishing {
10698
}
10799
}
108100

109-
//pluginBundle {
110-
//
111-
// website = 'https://github.com/synapticloop/h2zero'
112-
// vcsUrl = 'https://github.com/synapticloop/h2zero'
113-
// description = 'lightweight ORM generator for mysql, java and optionally jsp/servlets - this utilises the templar templating language'
114-
// tags = ['h2zero', 'ORM', 'generator']
115-
//
116-
// plugins {
117-
// h2zeroPlugin {
118-
// id = 'synapticloop.h2zero'
119-
// displayName = 'Synapticloop Gradle h2zero plugin'
120-
// }
121-
// }
122-
//}
101+
/*
102+
* The Gradle Plugin Publisher
103+
*/
104+
gradlePlugin {
105+
website = 'https://github.com/synapticloop/h2zero'
106+
vcsUrl = 'https://github.com/synapticloop/h2zero'
107+
108+
plugins {
109+
h2zeroPlugin {
110+
id = 'synapticloop.h2zero'
111+
implementationClass = 'synapticloop.h2zero.plugin.gradle.H2ZeroPlugin'
112+
displayName = 'Synapticloop Gradle h2zero plugin'
113+
description = 'lightweight ORM Java code generator for SQL databases: mysql, sqlite3, postgresql, and cockroach - this utilises the templar templating language'
114+
tags = ['h2zero', 'ORM', 'generator']
115+
}
116+
}
117+
}
123118

124119
copyrightr {
125120
dryRun = false
@@ -140,15 +135,3 @@ copyrightr {
140135

141136
failOnMissing = false
142137
}
143-
//
144-
//documentr {
145-
// // where to generate the README file
146-
// directory = '.'
147-
//
148-
// // wnether to be verbose and output more
149-
// verbose = 'true'
150-
//
151-
// // extension - can be either md or adoc
152-
// extension = 'md' // this is the default
153-
//// extension = 'adoc' // perhaps you want asciidoc?
154-
//}

build.sqlite.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 --no-daemon -b build.h2zero.sqlite3.gradle h2zero
5+

src/main/resources/java-create-updater.templar

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@ import java.sql.Types;{\n}
1717
import java.sql.Timestamp;{\n}
1818
{\n}
1919
import synapticloop.h2zero.base.manager.{options.database}.ConnectionManager;{\n}
20-
import {database.package}.finder.{table.javaClassName}Finder;{\n}
2120
import {database.package}.model.util.Constants;{\n}
2221
{\n}
22+
{import classpath:/snippet/global/java-logger.templar}
23+
{\n}
2324

2425
public class {table.javaClassName}Updater {{{\n}
2526
{-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2627
THE UPDATER STRINGS FIELDS
2728
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --}
29+
{set "Updater" as classType}
2830
{set table as baseSchemaObject}
2931
{import classpath:/snippet/global/java-binder-declaration.templar}
3032

33+
{set table.javaClassName as loggerClass}
34+
{import classpath:/snippet/global/java-logger-declaration.templar}
35+
{\n}
3136
{\t}// static fields generated by synapticloop h2zero{\n}
3237
{\t}private static final String SQL_UPDATE_START = "update {table.name} ";{\n}{\n}
3338

@@ -54,7 +59,19 @@ public class {table.javaClassName}Updater {{{\n}
5459
{\t} * See the '{updater.name}Silent' method for a non-throwing method.{\n}
5560
{\t} * {\n}
5661
{\t} * @param connection the connection to the database{\n}
57-
{\t} * {\n}
62+
{loop baseQueryObject.updateFields as setField}
63+
{\t} * @param {setField.javaName}{if setField.isInField}List{endif} the field to set as a {if setField.isInField}List<{whereField.javaType}>{else}{setField.javaType}{endif}{\n}
64+
{endloop}
65+
66+
{if baseQueryObject.hasWhereFieldAliases}
67+
{loop baseQueryObject.whereFields as whereField}
68+
{\t} * @param {whereField.javaName}{if whereField.isInField}List{endif} - The where clause to set as a {if whereField.isInField}List<{whereField.javaType}>{else}{whereField.javaType}{endif}{\n}
69+
{endloop}
70+
{else}
71+
{loop baseQueryObject.uniqueWhereFields as whereField}
72+
{\t} * @param {whereField.javaName}{if whereField.isInField}List{endif} - The where clause to set as a {if whereField.isInField}List<{whereField.javaType}>{else}{whereField.javaType}{endif}{\n}
73+
{endloop}
74+
{endif} {\t} * {\n}
5875
{\t} * @return The number of rows that were updated{\n}
5976
{\t} * @throws SQLException if there was an error in the statement or database connection{\n}
6077
{\t} */ {\n}
@@ -86,44 +103,86 @@ public class {table.javaClassName}Updater {{{\n}
86103
{\t}}{\n}
87104
{\n}
88105

106+
107+
108+
109+
{\t}/**{\n}
110+
{\t} * This is the updater for '{updater.name}' and will throw a SQLException on error{\n}
111+
{\t} * See the '{updater.name}Silent' method for a non-throwing method.{\n}
112+
{\t} * {\n}
113+
{loop baseQueryObject.updateFields as setField}
114+
{\t} * @param {setField.javaName}{if setField.isInField}List{endif} the field to set as a {if setField.isInField}List<{whereField.javaType}>{else}{setField.javaType}{endif}{\n}
115+
{endloop}
116+
117+
{if baseQueryObject.hasWhereFieldAliases}
118+
{loop baseQueryObject.whereFields as whereField}
119+
{\t} * @param {whereField.javaName}{if whereField.isInField}List{endif} - The where clause to set as a {if whereField.isInField}List<{whereField.javaType}>{else}{whereField.javaType}{endif}{\n}
120+
{endloop}
121+
{else}
122+
{loop baseQueryObject.uniqueWhereFields as whereField}
123+
{\t} * @param {whereField.javaName}{if whereField.isInField}List{endif} - The where clause to set as a {if whereField.isInField}List<{whereField.javaType}>{else}{whereField.javaType}{endif}{\n}
124+
{endloop}
125+
{endif} {\t} * {\n}
126+
{\t} * @return The number of rows that were updated or -1 on error{\n}
127+
{\t} */ {\n}
128+
89129
{\t}public static int {updater.name}(
90130

91131
{import classpath:/snippet/global/java-method-parameters.templar}
92132

93133
) throws SQLException {{{\n}
94134

95-
{\t}{\t}int numRowsUpdated = -1;{\n}
96135
{\t}{\t}try (Connection connection = ConnectionManager.getConnection()) {{{\n}
97-
{\t}{\t}{\t}numRowsUpdated = {updater.name}(connection{if fn:>[fn:+[updateFieldsLength, whereFieldsLength], '0']}, {endif}
136+
{\t}{\t}{\t}return({updater.name}(connection{if fn:>[fn:+[updateFieldsLength, whereFieldsLength], '0']}, {endif}
98137

99138
{import classpath:/snippet/global/java-method-parameters-call.templar}
100139

101-
);{\n}
140+
));{\n}
102141
{\t}{\t}}{\n}
103-
{\t}{\t}return(numRowsUpdated);{\n}
104142
{\t}}{\n}
105143
{\n}
106144

145+
146+
147+
148+
149+
{\t}/**{\n}
150+
{\t} * This is the updater for '{updater.name}' and will silently swallow any {\n}
151+
{\t} * SQLException on error and return a -1 as the number of rows updated.{\n}
152+
{\t} * See the '{updater.name}' method for a throwing method.{\n}
153+
{\t} * {\n}
154+
{loop baseQueryObject.updateFields as setField}
155+
{\t} * @param {setField.javaName}{if setField.isInField}List{endif} the field to set as a {if setField.isInField}List<{whereField.javaType}>{else}{setField.javaType}{endif}{\n}
156+
{endloop}
157+
158+
{if baseQueryObject.hasWhereFieldAliases}
159+
{loop baseQueryObject.whereFields as whereField}
160+
{\t} * @param {whereField.javaName}{if whereField.isInField}List{endif} - The where clause to set as a {if whereField.isInField}List<{whereField.javaType}>{else}{whereField.javaType}{endif}{\n}
161+
{endloop}
162+
{else}
163+
{loop baseQueryObject.uniqueWhereFields as whereField}
164+
{\t} * @param {whereField.javaName}{if whereField.isInField}List{endif} - The where clause to set as a {if whereField.isInField}List<{whereField.javaType}>{else}{whereField.javaType}{endif}{\n}
165+
{endloop}
166+
{endif} {\t} * {\n}
167+
{\t} * @return The number of rows that were updated or -1 on error{\n}
168+
{\t} */ {\n}
169+
107170
{\t}public static int {updater.name}Silent(
108171

109172
{import classpath:/snippet/global/java-method-parameters.templar}
110173

111174
) {{{\n}
112-
{\t}{\t}int numRowsUpdated = -1;{\n}
113175
{\t}{\t}try (Connection connection = ConnectionManager.getConnection()) {{{\n}
114-
{\t}{\t}{\t}numRowsUpdated = {updater.name}(connection{if fn:>[fn:+[updateFieldsLength, whereFieldsLength], '0']}, {endif}
176+
{\t}{\t}{\t}return({updater.name}(connection{if fn:>[fn:+[updateFieldsLength, whereFieldsLength], '0']}, {endif}
115177

116178
{import classpath:/snippet/global/java-method-parameters-call.templar}
117179

118-
);{\n}
180+
));{\n}
119181
{\t}{\t}} catch (SQLException sqlex) {{{\n}
120-
{\t}{\t}{\t}sqlex.printStackTrace();{\n}
182+
{import classpath:/snippet/global/exception-sql-log-silent.templar}
121183
{\t}{\t}{\t}return(-1);{\n}
122184
{\t}{\t}}{\n}
123-
{\t}{\t}return(numRowsUpdated);{\n}
124185
{\t}}{\n}
125186
{\n}
126-
127187
{endloop}
128-
129188
}

src/main/resources/snippet/finder/user-finders.templar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
{\t}{\t}}{\n}
188188
{\n}
189189
{\n}
190-
{\t}{\t}if(null == result{if !finder.unique}s || results.size() == 0{endif}) {{{\n}
190+
{\t}{\t}if({if !finder.unique}results.size() == 0{else}null == result{endif}) {{{\n}
191191
{\t}{\t}{\t}throw new H2ZeroFinderException("Could not find result.");{\n}
192192
{\t}{\t}}{\n}
193193
{\t}{\t}return(result{if !finder.unique}s{endif});{\n}

src/test/java/synapticloop/sample/h2zero/sqlite3/finder/AuthorFinder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public static List<Author> findByIdAuthorStatus(Connection connection, Long idAu
357357
}
358358

359359

360-
if(null == results || results.size() == 0) {
360+
if(results.size() == 0) {
361361
throw new H2ZeroFinderException("Could not find result.");
362362
}
363363
return(results);
@@ -471,7 +471,7 @@ public static List<Author> findByFlIsUpdating(Connection connection, Boolean flI
471471
}
472472

473473

474-
if(null == results || results.size() == 0) {
474+
if(results.size() == 0) {
475475
throw new H2ZeroFinderException("Could not find result.");
476476
}
477477
return(results);
@@ -702,7 +702,7 @@ public static List<Author> findAllToBeEvaluated(Connection connection, Timestamp
702702
}
703703

704704

705-
if(null == results || results.size() == 0) {
705+
if(results.size() == 0) {
706706
throw new H2ZeroFinderException("Could not find result.");
707707
}
708708
return(results);
@@ -933,7 +933,7 @@ public static List<Author> findLimitedToBeEvaluated(Connection connection, Times
933933
}
934934

935935

936-
if(null == results || results.size() == 0) {
936+
if(results.size() == 0) {
937937
throw new H2ZeroFinderException("Could not find result.");
938938
}
939939
return(results);

src/test/java/synapticloop/sample/h2zero/sqlite3/finder/PetFinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public static List<Pet> findByNmPetNumAge(Connection connection, String nmPet, I
349349
}
350350

351351

352-
if(null == results || results.size() == 0) {
352+
if(results.size() == 0) {
353353
throw new H2ZeroFinderException("Could not find result.");
354354
}
355355
return(results);

src/test/java/synapticloop/sample/h2zero/sqlite3/finder/UserFinder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public static List<User> findByNumAge(Connection connection, Integer numAge, Int
367367
}
368368

369369

370-
if(null == results || results.size() == 0) {
370+
if(results.size() == 0) {
371371
throw new H2ZeroFinderException("Could not find result.");
372372
}
373373
return(results);
@@ -483,7 +483,7 @@ public static List<User> findByFlIsAliveNumAge(Connection connection, Boolean fl
483483
}
484484

485485

486-
if(null == results || results.size() == 0) {
486+
if(results.size() == 0) {
487487
throw new H2ZeroFinderException("Could not find result.");
488488
}
489489
return(results);
@@ -964,7 +964,7 @@ public static List<User> findByNumAgeIn(Connection connection, List<Integer> num
964964
}
965965

966966

967-
if(null == results || results.size() == 0) {
967+
if(results.size() == 0) {
968968
throw new H2ZeroFinderException("Could not find result.");
969969
}
970970
return(results);
@@ -1080,7 +1080,7 @@ public static List<User> findByNumAgeBetween(Connection connection, Integer numA
10801080
}
10811081

10821082

1083-
if(null == results || results.size() == 0) {
1083+
if(results.size() == 0) {
10841084
throw new H2ZeroFinderException("Could not find result.");
10851085
}
10861086
return(results);

src/test/java/synapticloop/sample/h2zero/sqlite3/finder/UserTitleFinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public static List<UserTitle> findAllOrdered(Connection connection, Integer limi
347347
}
348348

349349

350-
if(null == results || results.size() == 0) {
350+
if(results.size() == 0) {
351351
throw new H2ZeroFinderException("Could not find result.");
352352
}
353353
return(results);

0 commit comments

Comments
 (0)