Skip to content

Commit

Permalink
feat: allow get space by entityType
Browse files Browse the repository at this point in the history
  • Loading branch information
CorvusYe committed Dec 18, 2024
1 parent 6635581 commit 1aef6f2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/org/nebula/contrib/ngbatis/utils/ReflectUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.nebula.contrib.ngbatis.annotations.Space;
import org.nebula.contrib.ngbatis.annotations.base.EdgeType;
import org.nebula.contrib.ngbatis.annotations.base.GraphId;
import org.nebula.contrib.ngbatis.annotations.base.Tag;
Expand Down Expand Up @@ -623,4 +624,25 @@ public static boolean isGraphId(Field field) {
}
return false;
}

/**
* 从实体类获取 space,并解析占位符
*/
public static String spaceFromEntity(Class<?> entityType) {
boolean hasSpace = entityType.isAnnotationPresent(Space.class);
String space = null;
if (hasSpace) {
Space spaceAnnotation = entityType.getAnnotation(Space.class);
space = spaceAnnotation.name();
}

boolean hasTable = entityType.isAnnotationPresent(Table.class);
if (hasTable) {
Table tableAnnotation = entityType.getAnnotation(Table.class);
space = tableAnnotation.schema();
}

return space;
}

}

0 comments on commit 1aef6f2

Please sign in to comment.