use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class AutoDeleteTest method testNoId.
@Test
public void testNoId(Config config) throws Exception {
NoIdDao dao = new NoIdDaoImpl(config);
NoId entity = new NoId();
entity.setValue1(1);
entity.setValue2(2);
try {
dao.delete(entity);
fail();
} catch (JdbcException expected) {
assertEquals(Message.DOMA2022, expected.getMessageResource());
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class AutoUpdateTest method testNoId.
@Test
public void testNoId(Config config) throws Exception {
NoIdDao dao = new NoIdDaoImpl(config);
NoId entity = new NoId();
entity.setValue1(1);
entity.setValue2(2);
try {
dao.update(entity);
fail();
} catch (JdbcException expected) {
assertEquals(Message.DOMA2022, expected.getMessageResource());
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class SqlFileSelectForUpdateTest method testUnsupported.
@Test
@Run(unless = { Dbms.H2, Dbms.POSTGRESQL, Dbms.ORACLE, Dbms.MYSQL, Dbms.DB2, Dbms.SQLSERVER })
public void testUnsupported(Config config) throws Exception {
EmployeeDao dao = new EmployeeDaoImpl(config);
try {
dao.selectById(1, SelectOptions.get().forUpdate());
fail();
} catch (JdbcException expected) {
assertEquals(Message.DOMA2023, expected.getMessageResource());
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class NodePreparedSqlBuilder method visitEmbeddedVariableNode.
@Override
public Void visitEmbeddedVariableNode(EmbeddedVariableNode node, Context p) {
SqlLocation location = node.getLocation();
String name = node.getVariableName();
EvaluationResult result = p.evaluate(location, name);
Object value = result.getValue();
if (value != null) {
String fragment = value.toString();
if (fragment.indexOf('\'') > -1) {
throw new JdbcException(Message.DOMA2116, location.getSql(), location.getLineNumber(), location.getPosition(), node.getVariableName());
}
if (fragment.indexOf(';') > -1) {
throw new JdbcException(Message.DOMA2117, location.getSql(), location.getLineNumber(), location.getPosition(), node.getVariableName());
}
if (fragment.contains("--")) {
throw new JdbcException(Message.DOMA2122, location.getSql(), location.getLineNumber(), location.getPosition(), node.getVariableName());
}
if (fragment.contains("/*")) {
throw new JdbcException(Message.DOMA2123, location.getSql(), location.getLineNumber(), location.getPosition(), node.getVariableName());
}
if (!startsWithClauseKeyword(fragment)) {
p.setAvailable(true);
}
p.appendRawSql(fragment);
p.appendFormattedSql(fragment);
}
for (SqlNode child : node.getChildren()) {
child.accept(this, p);
}
return null;
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class NodePreparedSqlBuilder method visitValueNode.
@SuppressWarnings("SameReturnValue")
protected Void visitValueNode(ValueNode node, Context p, Consumer<Scalar<?, ?>> valueHandler) {
SqlLocation location = node.getLocation();
String name = node.getVariableName();
EvaluationResult result = p.evaluate(location, name);
Object value = result.getValue();
Class<?> valueClass = result.getValueClass();
p.setAvailable(true);
if (node.isWordNodeIgnored()) {
handleSingleValueNode(node, p, value, valueClass, valueHandler);
} else if (node.isParensNodeIgnored()) {
ParensNode parensNode = node.getParensNode();
OtherNode openedFragmentNode = parensNode.getOpenedFragmentNode();
openedFragmentNode.accept(this, p);
if (Iterable.class.isAssignableFrom(valueClass)) {
handleIterableValueNode(node, p, (Iterable<?>) value, valueClass, valueHandler);
} else if (valueClass.isArray()) {
handleIterableValueNode(node, p, Arrays.asList((Object[]) value), valueClass, valueHandler);
} else {
throw new JdbcException(Message.DOMA2112, location.getSql(), location.getLineNumber(), location.getPosition(), node.getVariableName(), valueClass);
}
OtherNode closedFragmentNode = parensNode.getClosedFragmentNode();
closedFragmentNode.accept(this, p);
} else {
assertUnreachable();
}
return null;
}
Aggregations