Skip to content

Commit

Permalink
fied updaters - added comments, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
synapticloop committed Oct 25, 2023
1 parent 14aef93 commit bde957c
Show file tree
Hide file tree
Showing 16 changed files with 363 additions and 130 deletions.
5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 18 additions & 35 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ plugins {

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

// id 'com.gradle.plugin-publish' version '0.11.0'
id 'com.gradle.plugin-publish' version '1.2.1'
// id 'co.riiid.gradle' version '0.4.2'

id 'synapticloop.copyrightr' version '1.3.1'
// id 'synapticloop.documentr' version '3.1.0'

}

Expand Down Expand Up @@ -87,13 +86,6 @@ test {
maxParallelForks = 1
}

//shadowJar {
// configurations = [project.configurations.shadowRuntime]
//}
//
//build.finalizedBy(project.tasks.shadowJar)


publishing {
publications {
mavenJava(MavenPublication) {
Expand All @@ -106,20 +98,23 @@ publishing {
}
}

//pluginBundle {
//
// website = 'https://github.com/synapticloop/h2zero'
// vcsUrl = 'https://github.com/synapticloop/h2zero'
// description = 'lightweight ORM generator for mysql, java and optionally jsp/servlets - this utilises the templar templating language'
// tags = ['h2zero', 'ORM', 'generator']
//
// plugins {
// h2zeroPlugin {
// id = 'synapticloop.h2zero'
// displayName = 'Synapticloop Gradle h2zero plugin'
// }
// }
//}
/*
* The Gradle Plugin Publisher
*/
gradlePlugin {
website = 'https://github.com/synapticloop/h2zero'
vcsUrl = 'https://github.com/synapticloop/h2zero'

plugins {
h2zeroPlugin {
id = 'synapticloop.h2zero'
implementationClass = 'synapticloop.h2zero.plugin.gradle.H2ZeroPlugin'
displayName = 'Synapticloop Gradle h2zero plugin'
description = 'lightweight ORM Java code generator for SQL databases: mysql, sqlite3, postgresql, and cockroach - this utilises the templar templating language'
tags = ['h2zero', 'ORM', 'generator']
}
}
}

copyrightr {
dryRun = false
Expand All @@ -140,15 +135,3 @@ copyrightr {

failOnMissing = false
}
//
//documentr {
// // where to generate the README file
// directory = '.'
//
// // wnether to be verbose and output more
// verbose = 'true'
//
// // extension - can be either md or adoc
// extension = 'md' // this is the default
//// extension = 'adoc' // perhaps you want asciidoc?
//}
5 changes: 5 additions & 0 deletions build.sqlite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

./gradlew assemble pTML -b build.gradle
./gradlew --no-daemon -b build.h2zero.sqlite3.gradle h2zero

85 changes: 72 additions & 13 deletions src/main/resources/java-create-updater.templar
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ import java.sql.Types;{\n}
import java.sql.Timestamp;{\n}
{\n}
import synapticloop.h2zero.base.manager.{options.database}.ConnectionManager;{\n}
import {database.package}.finder.{table.javaClassName}Finder;{\n}
import {database.package}.model.util.Constants;{\n}
{\n}
{import classpath:/snippet/global/java-logger.templar}
{\n}

public class {table.javaClassName}Updater {{{\n}
{-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
THE UPDATER STRINGS FIELDS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --}
{set "Updater" as classType}
{set table as baseSchemaObject}
{import classpath:/snippet/global/java-binder-declaration.templar}

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

Expand All @@ -54,7 +59,19 @@ public class {table.javaClassName}Updater {{{\n}
{\t} * See the '{updater.name}Silent' method for a non-throwing method.{\n}
{\t} * {\n}
{\t} * @param connection the connection to the database{\n}
{\t} * {\n}
{loop baseQueryObject.updateFields as setField}
{\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}
{endloop}

{if baseQueryObject.hasWhereFieldAliases}
{loop baseQueryObject.whereFields as whereField}
{\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}
{endloop}
{else}
{loop baseQueryObject.uniqueWhereFields as whereField}
{\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}
{endloop}
{endif} {\t} * {\n}
{\t} * @return The number of rows that were updated{\n}
{\t} * @throws SQLException if there was an error in the statement or database connection{\n}
{\t} */ {\n}
Expand Down Expand Up @@ -86,44 +103,86 @@ public class {table.javaClassName}Updater {{{\n}
{\t}}{\n}
{\n}




{\t}/**{\n}
{\t} * This is the updater for '{updater.name}' and will throw a SQLException on error{\n}
{\t} * See the '{updater.name}Silent' method for a non-throwing method.{\n}
{\t} * {\n}
{loop baseQueryObject.updateFields as setField}
{\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}
{endloop}

{if baseQueryObject.hasWhereFieldAliases}
{loop baseQueryObject.whereFields as whereField}
{\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}
{endloop}
{else}
{loop baseQueryObject.uniqueWhereFields as whereField}
{\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}
{endloop}
{endif} {\t} * {\n}
{\t} * @return The number of rows that were updated or -1 on error{\n}
{\t} */ {\n}

{\t}public static int {updater.name}(

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

) throws SQLException {{{\n}

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

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

);{\n}
));{\n}
{\t}{\t}}{\n}
{\t}{\t}return(numRowsUpdated);{\n}
{\t}}{\n}
{\n}





{\t}/**{\n}
{\t} * This is the updater for '{updater.name}' and will silently swallow any {\n}
{\t} * SQLException on error and return a -1 as the number of rows updated.{\n}
{\t} * See the '{updater.name}' method for a throwing method.{\n}
{\t} * {\n}
{loop baseQueryObject.updateFields as setField}
{\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}
{endloop}

{if baseQueryObject.hasWhereFieldAliases}
{loop baseQueryObject.whereFields as whereField}
{\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}
{endloop}
{else}
{loop baseQueryObject.uniqueWhereFields as whereField}
{\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}
{endloop}
{endif} {\t} * {\n}
{\t} * @return The number of rows that were updated or -1 on error{\n}
{\t} */ {\n}

{\t}public static int {updater.name}Silent(

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

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

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

);{\n}
));{\n}
{\t}{\t}} catch (SQLException sqlex) {{{\n}
{\t}{\t}{\t}sqlex.printStackTrace();{\n}
{import classpath:/snippet/global/exception-sql-log-silent.templar}
{\t}{\t}{\t}return(-1);{\n}
{\t}{\t}}{\n}
{\t}{\t}return(numRowsUpdated);{\n}
{\t}}{\n}
{\n}

{endloop}

}
2 changes: 1 addition & 1 deletion src/main/resources/snippet/finder/user-finders.templar
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
{\t}{\t}}{\n}
{\n}
{\n}
{\t}{\t}if(null == result{if !finder.unique}s || results.size() == 0{endif}) {{{\n}
{\t}{\t}if({if !finder.unique}results.size() == 0{else}null == result{endif}) {{{\n}
{\t}{\t}{\t}throw new H2ZeroFinderException("Could not find result.");{\n}
{\t}{\t}}{\n}
{\t}{\t}return(result{if !finder.unique}s{endif});{\n}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public static List<Author> findByIdAuthorStatus(Connection connection, Long idAu
}


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


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


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


if(null == results || results.size() == 0) {
if(results.size() == 0) {
throw new H2ZeroFinderException("Could not find result.");
}
return(results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public static List<Pet> findByNmPetNumAge(Connection connection, String nmPet, I
}


if(null == results || results.size() == 0) {
if(results.size() == 0) {
throw new H2ZeroFinderException("Could not find result.");
}
return(results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public static List<User> findByNumAge(Connection connection, Integer numAge, Int
}


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


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


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


if(null == results || results.size() == 0) {
if(results.size() == 0) {
throw new H2ZeroFinderException("Could not find result.");
}
return(results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public static List<UserTitle> findAllOrdered(Connection connection, Integer limi
}


if(null == results || results.size() == 0) {
if(results.size() == 0) {
throw new H2ZeroFinderException("Could not find result.");
}
return(results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public static List<UserUserType> findByNmUser(Connection connection, String nmUs
}


if(null == results || results.size() == 0) {
if(results.size() == 0) {
throw new H2ZeroFinderException("Could not find result.");
}
return(results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@
import java.sql.Timestamp;

import synapticloop.h2zero.base.manager.sqlite3.ConnectionManager;
import synapticloop.sample.h2zero.sqlite3.finder.AllTypesFinder;
import synapticloop.sample.h2zero.sqlite3.model.util.Constants;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class AllTypesUpdater {
// the binder is unused in code, but will generate compile problems if this
// class is no longer referenced in the h2zero file. Just a nicety for
// removing dead code
@SuppressWarnings("unused")
private static final String BINDER = Constants.ALL_TYPES_BINDER;

private static final Logger LOGGER = LoggerFactory.getLogger(AllTypesUpdater.class);

// static fields generated by synapticloop h2zero
private static final String SQL_UPDATE_START = "update all_types ";

Expand Down
Loading

0 comments on commit bde957c

Please sign in to comment.