Skip to content

Instantly share code, notes, and snippets.

@alebon
Last active August 29, 2015 14:15
Show Gist options
  • Save alebon/b682436305ea1a692ebe to your computer and use it in GitHub Desktop.
Save alebon/b682436305ea1a692ebe to your computer and use it in GitHub Desktop.
class OrientIndexHandler(graph: OrientGraph) extends IndexHandler {
override def createUniqueIndexField[ModelType, FieldType](field: Field[ModelType, FieldType], label: String): Unit = {
val keyName = field.name
val indexName = s"idx${label}_$keyName"
val vertexType = graph.getVertexType(label)
if (!vertexType.existsProperty(keyName)) {
field match {
case uuidField: UuidField[_] =>
UuidPropertyCreator(keyName, indexName, vertexType)
case _ =>
// Ignore this field
}
}
}
override def createFulltextIndexField(property: String, label: String): Unit = {
}
/**
* UUID field property creator
*/
object UuidPropertyCreator {
def apply[ModelType](keyName: String, indexName: String, vertexType: OrientVertexType) = {
vertexType.createProperty(keyName, OType.STRING).setMin("36").setMax("36").setMandatory(true)
vertexType.createIndex(indexName, OClass.INDEX_TYPE.UNIQUE, keyName)
}
}
}
class OrientVertexBuilder(graph: TransactionalGraph) extends VertexBuilder {
/**
* Vertex creator method
*
* @param label
* @return
*/
override def createVertexWithLabel(label: String): Vertex = {
val vertex = graph match {
case og: OrientGraph =>
og.addVertex(label, null).asInstanceOf[Vertex]
case _ =>
graph.addVertex(null)
}
vertex
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment