Skip to content

Commit

Permalink
(has no effect yet): objects to safe and 'transport' information impl…
Browse files Browse the repository at this point in the history
…emented, creation queries (ns, tables) created (not yet executed)
  • Loading branch information
flurfis committed Nov 7, 2023
1 parent 46472ba commit 56d2041
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 80 deletions.
10 changes: 6 additions & 4 deletions dbms/src/main/java/org/polypheny/db/backup/BackupManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import lombok.extern.slf4j.Slf4j;
import org.polypheny.db.backup.datagatherer.GatherEntries;
import org.polypheny.db.backup.datagatherer.GatherSchema;
import org.polypheny.db.backup.datainserter.EnterSchema;
import org.polypheny.db.backup.datainserter.InsertSchema;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.information.*;

Expand All @@ -31,6 +31,7 @@ public class BackupManager {
private static BackupManager INSTANCE = null;
private InformationPage informationPage;
private InformationGroup informationGroupOverview;
private BupInformationObject bupInformationObject;
//private final Logger logger;


Expand Down Expand Up @@ -85,18 +86,19 @@ public static BackupManager setAndGetInstance( BackupManager backupManager ) {
}

public void startDataGathering() {
this.bupInformationObject = new BupInformationObject();
//GatherEntries gatherEntries = new GatherEntries();
GatherSchema gatherSchema = new GatherSchema();

//gatherEntries.start();
gatherSchema.start();
this.bupInformationObject = gatherSchema.start(bupInformationObject);
}


private void startInserting() {
EnterSchema enterSchema = new EnterSchema();
InsertSchema insertSchema = new InsertSchema();

enterSchema.start();
insertSchema.start(bupInformationObject);
}

}
182 changes: 182 additions & 0 deletions dbms/src/main/java/org/polypheny/db/backup/BupInformationObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* Copyright 2019-2023 The Polypheny Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.polypheny.db.backup;

import com.google.common.collect.ImmutableMap;
import lombok.Getter;
import lombok.Setter;
import org.polypheny.db.catalog.entity.LogicalConstraint;
import org.polypheny.db.catalog.entity.logical.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BupInformationObject {

//ImmutableMap<Long, LogicalNamespace> namespaces;
@Getter @Setter
List<LogicalNamespace> namespaces;
@Getter @Setter
List<LogicalNamespace> relNamespaces;
@Getter @Setter
List<LogicalNamespace> graphNamespaces;
@Getter @Setter
List<LogicalNamespace> docNamespaces;
@Getter @Setter
ImmutableMap<Long, BupSuperEntity<LogicalNamespace>> bupRelNamespaces;
@Getter @Setter
ImmutableMap<Long, BupSuperEntity<LogicalNamespace>> bupGraphNamespaces;
@Getter @Setter
ImmutableMap<Long, BupSuperEntity<LogicalNamespace>> bupDocNamespaces;

/*//TODO(FF): adjust (also to gather schema...there it is per table right now)
@Getter @Setter
List<LogicalView> views;
@Getter @Setter
List<LogicalMaterializedView> materializedViews;
*/

//namespace id, list of tables for the namespace
@Getter @Setter
ImmutableMap<Long, List<LogicalView>> views;
@Getter @Setter
ImmutableMap<Long, List<BupSuperEntity<LogicalView>>> bupViews;
@Getter @Setter
ImmutableMap<Long, List<LogicalMaterializedView>> materializedViews;
@Getter @Setter
ImmutableMap<Long, List<BupSuperEntity<LogicalMaterializedView>>> bupMaterializedViews;
@Getter @Setter
ImmutableMap<Long, List<LogicalTable>> tables;
@Getter @Setter
ImmutableMap<Long, List<BupSuperEntity<LogicalTable>>> bupTables;
@Getter @Setter
ImmutableMap<Long, List<LogicalCollection>> collections;
@Getter @Setter
ImmutableMap<Long, List<BupSuperEntity<LogicalCollection>>> bupCollections;
@Getter @Setter
ImmutableMap<Long, LogicalGraph> graphs;
@Getter @Setter
ImmutableMap<Long, List<BupSuperEntity<LogicalGraph>>> bupGraphs;

//table id, list of views for the table
@Getter @Setter
ImmutableMap<Long, List<LogicalColumn>> columns;
@Getter @Setter
ImmutableMap<Long, List<LogicalPrimaryKey>> primaryKeysPerTable;
@Getter @Setter
ImmutableMap<Long, List<LogicalForeignKey>> foreignKeysPerTable;
@Getter @Setter
ImmutableMap<Long, List<LogicalIndex>> logicalIndexes;
@Getter @Setter
ImmutableMap<Long, List<BupSuperEntity<LogicalIndex>>> bupLogicalIndexes;
@Getter @Setter
ImmutableMap<Long, List<LogicalConstraint>> constraints;

@Getter @Setter
Boolean collectedRelSchema = false;
@Getter @Setter
Boolean collectedDocSchema = false;
@Getter @Setter
Boolean collectedGraphSchema = false;


public ImmutableMap<Long, BupSuperEntity<LogicalNamespace>> transformNamespacesToBupSuperEntityMap( List<LogicalNamespace> namespaces, Boolean toBeInserted) {

ImmutableMap<Long, BupSuperEntity<LogicalNamespace>> resultMap;
Map<Long, BupSuperEntity<LogicalNamespace>> tempNS = new HashMap<>();
BupSuperEntity<LogicalNamespace> nsBupObj = new BupSuperEntity<>();

for (LogicalNamespace ns : namespaces ) {
nsBupObj.setEntityObject( ns );
nsBupObj.setToBeInserted( toBeInserted );
nsBupObj.setNameForQuery( ns.name );
tempNS.put( ns.id, nsBupObj );
}

resultMap = ImmutableMap.copyOf( tempNS );
return resultMap;
}

public ImmutableMap<Long, BupSuperEntity<LogicalNamespace>> transformNamespacesToBupSuperEntityMap( List<LogicalNamespace> namespaces) {

ImmutableMap<Long, BupSuperEntity<LogicalNamespace>> resultMap;
Map<Long, BupSuperEntity<LogicalNamespace>> tempNS = new HashMap<>();
BupSuperEntity<LogicalNamespace> nsBupObj = new BupSuperEntity<>();

for (LogicalNamespace ns : namespaces ) {
nsBupObj.setEntityObject( ns );
nsBupObj.setNameForQuery( ns.name );
tempNS.put( ns.id, nsBupObj );
}

resultMap = ImmutableMap.copyOf( tempNS );
return resultMap;
}

public ImmutableMap<Long, List<BupSuperEntity<LogicalEntity>>> transformLogicalEntitiesToBupSuperEntity( ImmutableMap<Long, List<LogicalEntity>> entityMap, Boolean toBeInserted) {

ImmutableMap<Long, List<BupSuperEntity<LogicalEntity>>> resultMap;
Map<Long, List<BupSuperEntity<LogicalEntity>>> tempMap = new HashMap<>();
BupSuperEntity<LogicalEntity> tempBupEntity = new BupSuperEntity<>();

//go through each element from entityMap, and for each list go through each element and transform it to a BupSuperEntity
for ( Map.Entry<Long, List<LogicalEntity>> entry : entityMap.entrySet() ) {
List<LogicalEntity> entityList = entry.getValue();
List<BupSuperEntity<LogicalEntity>> bupEntityList = new ArrayList<>();

for ( LogicalEntity entity : entityList ) {
tempBupEntity.setEntityObject( entity );
tempBupEntity.setToBeInserted( toBeInserted );
tempBupEntity.setNameForQuery( entity.name );
bupEntityList.add( tempBupEntity );
}
tempMap.put( entry.getKey(), bupEntityList );

}

resultMap = ImmutableMap.copyOf( tempMap );
return resultMap;
}

public ImmutableMap<Long, List<BupSuperEntity<LogicalEntity>>> transformLogicalEntitiesToBupSuperEntity( ImmutableMap<Long, List<LogicalEntity>> entityMap) {

ImmutableMap<Long, List<BupSuperEntity<LogicalEntity>>> resultMap;
Map<Long, List<BupSuperEntity<LogicalEntity>>> tempMap = new HashMap<>();
BupSuperEntity<LogicalEntity> tempBupEntity = new BupSuperEntity<>();

//go through each element from entityMap, and for each list go through each element and transform it to a BupSuperEntity
for ( Map.Entry<Long, List<LogicalEntity>> entry : entityMap.entrySet() ) {
List<LogicalEntity> entityList = entry.getValue();
List<BupSuperEntity<LogicalEntity>> bupEntityList = new ArrayList<>();

for ( LogicalEntity entity : entityList ) {
tempBupEntity.setEntityObject( entity );
tempBupEntity.setToBeInserted( true );
tempBupEntity.setNameForQuery( entity.name );
bupEntityList.add( tempBupEntity );
}
tempMap.put( entry.getKey(), bupEntityList );

}

resultMap = ImmutableMap.copyOf( tempMap );
return resultMap;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@
* limitations under the License.
*/

package org.polypheny.db.backup.datainserter;
package org.polypheny.db.backup;

import lombok.extern.slf4j.Slf4j;
import lombok.Getter;
import lombok.Setter;

@Slf4j
public class EnterSchema {
public class BupSuperEntity<E> {

public EnterSchema() {
}
@Getter @Setter
private E entityObject;

@Getter @Setter
private Boolean toBeInserted = true;

//default, original name (change if rename needed (options))
@Getter @Setter
private String nameForQuery;

public void start() {
log.debug( "insert schemas" );
}
}
66 changes: 0 additions & 66 deletions dbms/src/main/java/org/polypheny/db/backup/InformationObject.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.activej.serializer.annotations.Serialize;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.polypheny.db.backup.BupInformationObject;
import org.polypheny.db.catalog.Catalog;
import org.polypheny.db.catalog.IdBuilder;
import org.polypheny.db.catalog.catalogs.AllocationCatalog;
Expand All @@ -42,9 +43,11 @@ public class GatherSchema {
//gather the schemas from Polypheny-DB
private final IdBuilder idBuilder = IdBuilder.getInstance();
private Snapshot snapshot;
private BupInformationObject bupInformationObject;

private Catalog catalog = PolyCatalog.getInstance();

//TODO(FF): don't safe data here, but safe it informationobject...
//ImmutableMap<Long, LogicalNamespace> namespaces;
List<LogicalNamespace> namespaces;
List<LogicalNamespace> relNamespaces;
Expand Down Expand Up @@ -77,15 +80,17 @@ public class GatherSchema {
public GatherSchema() {
}

public void start() {
public BupInformationObject start( BupInformationObject bupInformationObject ) {
log.debug( "gather schemas" );
this.bupInformationObject = bupInformationObject;

//figure out how to get the snapshot from catalog bzw. how to create a new snapshot, and take infos out of it
getSnapshot();
getRelSchema();
getDocSchema();
getGraphSchema();
testPrint();
return bupInformationObject;
}


Expand Down
Loading

0 comments on commit 56d2041

Please sign in to comment.