mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
commit
0f65bb324b
@ -18,6 +18,8 @@ package com.mybatisflex.annotation;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 多对多映射。
|
||||
*
|
||||
* @author michael
|
||||
*/
|
||||
@Inherited
|
||||
@ -25,51 +27,52 @@ import java.lang.annotation.*;
|
||||
@Target({ElementType.FIELD})
|
||||
public @interface RelationManyToMany {
|
||||
|
||||
/**
|
||||
* 当前 entity 的属性
|
||||
*
|
||||
* @return 属性名称
|
||||
*/
|
||||
/**
|
||||
* 当前实体类的属性。
|
||||
*
|
||||
* @return 属性名称
|
||||
*/
|
||||
String selfField() default "";
|
||||
|
||||
/**
|
||||
* 目标对象的关联属性
|
||||
*
|
||||
* @return 属性名称
|
||||
/**
|
||||
* 目标实体类的关联属性。
|
||||
*
|
||||
* @return 属性名称
|
||||
*/
|
||||
String targetField() default "";
|
||||
|
||||
/**
|
||||
* 中间表
|
||||
*
|
||||
* @return 中间表名称
|
||||
/**
|
||||
* 中间表名称。
|
||||
*
|
||||
* @return 中间表名称
|
||||
*/
|
||||
String joinTable();
|
||||
|
||||
/**
|
||||
* 中间表与当前表的关联字段
|
||||
*
|
||||
* @return 字段名称,列名
|
||||
/**
|
||||
* 中间表与当前表的关联字段。
|
||||
*
|
||||
* @return 字段名称,列名
|
||||
*/
|
||||
String joinSelfColumn();
|
||||
|
||||
|
||||
/**
|
||||
* 目标表的关联字段名称
|
||||
*
|
||||
* @return 字段名称和表
|
||||
/**
|
||||
* 目标表的关联字段名称。
|
||||
*
|
||||
* @return 字段名称和表
|
||||
*/
|
||||
String joinTargetColumn();
|
||||
|
||||
/**
|
||||
* 查询排序
|
||||
*
|
||||
* @return 排序方式
|
||||
/**
|
||||
* 查询排序。
|
||||
*
|
||||
* @return 排序方式
|
||||
*/
|
||||
String orderBy() default "";
|
||||
|
||||
/**
|
||||
* 默认使用哪个数据源,若系统找不到该指定的数据源时,默认使用第一个数据源。
|
||||
/**
|
||||
* 默认使用哪个数据源,若系统找不到该指定的数据源时,默认使用第一个数据源。
|
||||
*
|
||||
* @return 数据源
|
||||
*/
|
||||
String dataSource() default "";
|
||||
|
||||
|
||||
@ -18,6 +18,8 @@ package com.mybatisflex.annotation;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 多对一映射。
|
||||
*
|
||||
* @author michael
|
||||
*/
|
||||
@Inherited
|
||||
@ -25,22 +27,24 @@ import java.lang.annotation.*;
|
||||
@Target({ElementType.FIELD})
|
||||
public @interface RelationManyToOne {
|
||||
|
||||
/**
|
||||
* 当前 entity 的属性
|
||||
*
|
||||
* @return 属性名称
|
||||
*/
|
||||
/**
|
||||
* 当前实体类的属性。
|
||||
*
|
||||
* @return 属性名称
|
||||
*/
|
||||
String selfField();
|
||||
|
||||
/**
|
||||
* 目标对象的关联属性
|
||||
*
|
||||
* @return 属性名称
|
||||
/**
|
||||
* 目标实体类的关联属性。
|
||||
*
|
||||
* @return 属性名称
|
||||
*/
|
||||
String targetField() default "";
|
||||
|
||||
/**
|
||||
* 默认使用哪个数据源,若系统找不到该指定的数据源时,默认使用第一个数据源。
|
||||
/**
|
||||
* 默认使用哪个数据源,若系统找不到该指定的数据源时,默认使用第一个数据源。
|
||||
*
|
||||
* @return 数据源
|
||||
*/
|
||||
String dataSource() default "";
|
||||
|
||||
|
||||
@ -18,6 +18,8 @@ package com.mybatisflex.annotation;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 一对多映射。
|
||||
*
|
||||
* @author michael
|
||||
*/
|
||||
@Inherited
|
||||
@ -25,36 +27,38 @@ import java.lang.annotation.*;
|
||||
@Target({ElementType.FIELD})
|
||||
public @interface RelationOneToMany {
|
||||
|
||||
/**
|
||||
* 当前 entity 的属性
|
||||
*
|
||||
* @return 属性名称
|
||||
*/
|
||||
/**
|
||||
* 当前实体类的属性。
|
||||
*
|
||||
* @return 属性名称
|
||||
*/
|
||||
String selfField() default "";
|
||||
|
||||
/**
|
||||
* 目标对象的关联属性
|
||||
*
|
||||
* @return 属性名称
|
||||
/**
|
||||
* 目标实体类的关联属性。
|
||||
*
|
||||
* @return 属性名称
|
||||
*/
|
||||
String targetField();
|
||||
|
||||
/**
|
||||
* 查询排序
|
||||
*
|
||||
* @return 排序方式
|
||||
/**
|
||||
* 查询排序。
|
||||
*
|
||||
* @return 排序方式
|
||||
*/
|
||||
String orderBy() default "";
|
||||
|
||||
/**
|
||||
* 现在查询的数据量
|
||||
*
|
||||
* @return 数据量
|
||||
/**
|
||||
* 现在查询的数据量。
|
||||
*
|
||||
* @return 数据量
|
||||
*/
|
||||
int limit() default 0;
|
||||
|
||||
/**
|
||||
* 默认使用哪个数据源,若系统找不到该指定的数据源时,默认使用第一个数据源。
|
||||
/**
|
||||
* 默认使用哪个数据源,若系统找不到该指定的数据源时,默认使用第一个数据源。
|
||||
*
|
||||
* @return 数据源
|
||||
*/
|
||||
String dataSource() default "";
|
||||
|
||||
|
||||
@ -18,6 +18,8 @@ package com.mybatisflex.annotation;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 一对一映射。
|
||||
*
|
||||
* @author michael
|
||||
*/
|
||||
@Inherited
|
||||
@ -25,22 +27,24 @@ import java.lang.annotation.*;
|
||||
@Target({ElementType.FIELD})
|
||||
public @interface RelationOneToOne {
|
||||
|
||||
/**
|
||||
* 当前 entity 的属性
|
||||
*
|
||||
* @return 属性名称
|
||||
*/
|
||||
/**
|
||||
* 当前实体类的属性。
|
||||
*
|
||||
* @return 属性名称
|
||||
*/
|
||||
String selfField() default "";
|
||||
|
||||
/**
|
||||
* 目标对象的关联属性
|
||||
*
|
||||
* @return 属性名称
|
||||
/**
|
||||
* 目标实体类的关联属性。
|
||||
*
|
||||
* @return 属性名称
|
||||
*/
|
||||
String targetField();
|
||||
|
||||
/**
|
||||
* 默认使用哪个数据源,若系统找不到该指定的数据源时,默认使用第一个数据源。
|
||||
/**
|
||||
* 默认使用哪个数据源,若系统找不到该指定的数据源时,默认使用第一个数据源。
|
||||
*
|
||||
* @return 数据源
|
||||
*/
|
||||
String dataSource() default "";
|
||||
|
||||
|
||||
@ -36,6 +36,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*/
|
||||
public class RelationManager {
|
||||
|
||||
private RelationManager() {
|
||||
}
|
||||
|
||||
private static Map<Class<?>, List<AbstractRelation>> classRelations = new ConcurrentHashMap<>();
|
||||
|
||||
private static List<AbstractRelation> getRelations(Class<?> clazz) {
|
||||
|
||||
@ -16,11 +16,17 @@
|
||||
|
||||
package com.mybatisflex.processor.config;
|
||||
|
||||
import com.mybatisflex.processor.util.FileUtil;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
@ -49,8 +55,16 @@ public class MybatisFlexConfig {
|
||||
FileObject aptConfigFileObject = filer.getResource(StandardLocation.CLASS_OUTPUT, "", APT_FILE_NAME);
|
||||
|
||||
List<File> aptConfigFiles = new ArrayList<>();
|
||||
|
||||
File moduleRoot = new File(aptConfigFileObject.toUri()).getParentFile().getParentFile().getParentFile();
|
||||
while (new File(moduleRoot, "pom.xml").exists()) {
|
||||
|
||||
// pom.xml -> Maven 项目
|
||||
// build.gradle -> Gradle 项目
|
||||
if (new File(moduleRoot, "build.gradle").exists()) {
|
||||
FileUtil.setBuildFile("build.gradle");
|
||||
}
|
||||
|
||||
while (FileUtil.existsBuildFile(moduleRoot)) {
|
||||
File aptConfig = new File(moduleRoot, APT_FILE_NAME);
|
||||
if (aptConfig.exists()) {
|
||||
aptConfigFiles.add(aptConfig);
|
||||
@ -59,7 +73,7 @@ public class MybatisFlexConfig {
|
||||
}
|
||||
|
||||
for (File aptConfigFile : aptConfigFiles) {
|
||||
try (InputStream stream = new FileInputStream(aptConfigFile);
|
||||
try (InputStream stream = Files.newInputStream(aptConfigFile.toPath());
|
||||
Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
|
||||
|
||||
Properties config = new Properties();
|
||||
@ -71,7 +85,7 @@ public class MybatisFlexConfig {
|
||||
properties.put(key, config.getProperty((String) key));
|
||||
}
|
||||
if ("processor.stopBubbling".equalsIgnoreCase((String) key)
|
||||
&& "true".equalsIgnoreCase(String.valueOf(config.getProperty((String) key)))) {
|
||||
&& "true".equalsIgnoreCase(String.valueOf(config.getProperty((String) key)))) {
|
||||
stopBubbling = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +29,16 @@ public class FileUtil {
|
||||
private FileUtil() {
|
||||
}
|
||||
|
||||
private static String buildFile = "pom.xml";
|
||||
|
||||
public static void setBuildFile(String buildFile) {
|
||||
FileUtil.buildFile = buildFile;
|
||||
}
|
||||
|
||||
public static boolean existsBuildFile(File file) {
|
||||
return new File(file, buildFile).exists();
|
||||
}
|
||||
|
||||
public static boolean isFromTestSource(String path) {
|
||||
return path.contains("test-sources") || path.contains("test-annotations");
|
||||
}
|
||||
@ -53,7 +63,7 @@ public class FileUtil {
|
||||
if (file.isFile()) {
|
||||
return getProjectRootPath(file.getParentFile(), --count);
|
||||
} else {
|
||||
if (new File(file, "pom.xml").exists() && !new File(file.getParentFile(), "pom.xml").exists()) {
|
||||
if (new File(file, buildFile).exists() && !new File(file.getParentFile(), buildFile).exists()) {
|
||||
return file.getAbsolutePath();
|
||||
} else {
|
||||
return getProjectRootPath(file.getParentFile(), --count);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user