Skip to content

Commit

Permalink
Possible fix for #80
Browse files Browse the repository at this point in the history
  • Loading branch information
ccleve committed Nov 10, 2022
1 parent 40eb705 commit d885147
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/main/java/com/dieselpoint/norm/sqlmakers/StandardSqlMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class StandardSqlMaker implements SqlMaker {

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

public StandardPojoInfo getPojoInfo(Class<?> rowClass) {
public synchronized StandardPojoInfo getPojoInfo(Class<?> rowClass) {
StandardPojoInfo pi = map.get(rowClass);
if (pi == null) {
pi = new StandardPojoInfo(rowClass);
Expand Down Expand Up @@ -69,7 +69,7 @@ public Object[] getUpdateArgs(Query query, Object row) {
args[i] = pojoInfo.getValue(row, pojoInfo.updateColumnNames[i]);
}
// add the value for the where clause to the end
for(int i = 0; i <numKeys; i++) {
for (int i = 0; i < numKeys; i++) {
Object pk = pojoInfo.getValue(row, pojoInfo.primaryKeyNames.get(i));
args[pojoInfo.updateSqlArgCount - (numKeys - i)] = pk;
}
Expand All @@ -92,7 +92,11 @@ public void makeUpdateSql(StandardPojoInfo pojoInfo) {
cols.add(prop.name);
}
pojoInfo.updateColumnNames = cols.toArray(new String[cols.size()]);
pojoInfo.updateSqlArgCount = pojoInfo.updateColumnNames.length + pojoInfo.primaryKeyNames.size(); // + # of primary keys for the where arg
pojoInfo.updateSqlArgCount = pojoInfo.updateColumnNames.length + pojoInfo.primaryKeyNames.size(); // + # of
// primary
// keys for
// the where
// arg

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

for(int i = 0; i < pojoInfo.primaryKeyNames.size(); i++){
for (int i = 0; i < pojoInfo.primaryKeyNames.size(); i++) {
if (i > 0) {
buf.append(" and ");
}
Expand Down Expand Up @@ -235,7 +239,7 @@ public String getCreateTableSql(Class<?> clazz) {

if (pojoInfo.primaryKeyNames.size() > 0) {
buf.append(", primary key (");
for(int i = 0; i < pojoInfo.primaryKeyNames.size(); i++){
for (int i = 0; i < pojoInfo.primaryKeyNames.size(); i++) {
if (i > 0) {
buf.append(",");
}
Expand Down Expand Up @@ -295,7 +299,7 @@ public String getDeleteSql(Query query, Object row) {

StringBuilder builder = new StringBuilder("delete from ");
builder.append(table).append(" where ");
for(int i = 0; i < pojoInfo.primaryKeyNames.size(); i++){
for (int i = 0; i < pojoInfo.primaryKeyNames.size(); i++) {
if (i > 0) {
builder.append(" and ");
}
Expand All @@ -310,7 +314,7 @@ public Object[] getDeleteArgs(Query query, Object row) {
StandardPojoInfo pojoInfo = getPojoInfo(row.getClass());
Object[] args = new Object[pojoInfo.primaryKeyNames.size()];

for(int i = 0; i < pojoInfo.primaryKeyNames.size(); i++) {
for (int i = 0; i < pojoInfo.primaryKeyNames.size(); i++) {
Object primaryKeyValue = pojoInfo.getValue(row, pojoInfo.primaryKeyNames.get(i));
args[i] = primaryKeyValue;
}
Expand Down

0 comments on commit d885147

Please sign in to comment.