Skip to content

Commit 26ab6d9

Browse files
authored
Merge pull request #195 from domaframework/oracle-identity
Oracle 12c 以降でIDENTITYを使った識別子の自動生成をサポート
2 parents 2154f49 + 2bbece9 commit 26ab6d9

File tree

8 files changed

+650
-407
lines changed

8 files changed

+650
-407
lines changed

src/main/java/org/seasar/doma/internal/jdbc/util/JdbcUtil.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ public static PreparedStatement prepareStatementForAutoGeneratedKeys(
7272
}
7373
}
7474

75+
public static PreparedStatement prepareStatementForAutoGeneratedKeysOfFirstColumn(
76+
Connection connection, Sql<?> sql) {
77+
try {
78+
return connection.prepareStatement(sql.getRawSql(),
79+
new int[] { 1 });
80+
} catch (SQLException e) {
81+
throw new JdbcException(Message.DOMA2016, e, sql.getSqlFilePath(),
82+
sql.getRawSql(), e);
83+
}
84+
}
85+
7586
public static CallableStatement prepareCall(Connection connection,
7687
Sql<?> sql) {
7788
try {

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.seasar.doma.jdbc.BatchOptimisticLockException;
2929
import org.seasar.doma.jdbc.BatchSqlExecutionException;
3030
import org.seasar.doma.jdbc.BatchUniqueConstraintException;
31+
import org.seasar.doma.jdbc.Config;
3132
import org.seasar.doma.jdbc.JdbcLogger;
3233
import org.seasar.doma.jdbc.PreparedSql;
3334
import org.seasar.doma.jdbc.dialect.Dialect;
@@ -82,8 +83,17 @@ public int[] execute() {
8283
protected PreparedStatement prepareStatement(Connection connection,
8384
PreparedSql sql) {
8485
if (query.isAutoGeneratedKeysSupported()) {
85-
return JdbcUtil.prepareStatementForAutoGeneratedKeys(connection,
86-
sql);
86+
Config config = query.getConfig();
87+
Dialect dialect = config.getDialect();
88+
switch (dialect.getAutoGeneratedKeysType()) {
89+
case FIRST_COLUMN:
90+
return JdbcUtil
91+
.prepareStatementForAutoGeneratedKeysOfFirstColumn(
92+
connection, sql);
93+
case DEFAULT:
94+
return JdbcUtil.prepareStatementForAutoGeneratedKeys(connection,
95+
sql);
96+
}
8797
}
8898
return JdbcUtil.prepareStatement(connection, sql);
8999
}

src/main/java/org/seasar/doma/jdbc/command/ModifyCommand.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.seasar.doma.internal.jdbc.command.PreparedSqlParameterBinder;
2525
import org.seasar.doma.internal.jdbc.util.JdbcUtil;
26+
import org.seasar.doma.jdbc.Config;
2627
import org.seasar.doma.jdbc.JdbcLogger;
2728
import org.seasar.doma.jdbc.OptimisticLockException;
2829
import org.seasar.doma.jdbc.PreparedSql;
@@ -82,8 +83,16 @@ public Integer execute() {
8283

8384
protected PreparedStatement prepareStatement(Connection connection) {
8485
if (query.isAutoGeneratedKeysSupported()) {
85-
return JdbcUtil.prepareStatementForAutoGeneratedKeys(connection,
86-
sql);
86+
Config config = query.getConfig();
87+
Dialect dialect = config.getDialect();
88+
switch (dialect.getAutoGeneratedKeysType()) {
89+
case FIRST_COLUMN:
90+
return JdbcUtil.prepareStatementForAutoGeneratedKeysOfFirstColumn(
91+
connection, sql);
92+
case DEFAULT:
93+
return JdbcUtil.prepareStatementForAutoGeneratedKeys(connection,
94+
sql);
95+
}
8796
}
8897
return JdbcUtil.prepareStatement(connection, sql);
8998
}

src/main/java/org/seasar/doma/jdbc/dialect/Dialect.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.seasar.doma.jdbc.Sql;
3030
import org.seasar.doma.jdbc.SqlLogFormattingVisitor;
3131
import org.seasar.doma.jdbc.SqlNode;
32+
import org.seasar.doma.jdbc.id.AutoGeneratedKeysType;
3233
import org.seasar.doma.jdbc.type.JdbcType;
3334
import org.seasar.doma.wrapper.Wrapper;
3435

@@ -290,4 +291,10 @@ Sql<?> getSequenceNextValSql(String qualifiedSequenceName,
290291
*/
291292
String getScriptBlockDelimiter();
292293

294+
/**
295+
* 自動生成キーのタイプを返します。
296+
*
297+
* @return 自動生成キーのタイプ
298+
*/
299+
AutoGeneratedKeysType getAutoGeneratedKeysType();
293300
}

0 commit comments

Comments
 (0)