mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-11 02:26:49 +00:00
Remove jdbi2 DAO objects
This commit is contained in:
parent
339e247059
commit
869bb2599b
@ -1,48 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DashboardDAO {
|
||||
@SqlUpdate("INSERT INTO dashboard_entity(json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlUpdate("UPDATE dashboard_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
|
||||
@SqlQuery("SELECT json FROM dashboard_entity WHERE id = :id")
|
||||
String findById(@Bind("id") String id);
|
||||
|
||||
@SqlQuery("SELECT json FROM dashboard_entity WHERE fullyQualifiedName = :name")
|
||||
String findByFQN(@Bind("name") String name);
|
||||
|
||||
@SqlQuery("SELECT count(*) FROM dashboard_entity WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL)")
|
||||
int listCount(@Bind("fqnPrefix") String fqnPrefix);
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT json FROM (" +
|
||||
"SELECT fullyQualifiedName, json FROM dashboard_entity WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL) AND " +// Filter by
|
||||
// service name
|
||||
"fullyQualifiedName < :before " + // Pagination by dashboard fullyQualifiedName
|
||||
"ORDER BY fullyQualifiedName DESC " + // Pagination ordering by chart 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 dashboard_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 dashboard_entity WHERE id = :id")
|
||||
int delete(@Bind("id") String id);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DashboardServiceDAO {
|
||||
@SqlUpdate("INSERT INTO dashboard_service_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlUpdate("UPDATE dashboard_service_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
|
||||
@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);
|
||||
|
||||
@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,50 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DatabaseDAO {
|
||||
@SqlUpdate("INSERT INTO database_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlUpdate("UPDATE database_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
|
||||
@SqlQuery("SELECT json FROM database_entity WHERE fullyQualifiedName = :name")
|
||||
String findByFQN(@Bind("name") String name);
|
||||
|
||||
@SqlQuery("SELECT json FROM database_entity WHERE id = :id")
|
||||
String findById(@Bind("id") String id);
|
||||
|
||||
@SqlQuery("SELECT count(*) FROM database_entity WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL)")
|
||||
int listCount(@Bind("fqnPrefix") String fqnPrefix);
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT json FROM (" +
|
||||
"SELECT fullyQualifiedName, json FROM database_entity 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(@Bind("fqnPrefix") String fqnPrefix, @Bind("limit") int limit,
|
||||
@Bind("before") String before);
|
||||
|
||||
@SqlQuery("SELECT json FROM database_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);
|
||||
|
||||
@SqlQuery("SELECT EXISTS (SELECT * FROM database_entity WHERE id = :id)")
|
||||
boolean exists(@Bind("id") String id);
|
||||
|
||||
@SqlUpdate("DELETE FROM database_entity WHERE id = :id")
|
||||
int delete(@Bind("id") String id);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DatabaseServiceDAO {
|
||||
@SqlUpdate("INSERT INTO dbservice_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlUpdate("UPDATE dbservice_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
|
||||
@SqlQuery("SELECT json FROM dbservice_entity WHERE id = :id")
|
||||
String findById(@Bind("id") String id);
|
||||
|
||||
@SqlQuery("SELECT json FROM dbservice_entity WHERE name = :name")
|
||||
String findByName(@Bind("name") String name);
|
||||
|
||||
@SqlQuery("SELECT json FROM dbservice_entity WHERE (name = :name OR :name is NULL)")
|
||||
List<String> list(@Bind("name") String name);
|
||||
|
||||
@SqlUpdate("DELETE FROM dbservice_entity WHERE id = :id")
|
||||
int delete(@Bind("id") String id);
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
public interface EntityExtensionDAO {
|
||||
@SqlUpdate("REPLACE INTO entity_extension(id, extension, jsonSchema, json) " +
|
||||
"VALUES (:id, :extension, :jsonSchema, :json)")
|
||||
void insert(@Bind("id") String id, @Bind("extension") String extension, @Bind("jsonSchema") String jsonSchema,
|
||||
@Bind("json") String json);
|
||||
|
||||
@SqlQuery("SELECT json FROM entity_extension WHERE id = :id AND extension = :extension")
|
||||
String getExtension(@Bind("id") String id, @Bind("extension") String extension);
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.catalog.jdbi3;
|
||||
|
||||
import org.openmetadata.catalog.type.EntityReference;
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EntityRelationshipDAO {
|
||||
@SqlUpdate("INSERT IGNORE INTO entity_relationship(fromId, toId, fromEntity, toEntity, relation) " +
|
||||
"VALUES (:fromId, :toId, :fromEntity, :toEntity, :relation)")
|
||||
int insert(@Bind("fromId") String fromId, @Bind("toId") String toId, @Bind("fromEntity") String fromEntity,
|
||||
@Bind("toEntity") String toEntity, @Bind("relation") int relation);
|
||||
|
||||
//
|
||||
// Find to operations
|
||||
//
|
||||
@SqlQuery("SELECT toId, toEntity FROM entity_relationship WHERE fromId = :fromId AND relation = :relation")
|
||||
@RegisterMapper(ToEntityReferenceMapper.class)
|
||||
List<EntityReference> findTo(@Bind("fromId") String fromId, @Bind("relation") int relation);
|
||||
|
||||
@SqlQuery("SELECT toId FROM entity_relationship WHERE " +
|
||||
"fromId = :fromId AND relation = :relation AND toEntity = :toEntity ORDER BY fromId")
|
||||
List<String> findTo(@Bind("fromId") String fromId, @Bind("relation") int relation,
|
||||
@Bind("toEntity") String toEntity);
|
||||
|
||||
@SqlQuery("SELECT count(*) FROM entity_relationship WHERE " +
|
||||
"fromId = :fromId AND relation = :relation AND toEntity = :toEntity ORDER BY fromId")
|
||||
int findToCount(@Bind("fromId") String fromId, @Bind("relation") int relation, @Bind("toEntity") String toEntity);
|
||||
|
||||
//
|
||||
// Find from operations
|
||||
//
|
||||
@SqlQuery("SELECT fromId FROM entity_relationship WHERE " +
|
||||
"toId = :toId AND relation = :relation AND fromEntity = :fromEntity ORDER BY fromId")
|
||||
List<String> findFrom(@Bind("toId") String toId, @Bind("relation") int relation,
|
||||
@Bind("fromEntity") String fromEntity);
|
||||
|
||||
@SqlQuery("SELECT fromId, fromEntity FROM entity_relationship WHERE toId = :toId AND relation = :relation " +
|
||||
"ORDER BY fromId")
|
||||
@RegisterMapper(FromEntityReferenceMapper.class)
|
||||
List<EntityReference> findFrom(@Bind("toId") String toId, @Bind("relation") int relation);
|
||||
|
||||
@SqlQuery("SELECT fromId, fromEntity FROM entity_relationship WHERE toId = :toId AND relation = :relation AND " +
|
||||
"fromEntity = :fromEntity ORDER BY fromId")
|
||||
@RegisterMapper(FromEntityReferenceMapper.class)
|
||||
List<EntityReference> findFromEntity(@Bind("toId") String toId, @Bind("relation") int relation,
|
||||
@Bind("fromEntity") String fromEntity);
|
||||
|
||||
//
|
||||
// Delete Operations
|
||||
//
|
||||
@SqlUpdate("DELETE from entity_relationship WHERE fromId = :fromId AND toId = :toId AND relation = :relation")
|
||||
void delete(@Bind("fromId") String fromId, @Bind("toId") String toId, @Bind("relation") int relation);
|
||||
|
||||
// Delete all the entity relationship fromID --- relation --> entity of type toEntity
|
||||
@SqlUpdate("DELETE from entity_relationship WHERE fromId = :fromId AND relation = :relation AND toEntity = :toEntity")
|
||||
void deleteFrom(@Bind("fromId") String fromId, @Bind("relation") int relation, @Bind("toEntity") String toEntity);
|
||||
|
||||
// Delete all the entity relationship fromID --- relation --> to any entity
|
||||
@SqlUpdate("DELETE from entity_relationship WHERE fromId = :fromId AND relation = :relation")
|
||||
void deleteFrom(@Bind("fromId") String fromId, @Bind("relation") int relation);
|
||||
|
||||
// Delete all the entity relationship toId <-- relation -- entity of type fromEntity
|
||||
@SqlUpdate("DELETE from entity_relationship WHERE toId = :toId AND relation = :relation AND fromEntity = :fromEntity")
|
||||
void deleteTo(@Bind("toId") String toId, @Bind("relation") int relation, @Bind("fromEntity") String fromEntity);
|
||||
|
||||
@SqlUpdate("DELETE from entity_relationship WHERE toId = :id OR fromId = :id")
|
||||
void deleteAll(@Bind("id") String id);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FeedDAO {
|
||||
@SqlUpdate("INSERT INTO thread_entity(json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlQuery("SELECT json FROM thread_entity WHERE id = :id")
|
||||
String findById(@Bind("id") String id);
|
||||
|
||||
@SqlQuery("SELECT json FROM thread_entity")
|
||||
List<String> list();
|
||||
|
||||
@SqlUpdate("UPDATE thread_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.StatementContext;
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
import org.skife.jdbi.v2.sqlobject.customizers.Mapper;
|
||||
import org.skife.jdbi.v2.tweak.ResultSetMapper;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public interface FieldRelationshipDAO {
|
||||
@SqlUpdate("INSERT IGNORE INTO field_relationship(fromFQN, toFQN, fromType, toType, relation) " +
|
||||
"VALUES (:fromFQN, :toFQN, :fromType, :toType, :relation)")
|
||||
void insert(@Bind("fromFQN") String fromFQN, @Bind("toFQN") String toFQN, @Bind("fromType") String fromType,
|
||||
@Bind("toType") String toType, @Bind("relation") int relation);
|
||||
|
||||
@SqlUpdate("INSERT INTO field_relationship(fromFQN, toFQN, fromType, toType, relation, jsonSchema, json) " +
|
||||
"VALUES (:fromFQN, :toFQN, :fromType, :toType, :relation, :jsonSchema, :json) " +
|
||||
"ON DUPLICATE KEY UPDATE json = :json")
|
||||
void upsert(@Bind("fromFQN") String fromFQN, @Bind("toFQN") String toFQN, @Bind("fromType") String fromType,
|
||||
@Bind("toType") String toType, @Bind("relation") int relation,
|
||||
@Bind("jsonSchema") String jsonSchema, @Bind("json") String json);
|
||||
|
||||
@SqlQuery("SELECT json FROM field_relationship WHERE " +
|
||||
"fromFQN = :fromFQN AND toFQN = :toFQN AND fromType = :fromType " +
|
||||
"AND toType = :toType AND relation = :relation")
|
||||
String find(@Bind("fromFQN") String fromFQN, @Bind("toFQN") String toFQN,
|
||||
@Bind("fromType") String fromType, @Bind("toType") String toType,
|
||||
@Bind("relation") int relation);
|
||||
|
||||
@SqlQuery("SELECT fromFQN, toFQN, json FROM field_relationship WHERE " +
|
||||
"toFQN LIKE CONCAT(:fqnPrefix, '%') AND fromType = :fromType AND toType = :toType AND relation = :relation")
|
||||
@Mapper(FromFieldMapper.class)
|
||||
List<List<String>> listFromByPrefix(@Bind("fqnPrefix") String fqnPrefix, @Bind("fromType") String fromType,
|
||||
@Bind("toType") String toType, @Bind("relation") int relation);
|
||||
|
||||
@SqlQuery("SELECT fromFQN, toFQN, json FROM field_relationship WHERE " +
|
||||
"fromFQN LIKE CONCAT(:fqnPrefix, '%') AND fromType = :fromType AND toType = :toType AND relation = :relation")
|
||||
@Mapper(ToFieldMapper.class)
|
||||
List<List<String>> listToByPrefix(@Bind("fqnPrefix") String fqnPrefix, @Bind("fromType") String fromType,
|
||||
@Bind("toType") String toType, @Bind("relation") int relation);
|
||||
|
||||
@SqlUpdate("DELETE from field_relationship WHERE " +
|
||||
"(toFQN LIKE CONCAT(:fqnPrefix, '.%') OR fromFQN LIKE CONCAT(:fqnPrefix, '.%')) " +
|
||||
"AND relation = :relation")
|
||||
void deleteAllByPrefix(@Bind("fqnPrefix") String fqnPrefix, @Bind("relation") int relation);
|
||||
|
||||
class ToFieldMapper implements ResultSetMapper<List<String>> {
|
||||
@Override
|
||||
public List<String> map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException {
|
||||
return Arrays.asList(resultSet.getString("fromFQN"), resultSet.getString("toFQN"),
|
||||
resultSet.getString("json"));
|
||||
}
|
||||
}
|
||||
|
||||
class FromFieldMapper implements ResultSetMapper<List<String>> {
|
||||
@Override
|
||||
public List<String> map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException {
|
||||
return Arrays.asList(resultSet.getString("toFQN"), resultSet.getString("fromFQN"),
|
||||
resultSet.getString("json"));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.catalog.jdbi3;
|
||||
|
||||
import org.openmetadata.catalog.type.EntityReference;
|
||||
import org.skife.jdbi.v2.StatementContext;
|
||||
import org.skife.jdbi.v2.tweak.ResultSetMapper;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FromEntityReferenceMapper implements ResultSetMapper<EntityReference> {
|
||||
@Override
|
||||
public EntityReference map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException {
|
||||
return new EntityReference().withId(UUID.fromString(resultSet.getString("fromId")))
|
||||
.withType(resultSet.getString("fromEntity"));
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MessagingServiceDAO {
|
||||
@SqlUpdate("INSERT INTO messaging_service_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlUpdate("UPDATE messaging_service_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
|
||||
@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);
|
||||
|
||||
@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);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MetricsDAO {
|
||||
@SqlUpdate("INSERT INTO metric_entity(json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlUpdate("UPDATE metrics_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
|
||||
@SqlQuery("SELECT json FROM metric_entity WHERE id = :id")
|
||||
String findById(@Bind("id") String id);
|
||||
|
||||
@SqlQuery("SELECT json FROM metric_entity WHERE fullyQualifiedName = :name")
|
||||
String findByFQN(@Bind("name") String name);
|
||||
|
||||
@SqlQuery("SELECT json FROM metric_entity")
|
||||
List<String> list();
|
||||
|
||||
@SqlQuery("SELECT EXISTS (SELECT * FROM metric_entity where id = :id)")
|
||||
boolean exists(@Bind("id") String id);
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ModelDAO {
|
||||
@SqlUpdate("INSERT INTO model_entity(json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlUpdate("UPDATE model_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
|
||||
@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);
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PipelineDAO {
|
||||
@SqlUpdate("INSERT INTO pipeline_entity(json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@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);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PipelineServiceDAO {
|
||||
@SqlUpdate("INSERT INTO pipeline_service_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlUpdate("UPDATE pipeline_service_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
|
||||
@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);
|
||||
|
||||
@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 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ReportDAO {
|
||||
@SqlUpdate("INSERT INTO report_entity(json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlUpdate("UPDATE report_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
|
||||
@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);
|
||||
|
||||
@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,50 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TableDAO {
|
||||
@SqlUpdate("INSERT INTO table_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlUpdate("UPDATE table_entity SET json = :json WHERE id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
|
||||
@SqlQuery("SELECT json FROM table_entity WHERE id = :tableId")
|
||||
String findById(@Bind("tableId") String tableId);
|
||||
|
||||
@SqlQuery("SELECT json FROM table_entity WHERE fullyQualifiedName = :tableFQN")
|
||||
String findByFqn(@Bind("tableFQN") String tableFQN);
|
||||
|
||||
@SqlQuery("SELECT count(*) FROM table_entity WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:databaseFQN, '.%') OR :databaseFQN IS NULL)")
|
||||
int listCount(@Bind("databaseFQN") String databaseFQN);
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT json FROM (" +
|
||||
"SELECT fullyQualifiedName, json FROM table_entity 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(@Bind("databaseFQN") String databaseFQN, @Bind("limit") int limit,
|
||||
@Bind("before") String before);
|
||||
|
||||
@SqlQuery("SELECT json FROM table_entity 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(@Bind("databaseFQN") String databaseFQN, @Bind("limit") int limit,
|
||||
@Bind("after") String after);
|
||||
|
||||
@SqlQuery("SELECT EXISTS (SELECT * FROM table_entity WHERE id = :id)")
|
||||
boolean exists(@Bind("id") String id);
|
||||
|
||||
@SqlUpdate("DELETE FROM table_entity WHERE id = :id")
|
||||
int delete(@Bind("id") String id);
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TaskDAO {
|
||||
@SqlUpdate("INSERT INTO task_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlUpdate("UPDATE task_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
|
||||
@SqlQuery("SELECT json FROM task_entity WHERE fullyQualifiedName = :name")
|
||||
String findByFQN(@Bind("name") String name);
|
||||
|
||||
@SqlQuery("SELECT json FROM task_entity WHERE id = :id")
|
||||
String findById(@Bind("id") String id);
|
||||
|
||||
@SqlQuery("SELECT count(*) FROM task_entity WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL)")
|
||||
int listCount(@Bind("fqnPrefix") String fqnPrefix);
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT json FROM (" +
|
||||
"SELECT fullyQualifiedName, json FROM task_entity WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL) AND " +// Filter by
|
||||
// service name
|
||||
"fullyQualifiedName < :before " + // Pagination by task fullyQualifiedName
|
||||
"ORDER BY fullyQualifiedName DESC " + // Pagination ordering by task 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 task_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);
|
||||
|
||||
@SqlQuery("SELECT EXISTS (SELECT * FROM task_entity WHERE id = :id)")
|
||||
boolean exists(@Bind("id") String id);
|
||||
|
||||
@SqlUpdate("DELETE FROM task_entity WHERE id = :id")
|
||||
int delete(@Bind("id") String id);
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TeamDAO {
|
||||
@SqlUpdate("INSERT INTO team_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlQuery("SELECT json FROM team_entity where id = :teamId")
|
||||
String findById(@Bind("teamId") String teamId);
|
||||
|
||||
@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);
|
||||
}
|
@ -26,14 +26,12 @@ import org.openmetadata.catalog.resources.teams.TeamResource.TeamList;
|
||||
import org.openmetadata.catalog.type.EntityReference;
|
||||
import org.openmetadata.catalog.type.TagLabel;
|
||||
import org.openmetadata.catalog.util.EntityInterface;
|
||||
import org.openmetadata.catalog.util.EntityUpdater;
|
||||
import org.openmetadata.catalog.util.EntityUpdater3;
|
||||
import org.openmetadata.catalog.util.EntityUtil;
|
||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||
import org.openmetadata.catalog.util.JsonUtils;
|
||||
import org.openmetadata.catalog.util.ResultList;
|
||||
import org.openmetadata.common.utils.CipherText;
|
||||
import org.skife.jdbi.v2.sqlobject.CreateSqlObject;
|
||||
import org.skife.jdbi.v2.sqlobject.Transaction;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.catalog.jdbi3;
|
||||
|
||||
import org.openmetadata.catalog.type.EntityReference;
|
||||
import org.skife.jdbi.v2.StatementContext;
|
||||
import org.skife.jdbi.v2.tweak.ResultSetMapper;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ToEntityReferenceMapper implements ResultSetMapper<EntityReference> {
|
||||
@Override
|
||||
public EntityReference map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException {
|
||||
return new EntityReference().withId(UUID.fromString(resultSet.getString("toId")))
|
||||
.withType(resultSet.getString("toEntity"));
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TopicDAO {
|
||||
@SqlUpdate("INSERT INTO topic_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlUpdate("UPDATE topic_entity SET json = :json where id = :id")
|
||||
void update(@Bind("id") String id, @Bind("json") String json);
|
||||
|
||||
@SqlQuery("SELECT json FROM topic_entity WHERE fullyQualifiedName = :name")
|
||||
String findByFQN(@Bind("name") String name);
|
||||
|
||||
@SqlQuery("SELECT json FROM topic_entity WHERE id = :id")
|
||||
String findById(@Bind("id") String id);
|
||||
|
||||
@SqlQuery("SELECT count(*) FROM topic_entity WHERE " +
|
||||
"(fullyQualifiedName LIKE CONCAT(:fqnPrefix, '.%') OR :fqnPrefix IS NULL)")
|
||||
// Filter by service name
|
||||
int listCount(@Bind("fqnPrefix") String fqnPrefix);
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT json FROM (" +
|
||||
"SELECT fullyQualifiedName, json FROM topic_entity 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(@Bind("fqnPrefix") String fqnPrefix, @Bind("limit") int limit,
|
||||
@Bind("before") String before);
|
||||
|
||||
@SqlQuery("SELECT json FROM topic_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);
|
||||
|
||||
@SqlQuery("SELECT EXISTS (SELECT * FROM topic_entity WHERE id = :id)")
|
||||
boolean exists(@Bind("id") String id);
|
||||
|
||||
@SqlUpdate("DELETE FROM topic_entity WHERE id = :id")
|
||||
int delete(@Bind("id") String id);
|
||||
}
|
@ -18,24 +18,20 @@ package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.openmetadata.catalog.Entity;
|
||||
import org.openmetadata.catalog.entity.data.Table;
|
||||
import org.openmetadata.catalog.entity.data.Topic;
|
||||
import org.openmetadata.catalog.entity.services.MessagingService;
|
||||
import org.openmetadata.catalog.exception.EntityNotFoundException;
|
||||
import org.openmetadata.catalog.resources.databases.TableResource.TableList;
|
||||
import org.openmetadata.catalog.resources.topics.TopicResource;
|
||||
import org.openmetadata.catalog.resources.topics.TopicResource.TopicList;
|
||||
import org.openmetadata.catalog.type.EntityReference;
|
||||
import org.openmetadata.catalog.type.TagLabel;
|
||||
import org.openmetadata.catalog.util.EntityInterface;
|
||||
import org.openmetadata.catalog.util.EntityUpdater;
|
||||
import org.openmetadata.catalog.util.EntityUpdater3;
|
||||
import org.openmetadata.catalog.util.EntityUtil;
|
||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||
import org.openmetadata.catalog.util.JsonUtils;
|
||||
import org.openmetadata.catalog.util.RestUtil.PutResponse;
|
||||
import org.openmetadata.catalog.util.ResultList;
|
||||
import org.openmetadata.common.utils.CipherText;
|
||||
import org.skife.jdbi.v2.sqlobject.Transaction;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -46,7 +42,6 @@ import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
@ -1,81 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.openmetadata.catalog.jdbi3.UsageRepositoryHelper.UsageDetailsMapper;
|
||||
import org.openmetadata.catalog.type.UsageDetails;
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterMapper(UsageDetailsMapper.class)
|
||||
public interface UsageDAO {
|
||||
@SqlUpdate("INSERT INTO entity_usage (usageDate, id, entityType, count1, count7, count30) " +
|
||||
"SELECT :date, :id, :entityType, :count1, " +
|
||||
"(:count1 + (SELECT COALESCE(SUM(count1), 0) FROM entity_usage WHERE id = :id AND usageDate >= :date - " +
|
||||
"INTERVAL 6 DAY)), " +
|
||||
"(:count1 + (SELECT COALESCE(SUM(count1), 0) FROM entity_usage WHERE id = :id AND usageDate >= :date - " +
|
||||
"INTERVAL 29 DAY))")
|
||||
void insert(@Bind("date") String date, @Bind("id") String id, @Bind("entityType") String entityType, @Bind(
|
||||
"count1") int count1);
|
||||
|
||||
@SqlUpdate("INSERT INTO entity_usage (usageDate, id, entityType, count1, count7, count30) " +
|
||||
"SELECT :date, :id, :entityType, :count1, " +
|
||||
"(:count1 + (SELECT COALESCE(SUM(count1), 0) FROM entity_usage WHERE id = :id AND usageDate >= :date - " +
|
||||
"INTERVAL 6 DAY)), " +
|
||||
"(:count1 + (SELECT COALESCE(SUM(count1), 0) FROM entity_usage WHERE id = :id AND usageDate >= :date - " +
|
||||
"INTERVAL 29 DAY)) " +
|
||||
"ON DUPLICATE KEY UPDATE count1 = count1 + :count1, count7 = count7 + :count1, count30 = count30 + :count1")
|
||||
void insertOrUpdateCount(@Bind("date") String date, @Bind("id") String id, @Bind("entityType") String entityType,
|
||||
@Bind("count1") int count1);
|
||||
|
||||
@SqlUpdate("UPDATE entity_usage u JOIN ( " +
|
||||
"SELECT u1.id, " +
|
||||
"(SELECT COUNT(*) FROM entity_usage as u2 WHERE u2.count1 < u1.count1 AND u2.entityType = :entityType " +
|
||||
"AND u2.usageDate = :date) as p1, " +
|
||||
"(SELECT COUNT(*) FROM entity_usage as u3 WHERE u3.count7 < u1.count7 AND u3.entityType = :entityType " +
|
||||
"AND u3.usageDate = :date) as p7, " +
|
||||
"(SELECT COUNT(*) FROM entity_usage as u4 WHERE u4.count30 < u1.count30 AND u4.entityType = :entityType " +
|
||||
"AND u4.usageDate = :date) as p30, " +
|
||||
"(SELECT COUNT(*) FROM entity_usage WHERE entityType = :entityType AND usageDate = :date) as total " +
|
||||
"FROM entity_usage u1 WHERE u1.entityType = :entityType AND u1.usageDate = :date" +
|
||||
") vals ON u.id = vals.id AND usageDate = :date " +
|
||||
"SET u.percentile1 = ROUND(100 * p1/total, 2), u.percentile7 = ROUND(p7 * 100/total, 2), u.percentile30 =" +
|
||||
" ROUND(p30*100/total, 2)")
|
||||
@SqlQuery("SELECT id, usageDate, entityType, count1, count7, count30, " +
|
||||
"percentile1, percentile7, percentile30 FROM entity_usage " +
|
||||
"WHERE id = :id AND usageDate >= :date - INTERVAL :days DAY AND usageDate <= :date ORDER BY usageDate DESC")
|
||||
List<UsageDetails> getUsageById(@Bind("id") String id, @Bind("date") String date, @Bind("days") int days);
|
||||
|
||||
/**
|
||||
* Get latest usage record
|
||||
**/
|
||||
@SqlQuery("SELECT id, usageDate, entityType, count1, count7, count30, " +
|
||||
"percentile1, percentile7, percentile30 FROM entity_usage " +
|
||||
"WHERE usageDate IN (SELECT MAX(usageDate) FROM entity_usage WHERE id = :id) AND id = :id")
|
||||
UsageDetails getLatestUsage(@Bind("id") String id);
|
||||
|
||||
@SqlUpdate("DELETE FROM entity_usage WHERE id = :id")
|
||||
int delete(@Bind("id") String id);
|
||||
|
||||
/**
|
||||
* Note not using in following percentile computation PERCENT_RANK function as unit tests use mysql5.7 and it does
|
||||
* not have window function
|
||||
*/
|
||||
@SqlUpdate("UPDATE entity_usage u JOIN ( " +
|
||||
"SELECT u1.id, " +
|
||||
"(SELECT COUNT(*) FROM entity_usage as u2 WHERE u2.count1 < u1.count1 AND u2.entityType = :entityType " +
|
||||
"AND u2.usageDate = :date) as p1, " +
|
||||
"(SELECT COUNT(*) FROM entity_usage as u3 WHERE u3.count7 < u1.count7 AND u3.entityType = :entityType " +
|
||||
"AND u3.usageDate = :date) as p7, " +
|
||||
"(SELECT COUNT(*) FROM entity_usage as u4 WHERE u4.count30 < u1.count30 AND u4.entityType = :entityType " +
|
||||
"AND u4.usageDate = :date) as p30, " +
|
||||
"(SELECT COUNT(*) FROM entity_usage WHERE entityType = :entityType AND usageDate = :date) as total " +
|
||||
"FROM entity_usage u1 WHERE u1.entityType = :entityType AND u1.usageDate = :date" +
|
||||
") vals ON u.id = vals.id AND usageDate = :date " +
|
||||
"SET u.percentile1 = ROUND(100 * p1/total, 2), u.percentile7 = ROUND(p7 * 100/total, 2), u.percentile30 =" +
|
||||
" ROUND(p30*100/total, 2)")
|
||||
void computePercentile(@Bind("entityType") String entityType, @Bind("date") String date);
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.skife.jdbi.v2.sqlobject.Bind;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlQuery;
|
||||
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserDAO {
|
||||
@SqlUpdate("INSERT INTO user_entity (json) VALUES (:json)")
|
||||
void insert(@Bind("json") String json);
|
||||
|
||||
@SqlQuery("SELECT json FROM user_entity WHERE id = :id")
|
||||
String findById(@Bind("id") String id);
|
||||
|
||||
@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);
|
||||
|
||||
@SqlQuery("SELECT json FROM user_entity")
|
||||
List<String> list();
|
||||
|
||||
@SqlQuery("SELECT count(*) FROM user_entity")
|
||||
int listCount();
|
||||
|
||||
@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);
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
package org.openmetadata.catalog.util;
|
||||
|
||||
import org.openmetadata.catalog.Entity;
|
||||
import org.openmetadata.catalog.jdbi3.EntityRelationshipDAO;
|
||||
import org.openmetadata.catalog.jdbi3.TableRepository3;
|
||||
import org.openmetadata.catalog.jdbi3.TagDAO;
|
||||
import org.openmetadata.catalog.type.EntityReference;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Used for updating the following common entity fields in PUT and PATCH operations.
|
||||
* - description
|
||||
* - tags
|
||||
* - owner
|
||||
*
|
||||
* This class handles tracking all the changes in an update operation and also versioning
|
||||
* of the entity.
|
||||
*
|
||||
* Concrete implementations need to implement update for other fields. See
|
||||
* {@link TableRepository3.TableUpdater} for an example implementation.
|
||||
*/
|
||||
public abstract class EntityUpdater {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(EntityUpdater.class);
|
||||
private final EntityInterface originalEntity;
|
||||
private final EntityInterface updatedEntity;
|
||||
private final EntityRelationshipDAO relationshipDAO;
|
||||
private final TagDAO tagDAO;
|
||||
|
||||
protected final boolean patchOperation;
|
||||
protected List<String> fieldsUpdated = new ArrayList<>();
|
||||
protected List<String> fieldsAdded = new ArrayList<>();
|
||||
protected List<String> fieldsDeleted = new ArrayList<>();
|
||||
protected boolean majorVersionChange = false;
|
||||
|
||||
public EntityUpdater(EntityInterface originalEntity, EntityInterface updatedEntity, boolean patchOperation,
|
||||
EntityRelationshipDAO relationshipDAO, TagDAO tagDAO) {
|
||||
this.originalEntity = originalEntity;
|
||||
this.updatedEntity = updatedEntity;
|
||||
this.patchOperation = patchOperation;
|
||||
this.relationshipDAO = relationshipDAO;
|
||||
this.tagDAO = tagDAO;
|
||||
}
|
||||
|
||||
public void updateAll() throws IOException {
|
||||
updateDescription();
|
||||
updateDisplayName();
|
||||
updateOwner();
|
||||
if (tagDAO != null) {
|
||||
updateTags(); // If tagDAO != null, the Entity supports tags
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDescription() {
|
||||
if (!patchOperation &&
|
||||
originalEntity.getDescription() != null && !originalEntity.getDescription().isEmpty()) {
|
||||
// Update description only when stored is empty to retain user authored descriptions
|
||||
updatedEntity.setDescription(originalEntity.getDescription());
|
||||
return;
|
||||
}
|
||||
update("description", originalEntity.getDescription(), updatedEntity.getDescription());
|
||||
}
|
||||
|
||||
private void updateDisplayName() {
|
||||
if (!patchOperation &&
|
||||
originalEntity.getDisplayName() != null && !originalEntity.getDisplayName().isEmpty()) {
|
||||
// Update displayName only when stored is empty to retain user authored descriptions
|
||||
updatedEntity.setDisplayName(originalEntity.getDisplayName());
|
||||
return;
|
||||
}
|
||||
update("displayName", originalEntity.getDisplayName(), updatedEntity.getDisplayName());
|
||||
}
|
||||
|
||||
private void updateOwner() {
|
||||
EntityReference origOwner = originalEntity.getOwner();
|
||||
EntityReference updatedOwner = updatedEntity.getOwner();
|
||||
if (update("owner", origOwner == null ? null : origOwner.getId(),
|
||||
updatedOwner == null ? null : updatedOwner.getId())) {
|
||||
EntityUtil.updateOwner(relationshipDAO, origOwner, updatedOwner, originalEntity.getId(), Entity.TABLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTags() throws IOException {
|
||||
// Remove current table tags in the database. It will be added back later from the merged tag list.
|
||||
EntityUtil.removeTagsByPrefix(tagDAO, originalEntity.getFullyQualifiedName());
|
||||
if (!patchOperation) {
|
||||
// PUT operation merges tags in the request with what already exists
|
||||
updatedEntity.setTags(EntityUtil.mergeTags(updatedEntity.getTags(), originalEntity.getTags()));
|
||||
}
|
||||
|
||||
update("tags", originalEntity.getTags() == null ? 0 : originalEntity.getTags().size(),
|
||||
updatedEntity.getTags() == null ? 0 : updatedEntity.getTags().size());
|
||||
EntityUtil.applyTags(tagDAO, updatedEntity.getTags(), updatedEntity.getFullyQualifiedName());
|
||||
}
|
||||
|
||||
public Double getNewVersion(Double oldVersion) {
|
||||
Double newVersion = oldVersion;
|
||||
if (majorVersionChange) {
|
||||
newVersion = oldVersion + 1.0;
|
||||
} else if (!fieldsUpdated.isEmpty() || !fieldsAdded.isEmpty() || !fieldsDeleted.isEmpty()) {
|
||||
newVersion = oldVersion + 0.1;
|
||||
}
|
||||
LOG.info("{}->{} - Fields added {}, updated {}, deleted {}",
|
||||
oldVersion, newVersion, fieldsAdded, fieldsUpdated, fieldsDeleted);
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
public abstract void store() throws IOException;
|
||||
|
||||
protected boolean update(String field, Object orig, Object updated) {
|
||||
if (orig == null && updated == null) {
|
||||
return false;
|
||||
}
|
||||
if (orig == null) {
|
||||
fieldsAdded.add(field);
|
||||
return true;
|
||||
} else if (updated == null) {
|
||||
fieldsDeleted.add(field);
|
||||
return true;
|
||||
} else if (!orig.equals(updated)) {
|
||||
fieldsUpdated.add(field);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -36,34 +36,22 @@ import org.openmetadata.catalog.entity.teams.User;
|
||||
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
|
||||
import org.openmetadata.catalog.exception.EntityNotFoundException;
|
||||
import org.openmetadata.catalog.jdbi3.ChartDAO3;
|
||||
import org.openmetadata.catalog.jdbi3.DashboardDAO;
|
||||
import org.openmetadata.catalog.jdbi3.DashboardDAO3;
|
||||
import org.openmetadata.catalog.jdbi3.DatabaseDAO;
|
||||
import org.openmetadata.catalog.jdbi3.DatabaseDAO3;
|
||||
import org.openmetadata.catalog.jdbi3.EntityRelationshipDAO;
|
||||
import org.openmetadata.catalog.jdbi3.EntityRelationshipDAO3;
|
||||
import org.openmetadata.catalog.jdbi3.EntityRepository;
|
||||
import org.openmetadata.catalog.jdbi3.MetricsDAO;
|
||||
import org.openmetadata.catalog.jdbi3.MetricsDAO3;
|
||||
import org.openmetadata.catalog.jdbi3.ModelDAO;
|
||||
import org.openmetadata.catalog.jdbi3.ModelDAO3;
|
||||
import org.openmetadata.catalog.jdbi3.PipelineDAO;
|
||||
import org.openmetadata.catalog.jdbi3.PipelineDAO3;
|
||||
import org.openmetadata.catalog.jdbi3.Relationship;
|
||||
import org.openmetadata.catalog.jdbi3.ReportDAO;
|
||||
import org.openmetadata.catalog.jdbi3.ReportDAO3;
|
||||
import org.openmetadata.catalog.jdbi3.TableDAO3;
|
||||
import org.openmetadata.catalog.jdbi3.TagDAO;
|
||||
import org.openmetadata.catalog.jdbi3.TagDAO3;
|
||||
import org.openmetadata.catalog.jdbi3.TaskDAO;
|
||||
import org.openmetadata.catalog.jdbi3.TaskDAO3;
|
||||
import org.openmetadata.catalog.jdbi3.TeamDAO;
|
||||
import org.openmetadata.catalog.jdbi3.TeamDAO3;
|
||||
import org.openmetadata.catalog.jdbi3.TopicDAO;
|
||||
import org.openmetadata.catalog.jdbi3.TopicDAO3;
|
||||
import org.openmetadata.catalog.jdbi3.UsageDAO;
|
||||
import org.openmetadata.catalog.jdbi3.UsageDAO3;
|
||||
import org.openmetadata.catalog.jdbi3.UserDAO;
|
||||
import org.openmetadata.catalog.jdbi3.UserDAO3;
|
||||
import org.openmetadata.catalog.resources.charts.ChartResource;
|
||||
import org.openmetadata.catalog.resources.dashboards.DashboardResource;
|
||||
@ -127,15 +115,6 @@ public final class EntityUtil {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static EntityReference getService(EntityRelationshipDAO dao, UUID entityId) {
|
||||
List<EntityReference> refs = dao.findFrom(entityId.toString(), Relationship.CONTAINS.ordinal());
|
||||
if (refs.size() > 1) {
|
||||
LOG.warn("Possible database issues - multiple services found for entity {}", entityId);
|
||||
return refs.get(0);
|
||||
}
|
||||
return refs.isEmpty() ? null : refs.get(0);
|
||||
}
|
||||
|
||||
public static EntityReference getService(EntityRelationshipDAO3 dao, UUID entityId) {
|
||||
List<EntityReference> refs = dao.findFrom(entityId.toString(), Relationship.CONTAINS.ordinal());
|
||||
if (refs.size() > 1) {
|
||||
@ -145,15 +124,6 @@ public final class EntityUtil {
|
||||
return refs.isEmpty() ? null : refs.get(0);
|
||||
}
|
||||
|
||||
public static EntityReference getService(EntityRelationshipDAO dao, UUID entityId, String serviceType) {
|
||||
List<EntityReference> refs = dao.findFromEntity(entityId.toString(), Relationship.CONTAINS.ordinal(), serviceType);
|
||||
if (refs.size() > 1) {
|
||||
LOG.warn("Possible database issues - multiple services found for entity {}", entityId);
|
||||
return refs.get(0);
|
||||
}
|
||||
return refs.isEmpty() ? null : refs.get(0);
|
||||
}
|
||||
|
||||
public static EntityReference getService(EntityRelationshipDAO3 dao, UUID entityId, String serviceType) {
|
||||
List<EntityReference> refs = dao.findFromEntity(entityId.toString(), Relationship.CONTAINS.ordinal(), serviceType);
|
||||
if (refs.size() > 1) {
|
||||
@ -208,28 +178,12 @@ public final class EntityUtil {
|
||||
Optional.ofNullable(list).orElse(Collections.emptyList()).forEach(ref -> addHref(uriInfo, ref));
|
||||
}
|
||||
|
||||
public static void validateUser(UserDAO userDAO, String userId) {
|
||||
if (!userDAO.exists(userId)) {
|
||||
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.USER, userId));
|
||||
}
|
||||
}
|
||||
|
||||
public static void validateUser(UserDAO3 userDAO, String userId) {
|
||||
if (!userDAO.exists(userId)) {
|
||||
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.USER, userId));
|
||||
}
|
||||
}
|
||||
|
||||
// Get owner for a given entity
|
||||
public static EntityReference populateOwner(UUID id, EntityRelationshipDAO entityRelationshipDAO, UserDAO userDAO,
|
||||
TeamDAO teamDAO) throws IOException {
|
||||
List<EntityReference> ids = entityRelationshipDAO.findFrom(id.toString(), Relationship.OWNS.ordinal());
|
||||
if (ids.size() > 1) {
|
||||
LOG.warn("Possible database issues - multiple owners {} found for entity {}", ids, id);
|
||||
}
|
||||
return ids.isEmpty() ? null : EntityUtil.populateOwner(userDAO, teamDAO, ids.get(0));
|
||||
}
|
||||
|
||||
// Get owner for a given entity
|
||||
public static EntityReference populateOwner(UUID id, EntityRelationshipDAO3 entityRelationshipDAO, UserDAO3 userDAO,
|
||||
TeamDAO3 teamDAO) throws IOException {
|
||||
@ -240,32 +194,6 @@ public final class EntityUtil {
|
||||
return ids.isEmpty() ? null : EntityUtil.populateOwner(userDAO, teamDAO, ids.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* For given Owner with Id and Type that can be either team or user,
|
||||
* validate Owner ID and return fully populated Owner
|
||||
*/
|
||||
public static EntityReference populateOwner(UserDAO userDAO, TeamDAO teamDAO, EntityReference owner)
|
||||
throws IOException {
|
||||
if (owner == null) {
|
||||
return null;
|
||||
}
|
||||
String id = owner.getId().toString();
|
||||
if (owner.getType().equalsIgnoreCase("user")) {
|
||||
User ownerInstance = EntityUtil.validate(id, userDAO.findById(id), User.class);
|
||||
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);
|
||||
owner.setDescription(ownerInstance.getDescription());
|
||||
owner.setName(ownerInstance.getName());
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format("Invalid ownerType %s", owner.getType()));
|
||||
}
|
||||
return owner;
|
||||
}
|
||||
|
||||
public static EntityReference populateOwner(UserDAO3 userDAO, TeamDAO3 teamDAO,
|
||||
EntityReference owner)
|
||||
throws IOException {
|
||||
@ -288,16 +216,6 @@ public final class EntityUtil {
|
||||
}
|
||||
return owner;
|
||||
}
|
||||
public static void setOwner(EntityRelationshipDAO dao, UUID ownedEntityId, String ownedEntityType,
|
||||
EntityReference owner) {
|
||||
// Add relationship owner --- owns ---> ownedEntity
|
||||
if (owner != null) {
|
||||
LOG.info("Adding owner {}:{} for entity {}", owner.getType(), owner.getId(), ownedEntityId);
|
||||
dao.insert(owner.getId().toString(), ownedEntityId.toString(), owner.getType(), ownedEntityType,
|
||||
Relationship.OWNS.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
public static void setOwner(EntityRelationshipDAO3 dao, UUID ownedEntityId, String ownedEntityType,
|
||||
EntityReference owner) {
|
||||
// Add relationship owner --- owns ---> ownedEntity
|
||||
@ -308,17 +226,6 @@ public final class EntityUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unassign owner relationship for a given entity
|
||||
*/
|
||||
public static void unassignOwner(EntityRelationshipDAO dao, EntityReference owner, String ownedEntityId) {
|
||||
if (owner != null && owner.getId() != null) {
|
||||
LOG.info("Removing owner {}:{} for entity {}", owner.getType(), owner.getId(),
|
||||
ownedEntityId);
|
||||
dao.delete(owner.getId().toString(), ownedEntityId, Relationship.OWNS.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unassign owner relationship for a given entity
|
||||
*/
|
||||
@ -330,14 +237,6 @@ public final class EntityUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateOwner(EntityRelationshipDAO dao, EntityReference originalOwner, EntityReference newOwner,
|
||||
UUID ownedEntityId, String ownedEntityType) {
|
||||
// TODO inefficient use replace instead of delete and add?
|
||||
// TODO check for orig and new owners being the same
|
||||
unassignOwner(dao, originalOwner, ownedEntityId.toString());
|
||||
setOwner(dao, ownedEntityId, ownedEntityType, newOwner);
|
||||
}
|
||||
|
||||
public static void updateOwner(EntityRelationshipDAO3 dao, EntityReference originalOwner, EntityReference newOwner,
|
||||
UUID ownedEntityId, String ownedEntityType) {
|
||||
// TODO inefficient use replace instead of delete and add?
|
||||
@ -528,40 +427,6 @@ public final class EntityUtil {
|
||||
.withType(Entity.PIPELINE_SERVICE);
|
||||
}
|
||||
|
||||
public static EntityReference validateEntityLink(EntityLink entityLink, UserDAO userDAO, TeamDAO teamDAO,
|
||||
TableDAO3 tableDAO, DatabaseDAO databaseDAO, MetricsDAO metricsDAO,
|
||||
DashboardDAO dashboardDAO, ReportDAO reportDAO, TopicDAO topicDAO,
|
||||
TaskDAO taskDAO, ModelDAO modelDAO, PipelineDAO pipelineDAO)
|
||||
throws IOException {
|
||||
String entityType = entityLink.getEntityType();
|
||||
String fqn = entityLink.getEntityId();
|
||||
if (entityType.equalsIgnoreCase(Entity.USER)) {
|
||||
return getEntityReference(EntityUtil.validate(fqn, userDAO.findByName(fqn), User.class));
|
||||
} else if (entityType.equalsIgnoreCase(Entity.TEAM)) {
|
||||
return getEntityReference(EntityUtil.validate(fqn, teamDAO.findByName(fqn), Team.class));
|
||||
} else if (entityType.equalsIgnoreCase(Entity.TABLE)) {
|
||||
return getEntityReference(tableDAO.findEntityByName(fqn));
|
||||
} else if (entityType.equalsIgnoreCase(Entity.DATABASE)) {
|
||||
return getEntityReference(EntityUtil.validate(fqn, databaseDAO.findByFQN(fqn), Database.class));
|
||||
} else if (entityType.equalsIgnoreCase(Entity.METRICS)) {
|
||||
return getEntityReference(EntityUtil.validate(fqn, metricsDAO.findByFQN(fqn), Metrics.class));
|
||||
} else if (entityType.equalsIgnoreCase(Entity.DASHBOARD)) {
|
||||
return getEntityReference(EntityUtil.validate(fqn, dashboardDAO.findByFQN(fqn), Dashboard.class));
|
||||
} else if (entityType.equalsIgnoreCase(Entity.REPORT)) {
|
||||
return getEntityReference(EntityUtil.validate(fqn, reportDAO.findByFQN(fqn), Report.class));
|
||||
} else if (entityType.equalsIgnoreCase(Entity.TOPIC)) {
|
||||
return getEntityReference(EntityUtil.validate(fqn, topicDAO.findByFQN(fqn), Topic.class));
|
||||
} else if (entityType.equalsIgnoreCase(Entity.TASK)) {
|
||||
return getEntityReference(EntityUtil.validate(fqn, taskDAO.findByFQN(fqn), Task.class));
|
||||
} else if (entityType.equalsIgnoreCase(Entity.PIPELINE)) {
|
||||
return getEntityReference(EntityUtil.validate(fqn, pipelineDAO.findByFQN(fqn), Pipeline.class));
|
||||
} else if (entityType.equalsIgnoreCase(Entity.MODEL)) {
|
||||
return getEntityReference(EntityUtil.validate(fqn, modelDAO.findByFQN(fqn), Model.class));
|
||||
} else {
|
||||
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(entityType, fqn));
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityReference validateEntityLink(EntityLink entityLink, UserDAO3 userDAO, TeamDAO3 teamDAO,
|
||||
TableDAO3 tableDAO, DatabaseDAO3 databaseDAO, MetricsDAO3 metricsDAO,
|
||||
DashboardDAO3 dashboardDAO, ReportDAO3 reportDAO, TopicDAO3 topicDAO,
|
||||
@ -596,18 +461,6 @@ public final class EntityUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static UsageDetails getLatestUsage(UsageDAO usageDAO, UUID entityId) {
|
||||
LOG.debug("Getting latest usage for {}", entityId);
|
||||
UsageDetails details = usageDAO.getLatestUsage(entityId.toString());
|
||||
if (details == null) {
|
||||
LOG.debug("Usage details not found. Sending default usage");
|
||||
UsageStats stats = new UsageStats().withCount(0).withPercentileRank(0.0);
|
||||
details = new UsageDetails().withDailyStats(stats).withWeeklyStats(stats).withMonthlyStats(stats)
|
||||
.withDate(RestUtil.DATE_FORMAT.format(new Date()));
|
||||
}
|
||||
return details;
|
||||
}
|
||||
|
||||
public static UsageDetails getLatestUsage(UsageDAO3 usageDAO, UUID entityId) {
|
||||
LOG.debug("Getting latest usage for {}", entityId);
|
||||
UsageDetails details = usageDAO.getLatestUsage(entityId.toString());
|
||||
@ -680,17 +533,6 @@ public final class EntityUtil {
|
||||
.withName(user.getName()).withType(Entity.USER);
|
||||
}
|
||||
|
||||
|
||||
public static void validateTags(TagDAO tagDAO, List<TagLabel> tagLabels) {
|
||||
Optional.ofNullable(tagLabels).orElse(Collections.emptyList()).forEach(tagLabel -> {
|
||||
if (!tagDAO.tagExists(tagLabel.getTagFQN())) {
|
||||
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Tag.class.getSimpleName(),
|
||||
tagLabel.getTagFQN()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply tags {@code tagLabels} to the entity or field identified by {@code targetFQN}
|
||||
*/
|
||||
@ -820,17 +662,6 @@ public final class EntityUtil {
|
||||
LOG.info(print);
|
||||
}
|
||||
|
||||
public static boolean addFollower(EntityRelationshipDAO dao, UserDAO userDAO, String followedEntityId,
|
||||
String followedEntityType, String followerId, String followerEntity)
|
||||
throws IOException {
|
||||
User user = EntityUtil.validate(followerId, userDAO.findById(followerId), User.class);
|
||||
if (Optional.ofNullable(user.getDeactivated()).orElse(false)) {
|
||||
throw new IllegalArgumentException(CatalogExceptionMessage.deactivatedUser(followerId));
|
||||
}
|
||||
return dao.insert(followerId, followedEntityId, followerEntity, followedEntityType,
|
||||
Relationship.FOLLOWS.ordinal()) > 0;
|
||||
}
|
||||
|
||||
public static boolean addFollower(EntityRelationshipDAO3 dao, UserDAO3 userDAO,
|
||||
String followedEntityId,
|
||||
String followedEntityType, String followerId, String followerEntity)
|
||||
@ -843,27 +674,10 @@ public final class EntityUtil {
|
||||
Relationship.FOLLOWS.ordinal()) > 0;
|
||||
}
|
||||
|
||||
public static void removeFollower(EntityRelationshipDAO dao, String followedEntityId, String followerId) {
|
||||
dao.delete(followerId, followedEntityId, Relationship.FOLLOWS.ordinal());
|
||||
}
|
||||
|
||||
public static void removeFollower(EntityRelationshipDAO3 dao, String followedEntityId, String followerId) {
|
||||
dao.delete(followerId, followedEntityId, Relationship.FOLLOWS.ordinal());
|
||||
}
|
||||
|
||||
public static List<EntityReference> getFollowers(UUID followedEntityId, EntityRelationshipDAO entityRelationshipDAO,
|
||||
UserDAO userDAO) throws IOException {
|
||||
List<String> followerIds = entityRelationshipDAO.findFrom(followedEntityId.toString(),
|
||||
Relationship.FOLLOWS.ordinal(),
|
||||
Entity.USER);
|
||||
List<EntityReference> followers = new ArrayList<>();
|
||||
for (String followerId : followerIds) {
|
||||
User user = EntityUtil.validate(followerId, userDAO.findById(followerId), User.class);
|
||||
followers.add(new EntityReference().withName(user.getName()).withId(user.getId()).withType("user"));
|
||||
}
|
||||
return followers;
|
||||
}
|
||||
|
||||
public static List<EntityReference> getFollowers(UUID followedEntityId, EntityRelationshipDAO3 entityRelationshipDAO,
|
||||
UserDAO3 userDAO) throws IOException {
|
||||
List<String> followerIds = entityRelationshipDAO.findFrom(followedEntityId.toString(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user