case ActionDesc.OP_NOTNULL:
processNullOperation(opCode, stack, result);
break;
case ActionDesc.OP_BETWEEN:
if (stack.size() < 3) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.stackempty")); // NOI18N
}
if (!(stack.get(stack.size() - 1) instanceof ConstraintField)) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.needfieldnode")); // NOI18N
} else {
result.append(getWhereText(stack));
result.append(" between "); // NOI18N
}
result.append(getWhereText(stack));
result.append(" and ");
result.append(getWhereText(stack));
break;
case ActionDesc.OP_IN:
case ActionDesc.OP_NOTIN:
processInOperation(opCode, stack, result);
break;
case ActionDesc.OP_NOTEXISTS:
case ActionDesc.OP_EXISTS:
if (!(opNode instanceof ConstraintSubquery)) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.generic.notinstanceof", // NOI18N
opNode.getClass().getName(), "ConstraintSubquery")); // NOI18N
}
ConstraintSubquery sqNode = (ConstraintSubquery) opNode;
result.append(prefixOperator(opCode));
result.append("("); // NOI18N
Statement sqstmt = (Statement) sqNode.plan.statements.get(0);
result.append(sqstmt.getText());
result.append(")"); // NOI18N
break;
case ActionDesc.OP_LIKE_ESCAPE:
if (stack.size() < 3) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.stackempty")); // NOI18N
}
if (vendorType.supportsLikeEscape()) {
if (!(stack.get(stack.size() - 1) instanceof ConstraintField)) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.needfieldnode")); // NOI18N
} else {
result.append(getWhereText(stack));
result.append(" LIKE "); // NOI18N
}
result.append(getWhereText(stack));
result.append(vendorType.getLeftLikeEscape());
result.append(" ESCAPE "); // NOI18N
result.append(getWhereText(stack));
result.append(vendorType.getRightLikeEscape());
} else {
throw new JDOFatalInternalException(
I18NHelper.getMessage(messages,
"sqlstore.sql.generator.statement.likeescapenotsupported")); //NOI18N
}
break;
case ActionDesc.OP_SUBSTRING:
if (stack.size() < 3) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.stackempty")); // NOI18N
}
result.append(vendorType.getSubstring());
result.append("("); // NOI18N
result.append(getWhereText(stack));
result.append(vendorType.getSubstringFrom());
result.append(getWhereText(stack));
result.append(vendorType.getSubstringFor());
result.append(getWhereText(stack));
result.append(")"); // NOI18N
break;
case ActionDesc.OP_POSITION:
if (stack.size() < 2) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.stackempty")); // NOI18N
}
result.append(vendorType.getPosition());
result.append("("); // NOI18N
boolean swap = vendorType.isPositionSearchSource();
if (swap) {
ConstraintNode expr =
(ConstraintNode)stack.remove(stack.size() - 1);
ConstraintNode pattern =
(ConstraintNode)stack.remove(stack.size() - 1);
stack.add(expr);
stack.add(pattern);
}
result.append(getWhereText(stack));
result.append(vendorType.getPositionSep());
result.append(" ").append(getWhereText(stack)); // NOI18N
result.append(")"); // NOI18N
break;
case ActionDesc.OP_POSITION_START:
if (stack.size() < 3) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.stackempty")); // NOI18N
}
boolean swapArgs = vendorType.isPositionSearchSource();
boolean threeArgs = vendorType.isPositionThreeArgs();
if (threeArgs) {
if (swapArgs) {
ConstraintNode expr =
(ConstraintNode)stack.remove(stack.size() - 1);
ConstraintNode pattern =
(ConstraintNode)stack.remove(stack.size() - 1);
stack.add(expr);
stack.add(pattern);
}
result.append(vendorType.getPosition());
result.append("("); // NOI18N
result.append(getWhereText(stack));
result.append(vendorType.getPositionSep());
result.append(" ").append(getWhereText(stack)); // NOI18N
result.append(vendorType.getPositionSep());
result.append(" ").append(getWhereText(stack)); // NOI18N
result.append(")"); // NOI18N
} else { //twoArgs
ConstraintValue valueNode =
(ConstraintValue)stack.remove(stack.size() - 3);
if (valueNode != null && ONE.equals(valueNode.getValue())) {
stack.add(new ConstraintOperation(ActionDesc.OP_POSITION));
result.append(getWhereText(stack));
} else {
throw new JDOFatalInternalException(
I18NHelper.getMessage(messages,
"sqlstore.sql.generator.statement.positionthreeargsnotsupported")); // NOI18N
}
}
break;
case ActionDesc.OP_MAYBE_NULL:
processMaybeNullOperation(stack, result);
break;
case ActionDesc.OP_MOD:
if (stack.size() < 2) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.stackempty")); // NOI18N
}
result.append(prefixOperator(opCode));
result.append("("); // NOI18N
result.append(getWhereText(stack));
result.append(", "); // NOI18N
result.append(getWhereText(stack));
result.append(")"); // NOI18N
break;
case ActionDesc.OP_CONCAT:
processConcatOperation(opCode, stack, result);
break;
default:
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.constraint.illegalop", // NOI18N
"" + opCode)); // NOI18N
}
}