Skip to content

Commit

Permalink
NamespaceModel for Namespace request
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Aug 25, 2023
1 parent bd73a52 commit d1c9c44
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
46 changes: 23 additions & 23 deletions webui/src/main/java/org/polypheny/db/webui/Crud.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@
import org.polypheny.db.webui.models.ForeignKey;
import org.polypheny.db.webui.models.Index;
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.QueryInterfaceModel;
import org.polypheny.db.webui.models.Schema;
import org.polypheny.db.webui.models.SidebarElement;
import org.polypheny.db.webui.models.SortState;
import org.polypheny.db.webui.models.TableConstraint;
Expand Down Expand Up @@ -2736,29 +2736,29 @@ RelationalResult executeAlg( final RelAlgRequest request, Session session ) {
/**
* Create or drop a namespace
*/
void schemaRequest( final Context ctx ) {
Schema schema = ctx.bodyAsClass( Schema.class );
void namespaceRequest( final Context ctx ) {
Namespace namespace = ctx.bodyAsClass( Namespace.class );
Transaction transaction = getTransaction();

NamespaceType type = schema.getType();
NamespaceType type = namespace.getType();

if ( type == NamespaceType.GRAPH ) {
handleGraphDdl( schema, transaction, ctx );
handleGraphDdl( namespace, transaction, ctx );
return;
}

// create namespace
if ( schema.isCreate() && !schema.isDrop() ) {
if ( namespace.isCreate() && !namespace.isDrop() ) {

StringBuilder query = new StringBuilder( "CREATE " );
if ( schema.getType() == NamespaceType.DOCUMENT ) {
if ( namespace.getType() == NamespaceType.DOCUMENT ) {
query.append( "DOCUMENT " );
}
query.append( "NAMESPACE " );

query.append( "\"" ).append( schema.getName() ).append( "\"" );
if ( schema.getAuthorization() != null && !schema.getAuthorization().equals( "" ) ) {
query.append( " AUTHORIZATION " ).append( schema.getAuthorization() );
query.append( "\"" ).append( namespace.getName() ).append( "\"" );
if ( namespace.getAuthorization() != null && !namespace.getAuthorization().equals( "" ) ) {
query.append( " AUTHORIZATION " ).append( namespace.getAuthorization() );
}
try {
int rows = executeSqlUpdate( transaction, query.toString() );
Expand All @@ -2775,21 +2775,21 @@ void schemaRequest( final Context ctx ) {
}
}
// drop namespace
else if ( !schema.isCreate() && schema.isDrop() ) {
else if ( !namespace.isCreate() && namespace.isDrop() ) {
if ( type == null ) {
List<LogicalNamespace> namespaces = catalog.getSnapshot().getNamespaces( new org.polypheny.db.catalog.logistic.Pattern( schema.getName() ) );
List<LogicalNamespace> namespaces = catalog.getSnapshot().getNamespaces( new org.polypheny.db.catalog.logistic.Pattern( namespace.getName() ) );
assert namespaces.size() == 1;
type = namespaces.get( 0 ).namespaceType;

if ( type == NamespaceType.GRAPH ) {
handleGraphDdl( schema, transaction, ctx );
handleGraphDdl( namespace, transaction, ctx );
return;
}
}

StringBuilder query = new StringBuilder( "DROP NAMESPACE " );
query.append( "\"" ).append( schema.getName() ).append( "\"" );
if ( schema.isCascade() ) {
query.append( "\"" ).append( namespace.getName() ).append( "\"" );
if ( namespace.isCascade() ) {
query.append( " CASCADE" );
}
try {
Expand All @@ -2811,17 +2811,17 @@ else if ( !schema.isCreate() && schema.isDrop() ) {
}


private void handleGraphDdl( Schema schema, Transaction transaction, Context ctx ) {
if ( schema.isCreate() && !schema.isDrop() ) {
private void handleGraphDdl( Namespace namespace, Transaction transaction, Context ctx ) {
if ( namespace.isCreate() && !namespace.isDrop() ) {
Statement statement = transaction.createStatement();
Processor processor = transaction.getProcessor( QueryLanguage.from( "cypher" ) );

String query = String.format( "CREATE DATABASE %s", schema.getName() );
String query = String.format( "CREATE DATABASE %s", namespace.getName() );

List<? extends Node> nodes = processor.parse( query );
ExtendedQueryParameters parameters = new ExtendedQueryParameters( query, NamespaceType.GRAPH, schema.getName() );
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() );
Expand All @@ -2834,14 +2834,14 @@ private void handleGraphDdl( Schema schema, Transaction transaction, Context ctx
}
ctx.json( RelationalResult.builder().error( e.getMessage() ).build() );
}
} else if ( schema.isDrop() && !schema.isCreate() ) {
} else if ( namespace.isDrop() && !namespace.isCreate() ) {
Statement statement = transaction.createStatement();
Processor processor = transaction.getProcessor( QueryLanguage.from( "cypher" ) );

String query = String.format( "DROP DATABASE %s", schema.getName() );
String query = String.format( "DROP DATABASE %s", namespace.getName() );

List<? extends Node> nodes = processor.parse( query );
ExtendedQueryParameters parameters = new ExtendedQueryParameters( query, NamespaceType.GRAPH, schema.getName() );
ExtendedQueryParameters parameters = new ExtendedQueryParameters( query, NamespaceType.GRAPH, namespace.getName() );
try {
PolyImplementation result = processor.prepareDdl( statement, nodes.get( 0 ), parameters );
int rowsChanged = result.getRowsChanged( statement );
Expand Down
2 changes: 1 addition & 1 deletion webui/src/main/java/org/polypheny/db/webui/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private void crudRoutes( Javalin webuiServer, Crud crud ) {

webuiServer.post( "/getAnalyzerPage", crud::getAnalyzerPage );

webuiServer.post( "/schemaRequest", crud::schemaRequest );
webuiServer.post( "/namespaceRequest", crud::namespaceRequest );

webuiServer.get( "/getTypeInfo", crud::getTypeInfo );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@


/**
* Model for a namespace of the logical schema.
* Model for a namespace of the logical namespace.
*/
@Getter
public class Schema {
public class Namespace {

private String name;
private NamespaceType type;
Expand All @@ -47,7 +47,7 @@ public class Schema {
* @param name name of the schema
* @param type type of the schema, e.g. relational
*/
public Schema( final String name, final NamespaceType type, @Nullable final String store ) {
public Namespace( final String name, final NamespaceType type, @Nullable final String store ) {
this.name = name;
this.type = type;

Expand Down

0 comments on commit d1c9c44

Please sign in to comment.