Skip to content

Commit

Permalink
reformatted code, fixed H2Zero finder error
Browse files Browse the repository at this point in the history
  • Loading branch information
synapticloop committed Apr 19, 2020
1 parent 1a20320 commit c7abd71
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 6 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.2.5'
version = '4.2.6'

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

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.2.5'
classpath 'synapticloop:h2zero:4.2.6'
// classpath 'synapticloop:h2zero-extension-taglibs:1.0.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.1.1'
classpath 'synapticloop:h2zero:4.2.6'
classpath 'synapticloop:h2zero-extension-taglibs:1.0.0'
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/synapticloop/h2zero/base/model/ModelBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -608,4 +608,14 @@ protected boolean isDifferent(Object from, Object to) {
protected void addtoJSONObject(JSONObject jsonObject, String key, Object object) {
jsonObject.put(key, object);
}

public JSONObject getToJSON() {
return(toJSON());
}

public abstract JSONObject toJSON();

public abstract String toJsonString();

public abstract String getJsonString();
}
26 changes: 26 additions & 0 deletions src/main/java/synapticloop/h2zero/base/model/ModelBaseHelper.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
package synapticloop.h2zero.base.model;

import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

public class ModelBaseHelper {
/**
* Add an object to the JSON object
*
* @param jsonObject The JSON object to add the object to
* @param key the key to add to the JSON object
* @param object the object to add
*/
public static void addtoJSONObject(JSONObject jsonObject, String key, Object object) {
jsonObject.put(key, object);
}

public static JSONArray getJSONArrayResponse(List<?> list) {
JSONArray jsonArray = new JSONArray();
for (Object object : list) {
jsonArray.put(((ModelBase)object).toJSON());
}
return(jsonArray);
}

public static JSONObject getJSONResponse(Object object) {
if(object instanceof List<?>) {
getJSONArrayResponse((List<?>)object);
}
return(((ModelBase)object).getToJSON());
}

}
3 changes: 1 addition & 2 deletions src/main/resources/java-create-model.templar
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ public class {table.javaClassName} {if !table.isConstant}extends ModelBase{endif

{\n}// Static lookups for fields in the hit counter.{\n}
{\t}public static final int HIT_TOTAL = 0;{\n}
{\t}public static final int HIT_PRIMARY_KEY = 0;{\n}
{loop table.fields as field}
{\t}public static final int HIT_{field.upperName} = {fieldStatus.index};{\n}
{endloop}{\n}
Expand Down Expand Up @@ -447,7 +446,7 @@ public class {table.javaClassName} {if !table.isConstant}extends ModelBase{endif
{\t}{\t}} catch (SQLException sqlex) {{{\n}
{\t}{\t}{\t}throw sqlex;{\n}
{\t}{\t}} finally {{{\n}
{\t}{\t}this.isHydrated = true;
{\t}{\t}this.isHydrated = true;{\n}
{\t}{\t}{\t}ConnectionManager.closeAll(resultSet, preparedStatement);{\n}
{\t}{\t}}{\n}
{\t}}{\n}
Expand Down
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 @@ -188,7 +188,7 @@
{\t}{\t}}{\n}
{\n}
{\n}
{\t}{\t}if(null == result{if !finder.unique}s{endif}) {{{\n}
{\t}{\t}if(null == result{if !finder.unique}s || results.size() == 0{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

0 comments on commit c7abd71

Please sign in to comment.