Skip to content

Commit 1aef6f2

Browse files
committed
feat: allow get space by entityType
1 parent 6635581 commit 1aef6f2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/main/java/org/nebula/contrib/ngbatis/utils/ReflectUtil.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import javax.persistence.Id;
2525
import javax.persistence.Table;
2626
import javax.persistence.Transient;
27+
import org.nebula.contrib.ngbatis.annotations.Space;
2728
import org.nebula.contrib.ngbatis.annotations.base.EdgeType;
2829
import org.nebula.contrib.ngbatis.annotations.base.GraphId;
2930
import org.nebula.contrib.ngbatis.annotations.base.Tag;
@@ -623,4 +624,25 @@ public static boolean isGraphId(Field field) {
623624
}
624625
return false;
625626
}
627+
628+
/**
629+
* 从实体类获取 space,并解析占位符
630+
*/
631+
public static String spaceFromEntity(Class<?> entityType) {
632+
boolean hasSpace = entityType.isAnnotationPresent(Space.class);
633+
String space = null;
634+
if (hasSpace) {
635+
Space spaceAnnotation = entityType.getAnnotation(Space.class);
636+
space = spaceAnnotation.name();
637+
}
638+
639+
boolean hasTable = entityType.isAnnotationPresent(Table.class);
640+
if (hasTable) {
641+
Table tableAnnotation = entityType.getAnnotation(Table.class);
642+
space = tableAnnotation.schema();
643+
}
644+
645+
return space;
646+
}
647+
626648
}

0 commit comments

Comments
 (0)