Skip to content

Commit 2e419d5

Browse files
committed
Remade the entire query builder
1 parent dc304d6 commit 2e419d5

File tree

14 files changed

+777
-432
lines changed

14 files changed

+777
-432
lines changed

src/main/java/org/javawebstack/orm/Model.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.javawebstack.orm;
22

3+
import org.javawebstack.orm.query.Query;
34
import org.javawebstack.orm.util.Helper;
45

56
import java.lang.reflect.Field;
@@ -10,11 +11,11 @@
1011

1112
public class Model {
1213

13-
private static Method saveMethod;
14-
private static Method deleteMethod;
15-
private static Method finalDeleteMethod;
16-
private static Method restoreMethod;
17-
private static Method refreshMethod;
14+
private static final Method saveMethod;
15+
private static final Method deleteMethod;
16+
private static final Method finalDeleteMethod;
17+
private static final Method restoreMethod;
18+
private static final Method refreshMethod;
1819

1920
static {
2021
try {
@@ -42,6 +43,7 @@ public void save(){
4243
try {
4344
saveMethod.invoke(ORM.repo(getClass()), this);
4445
} catch (IllegalAccessException | InvocationTargetException e) {
46+
e.printStackTrace();
4547
throw new RuntimeException(e);
4648
}
4749
}
@@ -120,11 +122,11 @@ public <T extends Model> List<T> hasMany(Class<T> child, String fieldName){
120122
return hasManyRelation(child, fieldName).all();
121123
}
122124

123-
public <T extends Model> QueryBuilder<T> hasManyRelation(Class<T> child){
125+
public <T extends Model> Query<T> hasManyRelation(Class<T> child){
124126
return hasManyRelation(child, Helper.pascalToCamelCase(getClass().getSimpleName())+"Id");
125127
}
126128

127-
public <T extends Model> QueryBuilder<T> hasManyRelation(Class<T> child, String fieldName){
129+
public <T extends Model> Query<T> hasManyRelation(Class<T> child, String fieldName){
128130
try {
129131
Repo<?> ownRepo = Repo.get(getClass());
130132
Integer id = (Integer) ownRepo.getInfo().getField(ownRepo.getInfo().getIdField()).get(this);

src/main/java/org/javawebstack/orm/ORMConfig.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,28 @@ public List<TypeMapper> getTypeMappers(){
5050
public boolean isIdPrimaryKey() {
5151
return idPrimaryKey;
5252
}
53+
public TypeMapper getTypeMapper(Class<?> type, int size){
54+
for(TypeMapper mapper : getTypeMappers()){
55+
SQLType sqlType = mapper.getType(type, size);
56+
if(sqlType != null)
57+
return mapper;
58+
}
59+
return null;
60+
}
61+
public SQLType getType(Class<?> type, int size){
62+
for(TypeMapper mapper : getTypeMappers()){
63+
SQLType sqlType = mapper.getType(type, size);
64+
if(sqlType != null)
65+
return sqlType;
66+
}
67+
return SQLType.TEXT;
68+
}
69+
public String getTypeParameters(Class<?> type, int size){
70+
for(TypeMapper mapper : getTypeMappers()){
71+
SQLType sqlType = mapper.getType(type, size);
72+
if(sqlType != null)
73+
return mapper.getTypeParameters(type, size);
74+
}
75+
return null;
76+
}
5377
}

0 commit comments

Comments
 (0)