|
| 1 | +package org.seasar.doma.jdbc.dialect; |
| 2 | + |
| 3 | +import java.sql.SQLException; |
| 4 | +import org.seasar.doma.DomaNullPointerException; |
| 5 | +import org.seasar.doma.expr.ExpressionFunctions; |
| 6 | +import org.seasar.doma.internal.jdbc.dialect.H2ForUpdateTransformer; |
| 7 | +import org.seasar.doma.internal.jdbc.dialect.H2PagingTransformer; |
| 8 | +import org.seasar.doma.jdbc.JdbcMappingVisitor; |
| 9 | +import org.seasar.doma.jdbc.SelectForUpdateType; |
| 10 | +import org.seasar.doma.jdbc.SqlLogFormattingVisitor; |
| 11 | +import org.seasar.doma.jdbc.SqlNode; |
| 12 | + |
| 13 | +/** A dialect for H2 version 1.4.199 and below. */ |
| 14 | +public class H214199Dialect extends H212126Dialect { |
| 15 | + |
| 16 | + /** the error code that represents unique violation */ |
| 17 | + protected static final int UNIQUE_CONSTRAINT_VIOLATION_ERROR_CODE = 23505; |
| 18 | + |
| 19 | + public H214199Dialect() { |
| 20 | + this( |
| 21 | + new H214199JdbcMappingVisitor(), |
| 22 | + new H214199SqlLogFormattingVisitor(), |
| 23 | + new H214199ExpressionFunctions()); |
| 24 | + } |
| 25 | + |
| 26 | + public H214199Dialect(JdbcMappingVisitor jdbcMappingVisitor) { |
| 27 | + this( |
| 28 | + jdbcMappingVisitor, new H214199SqlLogFormattingVisitor(), new H214199ExpressionFunctions()); |
| 29 | + } |
| 30 | + |
| 31 | + public H214199Dialect(SqlLogFormattingVisitor sqlLogFormattingVisitor) { |
| 32 | + this( |
| 33 | + new H214199JdbcMappingVisitor(), sqlLogFormattingVisitor, new H214199ExpressionFunctions()); |
| 34 | + } |
| 35 | + |
| 36 | + public H214199Dialect(ExpressionFunctions expressionFunctions) { |
| 37 | + this( |
| 38 | + new H214199JdbcMappingVisitor(), new H214199SqlLogFormattingVisitor(), expressionFunctions); |
| 39 | + } |
| 40 | + |
| 41 | + public H214199Dialect( |
| 42 | + JdbcMappingVisitor jdbcMappingVisitor, SqlLogFormattingVisitor sqlLogFormattingVisitor) { |
| 43 | + this(jdbcMappingVisitor, sqlLogFormattingVisitor, new H214199ExpressionFunctions()); |
| 44 | + } |
| 45 | + |
| 46 | + public H214199Dialect( |
| 47 | + JdbcMappingVisitor jdbcMappingVisitor, |
| 48 | + SqlLogFormattingVisitor sqlLogFormattingVisitor, |
| 49 | + ExpressionFunctions expressionFunctions) { |
| 50 | + super(jdbcMappingVisitor, sqlLogFormattingVisitor, expressionFunctions); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public boolean isUniqueConstraintViolated(SQLException sqlException) { |
| 55 | + if (sqlException == null) { |
| 56 | + throw new DomaNullPointerException("sqlException"); |
| 57 | + } |
| 58 | + int code = getErrorCode(sqlException); |
| 59 | + return UNIQUE_CONSTRAINT_VIOLATION_ERROR_CODE == code; |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + protected SqlNode toPagingSqlNode(SqlNode sqlNode, long offset, long limit) { |
| 64 | + H2PagingTransformer transformer = new H2PagingTransformer(offset, limit); |
| 65 | + return transformer.transform(sqlNode); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + protected SqlNode toForUpdateSqlNode( |
| 70 | + SqlNode sqlNode, SelectForUpdateType forUpdateType, int waitSeconds, String... aliases) { |
| 71 | + H2ForUpdateTransformer transformer = |
| 72 | + new H2ForUpdateTransformer(forUpdateType, waitSeconds, aliases); |
| 73 | + return transformer.transform(sqlNode); |
| 74 | + } |
| 75 | + |
| 76 | + public static class H214199JdbcMappingVisitor extends H212126JdbcMappingVisitor {} |
| 77 | + |
| 78 | + public static class H214199SqlLogFormattingVisitor extends H212126SqlLogFormattingVisitor {} |
| 79 | + |
| 80 | + public static class H214199ExpressionFunctions extends H212126ExpressionFunctions { |
| 81 | + |
| 82 | + public H214199ExpressionFunctions() { |
| 83 | + super(); |
| 84 | + } |
| 85 | + |
| 86 | + public H214199ExpressionFunctions(char[] wildcards) { |
| 87 | + super(wildcards); |
| 88 | + } |
| 89 | + |
| 90 | + protected H214199ExpressionFunctions(char escapeChar, char[] wildcards) { |
| 91 | + super(escapeChar, wildcards); |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments