Search in sources :

Example 26 with PropertyType

use of org.umlg.sqlg.structure.PropertyType in project sqlg by pietermartin.

the class GlobalUniqueIndex method createGlobalUniqueIndex.

@SuppressWarnings("OptionalGetWithoutIsPresent")
static GlobalUniqueIndex createGlobalUniqueIndex(SqlgGraph sqlgGraph, Topology topology, String globalUniqueIndexName, Set<PropertyColumn> properties) {
    // all PropertyColumns must be for the same PropertyType
    PropertyType propertyType = properties.iterator().next().getPropertyType();
    Map<String, PropertyType> valueColumn = new HashMap<>();
    valueColumn.put(GLOBAL_UNIQUE_INDEX_RECORD_ID, PropertyType.STRING);
    valueColumn.put(GLOBAL_UNIQUE_INDEX_PROPERTY_NAME, PropertyType.STRING);
    valueColumn.put(GLOBAL_UNIQUE_INDEX_VALUE, propertyType);
    VertexLabel vertexLabel = topology.getGlobalUniqueIndexSchema().ensureVertexLabelExist(globalUniqueIndexName, valueColumn);
    PropertyColumn valuePropertyColumn = vertexLabel.getProperty(GLOBAL_UNIQUE_INDEX_VALUE).get();
    PropertyColumn recordIdColumn = vertexLabel.getProperty(GLOBAL_UNIQUE_INDEX_RECORD_ID).get();
    PropertyColumn propertyColumn = vertexLabel.getProperty(GLOBAL_UNIQUE_INDEX_PROPERTY_NAME).get();
    vertexLabel.ensureIndexExists(IndexType.UNIQUE, Collections.singletonList(valuePropertyColumn));
    vertexLabel.ensureIndexExists(IndexType.UNIQUE, Arrays.asList(recordIdColumn, propertyColumn));
    GlobalUniqueIndex globalUniqueIndex = new GlobalUniqueIndex(topology, globalUniqueIndexName, properties);
    topology.getGlobalUniqueIndexSchema().globalUniqueIndexes.put(globalUniqueIndex.getName(), globalUniqueIndex);
    TopologyManager.addGlobalUniqueIndex(sqlgGraph, globalUniqueIndexName, properties);
    globalUniqueIndex.committed = false;
    return globalUniqueIndex;
}
Also used : PropertyType(org.umlg.sqlg.structure.PropertyType)

Example 27 with PropertyType

use of org.umlg.sqlg.structure.PropertyType in project sqlg by pietermartin.

the class SQLServerBaseCacheBulkRecord method addValues.

protected void addValues(List<Object> values) {
    for (String column : this.columns) {
        PropertyType propertyType;
        if (this.propertyColumns != null) {
            propertyType = this.propertyColumns.get(column).getPropertyType();
        } else {
            propertyType = this.properties.get(column);
        }
        Object value = getValue(column);
        switch(propertyType) {
            case BOOLEAN:
                values.add(value);
                break;
            case BYTE:
            case SHORT:
            case INTEGER:
            case LONG:
            case FLOAT:
            case DOUBLE:
            case JSON:
            case STRING:
                values.add(value);
                break;
            case LOCALDATE:
                values.add(value.toString());
                break;
            case LOCALDATETIME:
                Timestamp timestamp = Timestamp.valueOf((LocalDateTime) value);
                values.add(timestamp.toString());
                break;
            case LOCALTIME:
                values.add(value.toString());
                break;
            case ZONEDDATETIME:
                values.add(((ZonedDateTime) value).toLocalDateTime());
                TimeZone tz = TimeZone.getTimeZone(((ZonedDateTime) value).getZone());
                values.add(tz.getID());
                break;
            case PERIOD:
                Period period = (Period) value;
                values.add(period.getYears());
                values.add(period.getMonths());
                values.add(period.getDays());
                break;
            case DURATION:
                Duration duration = (Duration) value;
                values.add(duration.getSeconds());
                values.add(duration.getNano());
                break;
            case byte_ARRAY:
                values.add(value);
                break;
            case BYTE_ARRAY:
                byte[] byteArray = SqlgUtil.convertObjectArrayToBytePrimitiveArray((Object[]) value);
                values.add(byteArray);
                break;
            default:
                throw SqlgExceptions.invalidPropertyType(propertyType);
        }
    }
}
Also used : Period(java.time.Period) Duration(java.time.Duration) PropertyType(org.umlg.sqlg.structure.PropertyType) Timestamp(java.sql.Timestamp)

Example 28 with PropertyType

use of org.umlg.sqlg.structure.PropertyType in project sqlg by pietermartin.

the class H2Dialect method putJsonMetaObject.

@Override
public void putJsonMetaObject(ObjectMapper mapper, ArrayNode metaNodeArray, String columnName, int sqlType, Object o) {
    switch(sqlType) {
        case Types.ARRAY:
            try {
                ObjectNode metaNode = mapper.createObjectNode();
                metaNode.put("name", columnName);
                metaNodeArray.add(metaNode);
                java.sql.Array sqlA = (java.sql.Array) o;
                Object a = sqlA.getArray();
                if (Array.getLength(a) > 0) {
                    PropertyType pt = PropertyType.from(Array.get(a, 0));
                    switch(pt) {
                        case BOOLEAN:
                            metaNode.put("type", PropertyType.boolean_ARRAY.name());
                            break;
                        case SHORT:
                            metaNode.put("type", PropertyType.short_ARRAY.name());
                            break;
                        case INTEGER:
                            metaNode.put("type", PropertyType.int_ARRAY.name());
                            break;
                        case LONG:
                            metaNode.put("type", PropertyType.long_ARRAY.name());
                            break;
                        case FLOAT:
                            metaNode.put("type", PropertyType.float_ARRAY.name());
                            break;
                        case DOUBLE:
                            metaNode.put("type", PropertyType.double_ARRAY.name());
                            break;
                        case STRING:
                            metaNode.put("type", PropertyType.STRING_ARRAY.name());
                            break;
                        default:
                            throw new IllegalStateException("Unknown array sqlType " + sqlType);
                    }
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
            break;
        default:
            super.putJsonMetaObject(mapper, metaNodeArray, columnName, sqlType, o);
    }
}
Also used : Array(java.lang.reflect.Array) JdbcArray(org.h2.jdbc.JdbcArray) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PropertyType(org.umlg.sqlg.structure.PropertyType) java.sql(java.sql)

Aggregations

PropertyType (org.umlg.sqlg.structure.PropertyType)28 GeographyPoint (org.umlg.sqlg.gis.GeographyPoint)9 MultiMap (org.apache.tinkerpop.gremlin.util.tools.MultiMap)7 BaseTest (org.umlg.sqlg.test.BaseTest)7 Test (org.junit.Test)6 PGConnection (org.postgresql.PGConnection)5 SqlgGraph (org.umlg.sqlg.structure.SqlgGraph)4 VertexLabel (org.umlg.sqlg.structure.topology.VertexLabel)4 SecureRandom (java.security.SecureRandom)3 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 Array (java.lang.reflect.Array)2 java.sql (java.sql)2 HashMap (java.util.HashMap)2 Triple (org.apache.commons.lang3.tuple.Triple)2 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)2 JdbcArray (org.h2.jdbc.JdbcArray)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Preconditions (com.google.common.base.Preconditions)1