Skip to content

Commit

Permalink
fixed view getIsConstantsplit out generators
Browse files Browse the repository at this point in the history
  • Loading branch information
synapticloop committed Jun 10, 2020
1 parent b2f5356 commit fe76d73
Show file tree
Hide file tree
Showing 41 changed files with 2,073 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ plugins {
group = 'synapticloop'
archivesBaseName = 'h2zero'
description = """lightweight ORM generator for mysql/sqlite, java with extensions for taglibs and routemaster"""
version = '4.3.0'
version = '4.4.1'

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

Expand Down
2 changes: 1 addition & 1 deletion build.h2zero.cockroach.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

dependencies {
classpath 'synapticloop:h2zero:4.3.0'
classpath 'synapticloop:h2zero:4.4.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion build.h2zero.mysql.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

dependencies {
classpath 'synapticloop:h2zero:4.3.0'
classpath 'synapticloop:h2zero:4.4.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion build.h2zero.postgresql.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

dependencies {
classpath 'synapticloop:h2zero:4.3.0'
classpath 'synapticloop:h2zero:4.4.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion build.h2zero.sqlite3.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

dependencies {
classpath 'synapticloop:h2zero:4.3.0'
classpath 'synapticloop:h2zero:4.4.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion build.mysql.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

./gradlew assemble pTML -b build.gradle
./gradlew -b build.h2zero.mysql.gradle h2zero
./gradlew --stacktrace -b build.h2zero.mysql.gradle h2zero

10 changes: 8 additions & 2 deletions src/main/java/synapticloop/h2zero/generator/JavaGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private void generateTables(TemplarContext templarContext) throws ParseException
Parser javaCreateQuestionParser = getParser("/java-create-question.templar");
Parser javaCreateUpdaterParser = getParser("/java-create-updater.templar");
Parser javaCreateDeleterParser = getParser("/java-create-deleter.templar");
Parser javaCreateUpserterParser = getParser("/java-create-upserter.templar");

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



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

// the inserter
if(!table.getIsConstant()) {
// the inserter
pathname = outFile + options.getOutputCode() + database.getPackagePath() + "/inserter/" + table.getJavaClassName() + "Inserter.java";
renderToFile(templarContext, javaCreateInserterParser, pathname);

// the upserter
pathname = outFile + options.getOutputCode() + database.getPackagePath() + "/upserter/" + table.getJavaClassName() + "Upserter.java";
renderToFile(templarContext, javaCreateUpserterParser, pathname);
}


// the counters
pathname = outFile + options.getOutputCode() + database.getPackagePath() + "/counter/" + table.getJavaClassName() + "Counter.java";
renderToFile(templarContext, javaCreateCounterParser, pathname);
Expand Down
29 changes: 26 additions & 3 deletions src/main/java/synapticloop/h2zero/model/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class Table extends BaseSchemaObject {
ALLOWABLE_KEYS.add(JSONKeyConstants.FINDERS);
ALLOWABLE_KEYS.add(JSONKeyConstants.QUESTIONS);
ALLOWABLE_KEYS.add(JSONKeyConstants.UPDATERS);
ALLOWABLE_KEYS.add(JSONKeyConstants.UPSERTERS);
ALLOWABLE_KEYS.add(JSONKeyConstants.COUNTERS);
ALLOWABLE_KEYS.add(JSONKeyConstants.DELETERS);
ALLOWABLE_KEYS.add(JSONKeyConstants.INSERTERS);
Expand Down Expand Up @@ -101,6 +102,7 @@ public class Table extends BaseSchemaObject {

private List<Updater> updaters = new ArrayList<>(); // a list of all of the updaters
private List<Inserter> inserters = new ArrayList<>(); // a list of all of the inserters
private List<Upserter> upserters = new ArrayList<>(); // a list of all of the upserters
private List<Deleter> deleters = new ArrayList<>(); // a list of all of the deleters
private List<Constant> constants = new ArrayList<>(); // a list of all of the constants

Expand Down Expand Up @@ -184,6 +186,7 @@ public void populateActions() throws H2ZeroParseException {
populateUpdaters(jsonObject);
populateDeleters(jsonObject);
populateInserters(jsonObject);
populateUpserters(jsonObject);
populateConstants(jsonObject);
populateCounters(jsonObject);
populateQuestions(jsonObject);
Expand Down Expand Up @@ -481,6 +484,26 @@ private void populateInserters(JSONObject jsonObject) throws H2ZeroParseExceptio
jsonObject.remove(JSONKeyConstants.INSERTERS);
}

private void populateUpserters(JSONObject jsonObject) throws H2ZeroParseException {
JSONArray upserterJson = new JSONArray();
try {
upserterJson = jsonObject.getJSONArray(JSONKeyConstants.UPSERTERS);
} catch (JSONException ojjsonex) {
// do nothing - no finders is ok
}

for (int i = 0; i < upserterJson.length(); i++) {
try {
JSONObject upserterObject = upserterJson.getJSONObject(i);
upserters.add(new Upserter(this, upserterObject));
} catch (JSONException jsonex) {
throw new H2ZeroParseException("Could not parse upserters.", jsonex);
}
}

jsonObject.remove(JSONKeyConstants.UPSERTERS);
}

private void populateConstants(JSONObject jsonObject) throws H2ZeroParseException {
JSONArray constantJson = new JSONArray();
try {
Expand All @@ -501,9 +524,8 @@ private void populateConstants(JSONObject jsonObject) throws H2ZeroParseExceptio
jsonObject.remove(JSONKeyConstants.CONSTANTS);
}






// boring old getters and setters
public String getEngine() { return(this.engine); }
public String getCharset() { return(this.charset); }
Expand All @@ -513,6 +535,7 @@ private void populateConstants(JSONObject jsonObject) throws H2ZeroParseExceptio

public List<Updater> getUpdaters() { return(updaters); }
public List<Inserter> getInserters() { return(inserters); }
public List<Upserter> getUpserters() { return(upserters); }
public List<Deleter> getDeleters() { return(deleters); }
public List<Constant> getConstants() { return(constants); }

Expand Down
45 changes: 45 additions & 0 deletions src/main/java/synapticloop/h2zero/model/Upserter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package synapticloop.h2zero.model;

/*
* Copyright (c) 2020 synapticloop.
*
* All rights reserved.
*
* This source code and any derived binaries are covered by the terms and
* conditions of the Licence agreement ("the Licence"). You may not use this
* source code or any derived binaries except in compliance with the Licence.
* A copy of the Licence is available in the file named LICENCE shipped with
* this source code or binaries.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* Licence for the specific language governing permissions and limitations
* under the Licence.
*/

import org.json.JSONObject;

import synapticloop.h2zero.exception.H2ZeroParseException;
import synapticloop.h2zero.model.util.JSONKeyConstants;
import synapticloop.h2zero.util.JsonHelper;

public class Upserter extends BaseQueryObject {

/**
* Create an umodel object
*
* @param baseSchemaObject The base schema object to attach to
* @param upserterObject The JSON object that encapsulates the upserter
*
* @throws H2ZeroParseException If there was an error parsing the JSON upserter
* object
*/
public Upserter(BaseSchemaObject baseSchemaObject, JSONObject upserterObject) throws H2ZeroParseException {
super(baseSchemaObject, upserterObject);

}

@Override
public String getType() { return("Upserter"); }
}
2 changes: 2 additions & 0 deletions src/main/java/synapticloop/h2zero/model/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ private void populateFields(JSONObject jsonObject) throws H2ZeroParseException {
public boolean getCacheable() { return cacheable; }
public boolean getCacheFindAll() { return cacheFindAll; }

public boolean getIsConstant() { return(false); }

@Override public boolean getIsTable() { return(false); }
@Override public boolean getIsView() { return(true); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private JSONKeyConstants() {}
public static final String COUNTERS = "counters";
public static final String DELETERS = "deleters";
public static final String INSERTERS = "inserters";
public static final String UPSERTERS = "upserters";

public static final String UPDATERS = "updaters";
public static final String FIELD_UPDATERS = "fieldUpdaters";
Expand Down
45 changes: 45 additions & 0 deletions src/main/resources/java-create-upserter.templar
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PACKAGE DECLARATION, IMPORT STATEMENTS AND CLASS DEFINITION
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --}

package {database.package}.upserter;{\n}{\n}
// - - - - thoughtfully generated by synapticloop h2zero - - - - {\n}
// with the use of synapticloop templar templating language{\n}
// (java-create-upserter.templar){\n}{\n}

{import classpath:/snippet/global/finder-imports.templar}


public class {table.javaClassName}Upserter {{{\n}

{set table as baseSchemaObject}

{import classpath:/snippet/global/java-binder-declaration.templar}

{set "Upserter" as classType}
{set table.javaClassName as loggerClass}

{import classpath:/snippet/global/java-logger-declaration.templar}


{set table as tableOrView}

{-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
STATIC SQL STATEMENTS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --}

{import classpath:/snippet/finder/sql-statements.templar}

{-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
STATEMENT CACHES
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --}

{\n}{\t}private {table.javaClassName}Upserter() {{}{\n}{\n}
{loop table.upserters as upserter}
{set upserter as finder}
{\t}public static boolean {upserter.name}({import classpath:/snippet/finder/method-parameters.templar}) {{{\n}
{\t}{\t}return(false);{\n}
{\t}}{\n}
{\n}
{endloop}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package synapticloop.sample.h2zero.cockroach.upserter;

// - - - - thoughtfully generated by synapticloop h2zero - - - -
// with the use of synapticloop templar templating language
// (java-create-upserter.templar)

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.math.BigDecimal;
import java.util.List;
import java.util.ArrayList;

import synapticloop.h2zero.base.exception.H2ZeroFinderException;
import synapticloop.h2zero.base.manager.cockroach.ConnectionManager;
import synapticloop.h2zero.util.LruCache;


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


import synapticloop.sample.h2zero.cockroach.model.util.Constants;

import synapticloop.sample.h2zero.cockroach.model.AllTypes;

public class AllTypesUpserter {
// 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(AllTypesUpserter.class);
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";
private static final String SQL_BUILTIN_FIND_BY_PRIMARY_KEY = SQL_SELECT_START + " where id_all_types = ?";



private AllTypesUpserter() {}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package synapticloop.sample.h2zero.cockroach.upserter;

// - - - - thoughtfully generated by synapticloop h2zero - - - -
// with the use of synapticloop templar templating language
// (java-create-upserter.templar)

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Date;
import java.sql.Blob;
import java.math.BigDecimal;
import java.util.List;
import java.util.ArrayList;

import synapticloop.h2zero.base.exception.H2ZeroFinderException;
import synapticloop.h2zero.base.manager.cockroach.ConnectionManager;
import synapticloop.h2zero.util.LruCache;


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


import synapticloop.sample.h2zero.cockroach.model.util.Constants;

import synapticloop.sample.h2zero.cockroach.model.Pet;

public class PetUpserter {
// 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.PET_BINDER;

private static final Logger LOGGER = LoggerFactory.getLogger(PetUpserter.class);
private static final String SQL_SELECT_START = "select id_pet, nm_pet, num_age, flt_weight, dt_birthday, img_photo from pet";
private static final String SQL_BUILTIN_FIND_BY_PRIMARY_KEY = SQL_SELECT_START + " where id_pet = ?";

private static final String SQL_FIND_BY_NM_PET_NUM_AGE = SQL_SELECT_START + " where nm_pet = ? and num_age = ?";


private PetUpserter() {}

}
Loading

0 comments on commit fe76d73

Please sign in to comment.