getValues() {
15 | return values;
16 | }
17 |
18 | public void put(LinkedList path, T value) {
19 | if (path.isEmpty()) {
20 | values.add(value);
21 | return;
22 | }
23 | P key = path.removeFirst();
24 | PathTree
val = branches.get(key);
25 | if (val == null) {
26 | val = new PathTree<>();
27 | branches.put(key, val);
28 | }
29 | val.put(path, value);
30 | }
31 |
32 | public Set
getKeys() {
33 | return branches.keySet();
34 | }
35 |
36 | public PathTree
get(P p) {
37 | return branches.get(p);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/full/src/main/java/com/tqdev/crudapi/record/RecordService.java:
--------------------------------------------------------------------------------
1 | package com.tqdev.crudapi.record;
2 |
3 | import com.tqdev.crudapi.column.definition.DatabaseDefinitionException;
4 | import com.tqdev.crudapi.record.container.DatabaseRecords;
5 | import com.tqdev.crudapi.record.container.DatabaseRecordsException;
6 | import com.tqdev.crudapi.record.container.Record;
7 | import com.tqdev.crudapi.record.document.ListDocument;
8 |
9 | import java.io.IOException;
10 |
11 | public interface RecordService {
12 |
13 | // crud
14 |
15 | boolean exists(String table);
16 |
17 | String create(String table, Record record, Params params);
18 |
19 | Record read(String table, String id, Params params);
20 |
21 | int update(String table, String id, Record record, Params params);
22 |
23 | int increment(String table, String id, Record record, Params params);
24 |
25 | int delete(String table, String id, Params params);
26 |
27 | ListDocument list(String table, Params params);
28 |
29 | // meta
30 |
31 | void update();
32 |
33 | DatabaseRecords getDatabaseRecords();
34 |
35 | // initialization
36 |
37 | void initialize(String recordsFilename) throws IOException,
38 | DatabaseDefinitionException, DatabaseRecordsException;
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/full/src/main/java/com/tqdev/crudapi/record/RelationIncluder.java:
--------------------------------------------------------------------------------
1 | package com.tqdev.crudapi.record;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.HashMap;
6 | import java.util.LinkedList;
7 | import java.util.List;
8 |
9 | import org.jooq.Condition;
10 | import org.jooq.DSLContext;
11 | import org.jooq.Field;
12 | import org.jooq.ResultQuery;
13 | import org.jooq.impl.DSL;
14 |
15 | import com.tqdev.crudapi.column.reflection.DatabaseReflection;
16 | import com.tqdev.crudapi.column.reflection.ReflectedTable;
17 | import com.tqdev.crudapi.record.container.Record;
18 |
19 | public class RelationIncluder {
20 |
21 | private ColumnSelector columns;
22 |
23 | public RelationIncluder(ColumnSelector columns) {
24 | this.columns = columns;
25 | }
26 |
27 | public void addMandatoryColumns(ReflectedTable table, DatabaseReflection reflection, Params params) {
28 | if (!params.containsKey("include") || !params.containsKey("columns")) {
29 | return;
30 | }
31 | for (String tableNames : params.get("include")) {
32 | ReflectedTable t1 = table;
33 | for (String tableName : tableNames.split(",")) {
34 | ReflectedTable t2 = reflection.getTable(tableName);
35 | if (t2 == null) {
36 | continue;
37 | }
38 | List> fks1 = t1.getFksTo(t2.getName());
39 | ReflectedTable t3 = hasAndBelongsToMany(t1, t2, reflection);
40 | if (t3 != null || !fks1.isEmpty()) {
41 | params.add("mandatory", t2.getName() + "." + t2.getPk().getName());
42 | }
43 | for (Field