Unverified Commit 245f3b3b authored by Licho's avatar Licho Committed by GitHub

feat: add get all inner operations by reflactions (#1477)

Signed-off-by: 's avatarLicho <chinabhsun@gmail.com> Signed-off-by: 's avatarLicho <chinabhsun@gmail.com>
parent 87d5483c
......@@ -58,6 +58,10 @@
<artifactId>dlink-metadata-mysql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
......
......@@ -20,14 +20,14 @@
package com.dlink.trans;
import com.dlink.parser.SqlType;
import com.dlink.trans.ddl.AddJarOperation;
import com.dlink.trans.ddl.CreateAggTableOperation;
import com.dlink.trans.ddl.CreateCDCSourceOperation;
import com.dlink.trans.ddl.SetOperation;
import com.dlink.trans.ddl.ShowFragmentOperation;
import com.dlink.trans.ddl.ShowFragmentsOperation;
import lombok.extern.slf4j.Slf4j;
import org.reflections.Reflections;
import org.reflections.scanners.Scanners;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Set;
/**
* Operations
......@@ -35,15 +35,27 @@ import java.util.Arrays;
* @author wenmo
* @since 2021/5/25 15:50
**/
@Slf4j
public class Operations {
private Operations() {
}
private static final Operation[] ALL_OPERATIONS = {new CreateAggTableOperation(), new SetOperation(),
new CreateCDCSourceOperation(), new ShowFragmentsOperation(), new ShowFragmentOperation(),
new AddJarOperation()
};
private static final Operation[] ALL_OPERATIONS = getAllOperations();
private static Operation[] getAllOperations() {
Reflections reflections = new Reflections(Operation.class.getPackage().getName());
Set<Class<?>> operations = reflections.get(Scanners.SubTypes.of(Operation.class).asClass());
return operations.stream().filter(t -> !t.isInterface()).map(t -> {
try {
return t.getConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException e) {
log.error(String.format("getAllOperations error, class %s, err: %s", t, e));
throw new RuntimeException(e);
}
}).toArray(Operation[]::new);
}
public static SqlType getSqlTypeFromStatements(String statement) {
String[] statements = statement.split(";");
......
......@@ -94,10 +94,16 @@
<javax.annotation-api.version>1.3.2</javax.annotation-api.version>
<log4j.version>2.19.0</log4j.version>
<docker.java.version>3.2.13</docker.java.version>
<reflections.version>0.10.2</reflections.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>${reflections.version}</version>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment