use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class SqlParser method parseBindVariableBlockComment.
protected void parseBindVariableBlockComment() {
String variableName = tokenType.extract(token);
if (variableName.isEmpty()) {
throw new JdbcException(Message.DOMA2120, sql, tokenizer.getLineNumber(), tokenizer.getPosition(), token);
}
BindVariableNode node = new BindVariableNode(getLocation(), variableName, token);
appendNode(node);
push(node);
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class SqlTokenizer method peekOneChar.
protected void peekOneChar(char c) {
if (isWhitespace(c)) {
type = WHITESPACE;
} else if (c == '(') {
type = OPENED_PARENS;
} else if (c == ')') {
type = CLOSED_PARENS;
} else if (c == ';') {
type = DELIMITER;
} else if (c == '\'') {
type = QUOTE;
boolean closed = false;
while (buf.hasRemaining()) {
char c2 = buf.get();
if (c2 == '\'') {
if (buf.hasRemaining()) {
buf.mark();
char c3 = buf.get();
if (c3 != '\'') {
buf.reset();
closed = true;
break;
}
} else {
closed = true;
}
}
}
if (closed) {
return;
}
int pos = buf.position() - lineStartPosition;
throw new JdbcException(Message.DOMA2101, sql, lineNumber, pos);
} else if (isWordStart(c)) {
type = WORD;
while (buf.hasRemaining()) {
buf.mark();
char c2 = buf.get();
if (c2 == '\'') {
boolean closed = false;
while (buf.hasRemaining()) {
char c3 = buf.get();
if (c3 == '\'') {
if (buf.hasRemaining()) {
buf.mark();
char c4 = buf.get();
if (c4 != '\'') {
buf.reset();
closed = true;
break;
}
} else {
closed = true;
}
}
}
if (closed) {
return;
}
int pos = buf.position() - lineStartPosition;
throw new JdbcException(Message.DOMA2101, sql, lineNumber, pos);
}
if (!isWordPart(c2)) {
buf.reset();
return;
}
}
} else if (c == '\r' || c == '\n') {
type = EOL;
currentLineNumber++;
} else {
type = OTHER;
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class SqlTokenizer method peekTwoChars.
protected void peekTwoChars(char c, char c2) {
if ((c == 'o' || c == 'O') && (c2 == 'r' || c2 == 'R')) {
type = OR_WORD;
if (isWordTerminated()) {
return;
}
} else if (c == '/' && c2 == '*') {
type = BLOCK_COMMENT;
if (buf.hasRemaining()) {
char c3 = buf.get();
if (ExpressionUtil.isExpressionIdentifierStart(c3)) {
type = BIND_VARIABLE_BLOCK_COMMENT;
} else if (c3 == '^') {
type = LITERAL_VARIABLE_BLOCK_COMMENT;
} else if (c3 == '#') {
type = EMBEDDED_VARIABLE_BLOCK_COMMENT;
} else if (c3 == '%') {
if (buf.hasRemaining()) {
char c4 = buf.get();
if (buf.hasRemaining()) {
char c5 = buf.get();
if (c4 == 'i' && c5 == 'f') {
if (isBlockCommentDirectiveTerminated()) {
type = IF_BLOCK_COMMENT;
}
} else if (buf.hasRemaining()) {
char c6 = buf.get();
if (c4 == 'f' && c5 == 'o' && c6 == 'r') {
if (isBlockCommentDirectiveTerminated()) {
type = FOR_BLOCK_COMMENT;
}
} else if (c4 == 'e' && c5 == 'n' && c6 == 'd') {
if (isBlockCommentDirectiveTerminated()) {
type = END_BLOCK_COMMENT;
}
} else if (buf.hasRemaining()) {
char c7 = buf.get();
if (c4 == 'e' && c5 == 'l' && c6 == 's' && c7 == 'e') {
if (isBlockCommentDirectiveTerminated()) {
type = ELSE_BLOCK_COMMENT;
} else {
if (buf.hasRemaining()) {
char c8 = buf.get();
if (buf.hasRemaining()) {
char c9 = buf.get();
if (c8 == 'i' && c9 == 'f') {
if (isBlockCommentDirectiveTerminated()) {
type = ELSEIF_BLOCK_COMMENT;
}
} else {
buf.position(buf.position() - 6);
}
} else {
buf.position(buf.position() - 5);
}
}
}
} else if (buf.hasRemaining()) {
char c8 = buf.get();
if (buf.hasRemaining()) {
char c9 = buf.get();
if (c4 == 'e' && c5 == 'x' && c6 == 'p' && c7 == 'a' && c8 == 'n' && c9 == 'd') {
if (isBlockCommentDirectiveTerminated()) {
type = EXPAND_BLOCK_COMMENT;
}
} else if (buf.hasRemaining()) {
char c10 = buf.get();
if (buf.hasRemaining()) {
char c11 = buf.get();
if (c4 == 'p' && c5 == 'o' && c6 == 'p' && c7 == 'u' && c8 == 'l' && c9 == 'a' && c10 == 't' && c11 == 'e') {
if (isBlockCommentDirectiveTerminated()) {
type = POPULATE_BLOCK_COMMENT;
}
} else {
buf.position(buf.position() - 8);
}
} else {
buf.position(buf.position() - 7);
}
} else {
buf.position(buf.position() - 6);
}
} else {
buf.position(buf.position() - 5);
}
} else {
buf.position(buf.position() - 4);
}
} else {
buf.position(buf.position() - 3);
}
} else {
buf.position(buf.position() - 2);
}
} else {
buf.position(buf.position() - 1);
}
}
if (type != IF_BLOCK_COMMENT && type != FOR_BLOCK_COMMENT && type != END_BLOCK_COMMENT && type != ELSE_BLOCK_COMMENT && type != ELSEIF_BLOCK_COMMENT && type != EXPAND_BLOCK_COMMENT && type != POPULATE_BLOCK_COMMENT) {
int pos = buf.position() - lineStartPosition;
throw new JdbcException(Message.DOMA2119, sql, lineNumber, pos);
}
}
buf.position(buf.position() - 1);
}
while (buf.hasRemaining()) {
char c3 = buf.get();
if (buf.hasRemaining()) {
buf.mark();
char c4 = buf.get();
if (c3 == '*' && c4 == '/') {
return;
}
if ((c3 == '\r' || c3 == '\n')) {
currentLineNumber++;
}
buf.reset();
}
}
int pos = buf.position() - lineStartPosition;
throw new JdbcException(Message.DOMA2102, sql, lineNumber, pos);
} else if (c == '-' && c2 == '-') {
type = LINE_COMMENT;
while (buf.hasRemaining()) {
buf.mark();
char c3 = buf.get();
if (c3 == '\r' || c3 == '\n') {
buf.reset();
return;
}
}
return;
} else if (c == '\r' && c2 == '\n') {
type = EOL;
currentLineNumber++;
return;
}
buf.position(buf.position() - 1);
peekOneChar(c);
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class KeepAliveLocalTransactionTest method testBegin_failedToSetTransactionIsolation.
@Test
public void testBegin_failedToSetTransactionIsolation() {
final SQLException exception = new SQLException();
MockConnection connection = new MockConnection() {
@Override
public void setTransactionIsolation(int level) throws SQLException {
throw exception;
}
};
LocalTransactionDataSource dataSource = new LocalTransactionDataSource(new MockDataSource(connection));
LocalTransaction transaction = dataSource.getKeepAliveLocalTransaction(jdbcLogger);
try {
transaction.begin(TransactionIsolationLevel.READ_COMMITTED);
dataSource.getConnection();
fail();
} catch (JdbcException expected) {
System.out.println(expected.getMessage());
assertEquals(exception, expected.getCause());
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class LocalTransactionTest method testBegin_failedToSetTransactionIsolation.
@Test
public void testBegin_failedToSetTransactionIsolation() {
final SQLException exception = new SQLException();
MockConnection connection = new MockConnection() {
@Override
public void setTransactionIsolation(int level) throws SQLException {
throw exception;
}
};
LocalTransactionDataSource dataSource = new LocalTransactionDataSource(new MockDataSource(connection));
LocalTransaction transaction = dataSource.getLocalTransaction(jdbcLogger);
try {
transaction.begin(TransactionIsolationLevel.READ_COMMITTED);
dataSource.getConnection();
fail();
} catch (JdbcException expected) {
System.out.println(expected.getMessage());
assertEquals(exception, expected.getCause());
}
}
Aggregations