Skip to content

Commit d885147

Browse files
author
ccleve
committed
Possible fix for #80
1 parent 40eb705 commit d885147

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/main/java/com/dieselpoint/norm/sqlmakers/StandardSqlMaker.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class StandardSqlMaker implements SqlMaker {
1919

2020
private static ConcurrentHashMap<Class<?>, StandardPojoInfo> map = new ConcurrentHashMap<>();
2121

22-
public StandardPojoInfo getPojoInfo(Class<?> rowClass) {
22+
public synchronized StandardPojoInfo getPojoInfo(Class<?> rowClass) {
2323
StandardPojoInfo pi = map.get(rowClass);
2424
if (pi == null) {
2525
pi = new StandardPojoInfo(rowClass);
@@ -69,7 +69,7 @@ public Object[] getUpdateArgs(Query query, Object row) {
6969
args[i] = pojoInfo.getValue(row, pojoInfo.updateColumnNames[i]);
7070
}
7171
// add the value for the where clause to the end
72-
for(int i = 0; i <numKeys; i++) {
72+
for (int i = 0; i < numKeys; i++) {
7373
Object pk = pojoInfo.getValue(row, pojoInfo.primaryKeyNames.get(i));
7474
args[pojoInfo.updateSqlArgCount - (numKeys - i)] = pk;
7575
}
@@ -92,7 +92,11 @@ public void makeUpdateSql(StandardPojoInfo pojoInfo) {
9292
cols.add(prop.name);
9393
}
9494
pojoInfo.updateColumnNames = cols.toArray(new String[cols.size()]);
95-
pojoInfo.updateSqlArgCount = pojoInfo.updateColumnNames.length + pojoInfo.primaryKeyNames.size(); // + # of primary keys for the where arg
95+
pojoInfo.updateSqlArgCount = pojoInfo.updateColumnNames.length + pojoInfo.primaryKeyNames.size(); // + # of
96+
// primary
97+
// keys for
98+
// the where
99+
// arg
96100

97101
StringBuilder buf = new StringBuilder();
98102
buf.append("update %s set ");
@@ -105,7 +109,7 @@ public void makeUpdateSql(StandardPojoInfo pojoInfo) {
105109
}
106110
buf.append(" where ");
107111

108-
for(int i = 0; i < pojoInfo.primaryKeyNames.size(); i++){
112+
for (int i = 0; i < pojoInfo.primaryKeyNames.size(); i++) {
109113
if (i > 0) {
110114
buf.append(" and ");
111115
}
@@ -235,7 +239,7 @@ public String getCreateTableSql(Class<?> clazz) {
235239

236240
if (pojoInfo.primaryKeyNames.size() > 0) {
237241
buf.append(", primary key (");
238-
for(int i = 0; i < pojoInfo.primaryKeyNames.size(); i++){
242+
for (int i = 0; i < pojoInfo.primaryKeyNames.size(); i++) {
239243
if (i > 0) {
240244
buf.append(",");
241245
}
@@ -295,7 +299,7 @@ public String getDeleteSql(Query query, Object row) {
295299

296300
StringBuilder builder = new StringBuilder("delete from ");
297301
builder.append(table).append(" where ");
298-
for(int i = 0; i < pojoInfo.primaryKeyNames.size(); i++){
302+
for (int i = 0; i < pojoInfo.primaryKeyNames.size(); i++) {
299303
if (i > 0) {
300304
builder.append(" and ");
301305
}
@@ -310,7 +314,7 @@ public Object[] getDeleteArgs(Query query, Object row) {
310314
StandardPojoInfo pojoInfo = getPojoInfo(row.getClass());
311315
Object[] args = new Object[pojoInfo.primaryKeyNames.size()];
312316

313-
for(int i = 0; i < pojoInfo.primaryKeyNames.size(); i++) {
317+
for (int i = 0; i < pojoInfo.primaryKeyNames.size(); i++) {
314318
Object primaryKeyValue = pojoInfo.getValue(row, pojoInfo.primaryKeyNames.get(i));
315319
args[i] = primaryKeyValue;
316320
}

0 commit comments

Comments
 (0)