Skip to content

Commit

Permalink
Make room for future builtin index procedures
Browse files Browse the repository at this point in the history
  • Loading branch information
benbc committed Sep 14, 2016
1 parent 9da1520 commit aa2f892
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 219 deletions.
Expand Up @@ -54,30 +54,30 @@ public class BuiltInProcedures
@Context
public KernelTransaction tx;

@Description("List all labels in the database.")
@Procedure(name = "db.labels", mode = READ)
@Description( "List all labels in the database." )
@Procedure( name = "db.labels", mode = READ )
public Stream<LabelResult> listLabels()
{
return TokenAccess.LABELS.inUse( tx.acquireStatement() ).map( LabelResult::new ).stream();
}

@Description( "List all property keys in the database." )
@Procedure(name = "db.propertyKeys", mode = READ)
@Procedure( name = "db.propertyKeys", mode = READ )
public Stream<PropertyKeyResult> listPropertyKeys()
{
return TokenAccess.PROPERTY_KEYS.inUse( tx.acquireStatement() ).map( PropertyKeyResult::new ).stream();
}

@Description( "List all relationship types in the database." )
@Procedure(name = "db.relationshipTypes", mode = READ)
@Procedure( name = "db.relationshipTypes", mode = READ )
public Stream<RelationshipTypeResult> listRelationshipTypes()
{
return TokenAccess.RELATIONSHIP_TYPES.inUse( tx.acquireStatement() )
.map( RelationshipTypeResult::new ).stream();
}

@Description( "List all indexes in the database." )
@Procedure(name = "db.indexes", mode = READ)
@Procedure( name = "db.indexes", mode = READ )
public Stream<IndexResult> listIndexes() throws ProcedureException
{
try ( Statement statement = tx.acquireStatement() )
Expand Down Expand Up @@ -120,21 +120,21 @@ public Stream<IndexResult> listIndexes() throws ProcedureException
}
}

@Description("Await indexes in the database to come online.")
@Procedure(name = "db.awaitIndex", mode = READ)
public void awaitIndex( @Name("label") String labelName,
@Name("property") String propertyKeyName,
@Name(value = "timeOutSeconds", defaultValue = "300") long timeout )
@Description( "Wait for an index to come online." )
@Procedure( name = "db.awaitIndex", mode = READ )
public void awaitIndex( @Name( "label" ) String labelName,
@Name( "property" ) String propertyKeyName,
@Name( value = "timeOutSeconds", defaultValue = "300" ) long timeout )
throws ProcedureException
{
try ( AwaitIndexProcedure awaitIndexProcedure = new AwaitIndexProcedure( tx ) )
try ( IndexProcedures indexProcedures = indexProcedures() )
{
awaitIndexProcedure.execute( labelName, propertyKeyName, timeout, TimeUnit.SECONDS );
indexProcedures.awaitIndex( labelName, propertyKeyName, timeout, TimeUnit.SECONDS );
}
}

@Description( "List all constraints in the database." )
@Procedure(name = "db.constraints", mode = READ)
@Procedure( name = "db.constraints", mode = READ )
public Stream<ConstraintResult> listConstraints()
{
Statement statement = tx.acquireStatement();
Expand All @@ -150,7 +150,7 @@ public Stream<ConstraintResult> listConstraints()
}

@Description( "List all procedures in the DBMS." )
@Procedure(name = "dbms.procedures", mode = READ)
@Procedure( name = "dbms.procedures", mode = READ )
public Stream<ProcedureResult> listProcedures()
{
try ( Statement statement = tx.acquireStatement() )
Expand All @@ -175,6 +175,11 @@ public Stream<FunctionResult> listFunctions()
}
}

private IndexProcedures indexProcedures()
{
return new IndexProcedures( tx );
}

@SuppressWarnings( "unused" )
public class LabelResult
{
Expand Down
Expand Up @@ -35,18 +35,18 @@

import static java.lang.String.format;

public class AwaitIndexProcedure implements AutoCloseable
public class IndexProcedures implements AutoCloseable
{
private final Statement statement;
private final ReadOperations operations;
private Statement statement;

public AwaitIndexProcedure( KernelTransaction tx )
public IndexProcedures( KernelTransaction tx )
{
statement = tx.acquireStatement();
operations = statement.readOperations();
}

public void execute( String labelName, String propertyKeyName, long timeout, TimeUnit timeoutUnits )
public void awaitIndex( String labelName, String propertyKeyName, long timeout, TimeUnit timeoutUnits )
throws ProcedureException
{
int labelId = getLabelId( labelName );
Expand Down

0 comments on commit aa2f892

Please sign in to comment.