Skip to content

Commit

Permalink
default works now, changed for LogicalTable that polymorphism works now
Browse files Browse the repository at this point in the history
  • Loading branch information
flurfis committed Nov 23, 2023
1 parent 9712c0c commit 152ea92
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@EqualsAndHashCode(callSuper = false)
@Value
@SuperBuilder(toBuilder = true)
public class LogicalIndex implements Serializable {
public class LogicalIndex implements LogicalObject {

private static final long serialVersionUID = -318228681682792406L;

Expand Down Expand Up @@ -118,6 +118,18 @@ public Serializable[] getParameterArray( int ordinalPosition, String columnName
}


@Override
public Serializable[] getParameterArray() {
return new Serializable[0];
}


@Override
public Visibility getVisibility() {
return LogicalObject.super.getVisibility();
}


// Used for creating ResultSets
@RequiredArgsConstructor
@Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.polypheny.db.catalog.logistic;

import lombok.NonNull;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.config.RuntimeConfig;

public enum Collation {
Expand Down Expand Up @@ -64,7 +65,7 @@ public String collationToString( ) {
return "CASE INSENSITIVE";
}
else {
throw new RuntimeException( "Collation not supported" );
throw new GenericRuntimeException( "Collation not supported" );
}
} catch ( Exception e ) {
throw new RuntimeException( e );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

import lombok.Getter;
import lombok.Setter;
import org.polypheny.db.catalog.entity.LogicalObject;
import org.polypheny.db.catalog.entity.logical.LogicalEntity;

@Getter @Setter
public class BackupEntityWrapper<E> {
public class BackupEntityWrapper<E extends LogicalObject> {

private E entityObject;

Expand All @@ -31,4 +33,18 @@ public class BackupEntityWrapper<E> {

private EntityReferencer entityReferencer;


public BackupEntityWrapper( E entity, Boolean toBeInserted, String nameForQuery, EntityReferencer entityReferencer ) {
this.entityObject = entity;
this.toBeInserted = toBeInserted;
this.nameForQuery = nameForQuery;
this.entityReferencer = entityReferencer;
}

public BackupEntityWrapper( E entity, String nameForQuery, EntityReferencer entityReferencer ) {
this.entityObject = entity;
this.nameForQuery = nameForQuery;
this.entityReferencer = entityReferencer;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public class BackupInformationObject {

private ImmutableMap<Long, List<BackupEntityWrapper<LogicalMaterializedView>>> wrappedMaterializedViews;

private ImmutableMap<Long, List<LogicalTable>> tables;
private ImmutableMap<Long, List<LogicalEntity>> tables; //TODO: cast all to logicaltable - LogicalEntity.unwrap(logicalTable.class) to get logicalTAble, for everything here logicalEntity

private ImmutableMap<Long, List<BackupEntityWrapper<LogicalTable>>> wrappedTables;
private ImmutableMap<Long, List<BackupEntityWrapper<LogicalEntity>>> wrappedTables;

private ImmutableMap<Long, List<LogicalCollection>> collections;

Expand Down Expand Up @@ -100,12 +100,16 @@ public ImmutableMap<Long, BackupEntityWrapper<LogicalNamespace>> wrapNamespaces(

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

for ( LogicalNamespace ns : namespaces ) {
/*
nsBupObj.setEntityObject( ns );
nsBupObj.setToBeInserted( toBeInserted );
nsBupObj.setNameForQuery( ns.name );
*/
//E entity, Boolean toBeInserted, String nameForQuery, EntityReferencer entityReferencer
BackupEntityWrapper<LogicalNamespace> nsBupObj = new BackupEntityWrapper<>(ns, toBeInserted, ns.name, null);
tempNS.put( ns.id, nsBupObj );
}

Expand All @@ -120,9 +124,11 @@ public ImmutableMap<Long, BackupEntityWrapper<LogicalNamespace>> wrapNamespaces(
Map<Long, BackupEntityWrapper<LogicalNamespace>> tempNS = new HashMap<>();

for ( LogicalNamespace ns : namespaces ) {
/*
BackupEntityWrapper<LogicalNamespace> nsBupObj = new BackupEntityWrapper<>();
nsBupObj.setEntityObject( ns );
nsBupObj.setNameForQuery( ns.name );
*/

// create entityReferences for each namespace (if there is a reference) with namespacedependencies, and add entityReferences to the backupinformationobject
if ( namespaceDependencies.containsKey( ns.id ) || namespaceTableDependencies.containsKey( ns.id ) ) {
Expand All @@ -140,17 +146,21 @@ public ImmutableMap<Long, BackupEntityWrapper<LogicalNamespace>> wrapNamespaces(
}
entityReferencer.setReferencerTables( tempReferencerTables );
}
nsBupObj.setEntityReferencer( entityReferencer );
BackupEntityWrapper<LogicalNamespace> nsBupObj = new BackupEntityWrapper<>(ns, ns.name, entityReferencer);
tempNS.put( ns.id, nsBupObj );
//nsBupObj.setEntityReferencer( entityReferencer );
} else {
//E entity, Boolean toBeInserted, String nameForQuery, EntityReferencer entityReferencer
BackupEntityWrapper<LogicalNamespace> nsBupObj = new BackupEntityWrapper<>(ns, ns.name, null);
tempNS.put( ns.id, nsBupObj );
}

tempNS.put( ns.id, nsBupObj );
}

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


/*
public ImmutableMap<Long, List<BackupEntityWrapper<LogicalEntity>>> wrapLogicalEntities( ImmutableMap<Long, List<LogicalEntity>> entityMap, Boolean toBeInserted ) {
ImmutableMap<Long, List<BackupEntityWrapper<LogicalEntity>>> resultMap;
Expand Down Expand Up @@ -202,24 +212,29 @@ public ImmutableMap<Long, List<BackupEntityWrapper<LogicalEntity>>> wrapLogicalE
return resultMap;
}
*/

public ImmutableMap<Long, List<BackupEntityWrapper<LogicalTable>>> tempWrapLogicalTables( ImmutableMap<Long, List<LogicalTable>> entityMap, Map<Long, List<Long>> tableDependencies, Map<Long, List<Pair<Long, Long>>> namespaceTableDependendencies, Boolean toBeInserted ) {
public ImmutableMap<Long, List<BackupEntityWrapper<LogicalEntity>>> wrapLogicalEntities( Map<Long, List<LogicalEntity>> entityMap, Map<Long, List<Long>> tableDependencies, Map<Long, List<Pair<Long, Long>>> namespaceTableDependendencies, Boolean toBeInserted ) {

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

//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<LogicalTable>> entry : entityMap.entrySet() ) {
List<LogicalTable> entityList = entry.getValue();
List<BackupEntityWrapper<LogicalTable>> bupEntityList = new ArrayList<>();
for ( Map.Entry<Long, List<LogicalEntity>> entry : entityMap.entrySet() ) {
List<LogicalEntity> entityList = entry.getValue();
List<BackupEntityWrapper<LogicalEntity>> bupEntityList = new ArrayList<>();

for ( LogicalTable entity : entityList ) {
BackupEntityWrapper<LogicalTable> tempBupEntity = new BackupEntityWrapper<>();
for ( LogicalEntity entity : entityList ) {
BackupEntityWrapper<LogicalEntity> tempBupEntity = new BackupEntityWrapper<>(entity, toBeInserted, entity.name, null);
/*
tempBupEntity.setEntityObject( entity );
tempBupEntity.setToBeInserted( toBeInserted );
tempBupEntity.setNameForQuery( entity.name );
*/
bupEntityList.add( tempBupEntity );


// create entityReferences for each table (if there is a reference) with tableDependencies, and add entityReferences to the backupinformationobject
if (entity.getEntityType().equals( EntityType.ENTITY)) {
EntityReferencer entityReferencer = new EntityReferencer( entity.getId(), BackupEntityType.TABLE );
Expand Down Expand Up @@ -251,6 +266,7 @@ public void transformationManager() {
}


/*
public List<BackupEntityWrapper<LogicalEntity>> wrapLogicalEntity( List<LogicalEntity> entityList ) {
//go through each element from entityMap, and for each list go through each element and transform it to a BupSuperEntity
Expand All @@ -268,4 +284,24 @@ public List<BackupEntityWrapper<LogicalEntity>> wrapLogicalEntity( List<LogicalE
}
public ImmutableMap<Integer, ? extends LogicalEntity> test (List<? extends LogicalEntity> entityList) {
ImmutableMap<Integer, LogicalEntity> resultMap;
Map<Integer, LogicalEntity> tempMap = new HashMap<>();
tempMap.put( 1, entityList.get( 0 ) );
String name = entityList.get( 0 ).name;
resultMap = ImmutableMap.copyOf( tempMap );
return resultMap;
}
public Map<Integer, List<LogicalEntity>> test2 (Map<Long, List<LogicalEntity>> entityMap) {
ImmutableMap<Integer, List<LogicalEntity>> resultMap;
Map<Integer, List <LogicalEntity>> tempMap = new HashMap<>();
tempMap.put( 1, entityMap.get( 0 ));
String name = entityMap.get( 0 ).get( 0 ).name;
resultMap = ImmutableMap.copyOf( tempMap );
return resultMap;
}
*/

}
15 changes: 14 additions & 1 deletion dbms/src/main/java/org/polypheny/db/backup/BackupManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.polypheny.db.backup.datagatherer.GatherEntries;
import org.polypheny.db.backup.datagatherer.GatherSchema;
import org.polypheny.db.backup.datainserter.InsertSchema;
import org.polypheny.db.catalog.entity.logical.LogicalEntity;
import org.polypheny.db.catalog.entity.logical.LogicalForeignKey;
import org.polypheny.db.catalog.entity.logical.LogicalNamespace;
import org.polypheny.db.catalog.entity.logical.LogicalTable;
Expand Down Expand Up @@ -167,8 +168,20 @@ private void wrapEntities() {
backupInformationObject.setWrappedNamespaces( wrappedNamespaces );

// wrap all tables with BackupEntityWrapper
ImmutableMap<Long, List<BackupEntityWrapper<LogicalTable>>> wrappedTables = backupInformationObject.tempWrapLogicalTables( backupInformationObject.getTables(), tableDependencies, namespaceTableDependendencies, true);
ImmutableMap<Long, List<BackupEntityWrapper<LogicalEntity>>> wrappedTables = backupInformationObject.wrapLogicalEntities( backupInformationObject.getTables(), tableDependencies, namespaceTableDependendencies, true);
backupInformationObject.setWrappedTables( wrappedTables );

/*
ArrayList<LogicalTable> lol = new ArrayList<>();
lol.add( (LogicalTable) backupInformationObject.getTables().get( 0 ));
Map<Long, List<LogicalEntity>> lol2 = backupInformationObject.getTables();
Map<Integer, List<LogicalEntity>> lol3 = backupInformationObject.test2(lol2);
//ImmutableMap<Integer, LogicalTable> ha = backupInformationObject.test( lol );
*/
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class GatherSchema {
List<LogicalNamespace> docNamespaces;

//namespace id, list of tables for the namespace
ImmutableMap<Long, List<LogicalTable>> tables;
ImmutableMap<Long, List<LogicalEntity>> tables;
//TODO(FF): make views and materialized views not (? deleted?)... views and materialized views can be over several tables -> over several namespaces??
ImmutableMap<Long, List<LogicalView>> views;
ImmutableMap<Long, List<LogicalMaterializedView>> materializedViews;
Expand Down Expand Up @@ -138,6 +138,7 @@ private void getRelSchema() {

// get tables from namespace
List<LogicalTable> tablesFromNamespace = snapshot.rel().getTablesFromNamespace( namespaceId );
//List<LogicalEntity> tablesFromNamespace = snapshot.rel().getTables( namespaceId, null ).stream().map( v -> v.unwrap( LogicalEntity.class ) ).collect(Collectors.toList( ));
tables.put( namespaceId, tablesFromNamespace );

// get other schema information for each table
Expand Down Expand Up @@ -196,7 +197,9 @@ private void getRelSchema() {
}

//safes the gathered information in the class variables
this.tables = ImmutableMap.copyOf( tables );
this.tables = ImmutableMap.copyOf( tables.entrySet().stream().collect(Collectors.toMap(v -> v.getKey(), v -> v.getValue().stream().map( e -> e.unwrap( LogicalEntity.class ) ).collect(Collectors.toList() ) )));
//this.tables = ImmutableMap.copyOf( (Map<? extends Long, ? extends List<LogicalEntity>>) tables );
//this.tables = ImmutableMap.copyOf( (Map<Long, ? extends List<LogicalEntity>>) tables );
this.backupInformationObject.setTables( this.tables );
this.views = ImmutableMap.copyOf( views );
this.backupInformationObject.setViews( this.views );
Expand Down
Loading

0 comments on commit 152ea92

Please sign in to comment.