public void visit( Literal literal ) {
if (literal instanceof LiteralValue) {
LiteralValue literalValue = (LiteralValue)literal;
Value value = literalValue.getLiteralValue();
String typeName = null;
ValueFactories factories = context.getValueFactories();
switch (value.getType()) {
case PropertyType.UNDEFINED:
case PropertyType.STRING:
append(SINGLE_QUOTE);
String str = factories.getStringFactory().create(literalValue.value());
append(str);
append(SINGLE_QUOTE);
return;
case PropertyType.PATH:
append("CAST(");
append(factories.getPathFactory().create(literalValue.value()));
append(" AS ").append(PropertyType.TYPENAME_PATH.toUpperCase()).append(')');
return;
case PropertyType.NAME:
append("CAST(");
append(factories.getNameFactory().create(literalValue.value()));
append(" AS ").append(PropertyType.TYPENAME_NAME.toUpperCase()).append(')');
return;
case PropertyType.REFERENCE:
typeName = PropertyType.TYPENAME_REFERENCE;
break;
case PropertyType.WEAKREFERENCE:
typeName = PropertyType.TYPENAME_WEAKREFERENCE;
break;
case org.modeshape.jcr.api.PropertyType.SIMPLE_REFERENCE:
typeName = org.modeshape.jcr.api.PropertyType.TYPENAME_SIMPLE_REFERENCE;
break;
case PropertyType.BINARY:
typeName = PropertyType.TYPENAME_BINARY;
break;
case PropertyType.BOOLEAN:
typeName = PropertyType.TYPENAME_BOOLEAN;
break;
case PropertyType.DATE:
typeName = PropertyType.TYPENAME_DATE;
break;
case PropertyType.DECIMAL:
typeName = PropertyType.TYPENAME_DECIMAL;
break;
case PropertyType.DOUBLE:
typeName = PropertyType.TYPENAME_DOUBLE;
break;
case PropertyType.LONG:
typeName = PropertyType.TYPENAME_LONG;
break;
case PropertyType.URI:
typeName = PropertyType.TYPENAME_URI;
break;
}
assert typeName != null;
String str = factories.getStringFactory().create(literalValue.value());
append("CAST('").append(str).append("' AS ").append(typeName.toUpperCase()).append(')');
} else {
Object value = literal.value();
String typeName = null;
ValueFactories factories = context.getValueFactories();
if (value instanceof String || value instanceof Character) {
append(SINGLE_QUOTE);
String str = factories.getStringFactory().create(value);
append(str);
append(SINGLE_QUOTE);
return;
}
if (value instanceof Path) {
append("CAST(");
append(factories.getPathFactory().create(value));
append(" AS ").append(PropertyType.TYPENAME_PATH.toUpperCase()).append(')');
return;
}
if (value instanceof Name) {
append("CAST(");
append(factories.getNameFactory().create(value));
append(" AS ").append(PropertyType.TYPENAME_NAME.toUpperCase()).append(')');
return;
}
if (value instanceof Reference) {
typeName = ((Reference)value).isWeak() ? PropertyType.TYPENAME_WEAKREFERENCE.toUpperCase() : PropertyType.TYPENAME_REFERENCE.toUpperCase();
} else if (value instanceof Binary) {
typeName = PropertyType.TYPENAME_BINARY.toUpperCase();
} else if (value instanceof Boolean) {
typeName = PropertyType.TYPENAME_BOOLEAN.toUpperCase();
} else if (value instanceof DateTime) {
typeName = PropertyType.TYPENAME_DATE.toUpperCase();
} else if (value instanceof BigDecimal) {
typeName = PropertyType.TYPENAME_DECIMAL.toUpperCase();
} else if (value instanceof Double || value instanceof Float) {
typeName = PropertyType.TYPENAME_DOUBLE.toUpperCase();
} else if (value instanceof Long || value instanceof Integer || value instanceof Short) {
typeName = PropertyType.TYPENAME_LONG.toUpperCase();
} else if (value instanceof URI) {
typeName = PropertyType.TYPENAME_URI.toUpperCase();
}
assert typeName != null;
String str = factories.getStringFactory().create(value);
append("CAST('").append(str).append("' AS ").append(typeName.toUpperCase()).append(')');
}
}