From 20be93a1755234b0a47fcea67ebea7ed002fe09c Mon Sep 17 00:00:00 2001 From: Tobias Hafner Date: Wed, 27 Nov 2024 16:20:52 +0100 Subject: [PATCH] Add granular locking for ddls --- .../polypheny/db/catalog/entity/Entity.java | 2 +- .../entity/logical/LogicalCollection.java | 2 +- .../catalog/entity/logical/LogicalGraph.java | 2 +- .../entity/logical/LogicalNamespace.java | 2 +- .../catalog/entity/logical/LogicalTable.java | 2 +- .../polypheny/db/config/RuntimeConfig.java | 2 +- .../db/nodes/ExecutableStatement.java | 5 +- .../nodes/UnsupportedExecutableStatement.java | 9 ++ .../polypheny/db/processing/Processor.java | 8 +- .../transaction/locking/LockableObject.java | 2 +- .../locking/AlgEntityLockablesExtractor.java | 31 +----- ...chemaLockable.java => GlobalLockable.java} | 4 +- .../db/transaction/locking/LockableUtils.java | 96 ++++++++++++++++--- .../locking/LockablesRegistry.java | 5 +- .../admin/CypherAlterNamespaceAlias.java | 11 +++ .../cypher/admin/CypherCreateNamespace.java | 12 +++ .../admin/CypherCreateNamespaceAlias.java | 11 +++ .../db/cypher/admin/CypherDropAlias.java | 10 ++ .../db/cypher/admin/CypherDropNamespace.java | 10 ++ .../cypher/clause/CypherCreateConstraint.java | 9 ++ .../db/cypher/clause/CypherUseClause.java | 9 ++ .../db/cypher/ddl/CypherAddPlacement.java | 12 +++ .../db/cypher/ddl/CypherDropPlacement.java | 10 ++ .../db/cypher/expression/CypherUseGraph.java | 10 ++ .../db/cypher/query/CypherSingleQuery.java | 13 +++ .../db/languages/mql/MqlAddPlacement.java | 11 +++ .../db/languages/mql/MqlCreateCollection.java | 12 +++ .../db/languages/mql/MqlCreateView.java | 10 ++ .../db/languages/mql/MqlDeletePlacement.java | 10 ++ .../polypheny/db/languages/mql/MqlDrop.java | 21 ++++ .../db/languages/mql/MqlDropNamespace.java | 12 +++ .../db/languages/mql/MqlRenameCollection.java | 13 +++ .../db/languages/mql/MqlUseNamespace.java | 10 ++ .../org/polypheny/db/sql/language/SqlDdl.java | 31 ++++++ .../db/sql/language/SqlSetOption.java | 11 +++ .../sql/language/ddl/SqlAlterAdaptersAdd.java | 10 ++ .../language/ddl/SqlAlterAdaptersDrop.java | 11 +++ .../db/sql/language/ddl/SqlAlterConfig.java | 11 +++ .../language/ddl/SqlAlterInterfacesAdd.java | 9 ++ .../language/ddl/SqlAlterInterfacesDrop.java | 14 +++ .../db/sql/language/ddl/SqlAlterView.java | 4 + .../ddl/SqlCreateMaterializedView.java | 12 +++ .../sql/language/ddl/SqlCreateNamespace.java | 12 ++- .../db/sql/language/ddl/SqlCreateTable.java | 13 +++ .../db/sql/language/ddl/SqlCreateType.java | 14 +++ .../db/sql/language/ddl/SqlCreateView.java | 13 +++ .../db/sql/language/ddl/SqlDropFunction.java | 12 +++ .../language/ddl/SqlDropMaterializedView.java | 10 ++ .../db/sql/language/ddl/SqlDropNamespace.java | 14 +++ .../db/sql/language/ddl/SqlDropTable.java | 8 ++ .../db/sql/language/ddl/SqlDropType.java | 10 ++ .../db/sql/language/ddl/SqlDropView.java | 8 ++ .../db/sql/language/ddl/SqlTruncate.java | 8 ++ .../SqlAlterMaterializedViewAddIndex.java | 10 ++ .../SqlAlterMaterializedViewDropIndex.java | 9 ++ ...lAlterMaterializedViewFreshnessManual.java | 10 ++ .../SqlAlterMaterializedViewRename.java | 10 ++ .../SqlAlterMaterializedViewRenameColumn.java | 10 ++ .../SqlAlterNamespaceOwner.java | 10 ++ .../SqlAlterNamespaceRename.java | 13 +++ .../SqlAlterSourceTableAddColumn.java | 10 ++ .../altertable/SqlAlterTableAddColumn.java | 10 ++ .../SqlAlterTableAddForeignKey.java | 10 ++ .../ddl/altertable/SqlAlterTableAddIndex.java | 10 ++ .../SqlAlterTableAddPartitions.java | 10 ++ .../altertable/SqlAlterTableAddPlacement.java | 10 ++ .../SqlAlterTableAddPrimaryKey.java | 10 ++ .../SqlAlterTableAddUniqueConstraint.java | 10 ++ .../altertable/SqlAlterTableDropColumn.java | 10 ++ .../SqlAlterTableDropConstraint.java | 10 ++ .../SqlAlterTableDropForeignKey.java | 12 +++ .../altertable/SqlAlterTableDropIndex.java | 10 ++ .../SqlAlterTableDropPlacement.java | 10 ++ .../SqlAlterTableDropPrimaryKey.java | 10 ++ .../SqlAlterTableMergePartitions.java | 10 ++ .../altertable/SqlAlterTableModifyColumn.java | 10 ++ .../SqlAlterTableModifyPartitions.java | 10 ++ .../SqlAlterTableModifyPlacement.java | 10 ++ ...SqlAlterTableModifyPlacementAddColumn.java | 10 ++ ...qlAlterTableModifyPlacementDropColumn.java | 10 ++ .../ddl/altertable/SqlAlterTableOwner.java | 10 ++ .../ddl/altertable/SqlAlterTableRename.java | 10 ++ .../altertable/SqlAlterTableRenameColumn.java | 11 +++ .../ddl/alterview/SqlAlterViewRename.java | 11 +++ .../alterview/SqlAlterViewRenameColumn.java | 12 +++ 85 files changed, 891 insertions(+), 60 deletions(-) rename dbms/src/main/java/org/polypheny/db/transaction/locking/{GlobalSchemaLockable.java => GlobalLockable.java} (88%) diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/Entity.java b/core/src/main/java/org/polypheny/db/catalog/entity/Entity.java index 80fafb9634..cf7bcb173c 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/Entity.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/Entity.java @@ -163,7 +163,7 @@ public int compareTo( @NotNull Entity o ) { return Long.compare( this.id, o.id ); } - public ObjectType getObjectType() { + public ObjectType getLockableObjectType() { throw new UnsupportedOperationException( "Should be overwritten by child" ); } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalCollection.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalCollection.java index 98b091bfa3..f4fa1ae8cd 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalCollection.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalCollection.java @@ -53,7 +53,7 @@ public Expression asExpression() { @Override - public ObjectType getObjectType() { + public ObjectType getLockableObjectType() { return ObjectType.ENTITY; } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalGraph.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalGraph.java index 0167d49ecd..bc01c37083 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalGraph.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalGraph.java @@ -65,7 +65,7 @@ public Expression asExpression() { @Override - public ObjectType getObjectType() { + public ObjectType getLockableObjectType() { return ObjectType.ENTITY; } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalNamespace.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalNamespace.java index f2db635a86..0413675ca4 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalNamespace.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalNamespace.java @@ -77,7 +77,7 @@ public int compareTo( LogicalNamespace o ) { @Override - public ObjectType getObjectType() { + public ObjectType getLockableObjectType() { return ObjectType.NAMESPACE; } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalTable.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalTable.java index 5e332f83b8..6f892d0e17 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalTable.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalTable.java @@ -124,7 +124,7 @@ public List getConstraintIds() { @Override - public ObjectType getObjectType() { + public ObjectType getLockableObjectType() { return ObjectType.ENTITY; } diff --git a/core/src/main/java/org/polypheny/db/config/RuntimeConfig.java b/core/src/main/java/org/polypheny/db/config/RuntimeConfig.java index c70e71ccd4..c28cf20042 100644 --- a/core/src/main/java/org/polypheny/db/config/RuntimeConfig.java +++ b/core/src/main/java/org/polypheny/db/config/RuntimeConfig.java @@ -38,7 +38,7 @@ public enum RuntimeConfig { S2PL_LOCKING_LEVEL( "runtime/s2plLockingLevel", "Define the granularity of lock acquisition.", - S2plLockingLevel.GLOBAL, + S2plLockingLevel.ENTITY, ConfigType.ENUM ), diff --git a/core/src/main/java/org/polypheny/db/nodes/ExecutableStatement.java b/core/src/main/java/org/polypheny/db/nodes/ExecutableStatement.java index 3fafbfe28f..2e39bab32b 100644 --- a/core/src/main/java/org/polypheny/db/nodes/ExecutableStatement.java +++ b/core/src/main/java/org/polypheny/db/nodes/ExecutableStatement.java @@ -17,9 +17,12 @@ package org.polypheny.db.nodes; +import java.util.Map; import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; /** @@ -29,5 +32,5 @@ public interface ExecutableStatement { void execute( Context context, Statement statement, ParsedQueryContext parsedQueryContext ); - + Map deriveLockables(Context context, ParsedQueryContext parsedQueryContext); } diff --git a/core/src/main/java/org/polypheny/db/nodes/UnsupportedExecutableStatement.java b/core/src/main/java/org/polypheny/db/nodes/UnsupportedExecutableStatement.java index d5e695191c..a5b2ab6803 100644 --- a/core/src/main/java/org/polypheny/db/nodes/UnsupportedExecutableStatement.java +++ b/core/src/main/java/org/polypheny/db/nodes/UnsupportedExecutableStatement.java @@ -16,9 +16,14 @@ package org.polypheny.db.nodes; +import java.util.HashMap; +import java.util.Map; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; /** @@ -31,4 +36,8 @@ default void execute( Context context, Statement statement, ParsedQueryContext p throw new UnsupportedOperationException( "The operation is not supported by the used language." ); } + @Override + default Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return Map.of(); + } } diff --git a/core/src/main/java/org/polypheny/db/processing/Processor.java b/core/src/main/java/org/polypheny/db/processing/Processor.java index 9095b82534..fc64fc1594 100644 --- a/core/src/main/java/org/polypheny/db/processing/Processor.java +++ b/core/src/main/java/org/polypheny/db/processing/Processor.java @@ -18,6 +18,7 @@ import java.util.List; +import java.util.Map; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.PolyImplementation; import org.polypheny.db.algebra.AlgRoot; @@ -32,6 +33,7 @@ import org.polypheny.db.transaction.Transaction; import org.polypheny.db.transaction.TransactionException; import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; import org.polypheny.db.util.DeadlockException; import org.polypheny.db.util.Pair; @@ -47,9 +49,9 @@ public abstract class Processor { public PolyImplementation prepareDdl( Statement statement, ExecutableStatement node, ParsedQueryContext context ) { try { - // Acquire global schema lock - lock( statement.getTransaction(), context ); - // Execute statement + Map requiredLockables = node.deriveLockables( statement.getPrepareContext(), context ); + Transaction transaction = statement.getTransaction(); + requiredLockables.forEach( transaction::acquireLockable ); return getImplementation( statement, node, context ); } catch ( DeadlockException e ) { throw new DeadlockException( e.getMessage() + " Exception while acquiring global schema lock" ); diff --git a/core/src/main/java/org/polypheny/db/transaction/locking/LockableObject.java b/core/src/main/java/org/polypheny/db/transaction/locking/LockableObject.java index e2d83dc070..35f6703e4c 100644 --- a/core/src/main/java/org/polypheny/db/transaction/locking/LockableObject.java +++ b/core/src/main/java/org/polypheny/db/transaction/locking/LockableObject.java @@ -23,5 +23,5 @@ enum ObjectType { ENTITY } - ObjectType getObjectType(); + ObjectType getLockableObjectType(); } diff --git a/dbms/src/main/java/org/polypheny/db/transaction/locking/AlgEntityLockablesExtractor.java b/dbms/src/main/java/org/polypheny/db/transaction/locking/AlgEntityLockablesExtractor.java index 1789f55d3c..b7ba6fea79 100644 --- a/dbms/src/main/java/org/polypheny/db/transaction/locking/AlgEntityLockablesExtractor.java +++ b/dbms/src/main/java/org/polypheny/db/transaction/locking/AlgEntityLockablesExtractor.java @@ -24,7 +24,6 @@ import org.polypheny.db.algebra.AlgVisitor; import org.polypheny.db.algebra.core.relational.RelAlg; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.config.RuntimeConfig; import org.polypheny.db.partition.properties.PartitionProperty; @@ -60,7 +59,7 @@ private void visitRelationalNode( AlgNode currentNode ) { if ( RuntimeConfig.FOREIGN_KEY_ENFORCEMENT.getBoolean() ) { extractWriteConstraints( currentNode.getEntity().unwrap( LogicalTable.class ).orElseThrow() ); } - addResult( currentNode.getEntity(), lockType); + LockableUtils.updateMapOfDerivedLockables( currentNode.getEntity(), lockType, result ); } @@ -73,36 +72,12 @@ private void extractWriteConstraints( LogicalTable logicalTable ) { .filter( Optional::isPresent ) .map( Optional::get ); } ) - .forEach( entry -> addResult( entry, LockType.SHARED ) ); + .forEach( entry -> LockableUtils.updateMapOfDerivedLockables( entry, LockType.SHARED, result ) ); } private void visitNonRelationalNode( AlgNode currentNode ) { LockType lockType = currentNode.isDataModifying() ? LockType.EXCLUSIVE : LockType.SHARED; - result.put( LockablesRegistry.INSTANCE.getOrCreateLockable(LockableUtils.unwrapToLockableObject(currentNode.getEntity())) , lockType ); + LockableUtils.updateMapOfDerivedLockables( currentNode.getEntity(), lockType, result ); } - - private void addResult(Entity entity, LockType lockType) { - switch ((S2plLockingLevel) RuntimeConfig.S2PL_LOCKING_LEVEL.getEnum()) { - case GLOBAL -> { - LockType currentLockType = result.get( LockablesRegistry.GLOBAL_SCHEMA_LOCKABLE ); - if ( currentLockType == null || currentLockType == LockType.EXCLUSIVE ) { - result.put( LockablesRegistry.GLOBAL_SCHEMA_LOCKABLE, lockType ); - - } - } - case NAMESPACE -> { - Lockable lockable = LockablesRegistry.INSTANCE.getOrCreateLockable(LockableUtils.getNamespaceLockableObjectOfEntity(entity)); - LockType currentLockType = result.get( lockable ); - if ( currentLockType == null || currentLockType == LockType.EXCLUSIVE ) { - result.put( lockable, lockType ); - } - } - case ENTITY -> { - Lockable lockable = LockablesRegistry.INSTANCE.getOrCreateLockable(entity); - result.put(lockable, lockType); - } - } - } - } diff --git a/dbms/src/main/java/org/polypheny/db/transaction/locking/GlobalSchemaLockable.java b/dbms/src/main/java/org/polypheny/db/transaction/locking/GlobalLockable.java similarity index 88% rename from dbms/src/main/java/org/polypheny/db/transaction/locking/GlobalSchemaLockable.java rename to dbms/src/main/java/org/polypheny/db/transaction/locking/GlobalLockable.java index ee1a5b5fdd..4ea33da7b6 100644 --- a/dbms/src/main/java/org/polypheny/db/transaction/locking/GlobalSchemaLockable.java +++ b/dbms/src/main/java/org/polypheny/db/transaction/locking/GlobalLockable.java @@ -16,9 +16,9 @@ package org.polypheny.db.transaction.locking; -public class GlobalSchemaLockable extends LockableImpl { +public class GlobalLockable extends LockableImpl { - public GlobalSchemaLockable() { + public GlobalLockable() { super( null ); } diff --git a/dbms/src/main/java/org/polypheny/db/transaction/locking/LockableUtils.java b/dbms/src/main/java/org/polypheny/db/transaction/locking/LockableUtils.java index fcb8fa8a4f..0caa123ece 100644 --- a/dbms/src/main/java/org/polypheny/db/transaction/locking/LockableUtils.java +++ b/dbms/src/main/java/org/polypheny/db/transaction/locking/LockableUtils.java @@ -16,25 +16,23 @@ package org.polypheny.db.transaction.locking; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; import lombok.NonNull; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.Entity; +import org.polypheny.db.catalog.entity.logical.LogicalCollection; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; +import org.polypheny.db.config.RuntimeConfig; +import org.polypheny.db.prepare.Context; +import org.polypheny.db.processing.QueryContext.ParsedQueryContext; +import org.polypheny.db.transaction.locking.Lockable.LockType; public class LockableUtils { - public static LockableObject unwrapToLockableObject( Entity entity ) { - Optional lockableObject = entity.unwrap( LockableObject.class ); - if ( lockableObject.isPresent() ) { - return lockableObject.get(); - } - throw new RuntimeException( "Could not unwrap lockableObject" ); - } - - public static Lockable convertToLockable( @NonNull LockableObject lockableObject ) { - switch ( lockableObject.getObjectType() ) { + switch ( lockableObject.getLockableObjectType() ) { case NAMESPACE -> { return convertNamespaceToLockable( lockableObject ); } @@ -43,11 +41,8 @@ public static Lockable convertToLockable( @NonNull LockableObject lockableObject return convertEntityToLockable( lockableObject ); } - default -> { - throw new IllegalArgumentException( "Can not convert object of unknown type to lockable: " + lockableObject.getObjectType() ); - } + default -> throw new IllegalArgumentException( "Can not convert object of unknown type to lockable: " + lockableObject.getLockableObjectType() ); } - } @@ -68,4 +63,77 @@ public static LockableObject getNamespaceLockableObjectOfEntity( Entity entity ) return Catalog.getInstance().getSnapshot().getNamespace( entity.getNamespaceId() ).orElseThrow(); } + + public static void updateMapOfDerivedLockables( Entity entity, LockType lockType, Map currentLockables ) { + switch ( (S2plLockingLevel) RuntimeConfig.S2PL_LOCKING_LEVEL.getEnum() ) { + case GLOBAL -> updateLockableMapEntry( LockablesRegistry.GLOBAL_SCHEMA_LOCKABLE, lockType, currentLockables ); + case NAMESPACE -> { + Lockable lockable = LockablesRegistry.INSTANCE.getOrCreateLockable( LockableUtils.getNamespaceLockableObjectOfEntity( entity ) ); + updateLockableMapEntry( lockable, lockType, currentLockables ); + } + case ENTITY -> { + Lockable lockable = LockablesRegistry.INSTANCE.getOrCreateLockable( entity ); + updateLockableMapEntry( lockable, lockType, currentLockables ); + } + } + } + + + public static void updateMapOfDerivedLockables( LockableObject lockableObject, LockType lockType, Map currentLockables ) { + switch ( lockableObject.getLockableObjectType() ) { + case NAMESPACE -> { + S2plLockingLevel lockingLevel = (S2plLockingLevel) RuntimeConfig.S2PL_LOCKING_LEVEL.getEnum(); + if ( lockingLevel == S2plLockingLevel.GLOBAL ) { + updateLockableMapEntry( LockablesRegistry.GLOBAL_SCHEMA_LOCKABLE, lockType, currentLockables ); + return; + } + // this always returns a lockable on namespace level as we checked the lockable object type + Lockable lockable = LockablesRegistry.INSTANCE.getOrCreateLockable( lockableObject ); + updateLockableMapEntry( lockable, lockType, currentLockables ); + } + case ENTITY -> updateMapOfDerivedLockables( (Entity) lockableObject, lockType, currentLockables ); + } + } + + + private static void updateLockableMapEntry( Lockable lockable, LockType lockType, Map currentLockables ) { + LockType currentLockType = currentLockables.get( lockable ); + if ( currentLockType == null || currentLockType == LockType.EXCLUSIVE ) { + currentLockables.put( lockable, lockType ); + } + } + + public static Map getMapWithGlobalLockable(LockType lockType) { + HashMap lockableObjects = new HashMap<>(); + lockableObjects.put( LockablesRegistry.GLOBAL_SCHEMA_LOCKABLE, lockType ); + return lockableObjects; + } + + public static Map getMapOfNamespaceLockable(String namespaceName, Context context, LockType lockType) { + Optional logicalNamespace = context.getSnapshot().getNamespace( namespaceName ); + HashMap lockableObjects = new HashMap<>(); + logicalNamespace.ifPresent( n -> LockableUtils.updateMapOfDerivedLockables( n, lockType, lockableObjects ) ); + return lockableObjects; + } + + public static Map getMapOfNamespaceLockableFromContext(Context context, ParsedQueryContext parsedQueryContext, LockType lockType) { + long namespaceId = parsedQueryContext.getNamespaceId(); + LogicalNamespace namespace = context.getSnapshot().getNamespace( namespaceId ).orElseThrow(); + return getMapOfLockableFromObject( namespace, lockType ); + } + + public static Map getMapOfCollectionLockableFromContext(Context context, ParsedQueryContext parsedQueryContext, LockType lockType) { + long namespaceId = parsedQueryContext.getQueryNode().orElseThrow().getNamespaceId(); + LogicalCollection collection = context.getSnapshot().doc().getCollection( namespaceId ).orElseThrow(); + return getMapOfLockableFromObject( collection, lockType ); + } + + public static Map getMapOfLockableFromObject(LockableObject lockableObject, LockType lockType) { + HashMap lockableObjects = new HashMap<>(); + LockableUtils.updateMapOfDerivedLockables( lockableObject, lockType, lockableObjects ); + return lockableObjects; + } + + + } diff --git a/dbms/src/main/java/org/polypheny/db/transaction/locking/LockablesRegistry.java b/dbms/src/main/java/org/polypheny/db/transaction/locking/LockablesRegistry.java index ed8f607476..e7587cff46 100644 --- a/dbms/src/main/java/org/polypheny/db/transaction/locking/LockablesRegistry.java +++ b/dbms/src/main/java/org/polypheny/db/transaction/locking/LockablesRegistry.java @@ -18,13 +18,10 @@ import java.util.concurrent.ConcurrentHashMap; import lombok.NonNull; -import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.entity.Entity; -import org.polypheny.db.catalog.entity.logical.LogicalNamespace; public class LockablesRegistry { - public static final GlobalSchemaLockable GLOBAL_SCHEMA_LOCKABLE = new GlobalSchemaLockable(); + public static final GlobalLockable GLOBAL_SCHEMA_LOCKABLE = new GlobalLockable(); public static final LockablesRegistry INSTANCE = new LockablesRegistry(); private final ConcurrentHashMap lockables = new ConcurrentHashMap<>(); diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherAlterNamespaceAlias.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherAlterNamespaceAlias.java index b924cdf812..b00a4229b1 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherAlterNamespaceAlias.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherAlterNamespaceAlias.java @@ -16,7 +16,10 @@ package org.polypheny.db.cypher.admin; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Optional; import lombok.Getter; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -29,6 +32,9 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; @Getter @@ -65,4 +71,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().replaceGraphAlias( graphs.get( 0 ).id, targetName, aliasName ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapWithGlobalLockable( LockType.EXCLUSIVE ); + } + } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateNamespace.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateNamespace.java index 51dcfcd260..d71fb7d560 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateNamespace.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateNamespace.java @@ -16,7 +16,9 @@ package org.polypheny.db.cypher.admin; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import lombok.Getter; import org.jetbrains.annotations.Nullable; @@ -33,6 +35,10 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; +import org.polypheny.db.transaction.locking.LockablesRegistry; @Getter @@ -101,6 +107,12 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapWithGlobalLockable( LockType.EXCLUSIVE ); + } + + @Override public boolean isDdl() { return true; diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateNamespaceAlias.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateNamespaceAlias.java index 8cea208971..488395b9a6 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateNamespaceAlias.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherCreateNamespaceAlias.java @@ -16,7 +16,10 @@ package org.polypheny.db.cypher.admin; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.concurrent.locks.Lock; import lombok.Getter; import org.jetbrains.annotations.Nullable; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; @@ -30,6 +33,9 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; @Getter @@ -76,4 +82,9 @@ public boolean isDdl() { return targetName; } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapOfNamespaceLockableFromContext( context, parsedQueryContext, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropAlias.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropAlias.java index e4bb728df7..870106cbf7 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropAlias.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropAlias.java @@ -16,7 +16,9 @@ package org.polypheny.db.cypher.admin; +import java.util.HashMap; import java.util.List; +import java.util.Map; import lombok.Getter; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -29,6 +31,9 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; @Getter @@ -60,4 +65,9 @@ public boolean isDdl() { return true; } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapWithGlobalLockable( LockType.EXCLUSIVE ); + } + } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropNamespace.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropNamespace.java index ca53ca8c4a..1e4cfa6c8d 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropNamespace.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/admin/CypherDropNamespace.java @@ -16,7 +16,9 @@ package org.polypheny.db.cypher.admin; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import org.jetbrains.annotations.Nullable; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; @@ -31,6 +33,9 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; public class CypherDropNamespace extends CypherAdminCommand implements ExecutableStatement { @@ -89,4 +94,9 @@ public boolean isDdl() { return databaseName; } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapOfNamespaceLockableFromContext( context, parsedQueryContext, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherCreateConstraint.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherCreateConstraint.java index b113f1ccd6..2a47b99008 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherCreateConstraint.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherCreateConstraint.java @@ -17,6 +17,7 @@ package org.polypheny.db.cypher.clause; import java.util.List; +import java.util.Map; import lombok.Getter; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.cypher.ConstraintType; @@ -31,6 +32,8 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; @Getter @@ -79,4 +82,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa throw new GenericRuntimeException( "Constraints are not supported yet for graph data." ); } + + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return Map.of(); + } + } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUseClause.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUseClause.java index 19ef0733d0..d937318986 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUseClause.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/clause/CypherUseClause.java @@ -16,6 +16,7 @@ package org.polypheny.db.cypher.clause; +import java.util.Map; import java.util.Optional; import lombok.Getter; import org.polypheny.db.cypher.expression.CypherExpression; @@ -24,6 +25,8 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; @Getter @@ -56,6 +59,12 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return Map.of(); + } + + @Override public Optional switchesNamespace() { return Optional.ofNullable( expression.getName() ); diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherAddPlacement.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherAddPlacement.java index 694ad4a19e..bc2ac6fd69 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherAddPlacement.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherAddPlacement.java @@ -16,7 +16,9 @@ package org.polypheny.db.cypher.ddl; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; import org.polypheny.db.adapter.Adapter; @@ -24,6 +26,7 @@ import org.polypheny.db.adapter.DataStore; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.logical.LogicalGraph; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.Pattern; import org.polypheny.db.cypher.CypherParameter; @@ -35,6 +38,10 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; +import org.polypheny.db.transaction.locking.LockablesRegistry; public class CypherAddPlacement extends CypherAdminCommand implements ExecutableStatement { @@ -86,4 +93,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().createGraphPlacement( graphs.get( 0 ).id, dataStores, statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapWithGlobalLockable( LockType.EXCLUSIVE ); + } + } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherDropPlacement.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherDropPlacement.java index 3b92db0fb3..ab6b0bbbfd 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherDropPlacement.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/ddl/CypherDropPlacement.java @@ -16,7 +16,9 @@ package org.polypheny.db.cypher.ddl; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Stream; import org.polypheny.db.adapter.AdapterManager; import org.polypheny.db.adapter.DataStore; @@ -32,6 +34,9 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; public class CypherDropPlacement extends CypherAdminCommand implements ExecutableStatement { @@ -66,4 +71,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().dropGraphPlacement( graphs.get( 0 ).id, dataStore, statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapWithGlobalLockable( LockType.EXCLUSIVE ); + } + } diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherUseGraph.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherUseGraph.java index 8d580ccefb..00f7694046 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherUseGraph.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/expression/CypherUseGraph.java @@ -16,6 +16,7 @@ package org.polypheny.db.cypher.expression; +import java.util.Map; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.cypher.admin.CypherWithGraph; @@ -25,6 +26,8 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; @Getter @Slf4j @@ -52,6 +55,13 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + //TODO TH: Does this make sense? + return Map.of(); + } + + @Override public boolean isDdl() { return true; diff --git a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/query/CypherSingleQuery.java b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/query/CypherSingleQuery.java index 54e1ab9c74..90fe023b9a 100644 --- a/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/query/CypherSingleQuery.java +++ b/plugins/cypher-language/src/main/java/org/polypheny/db/cypher/query/CypherSingleQuery.java @@ -16,8 +16,11 @@ package org.polypheny.db.cypher.query; +import java.util.HashMap; import java.util.List; +import java.util.Map; import lombok.Getter; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.cypher.CypherNode; import org.polypheny.db.cypher.clause.CypherClause; @@ -28,6 +31,9 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.type.entity.PolyString; @Getter @@ -98,4 +104,11 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } } + + // TODO TH: for now we lock the entire namespace (=graph) + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapOfNamespaceLockableFromContext( context, parsedQueryContext, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlAddPlacement.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlAddPlacement.java index ddc797c8d9..e9f4231730 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlAddPlacement.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlAddPlacement.java @@ -16,13 +16,16 @@ package org.polypheny.db.languages.mql; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.jetbrains.annotations.Nullable; import org.polypheny.db.adapter.Adapter; import org.polypheny.db.adapter.AdapterManager; import org.polypheny.db.adapter.DataStore; import org.polypheny.db.catalog.entity.logical.LogicalCollection; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.Pattern; import org.polypheny.db.ddl.DdlManager; @@ -32,6 +35,9 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; public class MqlAddPlacement extends MqlCollectionStatement implements ExecutableStatement { @@ -77,4 +83,9 @@ public Type getMqlKind() { return getCollection(); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapOfNamespaceLockableFromContext( context, parsedQueryContext, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateCollection.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateCollection.java index 7e8647efd7..0e526e36e5 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateCollection.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateCollection.java @@ -16,12 +16,15 @@ package org.polypheny.db.languages.mql; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.bson.BsonDocument; import org.jetbrains.annotations.Nullable; import org.polypheny.db.adapter.AdapterManager; import org.polypheny.db.adapter.DataStore; +import org.polypheny.db.catalog.entity.logical.LogicalCollection; import org.polypheny.db.catalog.logistic.PlacementType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; @@ -30,6 +33,10 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; +import org.polypheny.db.transaction.locking.LockablesRegistry; public class MqlCreateCollection extends MqlNode implements ExecutableStatement { @@ -86,4 +93,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapOfNamespaceLockableFromContext( context, parsedQueryContext, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateView.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateView.java index b33839ed74..47383a1ce5 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateView.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlCreateView.java @@ -16,6 +16,7 @@ package org.polypheny.db.languages.mql; +import java.util.Map; import org.bson.BsonArray; import org.bson.BsonDocument; import org.jetbrains.annotations.Nullable; @@ -33,6 +34,9 @@ import org.polypheny.db.processing.QueryContext; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; public class MqlCreateView extends MqlNode implements ExecutableStatement { @@ -76,6 +80,12 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapOfNamespaceLockableFromContext( context, parsedQueryContext, LockType.EXCLUSIVE ); + } + + private String getTransformedPipeline() { String json = new BsonDocument( "key", this.pipeline ).toJson(); return json.substring( 8, json.length() - 1 ); diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDeletePlacement.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDeletePlacement.java index 0ec27dd0ef..f3b2476c49 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDeletePlacement.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDeletePlacement.java @@ -16,7 +16,9 @@ package org.polypheny.db.languages.mql; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.jetbrains.annotations.Nullable; import org.polypheny.db.adapter.Adapter; @@ -31,6 +33,9 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; public class MqlDeletePlacement extends MqlCollectionStatement implements ExecutableStatement { @@ -72,4 +77,9 @@ public Type getMqlKind() { return getCollection(); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapOfCollectionLockableFromContext( context, parsedQueryContext, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDrop.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDrop.java index 125cce3efa..87581186d2 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDrop.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDrop.java @@ -16,8 +16,11 @@ package org.polypheny.db.languages.mql; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.concurrent.locks.Lock; import org.jetbrains.annotations.Nullable; import org.polypheny.db.catalog.entity.logical.LogicalCollection; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; @@ -29,6 +32,9 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; public class MqlDrop extends MqlCollectionStatement implements ExecutableStatement { @@ -70,4 +76,19 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa return getCollection(); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + long namespaceId = parsedQueryContext.getNamespaceId(); + Optional optionalNamespace = context.getSnapshot().getNamespace( namespaceId ); + if ( optionalNamespace.isEmpty() ) { + return Map.of(); + } + LogicalNamespace namespace = optionalNamespace.get(); + List collections = context.getSnapshot().doc().getCollections( namespace.id, new Pattern( collection ) ); + if ( collections.size() != 1 ) { + return Map.of(); + } + return LockableUtils.getMapOfLockableFromObject( collections.get(0), LockType.EXCLUSIVE ); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDropNamespace.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDropNamespace.java index 70303c5c4b..0e5027df0e 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDropNamespace.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlDropNamespace.java @@ -16,7 +16,11 @@ package org.polypheny.db.languages.mql; +import java.util.HashMap; +import java.util.Map; import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.catalog.entity.logical.LogicalCollection; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -24,6 +28,9 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; public class MqlDropNamespace extends MqlNode implements ExecutableStatement { @@ -46,5 +53,10 @@ public Type getMqlKind() { return Type.DROP_DATABASE; } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapOfNamespaceLockableFromContext( context, parsedQueryContext, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlRenameCollection.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlRenameCollection.java index 8c934b9b78..df934c1507 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlRenameCollection.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlRenameCollection.java @@ -16,8 +16,12 @@ package org.polypheny.db.languages.mql; +import java.util.HashMap; +import java.util.Map; import org.jetbrains.annotations.Nullable; +import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.logical.LogicalCollection; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.languages.mql.Mql.Type; @@ -25,6 +29,9 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; public class MqlRenameCollection extends MqlCollectionStatement implements ExecutableStatement { @@ -61,6 +68,12 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapOfCollectionLockableFromContext(context, parsedQueryContext, LockType.EXCLUSIVE ); + } + + @Override public @Nullable String getEntity() { return getCollection(); diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUseNamespace.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUseNamespace.java index 88044fcf21..b717b13c64 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUseNamespace.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/mql/MqlUseNamespace.java @@ -16,6 +16,7 @@ package org.polypheny.db.languages.mql; +import java.util.Map; import java.util.Optional; import lombok.Getter; import org.polypheny.db.catalog.logistic.DataModel; @@ -26,6 +27,9 @@ import org.polypheny.db.prepare.Context; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; @Getter @@ -50,6 +54,12 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapOfNamespaceLockable( namespace, context, LockType.SHARED ); + } + + @Override public Type getMqlKind() { return Type.USE_DATABASE; diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlDdl.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlDdl.java index f04700fb17..2b2bfc1808 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlDdl.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlDdl.java @@ -19,7 +19,9 @@ import static org.polypheny.db.util.Static.RESOURCE; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import org.jetbrains.annotations.NotNull; @@ -30,11 +32,15 @@ import org.polypheny.db.adapter.DataStore; import org.polypheny.db.catalog.entity.logical.LogicalColumn; import org.polypheny.db.catalog.entity.logical.LogicalEntity; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.Operator; import org.polypheny.db.prepare.Context; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.CoreUtil; @@ -100,6 +106,31 @@ protected LogicalTable getTableFailOnEmpty( Context context, SqlIdentifier table } + protected Map getMapOfTableLockable(SqlIdentifier identifier, Context context, LockType lockType) { + Optional logicalTable = searchEntity( context, identifier ); + HashMap lockableObjects = new HashMap<>(); + logicalTable.ifPresent( t -> LockableUtils.updateMapOfDerivedLockables( t, lockType, lockableObjects ) ); + return lockableObjects; + } + + protected Map getMapOfNamespaceLockable(SqlIdentifier identifier, Context context, LockType lockType) { + return LockableUtils.getMapOfNamespaceLockable( identifier.getSimple(), context, lockType ); + } + + + + protected Map getMapOfNamespaceLockableOrDefault(SqlIdentifier identifier, Context context, LockType lockType) { + if ( identifier.names.size() == 2 ) { // NamespaceName.ViewName + return LockableUtils.getMapOfNamespaceLockable( identifier.names.get( 0 ), context, lockType ); + } + if ( identifier.names.size() == 1 ) { // ViewName + return LockableUtils.getMapOfNamespaceLockable( context.getDefaultNamespaceName(), context, lockType ); + } + return Map.of(); + } + + + @Nullable protected LogicalColumn getColumn( Context context, long tableId, SqlIdentifier columnName ) { return context.getSnapshot().rel().getColumn( tableId, columnName.getSimple() ).orElse( null ); diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlSetOption.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlSetOption.java index 762e9820f4..02ecbb6971 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlSetOption.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlSetOption.java @@ -18,7 +18,9 @@ import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import lombok.Getter; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.ddl.DdlManager; @@ -32,6 +34,10 @@ import org.polypheny.db.sql.language.validate.SqlValidator; import org.polypheny.db.sql.language.validate.SqlValidatorScope; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; +import org.polypheny.db.transaction.locking.LockablesRegistry; import org.polypheny.db.util.ImmutableNullableList; @@ -216,4 +222,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().setOption(); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapWithGlobalLockable(LockType.EXCLUSIVE); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersAdd.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersAdd.java index a54a398d04..c52f633117 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersAdd.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersAdd.java @@ -18,6 +18,7 @@ import com.google.gson.Gson; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -39,6 +40,10 @@ import org.polypheny.db.sql.language.SqlSpecialOperator; import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; +import org.polypheny.db.transaction.locking.LockablesRegistry; import org.polypheny.db.util.ImmutableNullableList; @@ -124,5 +129,10 @@ private String removeQuotationMarks( String str ) { return str; } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapWithGlobalLockable(LockType.EXCLUSIVE); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersDrop.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersDrop.java index 91c28f64c7..f4527a4f22 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersDrop.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterAdaptersDrop.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.algebra.constant.Kind; @@ -33,6 +35,10 @@ import org.polypheny.db.sql.language.SqlSpecialOperator; import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; +import org.polypheny.db.transaction.locking.LockablesRegistry; import org.polypheny.db.util.ImmutableNullableList; @@ -84,5 +90,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapWithGlobalLockable(LockType.EXCLUSIVE); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterConfig.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterConfig.java index b9418e408f..6eacab2922 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterConfig.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterConfig.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.apache.commons.lang3.StringUtils; import org.polypheny.db.algebra.constant.Kind; @@ -34,6 +36,10 @@ import org.polypheny.db.sql.language.SqlSpecialOperator; import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; +import org.polypheny.db.transaction.locking.LockablesRegistry; import org.polypheny.db.util.ImmutableNullableList; @@ -103,4 +109,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa config.parseStringAndSetValue( valueStr ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapWithGlobalLockable(LockType.EXCLUSIVE); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesAdd.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesAdd.java index 2d487024f0..71eca0b21c 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesAdd.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesAdd.java @@ -18,6 +18,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -36,6 +37,10 @@ import org.polypheny.db.sql.language.SqlSpecialOperator; import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; +import org.polypheny.db.transaction.locking.LockablesRegistry; import org.polypheny.db.util.ImmutableNullableList; @@ -111,5 +116,9 @@ private String removeQuotationMarks( String str ) { return str; } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapWithGlobalLockable(LockType.EXCLUSIVE); + } } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesDrop.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesDrop.java index 7edc4703b5..3c6134a2d6 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesDrop.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterInterfacesDrop.java @@ -17,13 +17,18 @@ package org.polypheny.db.sql.language.ddl; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; +import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.iface.QueryInterfaceManager; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.Node; @@ -35,6 +40,10 @@ import org.polypheny.db.sql.language.SqlSpecialOperator; import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; +import org.polypheny.db.transaction.locking.LockablesRegistry; import org.polypheny.db.util.ImmutableNullableList; @@ -95,5 +104,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapWithGlobalLockable(LockType.EXCLUSIVE); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterView.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterView.java index 3c47286b10..8ad4e38096 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterView.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlAlterView.java @@ -16,11 +16,15 @@ package org.polypheny.db.sql.language.ddl; +import java.util.Map; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.languages.ParserPos; +import org.polypheny.db.prepare.Context; import org.polypheny.db.sql.language.SqlAlter; import org.polypheny.db.sql.language.SqlOperator; import org.polypheny.db.sql.language.SqlSpecialOperator; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableObject; /** diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateMaterializedView.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateMaterializedView.java index a1a933a7df..dd47a34e8b 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateMaterializedView.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateMaterializedView.java @@ -17,9 +17,12 @@ package org.polypheny.db.sql.language.ddl; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.concurrent.TimeUnit; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -32,6 +35,7 @@ import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.MaterializedCriteria; import org.polypheny.db.catalog.entity.MaterializedCriteria.CriteriaType; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.PlacementType; import org.polypheny.db.catalog.snapshot.Snapshot; @@ -53,6 +57,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.dialect.PolyphenyDbSqlDialect; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; import org.polypheny.db.view.MaterializedViewManager; @@ -259,4 +266,9 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { } } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext) { + return getMapOfNamespaceLockableOrDefault( name, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateNamespace.java index ca882e2db8..2a05a48147 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateNamespace.java @@ -18,6 +18,7 @@ import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.catalog.logistic.DataModel; @@ -34,9 +35,11 @@ import org.polypheny.db.sql.language.SqlSpecialOperator; import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; - /** * Parse tree for {@code CREATE NAMESPACE} statement (has alias for CREATE SCHEMA). */ @@ -93,4 +96,11 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().createNamespace( name.getSimple(), type, ifNotExists, replace, statement ); } + + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapWithGlobalLockable(LockType.EXCLUSIVE); + + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateTable.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateTable.java index b2c0739d10..79bd743741 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateTable.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateTable.java @@ -19,8 +19,11 @@ import com.google.common.collect.ImmutableList; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.Optional; import lombok.EqualsAndHashCode; import lombok.Value; import lombok.extern.slf4j.Slf4j; @@ -31,6 +34,7 @@ import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.logical.LogicalColumn; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.Collation; import org.polypheny.db.catalog.logistic.PlacementType; @@ -46,6 +50,7 @@ import org.polypheny.db.nodes.Node; import org.polypheny.db.partition.raw.RawPartitionInformation; import org.polypheny.db.prepare.Context; +import org.polypheny.db.prepare.Prepare; import org.polypheny.db.processing.QueryContext.ParsedQueryContext; import org.polypheny.db.sql.language.SqlCreate; import org.polypheny.db.sql.language.SqlIdentifier; @@ -57,6 +62,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.transaction.Statement; import org.polypheny.db.transaction.locking.EntityIdentifierUtils; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.type.PolyType; import org.polypheny.db.type.entity.PolyBinary; import org.polypheny.db.type.entity.PolyValue; @@ -325,5 +333,10 @@ private ConstraintInformation getConstraintInformation( String constraintName, S }; } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfNamespaceLockableOrDefault(name, context, LockType.EXCLUSIVE); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateType.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateType.java index 41f7595630..6a9ffb49b5 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateType.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateType.java @@ -17,9 +17,15 @@ package org.polypheny.db.sql.language.ddl; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.Optional; import org.polypheny.db.algebra.constant.Kind; +import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; +import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.ExecutableStatement; @@ -35,6 +41,9 @@ import org.polypheny.db.sql.language.SqlSpecialOperator; import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -101,6 +110,11 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { } } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapOfNamespaceLockable( name.getSimple(), context, LockType.EXCLUSIVE ); + } + /* @Override public void execute( Context context ) { diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateView.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateView.java index 94d003ebb0..9f3504af5b 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateView.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlCreateView.java @@ -18,8 +18,11 @@ import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.Optional; import lombok.Getter; import org.apache.calcite.linq4j.Ord; import org.polypheny.db.algebra.AlgCollation; @@ -27,6 +30,8 @@ import org.polypheny.db.algebra.AlgRoot; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.catalog.entity.logical.LogicalEntity; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.PlacementType; import org.polypheny.db.catalog.snapshot.Snapshot; @@ -48,6 +53,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.dialect.PolyphenyDbSqlDialect; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -185,5 +193,10 @@ public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { query.unparse( writer, 0, 0 ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfNamespaceLockableOrDefault(name, context, LockType.EXCLUSIVE); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropFunction.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropFunction.java index e12fe5d99b..118c4ea966 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropFunction.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropFunction.java @@ -17,7 +17,11 @@ package org.polypheny.db.sql.language.ddl; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; import org.polypheny.db.algebra.constant.Kind; +import org.polypheny.db.catalog.entity.logical.LogicalEntity; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.prepare.Context; @@ -26,6 +30,9 @@ import org.polypheny.db.sql.language.SqlOperator; import org.polypheny.db.sql.language.SqlSpecialOperator; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; /** @@ -49,5 +56,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().dropFunction(); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapWithGlobalLockable(LockType.EXCLUSIVE); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropMaterializedView.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropMaterializedView.java index 7aee4b7fe2..c642bcb495 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropMaterializedView.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropMaterializedView.java @@ -16,6 +16,8 @@ package org.polypheny.db.sql.language.ddl; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.catalog.entity.logical.LogicalEntity; @@ -30,6 +32,9 @@ import org.polypheny.db.sql.language.SqlOperator; import org.polypheny.db.sql.language.SqlSpecialOperator; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.view.MaterializedViewManager; public class SqlDropMaterializedView extends SqlDropObject { @@ -79,4 +84,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa materializedManager.isDroppingMaterialized = false; } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( name, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropNamespace.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropNamespace.java index 2a0470563c..2bac7436d4 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropNamespace.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropNamespace.java @@ -18,8 +18,15 @@ import com.google.common.collect.ImmutableList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Optional; import org.polypheny.db.algebra.constant.Kind; +import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; +import org.polypheny.db.catalog.entity.logical.LogicalTable; +import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.ExecutableStatement; @@ -33,6 +40,9 @@ import org.polypheny.db.sql.language.SqlSpecialOperator; import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; /** @@ -81,4 +91,8 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().dropNamespace( name.getSimple(), ifExists, statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfNamespaceLockable( name, context, LockType.EXCLUSIVE ); + } } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropTable.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropTable.java index 1a78c7ac54..24f55d6fac 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropTable.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropTable.java @@ -17,6 +17,7 @@ package org.polypheny.db.sql.language.ddl; +import java.util.Map; import java.util.Optional; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.catalog.entity.logical.LogicalEntity; @@ -31,6 +32,8 @@ import org.polypheny.db.sql.language.SqlOperator; import org.polypheny.db.sql.language.SqlSpecialOperator; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; /** @@ -76,4 +79,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().dropTable( table, statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( name, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropType.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropType.java index f57b3010c4..0033bb1b5b 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropType.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropType.java @@ -17,6 +17,7 @@ package org.polypheny.db.sql.language.ddl; +import java.util.Map; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; @@ -26,6 +27,9 @@ import org.polypheny.db.sql.language.SqlOperator; import org.polypheny.db.sql.language.SqlSpecialOperator; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; /** @@ -46,5 +50,11 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().dropType(); } + + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return LockableUtils.getMapOfNamespaceLockable( name.getSimple(), context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropView.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropView.java index d58bc7c94a..761057081a 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropView.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlDropView.java @@ -17,6 +17,7 @@ package org.polypheny.db.sql.language.ddl; +import java.util.Map; import java.util.Optional; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.catalog.entity.logical.LogicalEntity; @@ -31,6 +32,8 @@ import org.polypheny.db.sql.language.SqlOperator; import org.polypheny.db.sql.language.SqlSpecialOperator; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; /** @@ -79,4 +82,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( name, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlTruncate.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlTruncate.java index 221c0f3049..d39aa96e46 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlTruncate.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/SqlTruncate.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; import java.util.List; +import java.util.Map; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.ddl.DdlManager; @@ -34,6 +35,8 @@ import org.polypheny.db.sql.language.SqlSpecialOperator; import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; /** @@ -82,5 +85,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().truncate( table, statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( name, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewAddIndex.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewAddIndex.java index 08239a9d6d..0a5e978639 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewAddIndex.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewAddIndex.java @@ -18,7 +18,9 @@ import static org.polypheny.db.util.Static.RESOURCE; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import lombok.EqualsAndHashCode; import lombok.Value; @@ -36,6 +38,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterMaterializedView; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.CoreUtil; import org.polypheny.db.util.ImmutableNullableList; @@ -142,4 +147,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewDropIndex.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewDropIndex.java index 9912809579..013306fbde 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewDropIndex.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewDropIndex.java @@ -16,7 +16,9 @@ package org.polypheny.db.sql.language.ddl.altermaterializedview; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -31,6 +33,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterMaterializedView; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -81,4 +86,8 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().dropIndex( table, indexName.getSimple(), statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewFreshnessManual.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewFreshnessManual.java index 534c2d4749..e40201e440 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewFreshnessManual.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewFreshnessManual.java @@ -16,7 +16,9 @@ package org.polypheny.db.sql.language.ddl.altermaterializedview; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.EntityType; @@ -30,6 +32,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterMaterializedView; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; public class SqlAlterMaterializedViewFreshnessManual extends SqlAlterMaterializedView { @@ -77,4 +82,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( name, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRename.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRename.java index 73062aa69a..fb3fc11223 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRename.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRename.java @@ -16,7 +16,9 @@ package org.polypheny.db.sql.language.ddl.altermaterializedview; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -31,6 +33,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterMaterializedView; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -88,4 +93,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().renameTable( catalogTable, newName.getSimple(), statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( oldName, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRenameColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRenameColumn.java index 8105eda71c..af7b5a1ae5 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRenameColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altermaterializedview/SqlAlterMaterializedViewRenameColumn.java @@ -16,7 +16,9 @@ package org.polypheny.db.sql.language.ddl.altermaterializedview; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -31,6 +33,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterMaterializedView; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; public class SqlAlterMaterializedViewRenameColumn extends SqlAlterMaterializedView { @@ -85,4 +90,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().renameColumn( table, columnOldName.getSimple(), columnNewName.getSimple(), statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( materializedView, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceOwner.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceOwner.java index 761aa84b0a..6a6495fc0b 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceOwner.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceOwner.java @@ -17,8 +17,11 @@ package org.polypheny.db.sql.language.ddl.alternamespace; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; +import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.Node; import org.polypheny.db.prepare.Context; @@ -28,6 +31,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterNamespace; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -78,4 +84,8 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa throw new UnsupportedOperationException( "This functionality is not yet supported." ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfNamespaceLockable( namespace, context, LockType.EXCLUSIVE ); + } } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceRename.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceRename.java index 9839590749..e454898d81 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceRename.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alternamespace/SqlAlterNamespaceRename.java @@ -17,8 +17,13 @@ package org.polypheny.db.sql.language.ddl.alternamespace; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; +import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.catalog.entity.logical.LogicalNamespace; +import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.Node; @@ -29,6 +34,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterNamespace; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -76,4 +84,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().renameNamespace( newName.getSimple(), currentName.getSimple() ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfNamespaceLockable( currentName, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterSourceTableAddColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterSourceTableAddColumn.java index 9dc5a6ff57..b13f13ab88 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterSourceTableAddColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterSourceTableAddColumn.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import lombok.EqualsAndHashCode; import lombok.Value; @@ -37,6 +39,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -133,5 +138,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddColumn.java index 8032afc309..ec48382de4 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddColumn.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import javax.annotation.Nullable; import lombok.EqualsAndHashCode; @@ -40,6 +42,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -151,5 +156,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddForeignKey.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddForeignKey.java index d7cbd9851b..a1f7b3468f 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddForeignKey.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddForeignKey.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -34,6 +36,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -123,5 +128,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddIndex.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddIndex.java index 64889397b9..3a3e129931 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddIndex.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddIndex.java @@ -19,7 +19,9 @@ import static org.polypheny.db.util.Static.RESOURCE; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.adapter.DataStore; import org.polypheny.db.adapter.index.IndexManager; @@ -37,6 +39,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.CoreUtil; import org.polypheny.db.util.ImmutableNullableList; @@ -148,4 +153,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPartitions.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPartitions.java index 3cbdff37eb..429ca492df 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPartitions.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPartitions.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.catalog.Catalog; @@ -38,6 +40,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -160,4 +165,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPlacement.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPlacement.java index 2373438670..43b09f9950 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPlacement.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPlacement.java @@ -18,7 +18,9 @@ import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.adapter.DataStore; @@ -37,6 +39,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -146,4 +151,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPrimaryKey.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPrimaryKey.java index b4c62fc650..639269d3c6 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPrimaryKey.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddPrimaryKey.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -33,6 +35,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -91,4 +96,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddUniqueConstraint.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddUniqueConstraint.java index fda9e89325..de294b8c02 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddUniqueConstraint.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableAddUniqueConstraint.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -33,6 +35,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -98,5 +103,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropColumn.java index d393afffc2..bebc98da5e 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropColumn.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -32,6 +34,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -89,5 +94,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().dropColumn( logicalTable, column.getSimple(), statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropConstraint.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropConstraint.java index b71a348927..47d710e2d3 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropConstraint.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropConstraint.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -32,6 +34,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -85,5 +90,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().dropConstraint( logicalTable, constraintName.getSimple() ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropForeignKey.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropForeignKey.java index dc2d58adbd..a66768b031 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropForeignKey.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropForeignKey.java @@ -17,10 +17,14 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; +import org.polypheny.db.catalog.Catalog; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; +import org.polypheny.db.catalog.logistic.ConstraintType; import org.polypheny.db.catalog.logistic.EntityType; import org.polypheny.db.ddl.DdlManager; import org.polypheny.db.languages.ParserPos; @@ -32,6 +36,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -86,5 +93,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().dropForeignKey( logicalTable, foreignKeyName.getSimple() ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropIndex.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropIndex.java index 4e32fc2d23..def877aee8 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropIndex.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropIndex.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -32,6 +34,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -85,5 +90,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().dropIndex( logicalTable, indexName.getSimple(), statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPlacement.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPlacement.java index 7317a6444c..fd33ffc626 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPlacement.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPlacement.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.adapter.DataStore; import org.polypheny.db.catalog.entity.logical.LogicalTable; @@ -33,6 +35,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -89,4 +94,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().dropPlacement( logicalTable, store, statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPrimaryKey.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPrimaryKey.java index 7d1e0d4302..e0c422795a 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPrimaryKey.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableDropPrimaryKey.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -32,6 +34,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -83,5 +88,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().dropPrimaryKey( logicalTable ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableMergePartitions.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableMergePartitions.java index cf6544c768..61dbc35720 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableMergePartitions.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableMergePartitions.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.catalog.entity.logical.LogicalTable; @@ -34,6 +36,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -99,4 +104,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyColumn.java index ebed07f3c7..5d413fab18 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyColumn.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import lombok.NonNull; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -36,6 +38,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -165,5 +170,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( tableName, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPartitions.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPartitions.java index b5c4a66dae..ba8ed9e1e8 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPartitions.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPartitions.java @@ -20,7 +20,9 @@ import static org.polypheny.db.util.Static.RESOURCE; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import lombok.extern.slf4j.Slf4j; @@ -41,6 +43,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.CoreUtil; import org.polypheny.db.util.ImmutableNullableList; @@ -164,4 +169,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacement.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacement.java index 2f9fc45df2..fe38790b51 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacement.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacement.java @@ -18,7 +18,9 @@ import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import lombok.EqualsAndHashCode; import lombok.NonNull; @@ -40,6 +42,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -162,4 +167,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementAddColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementAddColumn.java index eb3978db6b..0667a19f2d 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementAddColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementAddColumn.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.adapter.DataStore; import org.polypheny.db.catalog.entity.logical.LogicalColumn; @@ -34,6 +36,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -109,5 +114,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementDropColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementDropColumn.java index 191aff3936..284705bb51 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementDropColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableModifyPlacementDropColumn.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.adapter.DataStore; import org.polypheny.db.catalog.entity.logical.LogicalColumn; @@ -34,6 +36,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -105,5 +110,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableOwner.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableOwner.java index 1ffb6d6304..8a6180222f 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableOwner.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableOwner.java @@ -17,8 +17,11 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; +import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.languages.ParserPos; import org.polypheny.db.nodes.Node; @@ -29,6 +32,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -76,5 +82,9 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa throw new GenericRuntimeException( "This operation is not supported" ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRename.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRename.java index b5700fefd9..1e0ca32bed 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRename.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRename.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -31,6 +33,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -84,5 +89,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().renameTable( table, newName.getSimple(), statement ); } + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( oldName, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRenameColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRenameColumn.java index 5220d13966..b7be77c998 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRenameColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/altertable/SqlAlterTableRenameColumn.java @@ -17,7 +17,9 @@ package org.polypheny.db.sql.language.ddl.altertable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.ddl.DdlManager; @@ -30,6 +32,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterTable; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; @@ -83,5 +88,11 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().renameColumn( logicalTable, columnOldName.getSimple(), columnNewName.getSimple(), statement ); } + + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( table, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRename.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRename.java index c03070105f..a6d74d914a 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRename.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRename.java @@ -16,7 +16,9 @@ package org.polypheny.db.sql.language.ddl.alterview; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -31,6 +33,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterView; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; /** @@ -90,4 +95,10 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().renameTable( table, newName.getSimple(), statement ); } + + @Override + public Map deriveLockables( Context context, ParsedQueryContext parsedQueryContext ) { + return getMapOfTableLockable( oldName, context, LockType.EXCLUSIVE ); + } + } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRenameColumn.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRenameColumn.java index 7a318293a2..541cb4dfa1 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRenameColumn.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/ddl/alterview/SqlAlterViewRenameColumn.java @@ -16,7 +16,9 @@ package org.polypheny.db.sql.language.ddl.alterview; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; @@ -31,6 +33,9 @@ import org.polypheny.db.sql.language.SqlWriter; import org.polypheny.db.sql.language.ddl.SqlAlterView; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.Lockable; +import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.LockableUtils; import org.polypheny.db.util.ImmutableNullableList; public class SqlAlterViewRenameColumn extends SqlAlterView { @@ -84,4 +89,11 @@ public void execute( Context context, Statement statement, ParsedQueryContext pa DdlManager.getInstance().renameColumn( table, columnOldName.getSimple(), columnNewName.getSimple(), statement ); } + + @Override + public Map deriveLockables(Context context, ParsedQueryContext parsedQueryContext) { + return getMapOfTableLockable( view, context, LockType.EXCLUSIVE ); + } + + }