Skip to content

Commit 229c502

Browse files
authored
Add JavaDoc to org.seasar.doma.jdbc.command package (#1331)
2 parents 958b042 + 8c65c99 commit 229c502

24 files changed

+974
-1
lines changed

doma-core/src/main/java/org/seasar/doma/jdbc/command/BatchDeleteCommand.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,30 @@
2121
import org.seasar.doma.jdbc.PreparedSql;
2222
import org.seasar.doma.jdbc.query.BatchDeleteQuery;
2323

24+
/**
25+
* A command to execute a batch delete.
26+
*
27+
* <p>This command executes SQL DELETE statements in batch mode.
28+
*/
2429
public class BatchDeleteCommand extends BatchModifyCommand<BatchDeleteQuery> {
2530

31+
/**
32+
* Creates a new instance.
33+
*
34+
* @param query the batch delete query
35+
*/
2636
public BatchDeleteCommand(BatchDeleteQuery query) {
2737
super(query);
2838
}
2939

40+
/**
41+
* Executes the batch delete.
42+
*
43+
* @param preparedStatement the prepared statement
44+
* @param sqls the SQL statements
45+
* @return the array of deleted rows count
46+
* @throws SQLException if a database access error occurs
47+
*/
3048
@Override
3149
protected int[] executeInternal(PreparedStatement preparedStatement, List<PreparedSql> sqls)
3250
throws SQLException {

doma-core/src/main/java/org/seasar/doma/jdbc/command/BatchInsertCommand.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,34 @@
2424
import org.seasar.doma.jdbc.query.BatchInsertQuery;
2525
import org.seasar.doma.jdbc.statistic.StatisticManager;
2626

27+
/**
28+
* A command to execute a batch insert.
29+
*
30+
* <p>This command executes SQL INSERT statements in batch mode and generates IDs for entities if
31+
* necessary.
32+
*/
2733
public class BatchInsertCommand extends BatchModifyCommand<BatchInsertQuery> {
2834

35+
/**
36+
* Creates a new instance.
37+
*
38+
* @param query the batch insert query
39+
*/
2940
public BatchInsertCommand(BatchInsertQuery query) {
3041
super(query);
3142
}
3243

44+
/**
45+
* Executes the batch insert and generates IDs if necessary.
46+
*
47+
* <p>If batch operation is supported, it uses the batch execution mode. Otherwise, it executes
48+
* each SQL statement individually.
49+
*
50+
* @param preparedStatement the prepared statement
51+
* @param sqls the SQL statements
52+
* @return the array of inserted rows count
53+
* @throws SQLException if a database access error occurs
54+
*/
3355
@Override
3456
protected int[] executeInternal(PreparedStatement preparedStatement, List<PreparedSql> sqls)
3557
throws SQLException {
@@ -57,6 +79,15 @@ protected int[] executeInternal(PreparedStatement preparedStatement, List<Prepar
5779
return updatedRows;
5880
}
5981

82+
/**
83+
* Executes a single update operation.
84+
*
85+
* @param preparedStatement the prepared statement
86+
* @param sql the SQL statement
87+
* @return the number of affected rows
88+
* @throws SQLException if a database access error occurs
89+
* @throws BatchUniqueConstraintException if a unique constraint violation occurs
90+
*/
6091
protected int executeUpdate(PreparedStatement preparedStatement, PreparedSql sql)
6192
throws SQLException {
6293
try {
@@ -71,6 +102,13 @@ protected int executeUpdate(PreparedStatement preparedStatement, PreparedSql sql
71102
}
72103
}
73104

105+
/**
106+
* Generates IDs for the batch of entities after execution.
107+
*
108+
* @param preparedStatement the prepared statement
109+
* @param position the position of the first element in the batch
110+
* @param size the size of the executed batch
111+
*/
74112
@Override
75113
protected void postExecuteBatch(PreparedStatement preparedStatement, int position, int size) {
76114
query.generateIds(preparedStatement, position, size);

doma-core/src/main/java/org/seasar/doma/jdbc/command/BatchModifyCommand.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,44 @@
3434
import org.seasar.doma.jdbc.query.BatchModifyQuery;
3535
import org.seasar.doma.jdbc.statistic.StatisticManager;
3636

37+
/**
38+
* An abstract command for batch modification operations (insert, update, delete).
39+
*
40+
* <p>This class provides common functionality for executing SQL statements in batch mode.
41+
*
42+
* @param <QUERY> the query type
43+
*/
3744
public abstract class BatchModifyCommand<QUERY extends BatchModifyQuery> implements Command<int[]> {
3845

46+
/** The query to be executed. */
3947
protected final QUERY query;
4048

49+
/**
50+
* Creates a new instance.
51+
*
52+
* @param query the batch modification query
53+
* @throws AssertionError if the query is null
54+
*/
4155
protected BatchModifyCommand(QUERY query) {
4256
assertNotNull(query);
4357
this.query = query;
4458
}
4559

60+
/**
61+
* Returns the query.
62+
*
63+
* @return the query
64+
*/
4665
@Override
4766
public QUERY getQuery() {
4867
return query;
4968
}
5069

70+
/**
71+
* Executes the batch operation.
72+
*
73+
* @return the array of affected rows count
74+
*/
5175
@Override
5276
public int[] execute() {
5377
if (!query.isExecutable()) {
@@ -75,6 +99,13 @@ public int[] execute() {
7599
}
76100
}
77101

102+
/**
103+
* Prepares a statement for execution.
104+
*
105+
* @param connection the database connection
106+
* @param sql the SQL to be prepared
107+
* @return the prepared statement
108+
*/
78109
protected PreparedStatement prepareStatement(Connection connection, PreparedSql sql) {
79110
if (query.isAutoGeneratedKeysSupported()) {
80111
Config config = query.getConfig();
@@ -89,15 +120,37 @@ protected PreparedStatement prepareStatement(Connection connection, PreparedSql
89120
return JdbcUtil.prepareStatement(connection, sql);
90121
}
91122

123+
/**
124+
* Executes the batch operation internally.
125+
*
126+
* @param preparedStatement the prepared statement
127+
* @param sqls the SQL statements
128+
* @return the array of affected rows count
129+
* @throws SQLException if a database access error occurs
130+
*/
92131
protected abstract int[] executeInternal(
93132
PreparedStatement preparedStatement, List<PreparedSql> sqls) throws SQLException;
94133

134+
/**
135+
* Sets up options for the prepared statement.
136+
*
137+
* @param preparedStatement the prepared statement
138+
* @throws SQLException if a database access error occurs
139+
*/
95140
protected void setupOptions(PreparedStatement preparedStatement) throws SQLException {
96141
if (query.getQueryTimeout() > 0) {
97142
preparedStatement.setQueryTimeout(query.getQueryTimeout());
98143
}
99144
}
100145

146+
/**
147+
* Executes the batch operation.
148+
*
149+
* @param preparedStatement the prepared statement
150+
* @param sqls the SQL statements
151+
* @return the array of affected rows count
152+
* @throws SQLException if a database access error occurs
153+
*/
101154
protected int[] executeBatch(PreparedStatement preparedStatement, List<PreparedSql> sqls)
102155
throws SQLException {
103156
StatisticManager statisticManager = query.getConfig().getStatisticManager();
@@ -129,6 +182,15 @@ protected int[] executeBatch(PreparedStatement preparedStatement, List<PreparedS
129182
return updatedRows;
130183
}
131184

185+
/**
186+
* Executes the batch operation.
187+
*
188+
* @param preparedStatement the prepared statement
189+
* @param sql the SQL statement
190+
* @return the array of affected rows count
191+
* @throws SQLException if a database access error occurs
192+
* @throws BatchUniqueConstraintException if a unique constraint violation occurs
193+
*/
132194
protected int[] executeBatch(PreparedStatement preparedStatement, PreparedSql sql)
133195
throws SQLException {
134196
try {
@@ -152,17 +214,38 @@ protected int[] executeBatch(PreparedStatement preparedStatement, PreparedSql sq
152214
*/
153215
protected void postExecuteBatch(PreparedStatement preparedStatement, int position, int size) {}
154216

217+
/**
218+
* Logs the SQL statement.
219+
*
220+
* @param sql the SQL statement
221+
*/
155222
protected void log(PreparedSql sql) {
156223
JdbcLogger logger = query.getConfig().getJdbcLogger();
157224
logger.logSql(query.getClassName(), query.getMethodName(), sql);
158225
}
159226

227+
/**
228+
* Binds parameters to the prepared statement.
229+
*
230+
* @param preparedStatement the prepared statement
231+
* @param sql the SQL statement with parameters
232+
* @throws SQLException if a database access error occurs
233+
*/
160234
protected void bindParameters(PreparedStatement preparedStatement, PreparedSql sql)
161235
throws SQLException {
162236
PreparedSqlParameterBinder binder = new PreparedSqlParameterBinder(query);
163237
binder.bind(preparedStatement, sql.getParameters());
164238
}
165239

240+
/**
241+
* Validates the affected rows count.
242+
*
243+
* @param preparedStatement the prepared statement
244+
* @param sql the SQL statement
245+
* @param rows the array of affected rows count
246+
* @throws SQLException if a database access error occurs
247+
* @throws BatchOptimisticLockException if optimistic lock constraint is violated
248+
*/
166249
protected void validateRows(PreparedStatement preparedStatement, PreparedSql sql, int[] rows)
167250
throws SQLException {
168251
Dialect dialect = query.getConfig().getDialect();

doma-core/src/main/java/org/seasar/doma/jdbc/command/BatchUpdateCommand.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,31 @@
2121
import org.seasar.doma.jdbc.PreparedSql;
2222
import org.seasar.doma.jdbc.query.BatchUpdateQuery;
2323

24+
/**
25+
* A command to execute a batch update.
26+
*
27+
* <p>This command executes SQL UPDATE statements in batch mode and increments version numbers if
28+
* entities have optimistic lock control.
29+
*/
2430
public class BatchUpdateCommand extends BatchModifyCommand<BatchUpdateQuery> {
2531

32+
/**
33+
* Creates a new instance.
34+
*
35+
* @param query the batch update query
36+
*/
2637
public BatchUpdateCommand(BatchUpdateQuery query) {
2738
super(query);
2839
}
2940

41+
/**
42+
* Executes the batch update and increments version numbers.
43+
*
44+
* @param preparedStatement the prepared statement
45+
* @param sqls the SQL statements
46+
* @return the array of updated rows count
47+
* @throws SQLException if a database access error occurs
48+
*/
3049
@Override
3150
protected int[] executeInternal(PreparedStatement preparedStatement, List<PreparedSql> sqls)
3251
throws SQLException {

doma-core/src/main/java/org/seasar/doma/jdbc/command/Command.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,39 @@
1717

1818
import org.seasar.doma.jdbc.query.Query;
1919

20+
/**
21+
* A core interface for executing database operations in the Doma framework.
22+
*
23+
* <p>This interface represents a command pattern implementation for database access. Each command
24+
* encapsulates a specific database operation (such as select, insert, update, delete) along with
25+
* its execution logic. Commands are responsible for executing queries and processing their results.
26+
*
27+
* <p>The Command interface is designed to be extensible, with various implementations for different
28+
* types of database operations. Each implementation handles the specific details of executing its
29+
* associated query type and processing the results.
30+
*
31+
* @param <RESULT> the type of result that this command produces when executed
32+
*/
2033
public interface Command<RESULT> {
2134

35+
/**
36+
* Returns the query associated with this command.
37+
*
38+
* <p>The query contains the SQL statement and parameters that will be executed by this command.
39+
*
40+
* @return the query object that this command will execute
41+
*/
2242
Query getQuery();
2343

44+
/**
45+
* Executes the command and returns the result.
46+
*
47+
* <p>This method is responsible for executing the database operation encapsulated by this
48+
* command. It handles the execution of the SQL statement, processing of results, and any
49+
* necessary resource management.
50+
*
51+
* @return the result of executing the command, the type depends on the specific command
52+
* implementation
53+
*/
2454
RESULT execute();
2555
}

doma-core/src/main/java/org/seasar/doma/jdbc/command/CreateCommand.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,43 @@
2222
import org.seasar.doma.jdbc.query.CreateQuery;
2323
import org.seasar.doma.message.Message;
2424

25+
/**
26+
* A command to create a database object.
27+
*
28+
* <p>This command executes a query that creates a database object such as a table or index.
29+
*
30+
* @param <RESULT> the result type
31+
*/
2532
public class CreateCommand<RESULT> implements Command<RESULT> {
2633

34+
/** the query */
2735
protected final CreateQuery<RESULT> query;
2836

37+
/**
38+
* Creates a new instance.
39+
*
40+
* @param query the create query
41+
*/
2942
public CreateCommand(CreateQuery<RESULT> query) {
3043
this.query = query;
3144
}
3245

46+
/**
47+
* Returns the query.
48+
*
49+
* @return the query
50+
*/
3351
@Override
3452
public CreateQuery<RESULT> getQuery() {
3553
return query;
3654
}
3755

56+
/**
57+
* Executes the create operation.
58+
*
59+
* @return the result
60+
* @throws JdbcException if a database access error occurs
61+
*/
3862
@Override
3963
public RESULT execute() {
4064
Connection connection = JdbcUtil.getConnection(query.getConfig().getDataSource());

0 commit comments

Comments
 (0)