mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-11 18:11:59 +00:00
Cleaned up all DAO3 classes and moved common implementation to EntityDAO3
This commit is contained in:
parent
c600fc3f66
commit
aaa30c92f7
@ -36,7 +36,6 @@ import java.util.stream.Collectors;
|
||||
public class ConstraintViolationExceptionMapper implements ExceptionMapper<ConstraintViolationException> {
|
||||
@Override
|
||||
public Response toResponse(ConstraintViolationException exception) {
|
||||
System.out.println(exception.getMessage());
|
||||
Set<ConstraintViolation<?>> constraintViolations = exception.getConstraintViolations();
|
||||
List<String> errorMessages = constraintViolations.stream()
|
||||
.map(constraintViolation -> {
|
||||
|
@ -1,13 +1,6 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||
import org.jdbi.v3.sqlobject.customizer.Define;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.openmetadata.catalog.entity.data.Chart;
|
||||
import org.openmetadata.catalog.entity.data.Table;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ChartDAO3 extends EntityDAO<Chart>{
|
||||
@Override
|
||||
@ -17,40 +10,5 @@ public interface ChartDAO3 extends EntityDAO<Chart>{
|
||||
default Class<Chart> getEntityClass() { return Chart.class; }
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT json FROM <table> WHERE fullyQualifiedName = :name")
|
||||
String findByName(@Define("table") String table, @Bind("name") String name);
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT count(*) FROM <table> WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL)")
|
||||
int listCount(@Define("table") String table, @Bind("fqnPrefix") String fqnPrefix);
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT json FROM (" +
|
||||
"SELECT fullyQualifiedName, json FROM <table> WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL) AND " +// Filter by
|
||||
// service name
|
||||
"fullyQualifiedName < :before " + // Pagination by chart fullyQualifiedName
|
||||
"ORDER BY fullyQualifiedName DESC " + // Pagination ordering by chart fullyQualifiedName
|
||||
"LIMIT :limit" +
|
||||
") last_rows_subquery ORDER BY fullyQualifiedName")
|
||||
List<String> listBefore(@Define("table") String table, @Bind("fqnPrefix") String fqnPrefix, @Bind("limit") int limit,
|
||||
@Bind("before") String before);
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT json FROM <table> WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL) AND " +
|
||||
"fullyQualifiedName > :after " +
|
||||
"ORDER BY fullyQualifiedName " +
|
||||
"LIMIT :limit")
|
||||
List<String> listAfter(@Define("table") String table, @Bind("fqnPrefix") String fqnPrefix, @Bind("limit") int limit,
|
||||
@Bind("after") String after);
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT EXISTS (SELECT * FROM <table> WHERE id = :id)")
|
||||
boolean exists(@Define("table") String table, @Bind("id") String id);
|
||||
|
||||
@Override
|
||||
@SqlUpdate("DELETE FROM <table> WHERE id = :id")
|
||||
int delete(@Define("table") String table, @Bind("id") String id);
|
||||
default String getNameColumn() { return "fullyQualifiedName"; }
|
||||
}
|
||||
|
@ -250,8 +250,7 @@ public class ChartRepositoryHelper implements EntityRepository<Chart>{
|
||||
private EntityReference getService(EntityReference service) throws IOException {
|
||||
String id = service.getId().toString();
|
||||
if (service.getType().equalsIgnoreCase(Entity.DASHBOARD_SERVICE)) {
|
||||
DashboardService serviceInstance = EntityUtil.validate(id, repo3.dashboardServiceDAO().findById(id),
|
||||
DashboardService.class);
|
||||
DashboardService serviceInstance = repo3.dashboardServiceDAO().findEntityById(id);
|
||||
service.setDescription(serviceInstance.getDescription());
|
||||
service.setName(serviceInstance.getName());
|
||||
} else {
|
||||
|
@ -2,26 +2,20 @@ package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.openmetadata.catalog.entity.services.DashboardService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DashboardServiceDAO3 {
|
||||
@SqlUpdate("INSERT INTO dashboard_service_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
public interface DashboardServiceDAO3 extends EntityDAO<DashboardService> {
|
||||
@Override
|
||||
default String getTableName() { return "dashboard_service_entity"; }
|
||||
|
||||
@SqlUpdate("UPDATE dashboard_service_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
@Override
|
||||
default String getNameColumn() { return "name"; }
|
||||
|
||||
@SqlQuery("SELECT json FROM dashboard_service_entity WHERE id = :id")
|
||||
String findById(@Bind("id") String id);
|
||||
|
||||
@SqlQuery("SELECT json FROM dashboard_service_entity WHERE name = :name")
|
||||
String findByName(@Bind("name") String name);
|
||||
@Override
|
||||
default Class<DashboardService> getEntityClass() { return DashboardService.class; }
|
||||
|
||||
@SqlQuery("SELECT json FROM dashboard_service_entity WHERE (name = :name OR :name is NULL)")
|
||||
List<String> list(@Bind("name") String name);
|
||||
|
||||
@SqlUpdate("DELETE FROM dashboard_service_entity WHERE id = :id")
|
||||
int delete(@Bind("id") String id);
|
||||
}
|
||||
|
@ -1,13 +1,7 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||
import org.jdbi.v3.sqlobject.customizer.Define;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.openmetadata.catalog.entity.data.Database;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DatabaseDAO3 extends EntityDAO<Database> {
|
||||
@Override
|
||||
default String getTableName() { return "database_entity"; }
|
||||
@ -18,36 +12,5 @@ public interface DatabaseDAO3 extends EntityDAO<Database> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT json FROM <table> WHERE fullyQualifiedName = :name")
|
||||
String findByName(@Define("table") String table, @Bind("name") String name);
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT count(*) FROM <table> WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL)")
|
||||
int listCount(@Define("table") String table, @Bind("fqnPrefix") String fqnPrefix);
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT json FROM (" +
|
||||
"SELECT fullyQualifiedName, json FROM <table> WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL) AND " +// Filter by service name
|
||||
"fullyQualifiedName < :before " + // Pagination by database fullyQualifiedName
|
||||
"ORDER BY fullyQualifiedName DESC " + // Pagination ordering by database fullyQualifiedName
|
||||
"LIMIT :limit" +
|
||||
") last_rows_subquery ORDER BY fullyQualifiedName")
|
||||
List<String> listBefore(@Define("table") String table, @Bind("fqnPrefix") String parentFQN, @Bind("limit") int limit,
|
||||
@Bind("before") String before);
|
||||
|
||||
@SqlQuery("SELECT json FROM <table> WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL) AND " +
|
||||
"fullyQualifiedName > :after " +
|
||||
"ORDER BY fullyQualifiedName " +
|
||||
"LIMIT :limit")
|
||||
List<String> listAfter(@Define("table") String table, @Bind("fqnPrefix") String parentFQN, @Bind("limit") int limit,
|
||||
@Bind("after") String after);
|
||||
|
||||
@SqlQuery("SELECT EXISTS (SELECT * FROM <table> WHERE id = :id)")
|
||||
boolean exists(@Define("table") String table, @Bind("id") String id);
|
||||
|
||||
@SqlUpdate("DELETE FROM <table> WHERE id = :id")
|
||||
int delete(@Define("table") String table, @Bind("id") String id);
|
||||
default String getNameColumn() { return "fullyQualifiedName"; }
|
||||
}
|
||||
|
@ -4,48 +4,21 @@ package org.openmetadata.catalog.jdbi3;
|
||||
import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||
import org.jdbi.v3.sqlobject.customizer.Define;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.openmetadata.catalog.entity.data.Table;
|
||||
import org.openmetadata.catalog.entity.services.DatabaseService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DatabaseServiceDAO3 extends EntityDAO<DatabaseService> {
|
||||
@Override
|
||||
default String getTableName() { return "dbService_entity"; }
|
||||
default String getTableName() { return "dbService_Entity"; }
|
||||
|
||||
@Override
|
||||
default Class<DatabaseService> getEntityClass() { return DatabaseService.class; }
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT json FROM <table> WHERE name = :name")
|
||||
String findByName(@Define("table") String table, @Bind("name") String name);
|
||||
default String getNameColumn() { return "name"; }
|
||||
|
||||
// TODO clean this up
|
||||
@SqlQuery("SELECT json FROM dbService_Entity WHERE (name = :name OR :name is NULL)")
|
||||
List<String> list(@Define("table") String table, @Bind("name") String name);
|
||||
|
||||
@Override
|
||||
default List<String> listAfter(String table, String parentFQN, int limit, String after) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default List<String> listBefore(String table, String parentFQN, int limit, String before) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default int listCount(String table, String databaseFQN) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean exists(String table, String id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SqlUpdate("DELETE FROM <table> WHERE id = :id")
|
||||
int delete(@Define("table") String table, @Bind("id") String id);
|
||||
}
|
||||
|
@ -30,10 +30,16 @@ import java.util.List;
|
||||
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound;
|
||||
|
||||
public interface EntityDAO<T> {
|
||||
// TODO javadoc
|
||||
/**
|
||||
* Methods that need to be overridden by interfaces extending this
|
||||
*/
|
||||
String getTableName();
|
||||
Class<T> getEntityClass();
|
||||
String getNameColumn();
|
||||
|
||||
/**
|
||||
* Common queries for all entities implemented here. Do not override.
|
||||
*/
|
||||
@SqlUpdate("INSERT INTO <table> (json) VALUES (:json)")
|
||||
void insert(@Define("table") String table, @Bind("json") String json);
|
||||
|
||||
@ -43,13 +49,50 @@ public interface EntityDAO<T> {
|
||||
@SqlQuery("SELECT json FROM <table> WHERE id = :id")
|
||||
String findById(@Define("table") String table, @Bind("id") String id);
|
||||
|
||||
String findByName(String table, String name);
|
||||
int listCount(String table, String databaseFQN); // TODO check this
|
||||
List<String> listBefore(String table, String parentFQN, int limit, String before);
|
||||
List<String> listAfter(String table, String parentFQN, int limit, String after);
|
||||
boolean exists(String table, String id);
|
||||
int delete(String table, String id);
|
||||
@SqlQuery("SELECT json FROM <table> WHERE <nameColumn> = :name")
|
||||
String findByName(@Define("table") String table, @Define("nameColumn") String nameColumn,
|
||||
@Bind("name") String name);
|
||||
|
||||
@SqlQuery("SELECT count(*) FROM <table> WHERE " +
|
||||
"(<nameColumn> LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL)")
|
||||
int listCount(@Define("table") String table, @Define("nameColumn") String nameColumn,
|
||||
@Bind("fqnPrefix") String fqnPrefix);
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT json FROM (" +
|
||||
"SELECT <nameColumn>, json FROM <table> WHERE " +
|
||||
"(<nameColumn> LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL) AND " +// Filter by
|
||||
// service name
|
||||
"<nameColumn> < :before " + // Pagination by chart fullyQualifiedName
|
||||
"ORDER BY <nameColumn> DESC " + // Pagination ordering by chart fullyQualifiedName
|
||||
"LIMIT :limit" +
|
||||
") last_rows_subquery ORDER BY <nameColumn>")
|
||||
List<String> listBefore(@Define("table") String table,
|
||||
@Define("nameColumn") String nameColumn,
|
||||
@Bind("fqnPrefix") String fqnPrefix,
|
||||
@Bind("limit") int limit,
|
||||
@Bind("before") String before);
|
||||
|
||||
@SqlQuery("SELECT json FROM <table> WHERE " +
|
||||
"(<nameColumn> LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL) AND " +
|
||||
"<nameColumn> > :after " +
|
||||
"ORDER BY <nameColumn> " +
|
||||
"LIMIT :limit")
|
||||
List<String> listAfter(@Define("table") String table,
|
||||
@Define("nameColumn") String nameColumn,
|
||||
@Bind("fqnPrefix") String fqnPrefix,
|
||||
@Bind("limit") int limit,
|
||||
@Bind("after") String after);
|
||||
|
||||
@SqlQuery("SELECT EXISTS (SELECT * FROM <table> WHERE id = :id)")
|
||||
boolean exists(@Define("table") String table, @Bind("id") String id);
|
||||
|
||||
@SqlUpdate("DELETE FROM <table> WHERE id = :id")
|
||||
int delete(@Define("table") String table, @Bind("id") String id);
|
||||
|
||||
/**
|
||||
* Default methods that interfaces with implementation. Don't override
|
||||
*/
|
||||
default void insert(String json) {
|
||||
insert(getTableName(), json);
|
||||
}
|
||||
@ -73,7 +116,7 @@ public interface EntityDAO<T> {
|
||||
|
||||
default T findEntityByName(String fqn) throws IOException {
|
||||
Class<T> clz = getEntityClass();
|
||||
String json = findByName(getTableName(), fqn);
|
||||
String json = findByName(getTableName(), getNameColumn(), fqn);
|
||||
T entity = null;
|
||||
if (json != null) {
|
||||
entity = JsonUtils.readValue(json, clz);
|
||||
@ -89,19 +132,19 @@ public interface EntityDAO<T> {
|
||||
}
|
||||
|
||||
default String findJsonByFqn(String fqn) throws IOException {
|
||||
return findByName(getTableName(), fqn);
|
||||
return findByName(getTableName(), getNameColumn(), fqn);
|
||||
}
|
||||
|
||||
default int listCount(String databaseFQN) {
|
||||
return listCount(getTableName(), databaseFQN);
|
||||
return listCount(getTableName(), getNameColumn(), databaseFQN);
|
||||
}
|
||||
|
||||
default List<String> listBefore(String parentFQN, int limit, String before) {
|
||||
return listBefore(getTableName(), parentFQN, limit, before);
|
||||
return listBefore(getTableName(), getNameColumn(), parentFQN, limit, before);
|
||||
}
|
||||
|
||||
default List<String> listAfter(String databaseFQN, int limit, String after) {
|
||||
return listAfter(getTableName(), databaseFQN, limit, after);
|
||||
return listAfter(getTableName(), getNameColumn(), databaseFQN, limit, after);
|
||||
}
|
||||
|
||||
default boolean exists(String id) {
|
||||
|
@ -1,27 +1,22 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||
import org.jdbi.v3.sqlobject.customizer.Define;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.openmetadata.catalog.entity.services.MessagingService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MessagingServiceDAO3 {
|
||||
@SqlUpdate("INSERT INTO messaging_service_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
public interface MessagingServiceDAO3 extends EntityDAO<MessagingService> {
|
||||
@Override
|
||||
default String getTableName() { return "messaging_service_entity"; }
|
||||
|
||||
@SqlUpdate("UPDATE messaging_service_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
@Override
|
||||
default Class<MessagingService> getEntityClass() { return MessagingService.class; }
|
||||
|
||||
@SqlQuery("SELECT json FROM messaging_service_entity WHERE id = :id")
|
||||
String findById(@Bind("id") String id);
|
||||
|
||||
@SqlQuery("SELECT json FROM messaging_service_entity WHERE name = :name")
|
||||
String findByName(@Bind("name") String name);
|
||||
@Override
|
||||
default String getNameColumn() { return "name"; }
|
||||
|
||||
@SqlQuery("SELECT json FROM messaging_service_entity WHERE (name = :name OR :name is NULL)")
|
||||
List<String> list(@Bind("name") String name);
|
||||
|
||||
@SqlUpdate("DELETE FROM messaging_service_entity WHERE id = :id")
|
||||
int delete(@Bind("id") String id);
|
||||
List<String> list(@Define("table") String table, @Bind("name") String name);
|
||||
}
|
||||
|
@ -1,45 +1,21 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
|
||||
import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||
import org.jdbi.v3.sqlobject.customizer.Define;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.openmetadata.catalog.entity.data.Model;
|
||||
|
||||
import java.util.List;
|
||||
public interface ModelDAO3 extends EntityDAO<Model>{
|
||||
@Override
|
||||
default String getTableName() { return "model_entity"; }
|
||||
|
||||
public interface ModelDAO3 {
|
||||
@SqlUpdate("INSERT INTO model_entity(json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
@Override
|
||||
default Class<Model> getEntityClass() { return Model.class; }
|
||||
|
||||
@SqlUpdate("UPDATE model_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
@Override
|
||||
default String getNameColumn() { return "fullyQualifiedName"; }
|
||||
|
||||
@SqlQuery("SELECT json FROM model_entity WHERE id = :id")
|
||||
String findById(@Bind("id") String id);
|
||||
|
||||
@SqlQuery("SELECT json FROM model_entity WHERE fullyQualifiedName = :name")
|
||||
String findByFQN(@Bind("name") String name);
|
||||
|
||||
@SqlQuery("SELECT count(*) FROM model_entity")
|
||||
int listCount();
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT json FROM (" +
|
||||
"SELECT fullyQualifiedName, json FROM model_entity WHERE " +
|
||||
"fullyQualifiedName < :before " + // Pagination by model fullyQualifiedName
|
||||
"ORDER BY fullyQualifiedName DESC " +
|
||||
"LIMIT :limit" +
|
||||
") last_rows_subquery ORDER BY fullyQualifiedName")
|
||||
List<String> listBefore(@Bind("limit") int limit,
|
||||
@Bind("before") String before);
|
||||
|
||||
@SqlQuery("SELECT json FROM model_entity WHERE " +
|
||||
"fullyQualifiedName > :after " +
|
||||
"ORDER BY fullyQualifiedName " +
|
||||
"LIMIT :limit")
|
||||
List<String> listAfter(@Bind("limit") int limit,
|
||||
@Bind("after") String after);
|
||||
|
||||
@SqlUpdate("DELETE FROM model_entity WHERE id = :id")
|
||||
int delete(@Bind("id") String id);
|
||||
@Override
|
||||
@SqlQuery("SELECT count(*) FROM <table>")
|
||||
int listCount(@Define("table") String table);
|
||||
}
|
||||
|
@ -1,48 +1,14 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.openmetadata.catalog.entity.data.Pipeline;
|
||||
|
||||
import java.util.List;
|
||||
public interface PipelineDAO3 extends EntityDAO<Pipeline> {
|
||||
@Override
|
||||
default String getTableName() { return "pipeline_entity"; }
|
||||
|
||||
public interface PipelineDAO3 {
|
||||
@SqlUpdate("INSERT INTO pipeline_entity(json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
@Override
|
||||
default Class<Pipeline> getEntityClass() { return Pipeline.class; }
|
||||
|
||||
@SqlUpdate("UPDATE pipeline_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
|
||||
@SqlQuery("SELECT json FROM pipeline_entity WHERE id = :id")
|
||||
String findById(@Bind("id") String id);
|
||||
|
||||
@SqlQuery("SELECT json FROM pipeline_entity WHERE fullyQualifiedName = :name")
|
||||
String findByFQN(@Bind("name") String name);
|
||||
|
||||
@SqlQuery("SELECT count(*) FROM pipeline_entity WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL)")
|
||||
int listCount(@Bind("fqnPrefix") String fqnPrefix);
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT json FROM (" +
|
||||
"SELECT fullyQualifiedName, json FROM pipeline_entity WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL) AND " +// Filter by
|
||||
// service name
|
||||
"fullyQualifiedName < :before " + // Pagination by pipeline fullyQualifiedName
|
||||
"ORDER BY fullyQualifiedName DESC " + // Pagination ordering by fullyQualifiedName
|
||||
"LIMIT :limit" +
|
||||
") last_rows_subquery ORDER BY fullyQualifiedName")
|
||||
List<String> listBefore(@Bind("fqnPrefix") String fqnPrefix, @Bind("limit") int limit,
|
||||
@Bind("before") String before);
|
||||
|
||||
@SqlQuery("SELECT json FROM pipeline_entity WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL) AND " +
|
||||
"fullyQualifiedName > :after " +
|
||||
"ORDER BY fullyQualifiedName " +
|
||||
"LIMIT :limit")
|
||||
List<String> listAfter(@Bind("fqnPrefix") String fqnPrefix, @Bind("limit") int limit,
|
||||
@Bind("after") String after);
|
||||
|
||||
@SqlUpdate("DELETE FROM pipeline_entity WHERE id = :id")
|
||||
int delete(@Bind("id") String id);
|
||||
@Override
|
||||
default String getNameColumn() { return "fullyQualifiedName"; }
|
||||
}
|
||||
|
@ -2,26 +2,20 @@ package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.openmetadata.catalog.entity.services.PipelineService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PipelineServiceDAO3 {
|
||||
@SqlUpdate("INSERT INTO pipeline_service_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
public interface PipelineServiceDAO3 extends EntityDAO<PipelineService> {
|
||||
@Override
|
||||
default String getTableName() { return "pipeline_service_entity"; }
|
||||
|
||||
@SqlUpdate("UPDATE pipeline_service_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
@Override
|
||||
default Class<PipelineService> getEntityClass() { return PipelineService.class; }
|
||||
|
||||
@SqlQuery("SELECT json FROM pipeline_service_entity WHERE id = :id")
|
||||
String findById(@Bind("id") String id);
|
||||
|
||||
@SqlQuery("SELECT json FROM pipeline_service_entity WHERE name = :name")
|
||||
String findByName(@Bind("name") String name);
|
||||
@Override
|
||||
default String getNameColumn() { return "name"; }
|
||||
|
||||
@SqlQuery("SELECT json FROM pipeline_service_entity WHERE (name = :name OR :name is NULL)")
|
||||
List<String> list(@Bind("name") String name);
|
||||
|
||||
@SqlUpdate("DELETE FROM pipeline_service_entity WHERE id = :id")
|
||||
int delete(@Bind("id") String id);
|
||||
}
|
||||
|
@ -1,27 +1,20 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.openmetadata.catalog.entity.data.Report;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ReportDAO3 {
|
||||
@SqlUpdate("INSERT INTO report_entity(json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
public interface ReportDAO3 extends EntityDAO<Report> {
|
||||
@Override
|
||||
default String getTableName() { return "report_entity"; }
|
||||
|
||||
@SqlUpdate("UPDATE report_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
@Override
|
||||
default Class<Report> getEntityClass() { return Report.class; }
|
||||
|
||||
@SqlQuery("SELECT json FROM report_entity WHERE id = :id")
|
||||
String findById(@Bind("name") String id);
|
||||
|
||||
@SqlQuery("SELECT json FROM report_entity WHERE fullyQualifiedName = :name")
|
||||
String findByFQN(@Bind("name") String name);
|
||||
@Override
|
||||
default String getNameColumn() { return "fullyQualifiedName"; }
|
||||
|
||||
@SqlQuery("SELECT json FROM report_entity")
|
||||
List<String> list();
|
||||
|
||||
@SqlQuery("SELECT EXISTS (SELECT * FROM report_entity where id = :id)")
|
||||
boolean exists(@Bind("id") String id);
|
||||
}
|
||||
|
@ -1,14 +1,8 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
|
||||
import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||
import org.jdbi.v3.sqlobject.customizer.Define;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.openmetadata.catalog.entity.data.Table;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TableDAO3 extends EntityDAO<Table> {
|
||||
@Override
|
||||
default String getTableName() {
|
||||
@ -19,40 +13,5 @@ public interface TableDAO3 extends EntityDAO<Table> {
|
||||
default Class<Table> getEntityClass() { return Table.class; }
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT json FROM <table> WHERE fullyQualifiedName = :tableFQN")
|
||||
String findByName(@Define("table") String table, @Bind("tableFQN") String tableFQN);
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT count(*) FROM <table> WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:databaseFQN, '.%') OR :databaseFQN IS NULL)")
|
||||
int listCount(@Define("table") String table, @Bind("databaseFQN") String databaseFQN);
|
||||
|
||||
@Override
|
||||
@SqlQuery(
|
||||
"SELECT json FROM (" +
|
||||
"SELECT fullyQualifiedName, json FROM <table> WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:databaseFQN, '.%') OR :databaseFQN IS NULL) AND " +
|
||||
"fullyQualifiedName < :before " + // Pagination by table fullyQualifiedName
|
||||
"ORDER BY fullyQualifiedName DESC " + // Pagination ordering by table fullyQualifiedName
|
||||
"LIMIT :limit" +
|
||||
") last_rows_subquery ORDER BY fullyQualifiedName")
|
||||
List<String> listBefore(@Define("table") String table, @Bind("databaseFQN") String parentFQN, @Bind("limit") int limit,
|
||||
@Bind("before") String before);
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT json FROM <table> WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:databaseFQN, '.%') OR :databaseFQN IS NULL) AND "+//Filter by databaseName
|
||||
"fullyQualifiedName > :after " + // Pagination by table fullyQualifiedName
|
||||
"ORDER BY fullyQualifiedName " + // Pagination ordering by table fullyQualifiedName
|
||||
"LIMIT :limit")
|
||||
List<String> listAfter(@Define("table") String table, @Bind("databaseFQN") String parentFQN, @Bind("limit") int limit,
|
||||
@Bind("after") String after);
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT EXISTS (SELECT * FROM <table> WHERE id = :id)")
|
||||
boolean exists(@Define("table") String table, @Bind("id") String id);
|
||||
|
||||
@Override
|
||||
@SqlUpdate("DELETE FROM <table> WHERE id = :id")
|
||||
int delete(@Define("table") String table, @Bind("id") String id);
|
||||
default String getNameColumn() { return "fullyQualifiedName"; }
|
||||
}
|
||||
|
@ -1,43 +1,21 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
|
||||
import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||
import org.jdbi.v3.sqlobject.customizer.Define;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.openmetadata.catalog.entity.teams.Team;
|
||||
|
||||
import java.util.List;
|
||||
public interface TeamDAO3 extends EntityDAO<Team> {
|
||||
@Override
|
||||
default String getTableName() { return "team_entity"; }
|
||||
|
||||
public interface TeamDAO3 {
|
||||
@SqlUpdate("INSERT INTO team_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
@Override
|
||||
default Class<Team> getEntityClass() { return Team.class; }
|
||||
|
||||
@SqlQuery("SELECT json FROM team_entity where id = :teamId")
|
||||
String findById(@Bind("teamId") String teamId);
|
||||
@Override
|
||||
default String getNameColumn() { return "name"; }
|
||||
|
||||
@SqlQuery("SELECT json FROM team_entity where name = :name")
|
||||
String findByName(@Bind("name") String name);
|
||||
|
||||
@SqlQuery("SELECT count(*) FROM team_entity")
|
||||
int listCount();
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT json FROM (" +
|
||||
"SELECT name, json FROM team_entity WHERE " +
|
||||
"name < :before " + // Pagination by team name
|
||||
"ORDER BY name DESC " + // Pagination ordering by team name
|
||||
"LIMIT :limit" +
|
||||
") last_rows_subquery ORDER BY name")
|
||||
List<String> listBefore(@Bind("limit") int limit, @Bind("before") String before);
|
||||
|
||||
@SqlQuery("SELECT json FROM team_entity WHERE " +
|
||||
"name > :after " + // Pagination by team name
|
||||
"ORDER BY name " + // Pagination ordering by team name
|
||||
"LIMIT :limit")
|
||||
List<String> listAfter(@Bind("limit") int limit, @Bind("after") String after);
|
||||
|
||||
@SqlUpdate("DELETE FROM team_entity WHERE id = :teamId")
|
||||
int delete(@Bind("teamId") String teamId);
|
||||
|
||||
@SqlUpdate("UPDATE team_entity SET json = :json WHERE id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
@Override
|
||||
@SqlQuery("SELECT count(*) FROM <table>")
|
||||
int listCount(@Define("table") String table);
|
||||
}
|
||||
|
@ -1,15 +1,8 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
|
||||
import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||
import org.jdbi.v3.sqlobject.customizer.Define;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.openmetadata.catalog.entity.data.Table;
|
||||
import org.openmetadata.catalog.entity.data.Topic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TopicDAO3 extends EntityDAO<Topic> {
|
||||
@Override
|
||||
default String getTableName() { return "topic_entity"; }
|
||||
@ -18,42 +11,5 @@ public interface TopicDAO3 extends EntityDAO<Topic> {
|
||||
default Class<Topic> getEntityClass() { return Topic.class; }
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT json FROM <table> WHERE fullyQualifiedName = :name")
|
||||
String findByName(@Define("table") String table, @Bind("name") String name);
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT count(*) FROM <table> WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL)")
|
||||
// Filter by service name
|
||||
int listCount(@Define("table") String table, @Bind("fqnPrefix") String fqnPrefix);
|
||||
|
||||
@Override
|
||||
@SqlQuery(
|
||||
"SELECT json FROM (" +
|
||||
"SELECT fullyQualifiedName, json FROM <table> WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL) AND " +// Filter by
|
||||
// service name
|
||||
"fullyQualifiedName < :before " + // Pagination by topic fullyQualifiedName
|
||||
"ORDER BY fullyQualifiedName DESC " + // Pagination ordering by topic fullyQualifiedName
|
||||
"LIMIT :limit" +
|
||||
") last_rows_subquery ORDER BY fullyQualifiedName")
|
||||
List<String> listBefore(@Define("table") String table, @Bind("fqnPrefix") String fqnPrefix, @Bind("limit") int limit,
|
||||
@Bind("before") String before);
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT json FROM <table> WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL) AND " +
|
||||
"fullyQualifiedName > :after " +
|
||||
"ORDER BY fullyQualifiedName " +
|
||||
"LIMIT :limit")
|
||||
List<String> listAfter(@Define("table") String table, @Bind("fqnPrefix") String fqnPrefix, @Bind("limit") int limit,
|
||||
@Bind("after") String after);
|
||||
|
||||
@Override
|
||||
@SqlQuery("SELECT EXISTS (SELECT * FROM <table> WHERE id = :id)")
|
||||
boolean exists(@Define("table") String table, @Bind("id") String id);
|
||||
|
||||
@Override
|
||||
@SqlUpdate("DELETE FROM <table> WHERE id = :id")
|
||||
int delete(@Define("table") String table, @Bind("id") String id);
|
||||
default String getNameColumn() { return "fullyQualifiedName"; }
|
||||
}
|
||||
|
@ -256,8 +256,7 @@ public class TopicRepositoryHelper implements EntityRepository<Topic> {
|
||||
private EntityReference getService(EntityReference service) throws IOException {
|
||||
String id = service.getId().toString();
|
||||
if (service.getType().equalsIgnoreCase(Entity.MESSAGING_SERVICE)) {
|
||||
MessagingService serviceInstance = EntityUtil.validate(id, repo3.messageServiceDAO().findById(id),
|
||||
MessagingService.class);
|
||||
MessagingService serviceInstance = repo3.messageServiceDAO().findEntityById(id);
|
||||
service.setDescription(serviceInstance.getDescription());
|
||||
service.setName(serviceInstance.getName());
|
||||
} else {
|
||||
|
@ -1,48 +1,29 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||
import org.jdbi.v3.sqlobject.customizer.Define;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.openmetadata.catalog.entity.teams.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserDAO3 {
|
||||
@SqlUpdate("INSERT INTO user_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
public interface UserDAO3 extends EntityDAO<User> {
|
||||
@Override
|
||||
default String getTableName() { return "user_entity"; }
|
||||
|
||||
@SqlQuery("SELECT json FROM user_entity WHERE id = :id")
|
||||
String findById(@Bind("id") String id);
|
||||
@Override
|
||||
default Class<User> getEntityClass() { return User.class; }
|
||||
|
||||
@SqlQuery("SELECT json FROM user_entity WHERE name = :name")
|
||||
String findByName(@Bind("name") String name);
|
||||
|
||||
@SqlQuery("SELECT json FROM user_entity WHERE email = :email")
|
||||
String findByEmail(@Bind("email") String email);
|
||||
@Override
|
||||
default String getNameColumn() { return "name"; }
|
||||
|
||||
@SqlQuery("SELECT json FROM user_entity")
|
||||
List<String> list();
|
||||
|
||||
@SqlQuery("SELECT count(*) FROM user_entity")
|
||||
int listCount();
|
||||
@SqlQuery("SELECT json FROM user_entity WHERE email = :email")
|
||||
String findByEmail(@Bind("email") String email);
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT json FROM (" +
|
||||
"SELECT name, json FROM user_entity WHERE " +
|
||||
"name < :before " + // Pagination by user name
|
||||
"ORDER BY name DESC " + // Pagination ordering by user name
|
||||
"LIMIT :limit" +
|
||||
") last_rows_subquery ORDER BY name")
|
||||
List<String> listBefore(@Bind("limit") int limit, @Bind("before") String before);
|
||||
|
||||
@SqlQuery("SELECT json FROM user_entity WHERE " +
|
||||
"name > :after " + // Pagination by user name
|
||||
"ORDER BY name " + // Pagination ordering by user name
|
||||
"LIMIT :limit")
|
||||
List<String> listAfter(@Bind("limit") int limit, @Bind("after") String after);
|
||||
|
||||
@SqlUpdate("UPDATE user_entity SET json = :json WHERE id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
|
||||
@SqlQuery("SELECT EXISTS (SELECT * FROM user_entity where id = :id)")
|
||||
boolean exists(@Bind("id") String id);
|
||||
@Override
|
||||
@SqlQuery("SELECT count(*) FROM <table>")
|
||||
int listCount(@Define("table") String table);
|
||||
}
|
||||
|
@ -268,13 +268,13 @@ public final class EntityUtil {
|
||||
}
|
||||
String id = owner.getId().toString();
|
||||
if (owner.getType().equalsIgnoreCase("user")) {
|
||||
User ownerInstance = EntityUtil.validate(id, userDAO3.findById(id), User.class);
|
||||
User ownerInstance = userDAO3.findEntityById(id);
|
||||
owner.setName(ownerInstance.getName());
|
||||
if (Optional.ofNullable(ownerInstance.getDeactivated()).orElse(false)) {
|
||||
throw new IllegalArgumentException(CatalogExceptionMessage.deactivatedUser(id));
|
||||
}
|
||||
} else if (owner.getType().equalsIgnoreCase("team")) {
|
||||
Team ownerInstance = EntityUtil.validate(id, teamDAO.findById(id), Team.class);
|
||||
Team ownerInstance = teamDAO.findEntityById(id);
|
||||
owner.setDescription(ownerInstance.getDescription());
|
||||
owner.setName(ownerInstance.getName());
|
||||
} else {
|
||||
@ -933,7 +933,7 @@ public final class EntityUtil {
|
||||
String followedEntityId,
|
||||
String followedEntityType, String followerId, String followerEntity)
|
||||
throws IOException {
|
||||
User user = EntityUtil.validate(followerId, userDAO3.findById(followerId), User.class);
|
||||
User user = userDAO3.findEntityById(followerId);
|
||||
if (Optional.ofNullable(user.getDeactivated()).orElse(false)) {
|
||||
throw new IllegalArgumentException(CatalogExceptionMessage.deactivatedUser(followerId));
|
||||
}
|
||||
@ -969,7 +969,7 @@ public final class EntityUtil {
|
||||
Entity.USER);
|
||||
List<EntityReference> followers = new ArrayList<>();
|
||||
for (String followerId : followerIds) {
|
||||
User user = EntityUtil.validate(followerId, userDAO3.findById(followerId), User.class);
|
||||
User user = userDAO3.findEntityById(followerId);
|
||||
followers.add(new EntityReference().withName(user.getName()).withId(user.getId()).withType("user"));
|
||||
}
|
||||
return followers;
|
||||
|
Loading…
x
Reference in New Issue
Block a user