This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch materialized-views
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git


The following commit(s) were added to refs/heads/materialized-views by this 
push:
     new 948876aa2 Refactor materialized views package
948876aa2 is described below

commit 948876aa269c895667136e1717664c8540465db8
Author: Bertil Chapuis <[email protected]>
AuthorDate: Mon Jan 13 14:53:43 2025 +0100

    Refactor materialized views package
---
 .../baremaps/tasks/RefreshMaterializedViews.java   | 12 +++--
 .../apache/baremaps/postgres/graph/RefreshApp.java | 60 ----------------------
 .../DatabaseMetadataRetriever.java                 |  2 +-
 .../{graph => refresh}/DependencyGraphBuilder.java |  6 +--
 .../MaterializedViewRefresher.java                 |  8 +--
 5 files changed, 15 insertions(+), 73 deletions(-)

diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/tasks/RefreshMaterializedViews.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/tasks/RefreshMaterializedViews.java
index 84f105824..5e2778b5e 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/tasks/RefreshMaterializedViews.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/tasks/RefreshMaterializedViews.java
@@ -19,9 +19,9 @@ package org.apache.baremaps.tasks;
 
 import java.sql.SQLException;
 import javax.sql.DataSource;
-import org.apache.baremaps.postgres.graph.DatabaseMetadataRetriever;
-import org.apache.baremaps.postgres.graph.DependencyGraphBuilder;
-import org.apache.baremaps.postgres.graph.MaterializedViewRefresher;
+import org.apache.baremaps.postgres.refresh.DatabaseMetadataRetriever;
+import org.apache.baremaps.postgres.refresh.DependencyGraphBuilder;
+import org.apache.baremaps.postgres.refresh.MaterializedViewRefresher;
 import org.apache.baremaps.workflow.Task;
 import org.apache.baremaps.workflow.WorkflowContext;
 import org.slf4j.Logger;
@@ -33,12 +33,15 @@ public class RefreshMaterializedViews implements Task {
 
   private Object database;
 
+  private String schema = "public";
+
   public RefreshMaterializedViews() {
     // Default constructor
   }
 
-  public RefreshMaterializedViews(Object database) {
+  public RefreshMaterializedViews(Object database, String schema) {
     this.database = database;
+    this.schema = schema;
   }
 
   @Override
@@ -46,7 +49,6 @@ public class RefreshMaterializedViews implements Task {
     DataSource dataSource = context.getDataSource(database);
     try (var connection = dataSource.getConnection()) {
       LOGGER.info("Connected to PostgreSQL database.");
-      var schema = "public";
 
       // 1. Retrieve database objects (tables, views, materialized views).
       var objects = DatabaseMetadataRetriever.getObjects(connection, schema);
diff --git 
a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/graph/RefreshApp.java
 
b/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/graph/RefreshApp.java
deleted file mode 100644
index 55fd9f8a2..000000000
--- 
a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/graph/RefreshApp.java
+++ /dev/null
@@ -1,60 +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.apache.baremaps.postgres.graph;
-
-import java.sql.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Main entry point for refreshing materialized views in a robust, modular way.
- */
-public class RefreshApp {
-
-  private static final Logger LOGGER = 
LoggerFactory.getLogger(RefreshApp.class.getName());
-
-  private static final String DB_URL = 
"jdbc:postgresql://localhost:5432/baremaps";
-  private static final String DB_USER = "baremaps";
-  private static final String DB_PASSWORD = "baremaps";
-  private static final String SCHEMA = "public";
-
-  public static void main(String[] args) {
-    try (var connection = DriverManager.getConnection(DB_URL, DB_USER, 
DB_PASSWORD)) {
-      LOGGER.info("Connected to PostgreSQL database.");
-
-      // 1. Retrieve database objects (tables, views, materialized views).
-      var objects = DatabaseMetadataRetriever.getObjects(connection, SCHEMA);
-
-      // 2. Retrieve dependencies between database objects.
-      var dependencies = DatabaseMetadataRetriever.getDependencies(connection, 
SCHEMA, objects);
-
-      // 3. Build a directed graph of dependencies between the database 
objects.
-      var graph = DependencyGraphBuilder.buildGraph(connection, SCHEMA, 
objects, dependencies);
-
-      // 4. Perform a topological sort so that dependencies come before 
dependents.
-      var sorted = DependencyGraphBuilder.topologicalSort(graph);
-
-      // 5. Refresh materialized views, dropping and recreating indexes if 
present.
-      MaterializedViewRefresher.refreshMaterializedViews(connection, sorted);
-
-      LOGGER.info("Done refreshing materialized views.");
-    } catch (SQLException ex) {
-      LOGGER.error("Database error", ex);
-    }
-  }
-}
diff --git 
a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/graph/DatabaseMetadataRetriever.java
 
b/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/refresh/DatabaseMetadataRetriever.java
similarity index 99%
rename from 
baremaps-postgres/src/main/java/org/apache/baremaps/postgres/graph/DatabaseMetadataRetriever.java
rename to 
baremaps-postgres/src/main/java/org/apache/baremaps/postgres/refresh/DatabaseMetadataRetriever.java
index 24434c611..b94491e3e 100644
--- 
a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/graph/DatabaseMetadataRetriever.java
+++ 
b/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/refresh/DatabaseMetadataRetriever.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.baremaps.postgres.graph;
+package org.apache.baremaps.postgres.refresh;
 
 import java.sql.Connection;
 import java.sql.SQLException;
diff --git 
a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/graph/DependencyGraphBuilder.java
 
b/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/refresh/DependencyGraphBuilder.java
similarity index 93%
rename from 
baremaps-postgres/src/main/java/org/apache/baremaps/postgres/graph/DependencyGraphBuilder.java
rename to 
baremaps-postgres/src/main/java/org/apache/baremaps/postgres/refresh/DependencyGraphBuilder.java
index fc074bba6..64974b0e1 100644
--- 
a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/graph/DependencyGraphBuilder.java
+++ 
b/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/refresh/DependencyGraphBuilder.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.baremaps.postgres.graph;
+package org.apache.baremaps.postgres.refresh;
 
 import com.google.common.graph.GraphBuilder;
 import com.google.common.graph.MutableGraph;
@@ -25,8 +25,8 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
-import 
org.apache.baremaps.postgres.graph.DatabaseMetadataRetriever.DatabaseDependency;
-import 
org.apache.baremaps.postgres.graph.DatabaseMetadataRetriever.DatabaseObject;
+import 
org.apache.baremaps.postgres.refresh.DatabaseMetadataRetriever.DatabaseDependency;
+import 
org.apache.baremaps.postgres.refresh.DatabaseMetadataRetriever.DatabaseObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
diff --git 
a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/graph/MaterializedViewRefresher.java
 
b/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/refresh/MaterializedViewRefresher.java
similarity index 91%
rename from 
baremaps-postgres/src/main/java/org/apache/baremaps/postgres/graph/MaterializedViewRefresher.java
rename to 
baremaps-postgres/src/main/java/org/apache/baremaps/postgres/refresh/MaterializedViewRefresher.java
index aa4487c77..39dab6722 100644
--- 
a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/graph/MaterializedViewRefresher.java
+++ 
b/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/refresh/MaterializedViewRefresher.java
@@ -15,14 +15,14 @@
  * limitations under the License.
  */
 
-package org.apache.baremaps.postgres.graph;
+package org.apache.baremaps.postgres.refresh;
 
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.List;
-import 
org.apache.baremaps.postgres.graph.DatabaseMetadataRetriever.DatabaseIndex;
-import 
org.apache.baremaps.postgres.graph.DatabaseMetadataRetriever.DatabaseObject;
-import org.apache.baremaps.postgres.graph.DatabaseMetadataRetriever.ObjectType;
+import 
org.apache.baremaps.postgres.refresh.DatabaseMetadataRetriever.DatabaseIndex;
+import 
org.apache.baremaps.postgres.refresh.DatabaseMetadataRetriever.DatabaseObject;
+import 
org.apache.baremaps.postgres.refresh.DatabaseMetadataRetriever.ObjectType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Reply via email to