Skip to content

Commit

Permalink
fix longs
Browse files Browse the repository at this point in the history
  • Loading branch information
efekos committed Dec 11, 2024
1 parent 05e88ee commit c02d818
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.efekos</groupId>
<artifactId>SimpleQL</artifactId>
<version>1.1</version>
<version>1.1.1</version>

<properties>
<java_version>17</java_version>
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/dev/efekos/simple_ql/data/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import dev.efekos.simple_ql.annotation.Unique;
import dev.efekos.simple_ql.exception.NoGetterException;
import dev.efekos.simple_ql.exception.NoSetterException;
import dev.efekos.simple_ql.exception.TableException;
import dev.efekos.simple_ql.implementor.Implementor;
import dev.efekos.simple_ql.query.Query;
import dev.efekos.simple_ql.query.QueryResult;
Expand Down Expand Up @@ -93,11 +92,13 @@ public class Table<T extends TableRow<T>> {
private <C> Class<C> grabClass(Implementor<C, ?> implementor) {
try {
for (java.lang.reflect.Type type : implementor.getClass().getGenericInterfaces())
if (type instanceof ParameterizedType pt && pt.getRawType() == Implementor.class)
return (Class<C>) Class.forName(pt.getActualTypeArguments()[0].getTypeName());
if (type instanceof ParameterizedType pt && pt.getRawType() == Implementor.class) {
java.lang.reflect.Type t = pt.getActualTypeArguments()[0];
return (Class<C>) Class.forName(t instanceof ParameterizedType ptt ? ptt.getRawType().getTypeName() : t.getTypeName());
}
return null;
} catch (Exception e) {
throw new IllegalStateException();
throw new IllegalStateException(e.getMessage(),e);
}
}

Expand Down Expand Up @@ -147,6 +148,7 @@ void checkExistent() {
*
* @param row {@link T} instance to clean.
*/
@SuppressWarnings("unchecked")
void clean(T row) {
if (!row.isDirty()) return;

Expand All @@ -156,7 +158,10 @@ void clean(T row) {
row.getPrimaryField().setAccessible(true);
Optional<SetterAction<Object>> setter = findSetter(field.getType());
new UpdateActionThread(database.getConnection(), "UPDATE " + name + " SET " + field.getName() + "=? WHERE " + primaryKey.getName() + "= ?;", stmt -> {
if (setter.isPresent()) setter.get().set(stmt, 1, field.get(row));
if (setter.isPresent()) {
if(implementors.containsKey(field.getType())) setter.get().set(stmt, 1, ((Implementor<Object,Object>)implementors.get(field.getType())).write(field.get(row)));
else setter.get().set(stmt, 1, field.get(row));
}
setField(row, row.getPrimaryField(), stmt, 2);
return stmt;
}).start();
Expand Down Expand Up @@ -332,7 +337,7 @@ Optional<SetterAction<Object>> findSetter(Class<?> c) {
if (c == byte.class || c == Byte.class)
return Optional.of((stmt, index, value) -> stmt.setByte(index, (byte) value));
if (c == long.class || c == Long.class)
return Optional.of((stmt, index, value) -> stmt.setByte(index, (byte) value));
return Optional.of((stmt, index, value) -> stmt.setLong(index, (long) value));
if (TableRowTypeAdapter.class.isAssignableFrom(c)) return Optional.of((stmt, index, value) -> {
TableRowTypeAdapter adapter = (TableRowTypeAdapter) value;
stmt.setString(index, adapter.adapt());
Expand Down

0 comments on commit c02d818

Please sign in to comment.