Skip to content

Commit 4942731

Browse files
committed
...
1 parent 4837b36 commit 4942731

5 files changed

Lines changed: 51 additions & 4 deletions

File tree

hyperquery/src/main/java/org/slowcoders/hyperquery/core/QEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.lang.annotation.Retention;
44
import java.lang.annotation.RetentionPolicy;
55

6-
public interface QEntity<T extends QEntity<T>> extends QRecord<T> {
6+
public interface QEntity<T extends QEntity<T>> extends QUniqueRecord<T> {
77

88
@Retention(RetentionPolicy.RUNTIME)
99
@interface TColumn {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.slowcoders.hyperquery.core;
2+
3+
public interface QUniqueRecord<T extends QUniqueRecord<T>> extends QRecord<T> {
4+
}

hyperquery/src/main/java/org/slowcoders/hyperquery/impl/QRepository.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
package org.slowcoders.hyperquery.impl;
22

33

4+
import org.apache.ibatis.annotations.Param;
45
import org.apache.ibatis.annotations.Select;
56
import org.apache.ibatis.annotations.Update;
67
import org.slowcoders.hyperquery.core.QEntity;
78
import org.slowcoders.hyperquery.core.QFilter;
89
import org.slowcoders.hyperquery.core.QRecord;
10+
import org.slowcoders.hyperquery.core.QUniqueRecord;
11+
12+
import java.util.List;
913

1014
public interface QRepository {
1115

1216
@Select("${__sql__}")
13-
Object __select__(Object params);
17+
Object __select__(@Param("_parameter") Object params, @Param("__sql__") Object __sql__);
18+
19+
@Update("""
20+
WITH _DATA AS (
21+
${__input_data__}
22+
), _OLD AS (
23+
SELECT * FROM ${__table_name__} AS _OLD
24+
WHERE ${__filter__}
25+
), _NEW AS (
26+
INSERT INTO ${__table_name__} (${__column_names__})
27+
SELECT * FROM _DATA
28+
RETURNING *
29+
)
30+
""")
31+
Object __insert__(QEntity<?> entity);
1432

1533
@Update("""
1634
WITH _DATA AS (
@@ -26,7 +44,23 @@ ON CONFLICT (${__primary_keys__})
2644
RETURNING *
2745
)
2846
""")
29-
Object __insert_or_update__(QEntity entity);
47+
Object __insert_or_update__(QEntity<?> entity);
48+
49+
@Update("""
50+
WITH _DATA AS (
51+
${__input_data__}
52+
), _OLD AS (
53+
SELECT * FROM ${__table_name__} AS OLD
54+
WHERE ${__filter__}
55+
), _NEW AS (
56+
UPDATE ${__table_name__} NEW
57+
SET ${__assign_values__}
58+
FROM _OLD
59+
WHERE ${__new_pk_tuple__} IN (${__old_pk_tuple__})
60+
RETURNING *
61+
)
62+
""")
63+
QRecord<?> __updateAll__(QRecord<?> record, QFilter<?> filter);
3064

3165
@Update("""
3266
WITH _DATA AS (
@@ -42,5 +76,6 @@ WITH _DATA AS (
4276
RETURNING *
4377
)
4478
""")
45-
QRecord<?> __update__(QRecord<?> record, QFilter<?> filter);
79+
QRecord<?> __update__(QUniqueRecord<?> record);
80+
4681
}

hyperquery/src/main/java/org/slowcoders/hyperquery/impl/QStore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,11 @@ public <R extends QRecord<E>> List<R> selectList(Class<R> resultType, QFilter<E>
183183

184184
String id = registerMapper(null, relation, resultType);
185185

186+
HashMap<String, Object> params = new HashMap<>();
187+
params.put("_parameter", filter);
188+
params.put("__sql__", "AAA " + sql);
186189
filter.setSql(sql);
190+
187191
Object res = sqlSessionTemplate.selectList(id, filter);
188192
return (List) res;
189193
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.slowcoders.hyperquery.impl;
2+
3+
public class SqlGenerator {
4+
}

0 commit comments

Comments
 (0)