use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class QualifierTranslator method finishedChild.
@Override
public void finishedChild(Expression node, int childIndex, boolean hasMoreChildren) {
if (waitingForEndNode != null) {
return;
}
if (!hasMoreChildren) {
return;
}
Appendable out = (matchingObject) ? new StringBuilder() : this.out;
try {
switch(node.getType()) {
case Expression.AND:
out.append(" AND ");
break;
case Expression.OR:
out.append(" OR ");
break;
case Expression.EQUAL_TO:
// translate NULL as IS NULL
if (childIndex == 0 && node.getOperandCount() == 2 && node.getOperand(1) == null) {
out.append(" IS ");
} else {
out.append(" = ");
}
break;
case Expression.NOT_EQUAL_TO:
// translate NULL as IS NOT NULL
if (childIndex == 0 && node.getOperandCount() == 2 && node.getOperand(1) == null) {
out.append(" IS NOT ");
} else {
out.append(" <> ");
}
break;
case Expression.LESS_THAN:
out.append(" < ");
break;
case Expression.GREATER_THAN:
out.append(" > ");
break;
case Expression.LESS_THAN_EQUAL_TO:
out.append(" <= ");
break;
case Expression.GREATER_THAN_EQUAL_TO:
out.append(" >= ");
break;
case Expression.IN:
out.append(" IN ");
break;
case Expression.NOT_IN:
out.append(" NOT IN ");
break;
case Expression.LIKE:
out.append(" LIKE ");
break;
case Expression.NOT_LIKE:
out.append(" NOT LIKE ");
break;
case Expression.LIKE_IGNORE_CASE:
if (caseInsensitive) {
out.append(" LIKE ");
} else {
out.append(") LIKE UPPER(");
}
break;
case Expression.NOT_LIKE_IGNORE_CASE:
if (caseInsensitive) {
out.append(" NOT LIKE ");
} else {
out.append(") NOT LIKE UPPER(");
}
break;
case Expression.ADD:
out.append(" + ");
break;
case Expression.SUBTRACT:
out.append(" - ");
break;
case Expression.MULTIPLY:
out.append(" * ");
break;
case Expression.DIVIDE:
out.append(" / ");
break;
case Expression.BETWEEN:
if (childIndex == 0) {
out.append(" BETWEEN ");
} else if (childIndex == 1) {
out.append(" AND ");
}
break;
case Expression.NOT_BETWEEN:
if (childIndex == 0) {
out.append(" NOT BETWEEN ");
} else if (childIndex == 1) {
out.append(" AND ");
}
break;
case Expression.BITWISE_OR:
out.append(" ").append(operandForBitwiseOr()).append(" ");
break;
case Expression.BITWISE_AND:
out.append(" ").append(operandForBitwiseAnd()).append(" ");
break;
case Expression.BITWISE_XOR:
out.append(" ").append(operandForBitwiseXor()).append(" ");
break;
case Expression.BITWISE_LEFT_SHIFT:
out.append(" ").append(operandForBitwiseLeftShift()).append(" ");
break;
case Expression.BITWISE_RIGHT_SHIFT:
out.append(" ").append(operandForBitwiseRightShift()).append("");
break;
}
} catch (IOException ioex) {
throw new CayenneRuntimeException("Error appending content", ioex);
}
if (matchingObject) {
objectMatchTranslator.setOperation(out.toString());
objectMatchTranslator.setExpression(node);
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class JdbcAdapter method createUniqueConstraint.
/**
* Returns a DDL string to create a unique constraint over a set of columns.
*
* @since 1.1
*/
@Override
public String createUniqueConstraint(DbEntity source, Collection<DbAttribute> columns) {
if (columns == null || columns.isEmpty()) {
throw new CayenneRuntimeException("Can't create UNIQUE constraint - no columns specified.");
}
StringBuilder buf = new StringBuilder();
buf.append("ALTER TABLE ");
buf.append(quotingStrategy.quotedFullyQualifiedName(source));
buf.append(" ADD UNIQUE (");
Iterator<DbAttribute> it = columns.iterator();
DbAttribute first = it.next();
buf.append(quotingStrategy.quotedName(first));
while (it.hasNext()) {
DbAttribute next = it.next();
buf.append(", ");
buf.append(quotingStrategy.quotedName(next));
}
buf.append(")");
return buf.toString();
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class DataContextExtrasIT method testCommitChangesError.
@Test
public void testCommitChangesError() {
DataDomain domain = context.getParentDataDomain();
// setup mockup PK generator that will blow on PK request
// to emulate an exception
JdbcAdapter jdbcAdapter = objectFactory.newInstance(JdbcAdapter.class, JdbcAdapter.class.getName());
PkGenerator newGenerator = new JdbcPkGenerator(jdbcAdapter) {
@Override
public Object generatePk(DataNode node, DbAttribute pk) throws Exception {
throw new CayenneRuntimeException("Intentional");
}
};
PkGenerator oldGenerator = domain.getDataNodes().iterator().next().getAdapter().getPkGenerator();
JdbcAdapter adapter = (JdbcAdapter) domain.getDataNodes().iterator().next().getAdapter();
adapter.setPkGenerator(newGenerator);
try {
Artist newArtist = context.newObject(Artist.class);
newArtist.setArtistName("aaa");
context.commitChanges();
fail("Exception expected but not thrown due to missing PK generation routine.");
} catch (CayenneRuntimeException ex) {
// exception expected
} finally {
adapter.setPkGenerator(oldGenerator);
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class DataContextExtrasIT method testResolveFaultFailure.
@Test
public void testResolveFaultFailure() {
Persistent o1 = context.findOrCreateObject(new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, 234));
try {
context.prepareForAccess(o1, null, false);
fail("Must blow on non-existing fault.");
} catch (CayenneRuntimeException ignored) {
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class CayenneTransaction method processRollback.
@Override
protected void processRollback() {
status = BaseTransaction.STATUS_ROLLING_BACK;
if (connections == null || connections.isEmpty()) {
return;
}
Throwable deferredException = null;
for (Connection connection : connections.values()) {
try {
// continue with rollback even if an exception was thrown
// before
connection.rollback();
} catch (Throwable th) {
// stores last exception
// TODO: chain exceptions...
deferredException = th;
}
}
if (deferredException != null) {
throw new CayenneRuntimeException(deferredException);
}
}
Aggregations