From 7e3b054210073b3c58a4e246b14e06078b18bdfa Mon Sep 17 00:00:00 2001 From: anquetil Date: Wed, 22 Jul 2026 10:58:02 +0200 Subject: [PATCH] removing dead code in corese.core.storagemanager --- .../api/lifecycle/StorageLifecycle.java | 8 - .../api/operations/BulkOperations.java | 57 ----- .../api/operations/MutationOperations.java | 30 --- .../api/plugin/ExternalPluginLoader.java | 8 - .../api/support/config/StorageConfig.java | 20 -- .../api/support/exception/ErrorCode.java | 7 - .../support/exception/StorageException.java | 9 - .../api/support/model/MutationResult.java | 4 - .../api/support/model/StorageStatistics.java | 37 ---- .../api/transaction/IsolationLevel.java | 10 - .../api/transaction/TransactionManager.java | 9 - .../impl/graph/GraphAdapter.java | 11 - .../impl/transaction/TransactionImpl.java | 209 ------------------ 13 files changed, 419 deletions(-) delete mode 100644 src/main/java/fr/inria/corese/core/next/storagemanager/impl/transaction/TransactionImpl.java diff --git a/src/main/java/fr/inria/corese/core/next/storagemanager/api/lifecycle/StorageLifecycle.java b/src/main/java/fr/inria/corese/core/next/storagemanager/api/lifecycle/StorageLifecycle.java index 87081ee20..b8a84a072 100644 --- a/src/main/java/fr/inria/corese/core/next/storagemanager/api/lifecycle/StorageLifecycle.java +++ b/src/main/java/fr/inria/corese/core/next/storagemanager/api/lifecycle/StorageLifecycle.java @@ -40,12 +40,4 @@ public interface StorageLifecycle { */ StorageConfig getConfig(); - /** - * Checks whether the storage has been successfully initialized and is running. - * - * @return {@code true} if the storage is in {@link LifecycleState#RUNNING} state - */ - default boolean isInitialized() { - return getState() == LifecycleState.RUNNING; - } } \ No newline at end of file diff --git a/src/main/java/fr/inria/corese/core/next/storagemanager/api/operations/BulkOperations.java b/src/main/java/fr/inria/corese/core/next/storagemanager/api/operations/BulkOperations.java index d8807c219..35ff7c3e7 100644 --- a/src/main/java/fr/inria/corese/core/next/storagemanager/api/operations/BulkOperations.java +++ b/src/main/java/fr/inria/corese/core/next/storagemanager/api/operations/BulkOperations.java @@ -54,61 +54,4 @@ public interface BulkOperations { */ MutationResult clearContexts(List contexts, boolean silent) throws StorageException; - /** - * Clears all contexts (deletes entire model). - * - * @return Bulk mutation result with all deleted statements - * @throws StorageException if operation fails - */ - default MutationResult clearAll() throws StorageException { - return clearContexts(null, false); - } - - /** - * Adds statements from source context to target context. - * Statements remain in source context. - * - * @param sourceContext Source context - * @param targetContext Target context - * @param silent If true, don't fail if source doesn't exist - * @return Bulk mutation result - * @throws StorageException if operation fails - * @throws IllegalArgumentException if contexts are null - */ - default MutationResult addGraph(Resource sourceContext, Resource targetContext, boolean silent) - throws StorageException { - throw new UnsupportedOperationException("addGraph not implemented - Model API doesn't support this operation natively"); - } - - - /** - * Undeclares (deletes) a context and all its statements. - * - * @param context Context to undeclare - * @return Bulk mutation result with deleted statements - * @throws StorageException if operation fails - * @throws IllegalArgumentException if context is null - */ - default MutationResult undeclareContext(Resource context) throws StorageException { - if (context == null) { - throw new IllegalArgumentException("Context cannot be null"); - } - return clearContexts(List.of(context), false); - } - - /** - * Undeclares (deletes) multiple contexts and all their statements in a single batch operation. - * More efficient than calling undeclareContext() multiple times. - * - * @param contexts List of contexts to undeclare - * @return Bulk mutation result with all deleted statements - * @throws StorageException if operation fails - * @throws IllegalArgumentException if contexts is null or empty - */ - default MutationResult undeclareContexts(List contexts) throws StorageException { - if (contexts == null || contexts.isEmpty()) { - throw new IllegalArgumentException("Contexts list cannot be null or empty"); - } - return clearContexts(contexts, false); - } } \ No newline at end of file diff --git a/src/main/java/fr/inria/corese/core/next/storagemanager/api/operations/MutationOperations.java b/src/main/java/fr/inria/corese/core/next/storagemanager/api/operations/MutationOperations.java index c4c01e51a..e696225e2 100644 --- a/src/main/java/fr/inria/corese/core/next/storagemanager/api/operations/MutationOperations.java +++ b/src/main/java/fr/inria/corese/core/next/storagemanager/api/operations/MutationOperations.java @@ -60,36 +60,6 @@ MutationResult insertStatement(Resource subject, IRI predicate, Value object, Re MutationResult deleteStatements(Resource subject, IRI predicate, Value object, Resource... contexts) throws StorageException; - /** - * Updates a statement (delete + insert in one operation). - * - * @param oldStatement Statement to delete - * @param newStatement Statement to insert - * @return Mutation result - * @throws StorageException if operation fails - * @throws IllegalArgumentException if oldStatement or newStatement is null - */ - default MutationResult updateStatement(Statement oldStatement, Statement newStatement) - throws StorageException { - if (oldStatement == null || newStatement == null) { - throw new IllegalArgumentException("Both oldStatement and newStatement must be non-null"); - } - - MutationResult deleteResult = deleteStatement(oldStatement); - if (deleteResult.isFailure()) { - return deleteResult; - } - - MutationResult insertResult = insertStatement(newStatement); - if (insertResult.isFailure()) { - return MutationResult.failure( - "Insert failed after delete: " + insertResult.getMessage() - ); - } - - return insertResult; - } - /** * Clears statements from the specified contexts. * diff --git a/src/main/java/fr/inria/corese/core/next/storagemanager/api/plugin/ExternalPluginLoader.java b/src/main/java/fr/inria/corese/core/next/storagemanager/api/plugin/ExternalPluginLoader.java index b0a9335cb..731cf489f 100644 --- a/src/main/java/fr/inria/corese/core/next/storagemanager/api/plugin/ExternalPluginLoader.java +++ b/src/main/java/fr/inria/corese/core/next/storagemanager/api/plugin/ExternalPluginLoader.java @@ -84,12 +84,4 @@ public static int loadPluginsFromJar(File jarFile) throws Exception { return count; } - - /** - * Clears all loaded class loaders. - */ - public static void clear() { - logger.info("Clearing {} loaded class loaders", loadedClassLoaders.size()); - loadedClassLoaders.clear(); - } } \ No newline at end of file diff --git a/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/config/StorageConfig.java b/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/config/StorageConfig.java index 8bd4db9ca..64b53ec03 100644 --- a/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/config/StorageConfig.java +++ b/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/config/StorageConfig.java @@ -62,15 +62,6 @@ public Map getProperties() { return properties; } - /** - * Returns whether transaction support is enabled. - * - * @return {@code true} if transaction support is enabled - */ - public boolean hasTransactionSupport() { - return transactionSupport; - } - /** * Returns the storage type from properties. * @@ -135,17 +126,6 @@ public Builder property(String key, Object value) { return this; } - /** - * Enables or disables transaction support. - * - * @param enable {@code true} to enable transaction support - * @return this builder for method chaining - */ - public Builder transactionSupport(boolean enable) { - this.transactionSupport = enable; - return this; - } - /** * Builds the {@link StorageConfig} instance with the current configuration. * diff --git a/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/exception/ErrorCode.java b/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/exception/ErrorCode.java index 726a3a6a9..840bc9a7f 100644 --- a/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/exception/ErrorCode.java +++ b/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/exception/ErrorCode.java @@ -52,11 +52,4 @@ public enum ErrorCode { this.description = description; } - public String getCode() { - return code; - } - - public String getDescription() { - return description; - } } diff --git a/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/exception/StorageException.java b/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/exception/StorageException.java index 5d78a05d0..ec1754055 100644 --- a/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/exception/StorageException.java +++ b/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/exception/StorageException.java @@ -30,15 +30,6 @@ public StorageException(ErrorCode code, String message, Throwable cause) { this.code = code; } - /** - * Returns the error code. - * - * @return Error code - */ - public ErrorCode getCode() { - return code; - } - @Override public String toString() { return "StorageException{" + diff --git a/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/model/MutationResult.java b/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/model/MutationResult.java index 8a118e85c..36dbb7c93 100644 --- a/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/model/MutationResult.java +++ b/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/model/MutationResult.java @@ -332,10 +332,6 @@ public BulkBuilder message(String message) { return this; } - public void incrementSuccess() { - this.successCount++; - } - public BulkBuilder addSuccess(Statement statement) { if (statement != null) { diff --git a/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/model/StorageStatistics.java b/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/model/StorageStatistics.java index 3b5e70a20..ce1bc0288 100644 --- a/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/model/StorageStatistics.java +++ b/src/main/java/fr/inria/corese/core/next/storagemanager/api/support/model/StorageStatistics.java @@ -24,41 +24,4 @@ public record StorageStatistics( } } - /** - * Checks whether the storage is empty (contains no statements). - * - * @return {@code true} if {@code statementCount == 0} - */ - public boolean isEmpty() { - return statementCount == 0; - } - - /** - * Calculates the average number of statements per unique subject. - * - * @return the average statements per subject, or {@code 0.0} if no subjects exist - */ - public double getAverageStatementsPerSubject() { - return subjectCount > 0 ? (double) statementCount / subjectCount : 0.0; - } - - /** - * Calculates the average number of statements per unique predicate. - * - * - * @return the average statements per predicate, or {@code 0.0} if no predicates exist - */ - public double getAverageStatementsPerPredicate() { - return predicateCount > 0 ? (double) statementCount / predicateCount : 0.0; - } - - /** - * Calculates the average number of statements per named graph (context). - * - * - * @return the average statements per context, or {@code 0.0} if no contexts exist - */ - public double getAverageStatementsPerContext() { - return contextCount > 0 ? (double) statementCount / contextCount : 0.0; - } } \ No newline at end of file diff --git a/src/main/java/fr/inria/corese/core/next/storagemanager/api/transaction/IsolationLevel.java b/src/main/java/fr/inria/corese/core/next/storagemanager/api/transaction/IsolationLevel.java index 3d876772b..d82964586 100644 --- a/src/main/java/fr/inria/corese/core/next/storagemanager/api/transaction/IsolationLevel.java +++ b/src/main/java/fr/inria/corese/core/next/storagemanager/api/transaction/IsolationLevel.java @@ -35,14 +35,4 @@ public enum IsolationLevel { this.level = level; } - /** - * Returns the numeric isolation level. - * Higher number means stricter isolation. - * - * @return Numeric level - */ - public int getLevel() { - return level; - } - } \ No newline at end of file diff --git a/src/main/java/fr/inria/corese/core/next/storagemanager/api/transaction/TransactionManager.java b/src/main/java/fr/inria/corese/core/next/storagemanager/api/transaction/TransactionManager.java index b39faaa03..cc020215e 100644 --- a/src/main/java/fr/inria/corese/core/next/storagemanager/api/transaction/TransactionManager.java +++ b/src/main/java/fr/inria/corese/core/next/storagemanager/api/transaction/TransactionManager.java @@ -45,15 +45,6 @@ public interface TransactionManager { */ Optional getCurrentTransaction(); - /** - * Checks if a transaction is active on the current thread. - * - * @return true if a transaction is active - */ - default boolean hasActiveTransaction() { - return getCurrentTransaction().map(Transaction::isActive).orElse(false); - } - /** * Returns the default isolation level used for new transactions. * diff --git a/src/main/java/fr/inria/corese/core/next/storagemanager/impl/graph/GraphAdapter.java b/src/main/java/fr/inria/corese/core/next/storagemanager/impl/graph/GraphAdapter.java index eb6c13b8b..11c3adfb1 100644 --- a/src/main/java/fr/inria/corese/core/next/storagemanager/impl/graph/GraphAdapter.java +++ b/src/main/java/fr/inria/corese/core/next/storagemanager/impl/graph/GraphAdapter.java @@ -60,17 +60,6 @@ public boolean remove(Statement stmt) { return true; } - /** - * Checks if a statement exists in the underlying Graph. - * - * @param stmt the statement to check - * @return true if the statement exists - */ - public boolean contains(Statement stmt) { - Edge edge = statementToEdge(stmt); - return graph.exist(edge); - } - /** * Finds all statements matching the given pattern. * diff --git a/src/main/java/fr/inria/corese/core/next/storagemanager/impl/transaction/TransactionImpl.java b/src/main/java/fr/inria/corese/core/next/storagemanager/impl/transaction/TransactionImpl.java deleted file mode 100644 index 24cd0a3d6..000000000 --- a/src/main/java/fr/inria/corese/core/next/storagemanager/impl/transaction/TransactionImpl.java +++ /dev/null @@ -1,209 +0,0 @@ -package fr.inria.corese.core.next.storagemanager.impl.transaction; - -import fr.inria.corese.core.next.storagemanager.api.support.exception.StorageException; -import fr.inria.corese.core.next.storagemanager.api.support.exception.ErrorCode; -import fr.inria.corese.core.next.storagemanager.api.transaction.IsolationLevel; -import fr.inria.corese.core.next.storagemanager.api.transaction.Transaction; -import fr.inria.corese.core.next.storagemanager.api.transaction.TransactionState; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.time.Instant; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicReference; - -/** - * Implementation of a transaction handle for Model operations. - */ -public class TransactionImpl implements Transaction { - - private static final Logger logger = LoggerFactory.getLogger(TransactionImpl.class); - - private final String id; - private final IsolationLevel isolationLevel; - private final Instant startTime; - private final TransactionCallback callback; - - /** - * Thread-safe reference to the current state of the transaction. - */ - private final AtomicReference state; - - /** - * Callback interface for transaction operations. - * Allows the TransactionManager or DataManager to be notified of lifecycle changes. - */ - public interface TransactionCallback { - /** - * Invoked when the transaction is requested to commit. - * - * @param transaction the transaction being committed. - * @throws StorageException if the commit operation fails. - */ - void onCommit(TransactionImpl transaction) throws StorageException; - - /** - * Invoked when the transaction is requested to rollback. - * - * @param transaction the transaction being rolled back. - * @throws StorageException if the rollback operation fails. - */ - void onRollback(TransactionImpl transaction) throws StorageException; - } - - /** - * Constructs a new transaction handle. - * - * @param isolationLevel the requested isolation level for this transaction. - * @param callback the callback to handle persistence of changes. - */ - public TransactionImpl(IsolationLevel isolationLevel, TransactionCallback callback) { - this.id = UUID.randomUUID().toString(); - this.isolationLevel = isolationLevel; - this.startTime = Instant.now(); - this.callback = callback; - this.state = new AtomicReference<>(TransactionState.ACTIVE); - - logger.debug("Transaction {} started with isolation level {}", id, isolationLevel); - } - - @Override - public String getId() { - return id; - } - - /** - * Commits the changes made during this transaction. - * - * @throws IllegalStateException if the transaction is not in an ACTIVE state. - */ - @Override - public void commit() throws StorageException { - TransactionState currentState = state.get(); - - if (!currentState.isActive()) { - throw new IllegalStateException( - "Cannot commit transaction in state: " + currentState - ); - } - - logger.debug("Committing transaction {}", id); - - try { - // Execute the commit logic via the registered callback - callback.onCommit(this); - - // Atomically update state to COMMITTED - if (!state.compareAndSet(TransactionState.ACTIVE, TransactionState.COMMITTED)) { - throw new IllegalStateException( - "Transaction state changed during commit process" - ); - } - - logger.info("Transaction {} committed successfully", id); - - } catch (StorageException e) { - state.set(TransactionState.FAILED); - logger.error("Failed to commit transaction {}", id, e); - throw e; - - } catch (Exception e) { - state.set(TransactionState.FAILED); - logger.error("Unexpected error during commit of transaction {}", id, e); - throw new StorageException( - ErrorCode.TRANSACTION_ERROR, - "Failed to commit transaction: " + e.getMessage(), - e - ); - } - } - - /** - * Reverts the changes made during this transaction. - * - * @throws IllegalStateException if the transaction is not in an ACTIVE state. - * @throws StorageException if the rollback operation fails. - */ - @Override - public void rollback() throws StorageException { - TransactionState currentState = state.get(); - - if (!currentState.isActive()) { - throw new IllegalStateException( - "Cannot rollback transaction in state: " + currentState - ); - } - - logger.debug("Rolling back transaction {}", id); - - try { - // Execute the rollback logic via the registered callback - callback.onRollback(this); - - // Atomically update state to ROLLED_BACK - if (!state.compareAndSet(TransactionState.ACTIVE, TransactionState.ROLLED_BACK)) { - throw new IllegalStateException( - "Transaction state changed during rollback process" - ); - } - - logger.info("Transaction {} rolled back successfully", id); - - } catch (StorageException e) { - state.set(TransactionState.FAILED); - logger.error("Failed to rollback transaction {}", id, e); - throw e; - - } catch (Exception e) { - state.set(TransactionState.FAILED); - logger.error("Unexpected error during rollback of transaction {}", id, e); - throw new StorageException( - ErrorCode.TRANSACTION_ERROR, - "Failed to rollback transaction: " + e.getMessage(), - e - ); - } - } - - @Override - public boolean isActive() { - return state.get().isActive(); - } - - @Override - public TransactionState getState() { - return state.get(); - } - - /** - * Closes the transaction. If the transaction is still active, an automatic rollback is performed. - * - * @throws StorageException if an automatic rollback fails. - */ - @Override - public void close() throws StorageException { - TransactionState currentState = state.get(); - - if (currentState.isActive()) { - logger.warn("Transaction {} closed while still active; performing automatic rollback", id); - try { - rollback(); - } catch (StorageException e) { - logger.error("Failed to perform auto-rollback for transaction {}", id, e); - throw e; - } - } - - logger.debug("Transaction {} closed in state {}", id, state.get()); - } - - @Override - public String toString() { - return "Transaction{" + - "id='" + id + '\'' + - ", isolationLevel=" + isolationLevel + - ", state=" + state.get() + - ", startTime=" + startTime + - '}'; - } -} \ No newline at end of file