Skip to content

Instantly share code, notes, and snippets.

@wreulicke
Created July 30, 2016 16:00
Show Gist options
  • Save wreulicke/ed322c0a00f857d4255194849fe860f1 to your computer and use it in GitHub Desktop.
Save wreulicke/ed322c0a00f857d4255194849fe860f1 to your computer and use it in GitHub Desktop.
OrientDB memo
package test.jpa;
import java.lang.reflect.Field;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
public class VertexRegisterImpl implements VertexRegister{
@Override
public<T extends OrientVertex> void regist(OrientGraph graph, Class<T> vertexClass) {
String clazzName=vertexClass.getSimpleName();
Class<?> superClazz=vertexClass.getSuperclass();
String superClazzName=superClazz.equals(OrientVertex.class)?
OClass.VERTEX_CLASS_NAME :
superClazz.getSimpleName();
OrientVertexType type=graph.createVertexType(clazzName, superClazzName);
this.registProperty(type, vertexClass);
}
@Override
public <V extends OrientVertex> void registProperty(OrientVertexType type, Class<V> vertexClass) {
Field[] fields=vertexClass.getDeclaredFields();
for (Field field : fields) {
OProperty annotation=field.getAnnotation(OProperty.class);
if(annotation==null)continue;
type.createProperty(field.getName(),annotation.getType());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment