Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate the config element of the Dao annotation #603

Merged
merged 4 commits into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Using in DAO interface

.. code-block:: java

@Dao(config = AppConfig.class)
@Dao
public interface EmployeeDao {

@Select
Expand Down
14 changes: 8 additions & 6 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ All JDBC drivers are loaded automatically by the `service provider <service prov
For example, when you use Apache Tomcat, you will find the case.
See also: `DriverManager, the service provider mechanism and memory leaks <tomcat driver_>`_

.. _config-configuration-definition:

Configuration definition
========================

Expand All @@ -243,7 +245,6 @@ The simple definition is appropriate in following cases:

.. code-block:: java

@SingletonConfig
public class AppConfig implements Config {

private static final AppConfig CONFIG = new AppConfig();
Expand Down Expand Up @@ -282,22 +283,23 @@ The simple definition is appropriate in following cases:
}
}

.. note::
You can use the above ``AppConfig`` class as follows:

.. code-block:: java

Remember to annotate the class with ``@SingletonConfig``
EmployeeDao dao = new EmployeeDaoImpl(AppConfig.singleton());

Specify the above class to the config element of ``@Dao``.
The above ``EmployeeDao`` interface must be annotated with the ``@Dao`` annotation as follows:

.. code-block:: java

@Dao(config = AppConfig.class)
@Dao
public interface EmployeeDao {

@Select
Employee selectById(Integer id);
}


Advanced definition
-------------------

Expand Down
4 changes: 2 additions & 2 deletions docs/dao.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ You can get ``Config`` instance associated dao instance if you call ``Config.get

.. code-block:: java

@Dao(config = AppConfig.class)
@Dao
public interface EmployeeDao {

default int count() {
Expand Down Expand Up @@ -81,7 +81,7 @@ One dao interface can handle more than one entity classes.

.. code-block:: java

@Dao(config = AppConfig.class)
@Dao
public interface MyDao {

@Select
Expand Down
2 changes: 1 addition & 1 deletion docs/domain.rst
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ The Domain classes showed above are used as follows:

.. code-block:: java

@Dao(config = AppConfig.class)
@Dao
public interface EmployeeDao {

@Select
Expand Down
2 changes: 1 addition & 1 deletion docs/kotlin-support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Dao interfaces

.. code-block:: java

@Dao(config = AppConfig::class)
@Dao
interface PersonDao {
@Sql("""
select * from person where id = /*id*/0
Expand Down
2 changes: 1 addition & 1 deletion docs/query/batch-delete.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Annotate with ``@BatchDelete`` to Dao method for execute batch delete.

.. code-block:: java

@Config(config = AppConfig.class)
@Dao
public interface EmployeeDao {
@BatchDelete
int[] delete(List<Employee> employees);
Expand Down
2 changes: 1 addition & 1 deletion docs/query/batch-insert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Annotate with ``@BatchInsert`` to Dao method for execute batch insert.

.. code-block:: java

@Config(config = AppConfig.class)
@Dao
public interface EmployeeDao {
@BatchInsert
int[] insert(List<Employee> employees);
Expand Down
2 changes: 1 addition & 1 deletion docs/query/batch-update.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Annotate with ``@BatchUpdate`` to Dao method for execute batch update.

.. code-block:: java

@Config(config = AppConfig.class)
@Dao
public interface EmployeeDao {
@BatchUpdate
int[] update(List<Employee> employees);
Expand Down
2 changes: 1 addition & 1 deletion docs/query/delete.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Annotate with ``@Delete`` to Dao method for execute delete.

.. code-block:: java

@Config(config = AppConfig.class)
@Dao
public interface EmployeeDao {
@Delete
int delete(Employee employee);
Expand Down
2 changes: 1 addition & 1 deletion docs/query/function.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ To call stored functions, you must annotate DAO methods with the ``@Function`` a

.. code-block:: java

@Config(config = AppConfig.class)
@Dao
public interface EmployeeDao {
@Function
Integer execute(@In Integer id, @InOut Reference<BigDecimal> salary);
Expand Down
2 changes: 1 addition & 1 deletion docs/query/insert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Annotate with ``@Insert`` to Dao method for execute insert.

.. code-block:: java

@Config(config = AppConfig.class)
@Dao
public interface EmployeeDao {
@Insert
int insert(Employee employee);
Expand Down
2 changes: 1 addition & 1 deletion docs/query/procedure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ To call stored procedures, you must annotate DAO methods with the ``@Procedure``

.. code-block:: java

@Config(config = AppConfig.class)
@Dao
public interface EmployeeDao {
@Procedure
void execute(@In Integer id, @InOut Reference<BigDecimal> salary);
Expand Down
4 changes: 2 additions & 2 deletions docs/query/script.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ annotate DAO methods with ``@Script``:

.. code-block:: java

@Config(config = AppConfig.class)
@Dao
public interface EmployeeDao {
@Script
void createTable();
Expand Down Expand Up @@ -71,7 +71,7 @@ You can specify scripts to DAO methods with the ``@Sql`` annotation:

.. code-block:: java

@Config(config = AppConfig.class)
@Dao
public interface EmployeeDao {
@Sql("create table employee (id integer, name varchar(200))")
@Script
Expand Down
4 changes: 2 additions & 2 deletions docs/query/select.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Annotate with ``@Select`` to Dao method for execute search.

.. code-block:: java

@Config(config = AppConfig.class)
@Dao
public interface EmployeeDao {
@Select
List<Employee> selectByDepartmentName(String departmentName);
Expand Down Expand Up @@ -289,7 +289,7 @@ You define ``SelectOptions`` as Dao method parameter.

.. code-block:: java

@Config(config = AppConfig.class)
@Dao
public interface EmployeeDao {
@Select
List<Employee> selectByDepartmentName(String departmentName, SelectOptions options);
Expand Down
2 changes: 1 addition & 1 deletion docs/query/sql-processor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To mark a DAO method as an SQL processor, annotate the method with ``@SqlProcess

.. code-block:: java

@Config(config = AppConfig.class)
@Dao
public interface EmployeeDao {
@SqlProcessor
<R> R process(Integer id, BiFunction<Config, PreparedSql, R> handler);
Expand Down
2 changes: 1 addition & 1 deletion docs/query/update.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Annotate with ``@Update`` to Dao method for execute update.

.. code-block:: java

@Config(config = AppConfig.class)
@Dao
public interface EmployeeDao {
@Update
int update(Employee employee);
Expand Down
26 changes: 16 additions & 10 deletions docs/transaction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ This document explains how to configure and use the local transaction.
If you want to use global transaction, use frameworks or application servers
which support JTA (Java Transaction API).

See also :ref:`config-configuration-definition` .

Configuration
=============

Expand All @@ -28,7 +30,6 @@ Here is an example:

.. code-block:: java

@SingletonConfig
public class AppConfig implements Config {

private static final AppConfig CONFIG = new AppConfig();
Expand Down Expand Up @@ -67,24 +68,26 @@ Here is an example:
}
}

.. note::

The ``@SingletonConfig`` shows that this class is a singleton class.

Usage
======

Let's see examples on the condition that we use the following Dao interface annotated with
the ``AppConfig`` class which we saw in the `Configuration`_.
We use the following DAO interface in example code:

.. code-block:: java

@Dao(config = AppConfig.class)
@Dao
public interface EmployeeDao {
...
@Sql("select /*%expand*/* from employee where id = /*id*/0")
@Select
Employee selectById(Integer id);

@Update
int update(Employee employee);

@Delete
int delete(Employee employee);
}

The ``dao`` used in the code examples below are instances of this class.

Start and finish transactions
-----------------------------
Expand All @@ -100,6 +103,7 @@ Use a lambda expression to write a process which you want to run in a transactio
.. code-block:: java

TransactionManager tm = AppConfig.singleton().getTransactionManager();
EmployeeDao dao = new EmployeeDaoImpl(AppConfig.singleton());

tm.required(() -> {
Employee employee = dao.selectById(1);
Expand All @@ -119,6 +123,7 @@ Besides throwing an exception, you can use ``setRollbackOnly`` method to rollbac
.. code-block:: java

TransactionManager tm = AppConfig.singleton().getTransactionManager();
EmployeeDao dao = new EmployeeDaoImpl(AppConfig.singleton());

tm.required(() -> {
Employee employee = dao.selectById(1);
Expand All @@ -137,6 +142,7 @@ With a savepoint, you can cancel specific changes in a transaction.
.. code-block:: java

TransactionManager tm = AppConfig.singleton().getTransactionManager();
EmployeeDao dao = new EmployeeDaoImpl(AppConfig.singleton());

tm.required(() -> {
// Search and update
Expand Down
1 change: 1 addition & 0 deletions doma-core/src/main/java/org/seasar/doma/AnnotateWith.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
* }
* </pre>
*/
@SuppressWarnings("deprecation")
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface AnnotateWith {
Expand Down
2 changes: 1 addition & 1 deletion doma-core/src/main/java/org/seasar/doma/ArrayFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* <p>The annotated method must be a member of a {@link Dao} annotated interface.
*
* <pre>
* &#064;Dao(config = AppConfig.class)
* &#064;Dao
* public interface EmployeeDao {
*
* &#064;ArrayFactory(typeName = &quot;integer&quot;)
Expand Down
2 changes: 1 addition & 1 deletion doma-core/src/main/java/org/seasar/doma/BatchDelete.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* ...
* }
*
* &#064;Dao(config = AppConfig.class)
* &#064;Dao
* public interface EmployeeDao {
*
* &#064;BatchDelete
Expand Down
2 changes: 1 addition & 1 deletion doma-core/src/main/java/org/seasar/doma/BatchInsert.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* ...
* }
*
* &#064;Dao(config = AppConfig.class)
* &#064;Dao
* public interface EmployeeDao {
*
* &#064;BatchInsert
Expand Down
2 changes: 1 addition & 1 deletion doma-core/src/main/java/org/seasar/doma/BatchUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* ...
* }
*
* &#064;Dao(config = AppConfig.class)
* &#064;Dao
* public interface EmployeeDao {
*
* &#064;BatchUpdate
Expand Down
2 changes: 1 addition & 1 deletion doma-core/src/main/java/org/seasar/doma/BlobFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* <p>The annotated method must be a member of a {@link Dao} annotated interface.
*
* <pre>
* &#064;Dao(config = AppConfig.class)
* &#064;Dao
* public interface EmployeeDao {
*
* &#064;BlobFactory
Expand Down
2 changes: 1 addition & 1 deletion doma-core/src/main/java/org/seasar/doma/ClobFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* <p>The annotated method must be a member of a {@link Dao} annotated interface.
*
* <pre>
* &#064;Dao(config = AppConfig.class)
* &#064;Dao
* public interface EmployeeDao {
*
* &#064;ClobFactory
Expand Down
9 changes: 6 additions & 3 deletions doma-core/src/main/java/org/seasar/doma/Dao.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* <p>The annotated interface must be a top level interface.
*
* <pre>
* &#064;Dao(config = AppConfig.class)
* &#064;Dao
* public interface EmployeeDao {
*
* &#064;Insert
Expand All @@ -23,7 +23,7 @@
* <p>The interface can extend another DAO interface:
*
* <pre>
* &#064;Dao(config = AppConfig.class)
* &#064;Dao
* public interface WorkerDao {
*
* &#064;Insert
Expand All @@ -32,7 +32,7 @@
* </pre>
*
* <pre>
* &#064;Dao(config = AppConfig.class)
* &#064;Dao
* public interface EmployeeDao extends WorkerDao {
*
* &#064;Insert
Expand Down Expand Up @@ -71,7 +71,10 @@
* instance can be injected by using {@link AnnotateWith}.
*
* @return the configuration
* @deprecated always pass a {@link Config} instance to the constructor of DAO implementation
* class
*/
@Deprecated
Class<? extends Config> config() default Config.class;

/** @return the access level of the DAO implementation class. */
Expand Down
2 changes: 1 addition & 1 deletion doma-core/src/main/java/org/seasar/doma/Delete.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* ...
* }
*
* &#064;Dao(config = AppConfig.class)
* &#064;Dao
* public interface EmployeeDao {
*
* &#064;Delete
Expand Down
Loading