[#3686] Add support for default parameter values in SQL Server

This commit is contained in:
lukaseder 2018-05-15 16:53:29 +02:00
parent 07602b1a9b
commit 74d8bb278a
3 changed files with 141 additions and 26 deletions

View File

@ -55,11 +55,6 @@ public class DataAccessException extends RuntimeException {
*/
private static final long serialVersionUID = 491834858363345767L;
/**
* Never run infinite loops
*/
private static int maxCauseLookups = 256;
/**
* Constructor for DataAccessException.
*
@ -128,26 +123,7 @@ public class DataAccessException extends RuntimeException {
* Find a root cause of a given type, or <code>null</code> if no root cause
* of that type was found.
*/
@SuppressWarnings("unchecked")
public <T extends Throwable> T getCause(Class<? extends T> type) {
Throwable next = getCause();
Throwable prev;
for (int i = 0; i < maxCauseLookups; i++) {
if (next == null)
return null;
if (type.isInstance(next))
return (T) next;
prev = next;
next = next.getCause();
// Don't trust exceptions to respect the default behaviour of Throwable.getCause()
if (prev == next)
return null;
}
return null;
return ExceptionTools.getCause(this, type);
}
}

View File

@ -0,0 +1,78 @@
/*
* 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
*
* http://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.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.exception;
/**
* @author Lukas Eder
*/
public final class ExceptionTools {
/**
* Never run infinite loops
*/
private static int maxCauseLookups = 256;
/**
* Find a root cause of a given type, or <code>null</code> if no root cause
* of that type was found.
*/
@SuppressWarnings("unchecked")
public static <T extends Throwable> T getCause(Throwable t, Class<? extends T> type) {
Throwable next = t.getCause();
Throwable prev;
for (int i = 0; i < maxCauseLookups; i++) {
if (next == null)
return null;
if (type.isInstance(next))
return (T) next;
prev = next;
next = next.getCause();
// Don't trust exceptions to respect the default behaviour of Throwable.getCause()
if (prev == next)
return null;
}
return null;
}
private ExceptionTools() {}
}

View File

@ -344,6 +344,7 @@ import org.jooq.Name;
import org.jooq.OrderedAggregateFunction;
import org.jooq.OrderedAggregateFunctionOfDeferredType;
import org.jooq.Param;
import org.jooq.Parameter;
import org.jooq.Parser;
import org.jooq.Privilege;
import org.jooq.QualifiedAsterisk;
@ -564,6 +565,66 @@ final class ParserImpl implements Parser {
return result;
}
private static final void parseDelimiterSpecifications(ParserContext ctx) {
while (parseKeywordIf(ctx, "DELIMITER"))
ctx.delimiter(parseUntilEOL(ctx).trim());
@ -2792,7 +2853,7 @@ final class ParserImpl implements Parser {
throw ctx.expected("ADD", "ALTER", "COMMENT", "DROP", "MODIFY", "RENAME");
}
private static DDLQuery parseAlterTableAdd(ParserContext ctx, AlterTableStep s1, Table<?> tableName) {
private static final DDLQuery parseAlterTableAdd(ParserContext ctx, AlterTableStep s1, Table<?> tableName) {
List<FieldOrConstraint> list = new ArrayList<FieldOrConstraint>();
if (((parseKeywordIf(ctx, "SPATIAL INDEX")