parent
1b7718d420
commit
8b2f31ad32
@ -0,0 +1,14 @@
|
||||
package space.kklochko.jdbc_hospital_example.cli.commands;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class CommandData {
|
||||
public String name;
|
||||
public String datatype;
|
||||
public Map<String, String> arguments;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package space.kklochko.jdbc_hospital_example.cli.commands;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import space.kklochko.jdbc_hospital_example.db.repositories.AbstractRepository;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class CommandEntities<T> {
|
||||
private AbstractRepository<T> repository;
|
||||
private Method method;
|
||||
|
||||
public ArrayList<T> run() {
|
||||
try {
|
||||
return (ArrayList<T>) method.invoke(getRepository());
|
||||
} catch (InvocationTargetException e) {
|
||||
System.err.println(e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
System.err.println(e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package space.kklochko.jdbc_hospital_example.cli.commands;
|
||||
|
||||
import lombok.Data;
|
||||
import space.kklochko.jdbc_hospital_example.db.repositories.AbstractRepository;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@Data
|
||||
public class CommandEntity <A, T> {
|
||||
private AbstractRepository<T> repository;
|
||||
private Method method;
|
||||
private A argument;
|
||||
|
||||
public CommandEntity(AbstractRepository<T> repository, Method method, A argument) {
|
||||
this.repository = repository;
|
||||
this.method = method;
|
||||
this.argument = argument;
|
||||
}
|
||||
|
||||
public boolean run() {
|
||||
try {
|
||||
return (Boolean) method.invoke(getRepository(), getArgument());
|
||||
} catch (InvocationTargetException e) {
|
||||
System.err.println(e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
System.err.println(e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Reference in new issue