Skip to content

Commit

Permalink
Add Dialect
Browse files Browse the repository at this point in the history
- Oracle12
- Oracle18
- Oracle19
- Oracle21
- Oracle23
- MariaDB5
- MariaDB10
  • Loading branch information
HidekiSugimoto189 committed Sep 23, 2024
1 parent 11da69c commit 2dd7a0e
Show file tree
Hide file tree
Showing 18 changed files with 1,615 additions and 14 deletions.
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 src/main/java/jp/co/future/uroborosql/dialect/MariaDb5Dialect.java
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 src/main/java/jp/co/future/uroborosql/dialect/MariaDbDialect.java
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;
}

}
22 changes: 11 additions & 11 deletions src/main/java/jp/co/future/uroborosql/dialect/Oracle12Dialect.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
package jp.co.future.uroborosql.dialect;

/**
* Oracle12(以降のバージョンも含む)用のDialect
* Oracle12用のDialect
*
* @author H.Sugimoto
*/
Expand All @@ -19,6 +19,16 @@ public Oracle12Dialect() {
super('\\', new char[] { '%', '_', '%', '_' });
}

/**
* {@inheritDoc}
*
* @see jp.co.future.uroborosql.dialect.OracleDialect#isTargetVersion(int)
*/
@Override
protected boolean isTargetVersion(final int majorVersion) {
return majorVersion == 12;
}

/**
* {@inheritDoc}
*
Expand Down Expand Up @@ -61,14 +71,4 @@ public String getLimitClause(final long limit, final long offset) {
}
return builder.toString();
}

/**
* {@inheritDoc}
*
* @see jp.co.future.uroborosql.dialect.OracleDialect#isTargetVersion(int)
*/
@Override
protected boolean isTargetVersion(final int majorVersion) {
return majorVersion >= 12;
}
}
30 changes: 30 additions & 0 deletions src/main/java/jp/co/future/uroborosql/dialect/Oracle18Dialect.java
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 src/main/java/jp/co/future/uroborosql/dialect/Oracle19Dialect.java
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 src/main/java/jp/co/future/uroborosql/dialect/Oracle21Dialect.java
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;
}
}
Loading

0 comments on commit 2dd7a0e

Please sign in to comment.