-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Oracle12 - Oracle18 - Oracle19 - Oracle21 - Oracle23 - MariaDB5 - MariaDB10
- Loading branch information
1 parent
11da69c
commit 2dd7a0e
Showing
18 changed files
with
1,615 additions
and
14 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/main/java/jp/co/future/uroborosql/dialect/MariaDb10Dialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) 2017-present, Future Corporation | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
package jp.co.future.uroborosql.dialect; | ||
|
||
/** | ||
* MariaDB(ver10とそれ以降)用のDialect | ||
* | ||
* @author H.Sugimoto | ||
*/ | ||
public class MariaDb10Dialect extends MariaDbDialect { | ||
/** | ||
* コンストラクタ | ||
*/ | ||
public MariaDb10Dialect() { | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.MariaDbDialect#isTargetVersion(int) | ||
*/ | ||
@Override | ||
protected boolean isTargetVersion(final int majorVersion) { | ||
return majorVersion >= 10; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.MariaDbDialect#supportsSequence() | ||
*/ | ||
@Override | ||
public boolean supportsSequence() { | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.Dialect#getSequenceNextValSql(java.lang.String) | ||
*/ | ||
@Override | ||
public String getSequenceNextValSql(final String sequenceName) { | ||
return "nextval(" + sequenceName + ")"; | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/jp/co/future/uroborosql/dialect/MariaDb5Dialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright (c) 2017-present, Future Corporation | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
package jp.co.future.uroborosql.dialect; | ||
|
||
/** | ||
* MariaDB(ver5)用のDialect | ||
* | ||
* @author H.Sugimoto | ||
*/ | ||
public class MariaDb5Dialect extends MariaDbDialect { | ||
/** | ||
* コンストラクタ | ||
*/ | ||
public MariaDb5Dialect() { | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.MariaDbDialect#isTargetVersion(int) | ||
*/ | ||
@Override | ||
protected boolean isTargetVersion(final int majorVersion) { | ||
return majorVersion == 5; | ||
} | ||
|
||
} |
161 changes: 161 additions & 0 deletions
161
src/main/java/jp/co/future/uroborosql/dialect/MariaDbDialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/** | ||
* Copyright (c) 2017-present, Future Corporation | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
package jp.co.future.uroborosql.dialect; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import jp.co.future.uroborosql.connection.ConnectionSupplier; | ||
import jp.co.future.uroborosql.exception.UroborosqlRuntimeException; | ||
|
||
/** | ||
* MariaDB用のデフォルト設定用Dialect | ||
* | ||
* @author H.Sugimoto | ||
*/ | ||
public abstract class MariaDbDialect extends AbstractDialect { | ||
/** | ||
* 悲観ロックのErrorCode もしくは SqlState. MySQLの場合はErrorCodeで判定する. | ||
* <pre>ERROR 3572 (HY000): Statement aborted because lock(s) could not be acquired immediately and NOWAIT is set.</pre> | ||
*/ | ||
private static final Set<String> pessimisticLockingErrorCodes = Set.of("3572"); | ||
|
||
/** | ||
* コンストラクタ | ||
*/ | ||
protected MariaDbDialect() { | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.Dialect#accept(jp.co.future.uroborosql.connection.ConnectionSupplier) | ||
*/ | ||
@Override | ||
public boolean accept(final ConnectionSupplier supplier) { | ||
if (supplier == null) { | ||
return false; | ||
} | ||
|
||
var parts = supplier.getDatabaseName().split("-", 2); | ||
var databaseName = parts[0]; | ||
|
||
if (!databaseName.startsWith(getDatabaseName())) { | ||
return false; | ||
} | ||
|
||
var databaseVersion = parts[1]; | ||
|
||
try { | ||
var majorVersion = Integer.parseInt(databaseVersion.substring(0, databaseVersion.indexOf("."))); | ||
return isTargetVersion(majorVersion); | ||
} catch (NumberFormatException ex) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* 対象のMariaDBバージョンかどうかを判定する | ||
* | ||
* @param majorVersion コネクションから取得したメジャーバージョン | ||
* @return 対象のバージョンの場合<code>true</code> | ||
*/ | ||
protected abstract boolean isTargetVersion(int majorVersion); | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.Dialect#getDatabaseName() | ||
*/ | ||
@Override | ||
public String getDatabaseName() { | ||
return "MariaDB"; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.Dialect#supportsBulkInsert() | ||
*/ | ||
@Override | ||
public boolean supportsBulkInsert() { | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.Dialect#supportsLimitClause() | ||
*/ | ||
@Override | ||
public boolean supportsLimitClause() { | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.Dialect#supportsSequence() | ||
*/ | ||
@Override | ||
public boolean supportsSequence() { | ||
return false; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.Dialect#supportsForUpdateWait() | ||
*/ | ||
@Override | ||
public boolean supportsForUpdateWait() { | ||
return false; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.Dialect#supportsOptimizerHints() | ||
*/ | ||
@Override | ||
public boolean supportsOptimizerHints() { | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.Dialect#getSequenceNextValSql(java.lang.String) | ||
*/ | ||
@Override | ||
public String getSequenceNextValSql(final String sequenceName) { | ||
throw new UroborosqlRuntimeException("MariaDB does not support Sequence."); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.Dialect#addOptimizerHints(java.lang.StringBuilder, java.util.List) | ||
*/ | ||
@Override | ||
public StringBuilder addOptimizerHints(final StringBuilder sql, final List<String> hints) { | ||
var hintStr = "$1 " + hints.stream().collect(Collectors.joining(" ")) + System.lineSeparator(); | ||
return new StringBuilder(sql.toString().replaceFirst("((FROM|from)\\s+[^\\s]+)\\s*", hintStr)); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.Dialect#getPessimisticLockingErrorCodes() | ||
*/ | ||
@Override | ||
public Set<String> getPessimisticLockingErrorCodes() { | ||
return pessimisticLockingErrorCodes; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/jp/co/future/uroborosql/dialect/Oracle18Dialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) 2017-present, Future Corporation | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
package jp.co.future.uroborosql.dialect; | ||
|
||
/** | ||
* Oracle18用のDialect | ||
* | ||
* @author H.Sugimoto | ||
*/ | ||
public class Oracle18Dialect extends Oracle12Dialect { | ||
/** | ||
* コンストラクタ | ||
*/ | ||
public Oracle18Dialect() { | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.OracleDialect#isTargetVersion(int) | ||
*/ | ||
@Override | ||
protected boolean isTargetVersion(final int majorVersion) { | ||
return majorVersion == 18; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/jp/co/future/uroborosql/dialect/Oracle19Dialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) 2017-present, Future Corporation | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
package jp.co.future.uroborosql.dialect; | ||
|
||
/** | ||
* Oracle19用のDialect | ||
* | ||
* @author H.Sugimoto | ||
*/ | ||
public class Oracle19Dialect extends Oracle12Dialect { | ||
/** | ||
* コンストラクタ | ||
*/ | ||
public Oracle19Dialect() { | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.OracleDialect#isTargetVersion(int) | ||
*/ | ||
@Override | ||
protected boolean isTargetVersion(final int majorVersion) { | ||
return majorVersion == 19; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/jp/co/future/uroborosql/dialect/Oracle21Dialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) 2017-present, Future Corporation | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
package jp.co.future.uroborosql.dialect; | ||
|
||
/** | ||
* Oracle21用のDialect | ||
* | ||
* @author H.Sugimoto | ||
*/ | ||
public class Oracle21Dialect extends Oracle12Dialect { | ||
/** | ||
* コンストラクタ | ||
*/ | ||
public Oracle21Dialect() { | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see jp.co.future.uroborosql.dialect.OracleDialect#isTargetVersion(int) | ||
*/ | ||
@Override | ||
protected boolean isTargetVersion(final int majorVersion) { | ||
return majorVersion == 21; | ||
} | ||
} |
Oops, something went wrong.