[#6087] Make ParserException public
This commit is contained in:
parent
8efdd9ba22
commit
c848fbfdff
71
jOOQ/src/main/java/org/jooq/impl/ParserException.java
Normal file
71
jOOQ/src/main/java/org/jooq/impl/ParserException.java
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.impl;
|
||||
|
||||
import static org.jooq.exception.SQLStateSubclass.C42000_NO_SUBCLASS;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
import org.jooq.exception.SQLStateSubclass;
|
||||
|
||||
/**
|
||||
* An exception that arises while parsing SQL through
|
||||
* {@link DSLContext#parser()}.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public final class ParserException extends DataAccessException {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = -724913199583039157L;
|
||||
|
||||
public ParserException(String sql) {
|
||||
this(sql, null);
|
||||
}
|
||||
|
||||
public ParserException(String sql, String message) {
|
||||
this(sql, message, C42000_NO_SUBCLASS);
|
||||
}
|
||||
|
||||
public ParserException(String sql, String message, SQLStateSubclass state) {
|
||||
this(sql, message, state, null);
|
||||
}
|
||||
|
||||
public ParserException(String sql, String message, SQLStateSubclass state, Throwable cause) {
|
||||
super(state + ": " + (message == null ? "" : message + ": ") + sql, cause);
|
||||
}
|
||||
}
|
||||
@ -36,7 +36,6 @@ package org.jooq.impl;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.jooq.exception.SQLStateSubclass.C42000_NO_SUBCLASS;
|
||||
import static org.jooq.impl.DSL.acos;
|
||||
import static org.jooq.impl.DSL.ascii;
|
||||
import static org.jooq.impl.DSL.asin;
|
||||
@ -306,8 +305,6 @@ import org.jooq.WindowSpecification;
|
||||
import org.jooq.WindowSpecificationOrderByStep;
|
||||
import org.jooq.WindowSpecificationRowsAndStep;
|
||||
import org.jooq.WindowSpecificationRowsStep;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
import org.jooq.exception.SQLStateSubclass;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
@ -339,7 +336,7 @@ class ParserImpl implements Parser {
|
||||
while (parseIf(ctx, ";"));
|
||||
|
||||
if (!ctx.done())
|
||||
throw new ParserException(ctx);
|
||||
throw ctx.exception();
|
||||
|
||||
return new QueriesImpl(result);
|
||||
}
|
||||
@ -350,7 +347,7 @@ class ParserImpl implements Parser {
|
||||
Query result = parseQuery(ctx);
|
||||
|
||||
if (!ctx.done())
|
||||
throw new ParserException(ctx);
|
||||
throw ctx.exception();
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -361,7 +358,7 @@ class ParserImpl implements Parser {
|
||||
Table<?> result = parseTable(ctx);
|
||||
|
||||
if (!ctx.done())
|
||||
throw new ParserException(ctx);
|
||||
throw ctx.exception();
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -372,7 +369,7 @@ class ParserImpl implements Parser {
|
||||
Field<?> result = parseField(ctx);
|
||||
|
||||
if (!ctx.done())
|
||||
throw new ParserException(ctx);
|
||||
throw ctx.exception();
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -383,7 +380,7 @@ class ParserImpl implements Parser {
|
||||
RowN result = parseRow(ctx);
|
||||
|
||||
if (!ctx.done())
|
||||
throw new ParserException(ctx);
|
||||
throw ctx.exception();
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -394,7 +391,7 @@ class ParserImpl implements Parser {
|
||||
Condition result = parseCondition(ctx);
|
||||
|
||||
if (!ctx.done())
|
||||
throw new ParserException(ctx);
|
||||
throw ctx.exception();
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -405,7 +402,7 @@ class ParserImpl implements Parser {
|
||||
Name result = parseName(ctx);
|
||||
|
||||
if (!ctx.done())
|
||||
throw new ParserException(ctx);
|
||||
throw ctx.exception();
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -4937,7 +4934,7 @@ class ParserImpl implements Parser {
|
||||
));
|
||||
}
|
||||
|
||||
private static final class ParserContext {
|
||||
static final class ParserContext {
|
||||
private final DSLContext dsl;
|
||||
private final String sqlString;
|
||||
private final char[] sql;
|
||||
@ -4952,15 +4949,15 @@ class ParserImpl implements Parser {
|
||||
}
|
||||
|
||||
ParserException internalError() {
|
||||
return new ParserException(this, "Internal Error");
|
||||
return new ParserException(mark(), "Internal Error");
|
||||
}
|
||||
|
||||
ParserException exception() {
|
||||
return new ParserException(this);
|
||||
return new ParserException(mark());
|
||||
}
|
||||
|
||||
ParserException unexpectedToken() {
|
||||
return new ParserException(this, "Expected tokens: " + new TreeSet<String>(expectedTokens));
|
||||
return new ParserException(mark(), "Expected tokens: " + new TreeSet<String>(expectedTokens));
|
||||
}
|
||||
|
||||
char character() {
|
||||
@ -5001,33 +4998,6 @@ class ParserImpl implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ParserException extends DataAccessException {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = -724913199583039157L;
|
||||
private final ParserContext ctx;
|
||||
|
||||
public ParserException(ParserContext ctx) {
|
||||
this(ctx, null);
|
||||
}
|
||||
|
||||
public ParserException(ParserContext ctx, String message) {
|
||||
this(ctx, message, C42000_NO_SUBCLASS);
|
||||
}
|
||||
|
||||
public ParserException(ParserContext ctx, String message, SQLStateSubclass state) {
|
||||
this(ctx, message, state, null);
|
||||
}
|
||||
|
||||
public ParserException(ParserContext ctx, String message, SQLStateSubclass state, Throwable cause) {
|
||||
super(state + ": " + (message == null ? "" : message + ": ") + ctx.mark(), cause);
|
||||
|
||||
this.ctx = ctx;
|
||||
}
|
||||
}
|
||||
|
||||
private static enum TruthValue {
|
||||
TRUE,
|
||||
FALSE,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user