Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2021 Collate
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openmetadata.service.jdbi3;
import static org.openmetadata.service.exception.CatalogExceptionMessage.entityNotFound;
import static org.openmetadata.service.jdbi3.ListFilter.escape;
import static org.openmetadata.service.jdbi3.ListFilter.escapeApostrophe;
import static org.openmetadata.service.jdbi3.locator.ConnectionType.MYSQL;
import static org.openmetadata.service.jdbi3.locator.ConnectionType.POSTGRES;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import lombok.SneakyThrows;
import org.jdbi.v3.sqlobject.customizer.Bind;
import org.jdbi.v3.sqlobject.customizer.BindMap;
import org.jdbi.v3.sqlobject.customizer.Define;
import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
import org.openmetadata.schema.EntityInterface;
import org.openmetadata.schema.type.Include;
import org.openmetadata.service.Entity;
import org.openmetadata.service.exception.CatalogExceptionMessage;
import org.openmetadata.service.exception.EntityNotFoundException;
import org.openmetadata.service.jdbi3.locator.ConnectionAwareSqlQuery;
import org.openmetadata.service.jdbi3.locator.ConnectionAwareSqlUpdate;
import org.openmetadata.service.util.FullyQualifiedName;
import org.openmetadata.service.util.JsonUtils;
import org.openmetadata.service.util.jdbi.BindFQN;
import org.openmetadata.service.util.jdbi.BindUUID;
import org.openmetadata.service.workflows.searchIndex.ReindexingUtil;
public interface EntityDAO {
org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(EntityDAO.class);
/** Methods that need to be overridden by interfaces extending this */
String getTableName();
Class getEntityClass();
default String getNameHashColumn() {
return "nameHash";
}
default boolean supportsSoftDelete() {
return true;
}
/** Common queries for all entities implemented here. Do not override. */
@ConnectionAwareSqlUpdate(
value = "INSERT INTO
(, json) VALUES (:nameHashColumnValue, :json)",
connectionType = MYSQL)
@ConnectionAwareSqlUpdate(
value =
"INSERT INTO
")
int listCount(
@Define("table") String table,
@Define("nameHashColumn") String nameHashColumn,
@BindMap Map params,
@Define("cond") String cond);
@ConnectionAwareSqlQuery(
value = "SELECT count() FROM
",
connectionType = MYSQL)
@ConnectionAwareSqlQuery(
value = "SELECT count(*) FROM
",
connectionType = POSTGRES)
int listCount(
@Define("table") String table,
@Define("nameHashColumn") String nameHashColumn,
@BindMap Map params,
@Define("mysqlCond") String mysqlCond,
@Define("postgresCond") String postgresCond);
@ConnectionAwareSqlQuery(
value =
"SELECT json FROM ("
+ "SELECT
.name,
.id,
.json FROM
AND "
+ "(
.name < :beforeName OR (
.name = :beforeName AND
.id < :beforeId)) "
+ // Pagination by entity name or id (when entity name same)
"ORDER BY
.name DESC,
.id DESC "
+ // Pagination by entity name or id (when entity name same)
"LIMIT :limit"
+ ") last_rows_subquery ORDER BY name,id",
connectionType = MYSQL)
@ConnectionAwareSqlQuery(
value =
"SELECT json FROM ("
+ "SELECT
.name,
.id,
.json FROM
AND "
+ "(
.name < :beforeName OR (
.name = :beforeName AND
.id < :beforeId)) "
+ // Pagination by entity id or name (when entity have same name)
"ORDER BY
.name DESC,
.id DESC "
+ // Pagination by entity id or name (when entity have same name)
"LIMIT :limit"
+ ") last_rows_subquery ORDER BY name,id",
connectionType = POSTGRES)
List listBefore(
@Define("table") String table,
@BindMap Map params,
@Define("mysqlCond") String mysqlCond,
@Define("postgresCond") String postgresCond,
@Bind("limit") int limit,
@Bind("beforeName") String beforeName,
@Bind("beforeId") String beforeId);
@ConnectionAwareSqlQuery(
value =
"SELECT
.id "
+ "LIMIT :limit",
connectionType = POSTGRES)
List listAfter(
@Define("table") String table,
@BindMap Map params,
@Define("mysqlCond") String mysqlCond,
@Define("postgresCond") String postgresCond,
@Bind("limit") int limit,
@Bind("afterName") String afterName,
@Bind("afterId") String afterId);
@ConnectionAwareSqlQuery(
value = "SELECT count() FROM
",
connectionType = MYSQL)
@ConnectionAwareSqlQuery(value = "SELECT count(*) FROM
", connectionType = POSTGRES)
int listTotalCount(
@Define("table") String table, @Define("nameHashColumn") String nameHashColumn);
@ConnectionAwareSqlQuery(
value = "SELECT count(distinct()) FROM
",
connectionType = MYSQL)
@ConnectionAwareSqlQuery(
value = "SELECT count(distinct()) FROM
",
connectionType = POSTGRES)
int listCountDistinct(
@Define("table") String table,
@Define("mysqlCond") String mysqlCond,
@Define("postgresCond") String postgresCond,
@Define("distinctColumn") String distinctColumn);
@ConnectionAwareSqlQuery(
value =
"SELECT json FROM ("
+ "SELECT
.name,
.id,
.json FROM
AND "
+ "(
.name < :beforeName OR (
.name = :beforeName AND
.id < :beforeId)) "
+ " "
+ // Pagination by entity id or name (when entity have same name)
"ORDER BY
.name DESC,
.id DESC "
+ // Pagination by entity id or name (when entity have same name)
"LIMIT :limit"
+ ") last_rows_subquery ORDER BY name,id",
connectionType = MYSQL)
@ConnectionAwareSqlQuery(
value =
"SELECT json FROM ("
+ "SELECT
.name,
.id,
.json FROM
AND "
+ "(
.name < :beforeName OR (
.name = :beforeName AND
.id < :beforeId)) "
+ " "
+ // Pagination by entity fullyQualifiedName or name (when entity does not have fqn)
"ORDER BY
.name DESC,
.id DESC "
+ // Pagination ordering by entity fullyQualifiedName or name (when entity does not
// have fqn)
"LIMIT :limit"
+ ") last_rows_subquery ORDER BY name,id",
connectionType = POSTGRES)
List listBefore(
@Define("table") String table,
@Define("mysqlCond") String mysqlCond,
@Define("postgresCond") String postgresCond,
@Bind("limit") int limit,
@Bind("beforeName") String beforeName,
@Bind("beforeId") String beforeId,
@Define("groupBy") String groupBy);
@ConnectionAwareSqlQuery(
value =
"SELECT
AND "
+ "(name < :beforeName OR (name = :beforeName AND id < :beforeId)) "
+ // Pagination by entity id or name (when entity have same name)
"ORDER BY name DESC, id DESC "
+ // Pagination by entity id or name (when entity have same name)
"LIMIT :limit"
+ ") last_rows_subquery ORDER BY name,id")
List listBefore(
@Define("table") String table,
@BindMap Map params,
@Define("cond") String cond,
@Bind("limit") int limit,
@Bind("beforeName") String beforeName,
@Bind("beforeId") String beforeId);
@SqlQuery(
"SELECT json FROM
AND (
.name > :afterName OR (
.name = :afterName AND
.id > :afterId)) ORDER BY name,id LIMIT :limit")
List listAfter(
@Define("table") String table,
@BindMap Map params,
@Define("cond") String cond,
@Bind("limit") int limit,
@Bind("afterName") String afterName,
@Bind("afterId") String after);
@SqlQuery("SELECT json FROM
LIMIT :limit OFFSET :offset")
List listAfterWithOffset(
@Define("table") String table, @Bind("limit") int limit, @Bind("offset") int offset);
@SqlQuery(
"SELECT json FROM
WHERE = '' or is null LIMIT :limit")
List migrationListAfterWithOffset(
@Define("table") String table,
@Define("nameHashColumn") String nameHashColumnName,
@Bind("limit") int limit);
@SqlQuery("SELECT json FROM
ORDER BY name LIMIT :limit OFFSET :offset")
List listAfter(
@Define("table") String table,
@BindMap Map params,
@Define("cond") String cond,
@Bind("limit") int limit,
@Bind("offset") int offset);
@SqlQuery("SELECT EXISTS (SELECT * FROM
WHERE id = :id)")
boolean exists(@Define("table") String table, @BindUUID("id") UUID id);
@SqlQuery("SELECT EXISTS (SELECT * FROM
WHERE = :fqnHash)")
boolean existsByName(
@Define("table") String table,
@Define("nameColumnHash") String nameColumnHash,
@BindFQN("fqnHash") String fqnHash);
@SqlUpdate("DELETE FROM
WHERE id = :id")
int delete(@Define("table") String table, @BindUUID("id") UUID id);
@ConnectionAwareSqlUpdate(value = "ANALYZE TABLE