Last active
August 29, 2015 14:15
-
-
Save alebon/b682436305ea1a692ebe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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