Skip to content

Commit 0201c3d

Browse files
committed
Added extra fields to Model and added QueryWith but didn't yet implement it in the query builder as i'm way too tired (:
1 parent b22b7e8 commit 0201c3d

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class Model {
4141
private transient boolean internalEntryExists = false;
4242
private transient final Map<Class<? extends Model>, Object> internalJoinedModels = new HashMap<>();
4343
private transient Map<String, Object> internalOriginalValues = new HashMap<>();
44+
private transient Map<String, Object> internalExtraFields = new HashMap<>();
4445

4546
void internalAddJoinedModel(Class<? extends Model> type, Object entity) {
4647
internalJoinedModels.put(type, entity);
@@ -62,6 +63,14 @@ public Map<String, Object> getFieldValues() {
6263
return values;
6364
}
6465

66+
public Map<String, Object> getExtraFields() {
67+
return internalExtraFields;
68+
}
69+
70+
public <T> T getExtraField(String key) {
71+
return (T) internalExtraFields.get(key);
72+
}
73+
6574
public Map<String, Object> getOriginalValues() {
6675
return internalOriginalValues;
6776
}

src/main/java/org/javawebstack/orm/query/Query.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class Query<T extends Model> {
2727
private QueryColumn order;
2828
private boolean desc = false;
2929
private boolean withDeleted = false;
30+
private final List<QueryWith> withs = new ArrayList<>();
3031

3132
public Query(Class<T> model) {
3233
this(Repo.get(model), model);
@@ -46,6 +47,10 @@ public QueryGroup<T> getWhereGroup() {
4647
return where;
4748
}
4849

50+
public List<QueryWith> getWiths() {
51+
return withs;
52+
}
53+
4954
public Integer getLimit() {
5055
return limit;
5156
}
@@ -70,6 +75,15 @@ public Class<T> getModel() {
7075
return model;
7176
}
7277

78+
public Query<T> with(String extra) {
79+
return with(extra, null);
80+
}
81+
82+
public Query<T> with(String extra, String as) {
83+
withs.add(new QueryWith(extra, as));
84+
return this;
85+
}
86+
7387
public Query<T> and(Function<QueryGroup<T>, QueryGroup<T>> group) {
7488
where.and(group);
7589
return this;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.javawebstack.orm.query;
2+
3+
public class QueryWith {
4+
5+
private final String expression;
6+
private final String as;
7+
8+
public QueryWith(String expression, String as) {
9+
this.expression = expression;
10+
this.as = as;
11+
}
12+
13+
public String getExpression() {
14+
return expression;
15+
}
16+
17+
public String getAs() {
18+
return as;
19+
}
20+
}

0 commit comments

Comments
 (0)