23 changed files with 749 additions and 45 deletions
@ -0,0 +1,130 @@
@@ -0,0 +1,130 @@
|
||||
/* |
||||
* Copyright 2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.data.jdbc.testing; |
||||
|
||||
import lombok.RequiredArgsConstructor; |
||||
|
||||
import org.springframework.data.relational.core.dialect.AbstractDialect; |
||||
import org.springframework.data.relational.core.dialect.ArrayColumns; |
||||
import org.springframework.data.relational.core.dialect.LimitClause; |
||||
import org.springframework.data.relational.core.sql.IdentifierProcessing; |
||||
import org.springframework.util.Assert; |
||||
import org.springframework.util.ClassUtils; |
||||
|
||||
/** |
||||
* An SQL dialect for the ANSI SQL standard. |
||||
* |
||||
* @author Milan Milanov |
||||
* @since 2.0 |
||||
*/ |
||||
public class AnsiDialect extends AbstractDialect { |
||||
|
||||
/** |
||||
* Singleton instance. |
||||
*/ |
||||
public static final AnsiDialect INSTANCE = new AnsiDialect(); |
||||
|
||||
protected AnsiDialect() {} |
||||
|
||||
private static final LimitClause LIMIT_CLAUSE = new LimitClause() { |
||||
|
||||
/* |
||||
* (non-Javadoc) |
||||
* @see org.springframework.data.relational.core.dialect.LimitClause#getLimit(long) |
||||
*/ |
||||
@Override |
||||
public String getLimit(long limit) { |
||||
return String.format("FETCH FIRST %d ROWS ONLY", limit); |
||||
} |
||||
|
||||
/* |
||||
* (non-Javadoc) |
||||
* @see org.springframework.data.relational.core.dialect.LimitClause#getOffset(long) |
||||
*/ |
||||
@Override |
||||
public String getOffset(long offset) { |
||||
return String.format("OFFSET %d ROWS", offset); |
||||
} |
||||
|
||||
/* |
||||
* (non-Javadoc) |
||||
* @see org.springframework.data.relational.core.dialect.LimitClause#getClause(long, long) |
||||
*/ |
||||
@Override |
||||
public String getLimitOffset(long limit, long offset) { |
||||
return String.format("OFFSET %d ROWS FETCH FIRST %d ROWS ONLY", offset, limit); |
||||
} |
||||
|
||||
/* |
||||
* (non-Javadoc) |
||||
* @see org.springframework.data.relational.core.dialect.LimitClause#getClausePosition() |
||||
*/ |
||||
@Override |
||||
public Position getClausePosition() { |
||||
return Position.AFTER_ORDER_BY; |
||||
} |
||||
}; |
||||
|
||||
private final AnsiArrayColumns ARRAY_COLUMNS = new AnsiArrayColumns(); |
||||
|
||||
/* |
||||
* (non-Javadoc) |
||||
* @see org.springframework.data.relational.core.dialect.Dialect#limit() |
||||
*/ |
||||
@Override |
||||
public LimitClause limit() { |
||||
return LIMIT_CLAUSE; |
||||
} |
||||
|
||||
/* |
||||
* (non-Javadoc) |
||||
* @see org.springframework.data.relational.core.dialect.Dialect#getArraySupport() |
||||
*/ |
||||
@Override |
||||
public ArrayColumns getArraySupport() { |
||||
return ARRAY_COLUMNS; |
||||
} |
||||
|
||||
@RequiredArgsConstructor |
||||
static class AnsiArrayColumns implements ArrayColumns { |
||||
|
||||
/* |
||||
* (non-Javadoc) |
||||
* @see org.springframework.data.relational.core.dialect.ArrayColumns#isSupported() |
||||
*/ |
||||
@Override |
||||
public boolean isSupported() { |
||||
return true; |
||||
} |
||||
|
||||
/* |
||||
* (non-Javadoc) |
||||
* @see org.springframework.data.relational.core.dialect.ArrayColumns#getArrayType(java.lang.Class) |
||||
*/ |
||||
@Override |
||||
public Class<?> getArrayType(Class<?> userType) { |
||||
|
||||
Assert.notNull(userType, "Array component type must not be null"); |
||||
|
||||
return ClassUtils.resolvePrimitiveIfNecessary(userType); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public IdentifierProcessing getIdentifierProcessing() { |
||||
return IdentifierProcessing.ANSI; |
||||
} |
||||
} |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
/* |
||||
* Copyright 2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.data.jdbc.testing; |
||||
|
||||
|
||||
import org.springframework.data.relational.core.sql.IdentifierProcessing; |
||||
|
||||
/** |
||||
* The ANSI standard dialect, but without quoting the identifiers. |
||||
* |
||||
* @author Milan Milanov |
||||
* @since 2.0 |
||||
*/ |
||||
public class NonQuotingDialect extends AnsiDialect { |
||||
|
||||
public static final NonQuotingDialect INSTANCE = new NonQuotingDialect(); |
||||
|
||||
@Override |
||||
public IdentifierProcessing getIdentifierProcessing() { |
||||
return IdentifierProcessing.NONE; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue