/** * @see SqlDialect#valueToValuesString(PropertyType, Object) * @see PropertyType#from(Object) */ public SqlgQueryBuilder valueToValuesString(Object value) { return valueToValuesString(PropertyType.from(value), value); }
@Override public void handleOther(Map<String, Object> properties, String columnName, Object o, PropertyType propertyType) { switch (propertyType.ordinal()) { case JSON_ORDINAL: ObjectMapper objectMapper = new ObjectMapper(); try { JsonNode jsonNode = objectMapper.readTree(o.toString()); properties.put(columnName, jsonNode); } catch (IOException e) { throw new RuntimeException(e); } break; default: throw new IllegalStateException("sqlgDialect.handleOther does not handle " + propertyType.name()); } }
@Override public String[] propertyTypeToSqlDefinition(PropertyType propertyType) { switch (propertyType.ordinal()) { case BOOLEAN_ORDINAL: return new String[]{"BOOLEAN"}; return new String[]{"VARCHAR"}; case VARCHAR_ORDINAL: return new String[]{"VARCHAR(" + propertyType.getLength() + ")"}; case ZONEDDATETIME_ORDINAL: return new String[]{"TIMESTAMP", "VARCHAR"}; throw new IllegalStateException("H2 does not support gis types!"); default: throw new IllegalStateException("Unknown propertyType " + propertyType.name());
public static Index fromNotifyJson(AbstractLabel abstractLabel, JsonNode indexNode) { IndexType indexType = IndexType.fromNotifyJson(indexNode.get("indexType")); String name = indexNode.get("name").asText(); ArrayNode propertiesNode = (ArrayNode) indexNode.get("uncommittedProperties"); List<PropertyColumn> properties = new ArrayList<>(); for (JsonNode propertyNode : propertiesNode) { String propertyName = propertyNode.get("name").asText(); PropertyType propertyType = PropertyType.valueOf(propertyNode.get("propertyType").asText()); Optional<PropertyColumn> propertyColumnOptional = abstractLabel.getProperty(propertyName); Preconditions.checkState(propertyColumnOptional.isPresent(), "BUG: property %s for PropertyType %s not found.", propertyName, propertyType.name()); //noinspection OptionalGetWithoutIsPresent properties.add(propertyColumnOptional.get()); } return new Index(name, indexType, abstractLabel, properties); }
@Override public String[] propertyTypeToSqlDefinition(PropertyType propertyType) { switch (propertyType.ordinal()) { case BOOLEAN_ORDINAL: return new String[]{"BIT"}; return new String[]{"VARCHAR(2000)"}; case VARCHAR_ORDINAL: return new String[]{"VARCHAR(" + propertyType.getLength() + ")"}; case ZONEDDATETIME_ORDINAL: return new String[]{"DATETIME2(3)", "VARCHAR(255)"};
Object a = sqlA.getArray(); if (Array.getLength(a) > 0) { PropertyType pt = PropertyType.from(Array.get(a, 0)); switch (pt.ordinal()) { case BOOLEAN_ORDINAL: metaNode.put("type", PropertyType.boolean_ARRAY.name()); break; case SHORT_ORDINAL: metaNode.put("type", PropertyType.short_ARRAY.name()); break; case INTEGER_ORDINAL: metaNode.put("type", PropertyType.int_ARRAY.name()); break; case LONG_ORDINAL: metaNode.put("type", PropertyType.long_ARRAY.name()); break; case FLOAT_ORDINAL: metaNode.put("type", PropertyType.float_ARRAY.name()); break; case DOUBLE_ORDINAL: metaNode.put("type", PropertyType.double_ARRAY.name()); break; case STRING_ORDINAL: metaNode.put("type", PropertyType.STRING_ARRAY.name()); break; default:
.flatMap(e -> { Stream.Builder<String> keys = Stream.<String> builder().add(e.getKey()); PropertyType pt = PropertyType.from(e.getValue()); String[] postfixes = sqlgGraph.getSqlDialect().propertyTypeToSqlDefinition(pt); for (int i = 1; i < postfixes.length; ++i) { keys.add(e.getKey() + pt.getPostFixes()[i - 1]);
public boolean isArray() { return name().endsWith("_ARRAY"); }
void writeColumnNames(Map<String, Pair<PropertyType, Object>> keyValueMap, StringBuilder sql) { int i = 1; for (String column : keyValueMap.keySet()) { Pair<PropertyType, Object> propertyColumnValue = keyValueMap.get(column); PropertyType propertyType = propertyColumnValue.getLeft(); String[] sqlDefinitions = this.sqlgGraph.getSqlDialect().propertyTypeToSqlDefinition(propertyType); int count = 1; for (@SuppressWarnings("unused") String sqlDefinition : sqlDefinitions) { if (count > 1) { sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(column + propertyType.getPostFixes()[count - 2])); } else { sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(column)); } if (count++ < sqlDefinitions.length) { sql.append(","); } } if (i++ < keyValueMap.size()) { sql.append(", "); } } }
public static Object stringValueToType(PropertyType propertyType, String value) { switch (propertyType.ordinal()) { case STRING_ORDINAL: return value; case VARCHAR_ORDINAL: return value; default: throw new IllegalStateException(String.format("Unhandled propertyType %s", propertyType)); } }
switch (propertyType.ordinal()) { case BOOLEAN_ORDINAL: PropertyType.LOCALDATETIME )); bulkCopy.addColumnMapping(i, column + PropertyType.ZONEDDATETIME.getPostFixes()[0]); this.columnMetadata.put(i++, new ColumnMetadata( column, PropertyType.INTEGER )); bulkCopy.addColumnMapping(i, column + PropertyType.PERIOD.getPostFixes()[0]); this.columnMetadata.put(i++, new ColumnMetadata( column + PropertyType.PERIOD.getPostFixes()[0], sqlgGraph.getSqlDialect().propertyTypeToJavaSqlType(PropertyType.PERIOD)[1], 0, PropertyType.INTEGER )); bulkCopy.addColumnMapping(i, column + PropertyType.PERIOD.getPostFixes()[1]); this.columnMetadata.put(i++, new ColumnMetadata( column + PropertyType.PERIOD.getPostFixes()[1], sqlgGraph.getSqlDialect().propertyTypeToJavaSqlType(PropertyType.PERIOD)[2], 0, PropertyType.LONG )); bulkCopy.addColumnMapping(i, column + PropertyType.DURATION.getPostFixes()[0]); this.columnMetadata.put(i++, new ColumnMetadata(
public static PropertyType varChar(int length) { return new PropertyType(String.class.getName(), new String[]{}, length); }
sql.append(sqlDialect.maybeWrapInQoutes(property.getName())); if (property.getPropertyType().isString() && sqlgGraph.getSqlDialect().requiresIndexLengthLimit()) {
Object a = sqlA.getArray(); if (Array.getLength(a) > 0) { PropertyType pt = PropertyType.from(Array.get(a, 0)); switch (pt.ordinal()) { case BOOLEAN_ORDINAL: metaNode.put("type", PropertyType.boolean_ARRAY.name()); break; case SHORT_ORDINAL: metaNode.put("type", PropertyType.short_ARRAY.name()); break; case INTEGER_ORDINAL: metaNode.put("type", PropertyType.int_ARRAY.name()); break; case LONG_ORDINAL: metaNode.put("type", PropertyType.long_ARRAY.name()); break; case FLOAT_ORDINAL: metaNode.put("type", PropertyType.float_ARRAY.name()); break; case DOUBLE_ORDINAL: metaNode.put("type", PropertyType.double_ARRAY.name()); break; case STRING_ORDINAL: metaNode.put("type", PropertyType.STRING_ARRAY.name()); break; default:
PropertyType propertyType = PropertyType.from(value); String[] postfixes = propertyType.getPostFixes();
public boolean isArray() { return name().endsWith("_ARRAY"); }
void appendProperties(AbstractLabel edgeLabel, StringBuilder sql) { for (PropertyColumn propertyColumn : edgeLabel.getProperties().values()) { sql.append(", "); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(propertyColumn.getName())); // additional columns for time zone, etc. String[] ps = propertyColumn.getPropertyType().getPostFixes(); if (ps != null) { for (String p : propertyColumn.getPropertyType().getPostFixes()) { sql.append(", "); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(propertyColumn.getName() + p)); } } } }
public static Object stringValueToType(PropertyType propertyType, String value) { switch (propertyType.ordinal()) { case STRING_ORDINAL: return value; case VARCHAR_ORDINAL: return value; default: throw new IllegalStateException(String.format("Unhandled propertyType %s", propertyType)); } }