diff --git a/webui/src/main/java/org/polypheny/db/webui/Crud.java b/webui/src/main/java/org/polypheny/db/webui/Crud.java index 00892acf7e..9903a2add0 100644 --- a/webui/src/main/java/org/polypheny/db/webui/Crud.java +++ b/webui/src/main/java/org/polypheny/db/webui/Crud.java @@ -168,15 +168,15 @@ import org.polypheny.db.webui.models.AdapterModel; import org.polypheny.db.webui.models.DbTable; import org.polypheny.db.webui.models.ForeignKey; -import org.polypheny.db.webui.models.Index; +import org.polypheny.db.webui.models.IndexModel; import org.polypheny.db.webui.models.MaterializedInfos; import org.polypheny.db.webui.models.Namespace; import org.polypheny.db.webui.models.PartitionFunctionModel; import org.polypheny.db.webui.models.PartitionFunctionModel.FieldType; import org.polypheny.db.webui.models.PartitionFunctionModel.PartitionFunctionColumn; import org.polypheny.db.webui.models.PathAccessRequest; -import org.polypheny.db.webui.models.Placement; -import org.polypheny.db.webui.models.Placement.RelationalStore; +import org.polypheny.db.webui.models.PlacementModel; +import org.polypheny.db.webui.models.PlacementModel.RelationalStore; import org.polypheny.db.webui.models.QueryInterfaceModel; import org.polypheny.db.webui.models.SidebarElement; import org.polypheny.db.webui.models.SortState; @@ -237,7 +237,7 @@ public class Crud implements InformationObserver { */ public static void cleanupOldSession( ConcurrentHashMap> sessionXIds, final String sessionId ) { Set xIds = sessionXIds.remove( sessionId ); - if ( xIds == null || xIds.size() == 0 ) { + if ( xIds == null || xIds.isEmpty() ) { return; } for ( String xId : xIds ) { @@ -384,8 +384,8 @@ void getEntities( final Context ctx ) { void renameTable( final Context ctx ) { - Index table = ctx.bodyAsClass( Index.class ); - String query = String.format( "ALTER TABLE \"%s\".\"%s\" RENAME TO \"%s\"", table.getSchema(), table.getTable(), table.getName() ); + IndexModel table = ctx.bodyAsClass( IndexModel.class ); + String query = String.format( "ALTER TABLE \"%s\".\"%s\" RENAME TO \"%s\"", table.getNamespaceId(), table.getEntityId(), table.getName() ); Transaction transaction = getTransaction(); RelationalResult result; try { @@ -1093,12 +1093,12 @@ void getColumns( final Context ctx ) { void getDataSourceColumns( final Context ctx ) { UIRequest request = ctx.bodyAsClass( UIRequest.class ); - LogicalTable catalogTable = catalog.getSnapshot().rel().getTable( request.entityId ).orElseThrow(); + LogicalTable tablee = catalog.getSnapshot().rel().getTable( request.entityId ).orElseThrow(); - if ( catalogTable.entityType == EntityType.VIEW ) { + if ( tablee.entityType == EntityType.VIEW ) { List columns = new ArrayList<>(); - List cols = catalog.getSnapshot().rel().getColumns( catalogTable.id ); + List cols = catalog.getSnapshot().rel().getColumns( tablee.id ); for ( LogicalColumn col : cols ) { columns.add( UiColumnDefinition.builder() .name( col.name ) @@ -1116,16 +1116,16 @@ void getDataSourceColumns( final Context ctx ) { } ctx.json( RelationalResult.builder().header( columns.toArray( new UiColumnDefinition[0] ) ).type( ResultType.VIEW ).build() ); } else { - List allocs = catalog.getSnapshot().alloc().getFromLogical( catalogTable.id ); - if ( catalog.getSnapshot().alloc().getFromLogical( catalogTable.id ).size() != 1 ) { + List allocs = catalog.getSnapshot().alloc().getFromLogical( tablee.id ); + if ( catalog.getSnapshot().alloc().getFromLogical( tablee.id ).size() != 1 ) { throw new RuntimeException( "The table has an unexpected number of placements!" ); } long adapterId = allocs.get( 0 ).adapterId; - LogicalPrimaryKey primaryKey = catalog.getSnapshot().rel().getPrimaryKey( catalogTable.primaryKey ).orElseThrow(); + LogicalPrimaryKey primaryKey = catalog.getSnapshot().rel().getPrimaryKey( tablee.primaryKey ).orElseThrow(); List pkColumnNames = primaryKey.getColumnNames(); List columns = new ArrayList<>(); - for ( AllocationColumn ccp : catalog.getSnapshot().alloc().getColumnPlacementsOnAdapterPerTable( adapterId, catalogTable.id ) ) { + for ( AllocationColumn ccp : catalog.getSnapshot().alloc().getColumnPlacementsOnAdapterPerTable( adapterId, tablee.id ) ) { LogicalColumn col = catalog.getSnapshot().rel().getColumn( ccp.columnId ).orElseThrow(); columns.add( UiColumnDefinition.builder().name( col.name ).dataType( @@ -1193,13 +1193,12 @@ void getAvailableSourceColumns( final Context ctx ) { void getMaterializedInfo( final Context ctx ) { EditTableRequest request = ctx.bodyAsClass( EditTableRequest.class ); - Pair namespaceTable = getNamespaceTable( request ); - LogicalTable catalogTable = getLogicalTable( namespaceTable.left.name, namespaceTable.right.name ); + LogicalTable table = getLogicalTable( namespaceTable.left.name, namespaceTable.right.name ); - if ( catalogTable.entityType == EntityType.MATERIALIZED_VIEW ) { - LogicalMaterializedView logicalMaterializedView = (LogicalMaterializedView) catalogTable; + if ( table.entityType == EntityType.MATERIALIZED_VIEW ) { + LogicalMaterializedView logicalMaterializedView = (LogicalMaterializedView) table; MaterializedCriteria materializedCriteria = logicalMaterializedView.getMaterializedCriteria(); @@ -1412,7 +1411,7 @@ void addColumn( final Context ctx ) { } query = query + ")"; } - if ( !request.newColumn.collectionsType.equals( "" ) ) { + if ( !request.newColumn.collectionsType.isEmpty() ) { query = query + " " + request.newColumn.collectionsType; int dimension = request.newColumn.dimension == null ? -1 : request.newColumn.dimension; int cardinality = request.newColumn.cardinality == null ? -1 : request.newColumn.cardinality; @@ -1422,9 +1421,9 @@ void addColumn( final Context ctx ) { query = query + " NOT NULL"; } } - if ( request.newColumn.defaultValue != null && !request.newColumn.defaultValue.equals( "" ) ) { + if ( request.newColumn.defaultValue != null && !request.newColumn.defaultValue.isEmpty() ) { query = query + " DEFAULT "; - if ( request.newColumn.collectionsType != null && !request.newColumn.collectionsType.equals( "" ) ) { + if ( request.newColumn.collectionsType != null && !request.newColumn.collectionsType.isEmpty() ) { //handle the case if the user says "ARRAY[1,2,3]" or "[1,2,3]" if ( !request.newColumn.defaultValue.startsWith( request.newColumn.collectionsType ) ) { query = query + request.newColumn.collectionsType; @@ -1517,33 +1516,33 @@ void getConstraints( final Context ctx ) { RelationalResult result; List resultList = new ArrayList<>(); - Map> temp = new HashMap<>(); + Map> temp = new HashMap<>(); - LogicalTable catalogTable = catalog.getSnapshot().rel().getTable( request.entityId ).orElseThrow(); + LogicalTable table = catalog.getSnapshot().rel().getTable( request.entityId ).orElseThrow(); // get primary key - if ( catalogTable.primaryKey != null ) { - LogicalPrimaryKey primaryKey = catalog.getSnapshot().rel().getPrimaryKey( catalogTable.primaryKey ).orElseThrow(); + if ( table.primaryKey != null ) { + LogicalPrimaryKey primaryKey = catalog.getSnapshot().rel().getPrimaryKey( table.primaryKey ).orElseThrow(); for ( String columnName : primaryKey.getColumnNames() ) { if ( !temp.containsKey( "" ) ) { temp.put( "", new ArrayList<>() ); } temp.get( "" ).add( columnName ); } - for ( Map.Entry> entry : temp.entrySet() ) { + for ( Map.Entry> entry : temp.entrySet() ) { resultList.add( new TableConstraint( entry.getKey(), "PRIMARY KEY", entry.getValue() ) ); } } // get unique constraints. temp.clear(); - List constraints = catalog.getSnapshot().rel().getConstraints( catalogTable.id ); + List constraints = catalog.getSnapshot().rel().getConstraints( table.id ); for ( LogicalConstraint logicalConstraint : constraints ) { if ( logicalConstraint.type == ConstraintType.UNIQUE ) { temp.put( logicalConstraint.name, new ArrayList<>( logicalConstraint.key.getColumnNames() ) ); } } - for ( Map.Entry> entry : temp.entrySet() ) { + for ( Map.Entry> entry : temp.entrySet() ) { resultList.add( new TableConstraint( entry.getKey(), "UNIQUE", entry.getValue() ) ); } @@ -1675,8 +1674,8 @@ void getIndexes( final Context ctx ) { EditTableRequest request = ctx.bodyAsClass( EditTableRequest.class ); Pair namespaceTable = getNamespaceTable( request ); - LogicalTable catalogTable = getLogicalTable( namespaceTable.left.name, namespaceTable.right.name ); - List logicalIndices = catalog.getSnapshot().rel().getIndexes( catalogTable.id, false ); + LogicalTable table = getLogicalTable( namespaceTable.left.name, namespaceTable.right.name ); + List logicalIndices = catalog.getSnapshot().rel().getIndexes( table.id, false ); UiColumnDefinition[] header = { UiColumnDefinition.builder().name( "Name" ).build(), @@ -1706,7 +1705,7 @@ void getIndexes( final Context ctx ) { } // Get functional indexes - List allocs = catalog.getSnapshot().alloc().getFromLogical( catalogTable.id ); + List allocs = catalog.getSnapshot().alloc().getFromLogical( table.id ); for ( AllocationEntity alloc : allocs ) { Adapter adapter = AdapterManager.getInstance().getAdapter( alloc.adapterId ); DataStore store; @@ -1715,7 +1714,7 @@ void getIndexes( final Context ctx ) { } else { break; } - for ( FunctionalIndexInfo fif : store.getFunctionalIndexes( catalogTable ) ) { + for ( FunctionalIndexInfo fif : store.getFunctionalIndexes( table ) ) { String[] arr = new String[5]; arr[0] = ""; arr[1] = String.join( ", ", fif.getColumnNames() ); @@ -1736,10 +1735,10 @@ void getIndexes( final Context ctx ) { * @param ctx */ void dropIndex( final Context ctx ) { - Index index = ctx.bodyAsClass( Index.class ); + IndexModel index = ctx.bodyAsClass( IndexModel.class ); Transaction transaction = getTransaction(); - String tableId = String.format( "\"%s\".\"%s\"", index.getSchema(), index.getTable() ); + String tableId = String.format( "\"%s\".\"%s\"", index.getNamespaceId(), index.getEntityId() ); String query = String.format( "ALTER TABLE %s DROP INDEX \"%s\"", tableId, index.getName() ); RelationalResult result; try { @@ -1763,17 +1762,20 @@ void dropIndex( final Context ctx ) { * Create an index for a table */ void createIndex( final Context ctx ) { - Index index = ctx.bodyAsClass( Index.class ); + IndexModel index = ctx.bodyAsClass( IndexModel.class ); Transaction transaction = getTransaction(); - String tableId = String.format( "\"%s\".\"%s\"", index.getSchema(), index.getTable() ); + LogicalNamespace namespace = Catalog.snapshot().getNamespace( index.namespaceId ).orElseThrow(); + LogicalTable table = Catalog.snapshot().rel().getTable( index.entityId ).orElseThrow(); + + String tableId = String.format( "\"%s\".\"%s\"", namespace.name, table.name ); RelationalResult result; StringJoiner colJoiner = new StringJoiner( ",", "(", ")" ); - for ( String col : index.getColumns() ) { - colJoiner.add( "\"" + col + "\"" ); + for ( long col : index.columnIds ) { + colJoiner.add( "\"" + Catalog.snapshot().rel().getColumn( col ).orElseThrow().name + "\"" ); } String store = "POLYPHENY"; - if ( !index.getStoreUniqueName().equals( "Polypheny-DB" ) ) { + if ( index.storeUniqueName != null && !index.storeUniqueName.equals( "Polypheny-DB" ) ) { store = index.getStoreUniqueName(); } String onStore = String.format( "ON STORE \"%s\"", store ); @@ -1799,10 +1801,10 @@ void createIndex( final Context ctx ) { void getUnderlyingTable( final Context ctx ) { UIRequest request = ctx.bodyAsClass( UIRequest.class ); - LogicalTable catalogTable = catalog.getSnapshot().rel().getTable( request.entityId ).orElseThrow(); + LogicalTable table = catalog.getSnapshot().rel().getTable( request.entityId ).orElseThrow(); - if ( catalogTable.entityType == EntityType.VIEW ) { - ImmutableMap> underlyingTableOriginal = catalogTable.unwrap( LogicalView.class ).underlyingTables; + if ( table.entityType == EntityType.VIEW ) { + ImmutableMap> underlyingTableOriginal = table.unwrap( LogicalView.class ).underlyingTables; Map> underlyingTable = new HashMap<>(); for ( Entry> entry : underlyingTableOriginal.entrySet() ) { List columns = new ArrayList<>(); @@ -1822,18 +1824,16 @@ void getUnderlyingTable( final Context ctx ) { * Get placements of a table */ void getPlacements( final Context ctx ) { - Index index = ctx.bodyAsClass( Index.class ); + IndexModel index = ctx.bodyAsClass( IndexModel.class ); ctx.json( getPlacements( index ) ); } - private Placement getPlacements( final Index index ) { - String namespaceName = index.getSchema(); - String tableName = index.getTable(); + private PlacementModel getPlacements( final IndexModel index ) { Snapshot snapshot = Catalog.getInstance().getSnapshot(); - LogicalTable table = getLogicalTable( namespaceName, tableName ); - Placement p = new Placement( snapshot.alloc().getFromLogical( table.id ).size() > 1, snapshot.alloc().getPartitionGroupNames( table.id ), table.entityType ); + LogicalTable table = Catalog.snapshot().rel().getTable( index.entityId ).orElseThrow(); + PlacementModel p = new PlacementModel( snapshot.alloc().getFromLogical( table.id ).size() > 1, snapshot.alloc().getPartitionGroupNames( table.id ), table.entityType ); if ( table.entityType != EntityType.VIEW ) { long pkid = table.primaryKey; List pkColumnIds = snapshot.rel().getPrimaryKey( pkid ).orElseThrow().columnIds; @@ -1861,7 +1861,7 @@ private Placement getPlacements( final Index index ) { * Index method: either 'ADD' or 'DROP' */ void addDropPlacement( final Context ctx ) { - Index index = ctx.bodyAsClass( Index.class ); + IndexModel index = ctx.bodyAsClass( IndexModel.class ); if ( !index.getMethod().equalsIgnoreCase( "ADD" ) && !index.getMethod().equalsIgnoreCase( "DROP" ) && !index.getMethod().equalsIgnoreCase( "MODIFY" ) ) { ctx.json( RelationalResult.builder().error( "Invalid request" ).build() ); return; @@ -1869,16 +1869,16 @@ void addDropPlacement( final Context ctx ) { StringJoiner columnJoiner = new StringJoiner( ",", "(", ")" ); int counter = 0; if ( !index.getMethod().equalsIgnoreCase( "DROP" ) ) { - for ( String col : index.getColumns() ) { - columnJoiner.add( "\"" + col + "\"" ); + for ( long col : index.columnIds ) { + columnJoiner.add( "\"" + Catalog.snapshot().rel().getColumn( col ).orElseThrow().name + "\"" ); counter++; } } String columnListStr = counter > 0 ? columnJoiner.toString() : ""; String query = String.format( "ALTER TABLE \"%s\".\"%s\" %s PLACEMENT %s ON STORE \"%s\"", - index.getSchema(), - index.getTable(), + index.getNamespaceId(), + index.getEntityId(), index.getMethod().toUpperCase(), columnListStr, index.getStoreUniqueName() ); @@ -2024,22 +2024,22 @@ void partitionTable( final Context ctx ) { PartitionFunctionInfo functionInfo = partitionManager.getPartitionFunctionInfo(); - String content = ""; + StringBuilder content = new StringBuilder(); for ( List currentRow : request.rows ) { boolean rowSeparationApplied = false; for ( PartitionFunctionColumn currentColumn : currentRow ) { if ( currentColumn.modifiable ) { // If more than one row, keep appending ',' if ( !rowSeparationApplied && request.rows.indexOf( currentRow ) != 0 ) { - content = content + functionInfo.getRowSeparation(); + content.append( functionInfo.getRowSeparation() ); rowSeparationApplied = true; } - content = content + currentColumn.sqlPrefix + " " + currentColumn.value + " " + currentColumn.sqlSuffix; + content.append( currentColumn.sqlPrefix ).append( " " ).append( currentColumn.value ).append( " " ).append( currentColumn.sqlSuffix ); } } } - content = functionInfo.getSqlPrefix() + " " + content + " " + functionInfo.getSqlSuffix(); + content = new StringBuilder( functionInfo.getSqlPrefix() + " " + content + " " + functionInfo.getSqlSuffix() ); //INFO - do discuss //Problem is that we took the structure completely out of the original JSON therefore losing valuable information and context @@ -2049,7 +2049,7 @@ void partitionTable( final Context ctx ) { //Changes to extensions to this model now have to be made on two parts String query = String.format( "ALTER TABLE \"%s\".\"%s\" PARTITION BY %s (\"%s\") %s ", - request.schemaName, request.tableName, request.functionName, request.partitionColumnName, content ); + request.schemaName, request.tableName, request.functionName, request.partitionColumnName, content.toString() ); Transaction trx = getTransaction(); try { @@ -2125,13 +2125,13 @@ void getStores( final Context ctx ) { /** * Get the available stores on which a new index can be placed. 'Polypheny-DB' is part of the list, if polystore-indexes are enabled */ - void getAvailableStoresForIndexes( final Context ctx, Gson gson ) { - Index index = ctx.bodyAsClass( Index.class ); - Placement dataPlacements = getPlacements( index ); - ImmutableMap> stores = AdapterManager.getInstance().getStores(); + void getAvailableStoresForIndexes( final Context ctx ) { + IndexModel index = ctx.bodyAsClass( IndexModel.class ); + PlacementModel dataPlacements = getPlacements( index ); + Map> stores = AdapterManager.getInstance().getStores(); //see https://stackoverflow.com/questions/18857884/how-to-convert-arraylist-of-custom-class-to-jsonarray-in-java - JsonArray jsonArray = gson.toJsonTree( stores.values().stream().filter( ( s ) -> { - if ( s.getAvailableIndexMethods() == null || s.getAvailableIndexMethods().size() == 0 ) { + JsonArray jsonArray = HttpServer.gson.toJsonTree( stores.values().stream().filter( ( s ) -> { + if ( s.getAvailableIndexMethods() == null || s.getAvailableIndexMethods().isEmpty() ) { return false; } return dataPlacements.stores.stream().anyMatch( ( dp ) -> dp.uniqueName.equals( s.getUniqueName() ) ); @@ -2139,7 +2139,7 @@ void getAvailableStoresForIndexes( final Context ctx, Gson gson ) { if ( RuntimeConfig.POLYSTORE_INDEXES_ENABLED.getBoolean() ) { JsonObject pdbFakeStore = new JsonObject(); pdbFakeStore.addProperty( "uniqueName", "Polypheny-DB" ); - pdbFakeStore.add( "availableIndexMethods", gson.toJsonTree( IndexManager.getAvailableIndexMethods() ) ); + pdbFakeStore.add( "availableIndexMethods", HttpServer.gson.toJsonTree( IndexManager.getAvailableIndexMethods() ) ); jsonArray.add( pdbFakeStore ); } ctx.json( jsonArray ); @@ -2226,7 +2226,7 @@ void getSources( final Context ctx ) { /** * Deploy a new adapter */ - void addAdapter( final Context ctx, Gson gson ) throws ServletException, IOException { + void addAdapter( final Context ctx ) throws ServletException, IOException { initMultipart( ctx ); String body = ""; Map inputStreams = new HashMap<>(); @@ -2239,7 +2239,7 @@ void addAdapter( final Context ctx, Gson gson ) throws ServletException, IOExcep } } - AdapterModel a = gson.fromJson( body, AdapterModel.class ); + AdapterModel a = HttpServer.gson.fromJson( body, AdapterModel.class ); Map settings = new HashMap<>(); ConnectionMethod method = ConnectionMethod.UPLOAD; @@ -2417,9 +2417,9 @@ void getUml( final Context ctx ) { LogicalRelSnapshot relSnapshot = catalog.getSnapshot().rel(); long namespaceId = request.namespaceId == null ? Catalog.defaultNamespaceId : request.namespaceId; LogicalNamespace namespace = catalog.getSnapshot().getNamespace( namespaceId ).orElseThrow(); - List catalogEntities = relSnapshot.getTablesFromNamespace( namespace.id ); + List entities = relSnapshot.getTablesFromNamespace( namespace.id ); - for ( LogicalTable table : catalogEntities ) { + for ( LogicalTable table : entities ) { if ( table.entityType == EntityType.ENTITY || table.entityType == EntityType.SOURCE ) { // get foreign keys List foreignKeys = catalog.getSnapshot().rel().getForeignKeys( table.id ); @@ -2448,8 +2448,8 @@ void getUml( final Context ctx ) { // get primary key with its columns if ( table.primaryKey != null ) { - LogicalPrimaryKey catalogPrimaryKey = catalog.getSnapshot().rel().getPrimaryKey( table.primaryKey ).orElseThrow(); - for ( String columnName : catalogPrimaryKey.getColumnNames() ) { + LogicalPrimaryKey primaryKey = catalog.getSnapshot().rel().getPrimaryKey( table.primaryKey ).orElseThrow(); + for ( String columnName : primaryKey.getColumnNames() ) { dbTable.addPrimaryKeyField( columnName ); } } @@ -2767,7 +2767,7 @@ void namespaceRequest( final Context ctx ) { query.append( "NAMESPACE " ); query.append( "\"" ).append( namespace.getName() ).append( "\"" ); - if ( namespace.getAuthorization() != null && !namespace.getAuthorization().equals( "" ) ) { + if ( namespace.getAuthorization() != null && !namespace.getAuthorization().isEmpty() ) { query.append( " AUTHORIZATION " ).append( namespace.getAuthorization() ); } try { @@ -2853,7 +2853,7 @@ private void handleGraphDdl( Namespace namespace, Transaction transaction, Conte List nodes = processor.parse( query ); ExtendedQueryParameters parameters = new ExtendedQueryParameters( query, NamespaceType.GRAPH, namespace.getName() ); try { - PolyImplementation result = processor.prepareDdl( statement, nodes.get( 0 ), parameters ); + PolyImplementation result = processor.prepareDdl( statement, nodes.get( 0 ), parameters ); int rowsChanged = result.getRowsChanged( statement ); transaction.commit(); ctx.json( RelationalResult.builder().affectedRows( rowsChanged ).build() ); @@ -3547,6 +3547,7 @@ public void unloadPlugin( final Context ctx ) { private static void zipDirectory( String basePath, File dir, ZipOutputStream zipOut ) throws IOException { byte[] buffer = new byte[4096]; File[] files = dir.listFiles(); + assert files != null; for ( File file : files ) { if ( file.isDirectory() ) { String path = basePath + file.getName() + "/"; diff --git a/webui/src/main/java/org/polypheny/db/webui/HttpServer.java b/webui/src/main/java/org/polypheny/db/webui/HttpServer.java index f1cf38137f..ac0cf80e38 100644 --- a/webui/src/main/java/org/polypheny/db/webui/HttpServer.java +++ b/webui/src/main/java/org/polypheny/db/webui/HttpServer.java @@ -309,7 +309,7 @@ private void crudRoutes( Javalin webuiServer, Crud crud ) { webuiServer.get( "/getSources", crud::getSources ); - webuiServer.post( "/getAvailableStoresForIndexes", ( ctx ) -> crud.getAvailableStoresForIndexes( ctx, gson ) ); + webuiServer.post( "/getAvailableStoresForIndexes", crud::getAvailableStoresForIndexes ); webuiServer.post( "/removeAdapter", crud::removeAdapter ); @@ -319,7 +319,7 @@ private void crudRoutes( Javalin webuiServer, Crud crud ) { webuiServer.get( "/getAvailableSources", crud::getAvailableSources ); - webuiServer.post( "/addAdapter", ( ctx ) -> crud.addAdapter( ctx, gson ) ); + webuiServer.post( "/addAdapter", crud::addAdapter ); webuiServer.post( "/pathAccess", crud::startAccessRequest ); diff --git a/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java b/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java index 65010d68f0..b12284fb9a 100644 --- a/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java +++ b/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java @@ -46,7 +46,6 @@ import org.polypheny.db.catalog.entity.logical.LogicalTable; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.EntityType; -import org.polypheny.db.catalog.logistic.Pattern; import org.polypheny.db.config.RuntimeConfig; import org.polypheny.db.information.InformationManager; import org.polypheny.db.information.InformationObserver; @@ -61,9 +60,9 @@ import org.polypheny.db.type.entity.graph.PolyGraph; import org.polypheny.db.webui.Crud; import org.polypheny.db.webui.models.FieldDefinition; -import org.polypheny.db.webui.models.Index; -import org.polypheny.db.webui.models.Placement; -import org.polypheny.db.webui.models.Placement.DocumentStore; +import org.polypheny.db.webui.models.IndexModel; +import org.polypheny.db.webui.models.PlacementModel; +import org.polypheny.db.webui.models.PlacementModel.DocumentStore; import org.polypheny.db.webui.models.SortState; import org.polypheny.db.webui.models.UiColumnDefinition; import org.polypheny.db.webui.models.requests.EditCollectionRequest; @@ -363,33 +362,23 @@ public void getDocumentDatabases( final Context ctx ) { public void getGraphPlacements( final Context ctx ) { - Index index = ctx.bodyAsClass( Index.class ); + IndexModel index = ctx.bodyAsClass( IndexModel.class ); ctx.json( getPlacements( index ) ); } - private Placement getPlacements( final Index index ) { + private PlacementModel getPlacements( final IndexModel index ) { Catalog catalog = Catalog.getInstance(); - String graphName = index.getSchema(); - List namespaces = catalog.getSnapshot().getNamespaces( new Pattern( graphName ) ); - if ( namespaces.size() != 1 ) { - throw new RuntimeException(); - } - List graphs = catalog.getSnapshot().graph().getGraphs( new Pattern( graphName ) ); - if ( graphs.size() != 1 ) { - log.error( "The requested graph does not exist." ); - return new Placement( new RuntimeException( "The requested graph does not exist." ) ); - } - LogicalGraph graph = graphs.get( 0 ); + LogicalGraph graph = Catalog.snapshot().graph().getGraph( index.namespaceId ).orElseThrow(); EntityType type = EntityType.ENTITY; - Placement p = new Placement( false, List.of(), EntityType.ENTITY ); + PlacementModel p = new PlacementModel( false, List.of(), EntityType.ENTITY ); if ( type == EntityType.VIEW ) { return p; } else { List placements = catalog.getSnapshot().alloc().getDataPlacements( graph.id ); for ( CatalogDataPlacement placement : placements ) { Adapter adapter = AdapterManager.getInstance().getAdapter( placement.adapterId ); - p.addAdapter( new Placement.GraphStore( + p.addAdapter( new PlacementModel.GraphStore( adapter.getUniqueName(), adapter.getUniqueName(), catalog.getSnapshot().alloc().getFromLogical( placement.adapterId ), @@ -414,21 +403,11 @@ public void getFixedFields( Context context ) { public void getCollectionPlacements( Context context ) { - Index index = context.bodyAsClass( Index.class ); - String namespace = index.getSchema(); - String collectionName = index.getTable(); + IndexModel index = context.bodyAsClass( IndexModel.class ); Catalog catalog = Catalog.getInstance(); - long namespaceId = catalog.getSnapshot().getNamespace( namespace ).orElseThrow().id; - List collections = catalog.getSnapshot().doc().getCollections( namespaceId, new Pattern( collectionName ) ); - - if ( collections.size() != 1 ) { - context.json( new Placement( new RuntimeException( "The collation is not know" ) ) ); - return; - } - - LogicalCollection collection = collections.get( 0 ); + LogicalCollection collection = catalog.getSnapshot().doc().getCollection( index.entityId ).orElseThrow(); - Placement p = new Placement( false, List.of(), EntityType.ENTITY ); + PlacementModel p = new PlacementModel( false, List.of(), EntityType.ENTITY ); List allocs = catalog.getSnapshot().alloc().getFromLogical( collection.id ); diff --git a/webui/src/main/java/org/polypheny/db/webui/models/Index.java b/webui/src/main/java/org/polypheny/db/webui/models/IndexModel.java similarity index 53% rename from webui/src/main/java/org/polypheny/db/webui/models/Index.java rename to webui/src/main/java/org/polypheny/db/webui/models/IndexModel.java index 7e6d337ab9..65235872c5 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/Index.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/IndexModel.java @@ -17,41 +17,34 @@ package org.polypheny.db.webui.models; +import java.util.List; import lombok.Getter; +import lombok.Value; /** * Schema for the index of a table */ @Getter -public class Index { +@Value +public class IndexModel { - private String schema; - private String table; - private String name; - private String storeUniqueName; - private String method; - private String[] columns; + public Long namespaceId; + public Long entityId; + public String name; + public String storeUniqueName; + public String method; + public List columnIds; - public Index( final String schema, final String table, final String name, final String method, final String[] columns ) { - this.schema = schema; - this.table = table; + public IndexModel( final Long namespaceId, final Long entityId, final String name, final String method, final List columnIds ) { + this.namespaceId = namespaceId; + this.entityId = entityId; this.name = name; this.method = method; - this.columns = columns; + this.columnIds = columnIds; + this.storeUniqueName = null; } - /** - * Convert index to a row to display in the UI - */ - public String[] asRow() { - String[] row = new String[3]; - row[0] = this.name; - row[1] = this.method; - row[2] = String.join( ",", this.columns ); - return row; - } - } diff --git a/webui/src/main/java/org/polypheny/db/webui/models/Placement.java b/webui/src/main/java/org/polypheny/db/webui/models/PlacementModel.java similarity index 93% rename from webui/src/main/java/org/polypheny/db/webui/models/Placement.java rename to webui/src/main/java/org/polypheny/db/webui/models/PlacementModel.java index 4435a908ca..a62a034648 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/Placement.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/PlacementModel.java @@ -31,7 +31,7 @@ /** * A model for the UI, modelling the placements of a table */ -public class Placement { +public class PlacementModel { Throwable exception; public List stores = new ArrayList<>(); @@ -40,19 +40,19 @@ public class Placement { String tableType; - public Placement( final boolean isPartitioned, final List partitionNames, final EntityType entityType ) { + public PlacementModel( final boolean isPartitioned, final List partitionNames, final EntityType entityType ) { this.isPartitioned = isPartitioned; this.partitionNames = partitionNames; this.tableType = entityType.name(); } - public Placement( final Throwable exception ) { + public PlacementModel( final Throwable exception ) { this.exception = exception; } - public Placement addAdapter( final RelationalStore s ) { + public PlacementModel addAdapter( final RelationalStore s ) { if ( s.columnPlacements.size() > 0 ) { this.stores.add( s ); } @@ -60,14 +60,14 @@ public Placement addAdapter( final RelationalStore s ) { } - public Placement addAdapter( final GraphStore s ) { + public PlacementModel addAdapter( final GraphStore s ) { this.stores.add( s ); return this; } - public Placement addAdapter( final DocumentStore s ) { + public PlacementModel addAdapter( final DocumentStore s ) { this.stores.add( s ); return this; diff --git a/webui/src/main/java/org/polypheny/db/webui/models/TableConstraint.java b/webui/src/main/java/org/polypheny/db/webui/models/TableConstraint.java index 2f768c95ec..40800a41f2 100644 --- a/webui/src/main/java/org/polypheny/db/webui/models/TableConstraint.java +++ b/webui/src/main/java/org/polypheny/db/webui/models/TableConstraint.java @@ -17,7 +17,7 @@ package org.polypheny.db.webui.models; -import java.util.ArrayList; +import java.util.List; import java.util.StringJoiner; @@ -30,7 +30,7 @@ public class TableConstraint { public String[] columns; - public TableConstraint( final String name, final String type, ArrayList columns ) { + public TableConstraint( final String name, final String type, List columns ) { this.name = name; this.type = type; this.columns = columns.toArray( new String[0] );