|
1 | 1 | package me.zort.sqllib; |
2 | 2 |
|
3 | 3 | import lombok.AllArgsConstructor; |
| 4 | +import lombok.Data; |
4 | 5 | import lombok.Getter; |
5 | 6 | import me.zort.sqllib.api.Query; |
6 | 7 | import me.zort.sqllib.api.SQLConnection; |
|
12 | 13 | import me.zort.sqllib.internal.impl.QueryResultImpl; |
13 | 14 | import me.zort.sqllib.internal.query.*; |
14 | 15 | import me.zort.sqllib.internal.query.part.SetStatement; |
| 16 | +import me.zort.sqllib.transaction.Transaction; |
| 17 | +import org.jetbrains.annotations.ApiStatus; |
15 | 18 | import org.jetbrains.annotations.NotNull; |
16 | 19 | import org.jetbrains.annotations.Nullable; |
17 | 20 |
|
@@ -41,6 +44,12 @@ public SQLDatabaseConnection(final @NotNull SQLConnectionFactory connectionFacto |
41 | 44 | SQLConnectionRegistry.register(this); |
42 | 45 | } |
43 | 46 |
|
| 47 | + /** |
| 48 | + * @deprecated Use {@link SQLDatabaseConnection#createProxy(Class)} instead. |
| 49 | + */ |
| 50 | + @Deprecated |
| 51 | + public abstract <T> T createGate(Class<T> mappingInterface); |
| 52 | + |
44 | 53 | /** |
45 | 54 | * Constructs a mapping repository based on provided interface. |
46 | 55 | * The interface should follow rules for creating mapping repositories |
@@ -72,8 +81,8 @@ public SQLDatabaseConnection(final @NotNull SQLConnectionFactory connectionFacto |
72 | 81 | * @return Mapping repository. |
73 | 82 | * @param <T> Type of mapping repository. |
74 | 83 | */ |
75 | | - public abstract <T> T createGate(Class<T> mappingInterface); |
76 | | - public abstract <T> T createGate(Class<T> mappingInterface, @NotNull StatementMappingOptions options); |
| 84 | + public abstract <T> T createProxy(Class<T> mappingInterface); |
| 85 | + public abstract <T> T createProxy(Class<T> mappingInterface, @NotNull StatementMappingOptions options); |
77 | 86 | public abstract boolean buildEntitySchema(String tableName, Class<?> entityClass); |
78 | 87 |
|
79 | 88 | /** |
@@ -112,27 +121,21 @@ public SQLDatabaseConnection(final @NotNull SQLConnectionFactory connectionFacto |
112 | 121 | */ |
113 | 122 | public abstract QueryResult exec(Query query); |
114 | 123 | public abstract QueryResult exec(String query); |
| 124 | + @ApiStatus.Experimental |
| 125 | + public abstract Transaction beginTransaction(); |
| 126 | + @ApiStatus.Experimental |
| 127 | + public abstract void closeTransaction(); |
| 128 | + @ApiStatus.Experimental |
| 129 | + @Nullable |
| 130 | + public abstract Transaction getTransaction(); |
| 131 | + public abstract boolean isTransactionActive(); |
115 | 132 | protected abstract DefsVals buildDefsVals(Object obj); |
116 | 133 | public abstract boolean isLogSqlErrors(); |
117 | 134 | public abstract boolean isDebug(); |
118 | 135 |
|
119 | | - /** |
120 | | - * Saves this mapping object into database using upsert query. |
121 | | - * <p> |
122 | | - * All mapping strategies are described in: |
123 | | - * {@link SQLDatabaseConnection#query(Query, Class)}. |
124 | | - * |
125 | | - * @param table Table to save into. |
126 | | - * @param obj The object to save. |
127 | | - * @return Result of the query. |
128 | | - */ |
129 | | - // by default, it creates and upsert request. |
130 | | - public QueryResult save(final @NotNull String table, final @NotNull Object obj) { |
131 | | - DefsVals defsVals = buildDefsVals(obj); |
132 | | - |
133 | | - if(defsVals == null) return new QueryResultImpl(false); |
134 | | - |
135 | | - return save(obj).table(table).execute(); |
| 136 | + public UpsertQuery save(final @NotNull String table, final @NotNull Object obj) { |
| 137 | + if(buildDefsVals(obj) == null) throw new IllegalArgumentException("Cannot create save query! (defsVals == null)"); |
| 138 | + return save(obj).table(table); |
136 | 139 | } |
137 | 140 |
|
138 | 141 | public UpsertQuery save(final @NotNull Object obj) { |
@@ -240,4 +243,10 @@ protected static class DefsVals { |
240 | 243 | private final String[] defs; |
241 | 244 | private final SQLDatabaseConnectionImpl.UnknownValueWrapper[] vals; |
242 | 245 | } |
| 246 | + |
| 247 | + @AllArgsConstructor |
| 248 | + @Data |
| 249 | + public static class UnknownValueWrapper { |
| 250 | + private Object object; |
| 251 | + } |
243 | 252 | } |
0 commit comments