1313import me .zort .sqllib .api .data .QueryResult ;
1414import me .zort .sqllib .api .data .QueryRowsResult ;
1515import me .zort .sqllib .api .data .Row ;
16- import me .zort .sqllib .api .mapping .MappingProxyInstance ;
17- import me .zort .sqllib .api .mapping .StatementMappingFactory ;
18- import me .zort .sqllib .api .mapping .StatementMappingOptions ;
19- import me .zort .sqllib .api .mapping .StatementMappingRegistry ;
2016import me .zort .sqllib .api .model .SchemaSynchronizer ;
2117import me .zort .sqllib .api .model .TableSchema ;
2218import me .zort .sqllib .api .model .TableSchemaBuilder ;
2824import me .zort .sqllib .internal .fieldResolver .LinkedOneFieldResolver ;
2925import me .zort .sqllib .internal .impl .DefaultObjectMapper ;
3026import me .zort .sqllib .internal .impl .QueryResultImpl ;
31- import me .zort .sqllib .mapping .DefaultStatementMappingFactory ;
32- import me .zort .sqllib .mapping .MappingRegistryImpl ;
33- import me .zort .sqllib .mapping .ProxyInstanceImpl ;
27+ import me .zort .sqllib .model .SQLSchemaSynchronizer ;
3428import me .zort .sqllib .model .builder .DatabaseSchemaBuilder ;
3529import me .zort .sqllib .model .builder .EntitySchemaBuilder ;
36- import me .zort .sqllib .model .SQLSchemaSynchronizer ;
3730import me .zort .sqllib .pool .PooledSQLDatabaseConnection ;
3831import me .zort .sqllib .transaction .Transaction ;
3932import me .zort .sqllib .util .Validator ;
4336
4437import java .lang .reflect .Field ;
4538import java .lang .reflect .Modifier ;
46- import java .lang .reflect .Proxy ;
4739import java .sql .*;
4840import java .util .HashMap ;
4941import java .util .Map ;
@@ -80,8 +72,6 @@ static SQLDatabaseOptions defaultOptions() {
8072
8173 @ Getter
8274 private final ISQLDatabaseOptions options ;
83- private final transient StatementMappingRegistry mappingRegistry ;
84- private transient StatementMappingFactory mappingFactory ;
8575 private transient ObjectMapper objectMapper ;
8676 private transient CacheManager cacheManager ;
8777 @ Setter
@@ -110,10 +100,8 @@ public SQLDatabaseConnectionImpl(final @NotNull SQLConnectionFactory connectionF
110100 super (connectionFactory );
111101 this .options = options == null ? defaultOptions () : options ;
112102 this .objectMapper = new DefaultObjectMapper (this );
113- this .mappingFactory = new DefaultStatementMappingFactory ();
114103 this .transaction = null ;
115104 this .logger = Logger .getGlobal ();
116- this .mappingRegistry = new MappingRegistryImpl (this );
117105
118106 setSchemaSynchronizer (new SQLSchemaSynchronizer ());
119107 enableCaching (CacheManager .noCache ());
@@ -146,15 +134,6 @@ public void setObjectMapper(final @NotNull ObjectMapper objectMapper) {
146134 this .objectMapper = Objects .requireNonNull (objectMapper , "Object mapper cannot be null!" );
147135 }
148136
149- /**
150- * Sets a mapping to use when using {@link SQLDatabaseConnection#createProxy(Class, StatementMappingOptions)}.
151- *
152- * @param mappingFactory Mapping factory to use.
153- */
154- public void setProxyMapping (final @ NotNull StatementMappingFactory mappingFactory ) {
155- this .mappingFactory = Objects .requireNonNull (mappingFactory , "Mapping factory cannot be null!" );
156- }
157-
158137 /**
159138 * Enabled caching for this connection.
160139 *
@@ -176,7 +155,7 @@ public void enableCaching(CacheManager cacheManager) {
176155 @ ApiStatus .Experimental
177156 @ Override
178157 public boolean synchronizeModel () {
179- return mappingRegistry .getProxyInstances ()
158+ return getMappingRegistry () .getProxyInstances ()
180159 .stream ().flatMap (i -> i .getTableSchemas (
181160 getOptions ().getNamingStrategy (),
182161 this instanceof SQLiteDatabaseConnection ).stream ())
@@ -235,86 +214,6 @@ public SchemaSynchronizer<SQLDatabaseConnection> getSchemaSynchronizer() {
235214 return schemaSynchronizer ;
236215 }
237216
238- @ ApiStatus .Experimental
239- @ Override
240- public StatementMappingRegistry getMappingRegistry () {
241- return mappingRegistry ;
242- }
243-
244- /**
245- * Constructs a mapping proxy based on provided interface.
246- * The interface should follow rules for creating mapping repositories
247- * in this library.
248- *
249- * @param mappingInterface Interface to create mapping repository for.
250- * @param <T> Type of mapping repository.
251- * @return Mapping repository.
252- * @see SQLDatabaseConnection#createProxy(Class, StatementMappingOptions)
253- */
254- public <T > T createProxy (Class <T > mappingInterface ) {
255- return createProxy (mappingInterface , new StatementMappingOptions .Builder ().build ());
256- }
257-
258- /**
259- * Replaced with {@link SQLDatabaseConnection#createProxy(Class)}.
260- *
261- * @deprecated Will be removed in future releases.
262- */
263- @ Deprecated
264- @ Override
265- public <T > T createGate (Class <T > mappingInterface ) {
266- return createProxy (mappingInterface );
267- }
268-
269- /**
270- * Constructs a mapping repository based on provided interface.
271- * The interface should follow rules for creating mapping repositories
272- * in this library.
273- * <p>
274- * Example:
275- * <pre>
276- * @Table("users")
277- * public interface MyRepository {
278- * @Select("*")
279- * @Where(@Where.Condition(column = "firstname", value = "{First Name}"))
280- * @Limit(1)
281- * Optional<User> getUser(@Placeholder("First Name") String firstName);
282- *
283- * @Select
284- * List<User> getUsers();
285- *
286- * @Delete
287- * QueryResult deleteUsers();
288- * }
289- *
290- * SQLDatabaseConnection connection = ...;
291- * MyRepository repository = connection.createGate(MyRepository.class);
292- *
293- * Optional<User> user = repository.getUser("John");
294- * </pre>
295- *
296- * @param mappingInterface Interface to create mapping repository for.
297- * @param <T> Type of mapping repository.
298- * @return Mapping repository.
299- */
300- @ SuppressWarnings ("unchecked" )
301- public final <T > T createProxy (final @ NotNull Class <T > mappingInterface , final @ NotNull StatementMappingOptions options ) {
302- Objects .requireNonNull (mappingInterface , "Mapping interface cannot be null!" );
303- Objects .requireNonNull (options , "Options cannot be null!" );
304-
305- AtomicReference <MappingProxyInstance <T >> instanceReference = new AtomicReference <>();
306- T rawInstance = (T ) Proxy .newProxyInstance (mappingInterface .getClassLoader (),
307- new Class []{mappingInterface }, (proxy , method , args ) -> instanceReference .get ().invoke (proxy , method , args ));
308- instanceReference .set (new ProxyInstanceImpl <>(mappingInterface ,
309- options ,
310- mappingFactory .strategy (mappingInterface , this ),
311- mappingFactory .resultAdapter ()));
312-
313- MappingProxyInstance <T > proxyInstanceWrapper = instanceReference .get ();
314- mappingRegistry .registerProxy (proxyInstanceWrapper );
315- return rawInstance ;
316- }
317-
318217 @ ApiStatus .Experimental
319218 public final boolean buildEntitySchema (final @ NotNull String tableName , final @ NotNull Class <?> entityClass ) {
320219 Objects .requireNonNull (entityClass , "Entity class cannot be null!" );
0 commit comments