Skip to content

Commit c7abd71

Browse files
author
synapticloop
committed
reformatted code, fixed H2Zero finder error
1 parent 1a20320 commit c7abd71

File tree

7 files changed

+41
-6
lines changed

7 files changed

+41
-6
lines changed

build.gradle

+1-1
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.2.5'
24+
version = '4.2.6'
2525

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

build.h2zero.mysql.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010

1111
dependencies {
12-
classpath 'synapticloop:h2zero:4.2.5'
12+
classpath 'synapticloop:h2zero:4.2.6'
1313
// classpath 'synapticloop:h2zero-extension-taglibs:1.0.0'
1414
}
1515
}

build.h2zero.sqlite3.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010

1111
dependencies {
12-
classpath 'synapticloop:h2zero:4.1.1'
12+
classpath 'synapticloop:h2zero:4.2.6'
1313
classpath 'synapticloop:h2zero-extension-taglibs:1.0.0'
1414
}
1515
}

src/main/java/synapticloop/h2zero/base/model/ModelBase.java

+10
Original file line numberDiff line numberDiff line change
@@ -608,4 +608,14 @@ protected boolean isDifferent(Object from, Object to) {
608608
protected void addtoJSONObject(JSONObject jsonObject, String key, Object object) {
609609
jsonObject.put(key, object);
610610
}
611+
612+
public JSONObject getToJSON() {
613+
return(toJSON());
614+
}
615+
616+
public abstract JSONObject toJSON();
617+
618+
public abstract String toJsonString();
619+
620+
public abstract String getJsonString();
611621
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
11
package synapticloop.h2zero.base.model;
22

3+
import java.util.List;
4+
5+
import org.json.JSONArray;
36
import org.json.JSONObject;
47

58
public class ModelBaseHelper {
9+
/**
10+
* Add an object to the JSON object
11+
*
12+
* @param jsonObject The JSON object to add the object to
13+
* @param key the key to add to the JSON object
14+
* @param object the object to add
15+
*/
616
public static void addtoJSONObject(JSONObject jsonObject, String key, Object object) {
717
jsonObject.put(key, object);
818
}
19+
20+
public static JSONArray getJSONArrayResponse(List<?> list) {
21+
JSONArray jsonArray = new JSONArray();
22+
for (Object object : list) {
23+
jsonArray.put(((ModelBase)object).toJSON());
24+
}
25+
return(jsonArray);
26+
}
27+
28+
public static JSONObject getJSONResponse(Object object) {
29+
if(object instanceof List<?>) {
30+
getJSONArrayResponse((List<?>)object);
31+
}
32+
return(((ModelBase)object).getToJSON());
33+
}
34+
935
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ public class {table.javaClassName} {if !table.isConstant}extends ModelBase{endif
168168

169169
{\n}// Static lookups for fields in the hit counter.{\n}
170170
{\t}public static final int HIT_TOTAL = 0;{\n}
171-
{\t}public static final int HIT_PRIMARY_KEY = 0;{\n}
172171
{loop table.fields as field}
173172
{\t}public static final int HIT_{field.upperName} = {fieldStatus.index};{\n}
174173
{endloop}{\n}
@@ -447,7 +446,7 @@ public class {table.javaClassName} {if !table.isConstant}extends ModelBase{endif
447446
{\t}{\t}} catch (SQLException sqlex) {{{\n}
448447
{\t}{\t}{\t}throw sqlex;{\n}
449448
{\t}{\t}} finally {{{\n}
450-
{\t}{\t}this.isHydrated = true;
449+
{\t}{\t}this.isHydrated = true;{\n}
451450
{\t}{\t}{\t}ConnectionManager.closeAll(resultSet, preparedStatement);{\n}
452451
{\t}{\t}}{\n}
453452
{\t}}{\n}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
{\t}{\t}}{\n}
189189
{\n}
190190
{\n}
191-
{\t}{\t}if(null == result{if !finder.unique}s{endif}) {{{\n}
191+
{\t}{\t}if(null == result{if !finder.unique}s || results.size() == 0{endif}) {{{\n}
192192
{\t}{\t}{\t}throw new H2ZeroFinderException("Could not find result.");{\n}
193193
{\t}{\t}}{\n}
194194
{\t}{\t}return(result{if !finder.unique}s{endif});{\n}

0 commit comments

Comments
 (0)