Пример #1
0
func (g GremlinBackend) AddMetadata(i interface{}, k string, v interface{}) bool {
	var e graphElement
	var elType string

	switch i.(type) {
	case *Node:
		e = i.(*Node).graphElement
		elType = "V"
	case *Edge:
		e = i.(*Edge).graphElement
		elType = "V"
	}

	properties, err := idToPropertiesString(e.ID)
	if err != nil {
		logging.GetLogger().Errorf("Error while retrieving a Node: %s", err.Error())
		return false
	}

	encoder := gremlin.GremlinPropertiesEncoder{}
	encoder.EncodeKVPair(k, v)

	query := "g." + elType + "().has(" + properties + ").property(" + encoder.String() + ")"

	_, err = g.client.Query(query)
	if err != nil {
		logging.GetLogger().Errorf("Gremlin query error: %s, %s", query, err.Error())
		return false
	}

	return true
}
Пример #2
0
func idToPropertiesString(i Identifier) (string, error) {
	properties := map[string]interface{}{
		"_ID": string(i),
	}

	encoder := gremlin.GremlinPropertiesEncoder{}
	err := encoder.Encode(properties)
	if err != nil {
		logging.GetLogger().Errorf("Error while retrieving a Node: %s", err.Error())
		return "", err
	}

	return encoder.String(), nil
}
Пример #3
0
func metadataToString(m Metadata) (string, error) {
	properties := map[string]interface{}{}
	for k, v := range m {
		if k[0] == '_' {
			return "", errors.New("Properties starting with _ are reserved")
		}
		properties[k] = v
	}

	encoder := gremlin.GremlinPropertiesEncoder{}
	err := encoder.Encode(properties)

	return encoder.String(), err
}
Пример #4
0
func toPropertiesString(e graphElement) ([]byte, error) {
	properties := map[string]interface{}{
		"_ID":   string(e.ID),
		"_host": e.host,
	}
	for k, v := range e.metadata {
		if k[0] == '_' {
			return nil, errors.New("Properties starting with _ are reserved")
		}
		properties[k] = v
	}

	encoder := gremlin.GremlinPropertiesEncoder{}
	err := encoder.Encode(properties)

	return encoder.Bytes(), err
}