Skip to content

Commit

Permalink
Introduce ProcedureGDSFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
boggle committed Feb 18, 2016
1 parent 4c1e995 commit 5513bae
Show file tree
Hide file tree
Showing 30 changed files with 822 additions and 377 deletions.
Expand Up @@ -44,10 +44,10 @@
import org.neo4j.kernel.api.exceptions.KernelException;
import org.neo4j.kernel.api.index.SchemaIndexProvider;
import org.neo4j.kernel.api.labelscan.LabelScanStore;
import org.neo4j.kernel.api.legacyindex.AutoIndexing;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.extension.dependency.HighestSelectionStrategy;
import org.neo4j.kernel.guard.Guard;
import org.neo4j.kernel.impl.api.AutoIndexing;
import org.neo4j.kernel.impl.api.CommitProcessFactory;
import org.neo4j.kernel.impl.api.ConstraintEnforcingEntityOperations;
import org.neo4j.kernel.impl.api.DataIntegrityValidatingStatementOperations;
Expand Down
Expand Up @@ -561,9 +561,6 @@ DoubleLongRegister indexSample( IndexDescriptor index, DoubleLongRegister target
//== PROCEDURE OPERATIONS ===================
//===========================================

/** For managed procedures, this gives access to the current statement. */
CallableProcedure.Key<Statement> statement = CallableProcedure.Key.key("statement", Statement.class );

/** Fetch a procedure given its signature. */
ProcedureSignature procedureGet( ProcedureSignature.ProcedureName name ) throws ProcedureException;

Expand Down
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.api.legacyindex;

import java.util.Set;

import org.neo4j.kernel.api.DataWriteOperations;
import org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException;
import org.neo4j.kernel.api.properties.Property;

/**
* Abstract interface for accessing legacy auto indexing facilities for a given type of entity (nodes or relationships)
*
* Instances have three main concerns:
* - Controlling if auto indexing of the underlying entity type (node/relationship) is enabled or disabled
* - Controlling which properties are being indexed currently
* - Tracking updates
*
* @see AutoIndexing
* @see org.neo4j.kernel.impl.api.legacyindex.InternalAutoIndexOperations
*/
public interface AutoIndexOperations
{
void propertyAdded( DataWriteOperations ops, long entityId, Property property ) throws AutoIndexingKernelException;
void propertyChanged( DataWriteOperations ops, long entityId, Property oldProperty, Property newProperty )
throws AutoIndexingKernelException;
void propertyRemoved( DataWriteOperations ops, long entityId, int propertyKey )
throws AutoIndexingKernelException;

void entityRemoved( DataWriteOperations ops, long entityId ) throws AutoIndexingKernelException;

boolean enabled();
void enabled( boolean enabled );

void startAutoIndexingProperty( String propName );
void stopAutoIndexingProperty( String propName );

Set<String> getAutoIndexedProperties();

/**
* Instance of {@link AutoIndexOperations} that throws {@link UnsupportedOperationException} when any of its methods is invoked
*/
AutoIndexOperations UNSUPPORTED = new AutoIndexOperations()
{
@Override
public void propertyAdded( DataWriteOperations ops, long entityId, Property property ) throws AutoIndexingKernelException
{
throw new UnsupportedOperationException();
}

@Override
public void propertyChanged( DataWriteOperations ops, long entityId, Property oldProperty, Property newProperty ) throws AutoIndexingKernelException
{
throw new UnsupportedOperationException();
}

@Override
public void propertyRemoved( DataWriteOperations ops, long entityId, int propertyKey ) throws
AutoIndexingKernelException
{
throw new UnsupportedOperationException();
}

@Override
public void entityRemoved( DataWriteOperations ops, long entityId ) throws AutoIndexingKernelException
{
throw new UnsupportedOperationException();
}

@Override
public boolean enabled()
{
return false;
}

@Override
public void enabled( boolean enabled )
{
throw new UnsupportedOperationException();
}

@Override
public void startAutoIndexingProperty( String propName )
{
throw new UnsupportedOperationException();
}

@Override
public void stopAutoIndexingProperty( String propName )
{
throw new UnsupportedOperationException();
}

@Override
public Set<String> getAutoIndexedProperties()
{
throw new UnsupportedOperationException();
}
};
}
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.api.legacyindex;

/**
* Abstract interface for accessing legacy auto indexing facilities for nodes and relationships
*
* @see AutoIndexOperations
* @see org.neo4j.kernel.impl.api.legacyindex.InternalAutoIndexing
*/
public interface AutoIndexing
{
/**
* An instance of {@link AutoIndexing} that only returns {@link AutoIndexOperations}
* that throw {@link UnsupportedOperationException} when any method is invoked on them.
*/
AutoIndexing UNSUPPORTED = new AutoIndexing()
{
@Override
public AutoIndexOperations nodes()
{
return AutoIndexOperations.UNSUPPORTED;
}

@Override
public AutoIndexOperations relationships()
{
return AutoIndexOperations.UNSUPPORTED;
}
};

/**
* @return {@link AutoIndexOperations} for nodes
*/
AutoIndexOperations nodes();

/**
* @return {@link AutoIndexOperations} for relationships
*/
AutoIndexOperations relationships();
}
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;

import org.neo4j.collection.RawIterator;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.exceptions.ProcedureException;
import org.neo4j.kernel.api.exceptions.Status;

Expand All @@ -39,6 +40,8 @@ public interface CallableProcedure
*/
interface Context
{
Key<KernelTransaction> KERNEL_TRANSACTION = Key.key( "KernelTransaction", KernelTransaction.class );

<T> T get( Key<T> key ) throws ProcedureException;
}

Expand Down
Expand Up @@ -29,7 +29,6 @@

import static org.neo4j.helpers.collection.Iterables.asRawIterator;
import static org.neo4j.helpers.collection.Iterables.map;
import static org.neo4j.kernel.api.ReadOperations.statement;
import static org.neo4j.kernel.api.proc.ProcedureSignature.procedureSignature;

public class ListLabelsProcedure extends CallableProcedure.BasicProcedure
Expand All @@ -42,7 +41,7 @@ public ListLabelsProcedure( ProcedureName name )
@Override
public RawIterator<Object[], ProcedureException> apply( Context ctx, Object[] input ) throws ProcedureException
{
RawIterator<Label,ProcedureException> labels = asRawIterator( TokenAccess.LABELS.inUse( ctx.get( statement ) ) );
RawIterator<Label,ProcedureException> labels = asRawIterator( TokenAccess.LABELS.inUse( ctx.get( Context.KERNEL_TRANSACTION ).acquireStatement() ) );
return map( ( l) -> new Object[]{l.name()}, labels );
}
}
Expand Up @@ -29,7 +29,6 @@

import static org.neo4j.helpers.collection.Iterables.asRawIterator;
import static org.neo4j.helpers.collection.Iterables.map;
import static org.neo4j.kernel.api.ReadOperations.statement;
import static org.neo4j.kernel.api.proc.Neo4jTypes.NTString;

public class ListProceduresProcedure extends CallableProcedure.BasicProcedure
Expand All @@ -45,7 +44,7 @@ public ListProceduresProcedure( ProcedureSignature.ProcedureName procedureName )
@Override
public RawIterator<Object[],ProcedureException> apply( Context ctx, Object[] input ) throws ProcedureException
{
Set<ProcedureSignature> procedureSignatures = ctx.get( statement ).readOperations().proceduresGetAll();
Set<ProcedureSignature> procedureSignatures = ctx.get( Context.KERNEL_TRANSACTION ).acquireStatement().readOperations().proceduresGetAll();
ArrayList<ProcedureSignature> sorted = new ArrayList<>( procedureSignatures );
sorted.sort( (a,b) -> a.name().toString().compareTo( b.name().toString() ) );

Expand Down
Expand Up @@ -28,7 +28,6 @@

import static org.neo4j.helpers.collection.Iterables.asRawIterator;
import static org.neo4j.helpers.collection.Iterables.map;
import static org.neo4j.kernel.api.ReadOperations.statement;
import static org.neo4j.kernel.api.proc.ProcedureSignature.procedureSignature;

public class ListPropertyKeysProcedure extends CallableProcedure.BasicProcedure
Expand All @@ -41,7 +40,7 @@ public ListPropertyKeysProcedure( ProcedureSignature.ProcedureName name )
@Override
public RawIterator<Object[], ProcedureException> apply( Context ctx, Object[] input ) throws ProcedureException
{
RawIterator<String,ProcedureException> labels = asRawIterator( TokenAccess.PROPERTY_KEYS.inUse( ctx.get( statement ) ) );
RawIterator<String,ProcedureException> labels = asRawIterator( TokenAccess.PROPERTY_KEYS.inUse( ctx.get( Context.KERNEL_TRANSACTION ).acquireStatement() ) );
return map( ( key) -> new Object[]{key}, labels );
}
}
Expand Up @@ -29,7 +29,6 @@

import static org.neo4j.helpers.collection.Iterables.asRawIterator;
import static org.neo4j.helpers.collection.Iterables.map;
import static org.neo4j.kernel.api.ReadOperations.statement;
import static org.neo4j.kernel.api.proc.ProcedureSignature.procedureSignature;

public class ListRelationshipTypesProcedure extends CallableProcedure.BasicProcedure
Expand All @@ -43,7 +42,7 @@ public ListRelationshipTypesProcedure( ProcedureSignature.ProcedureName name )
public RawIterator<Object[], ProcedureException> apply( Context ctx, Object[] input ) throws ProcedureException
{
RawIterator<RelationshipType,ProcedureException> types =
asRawIterator( TokenAccess.RELATIONSHIP_TYPES.inUse( ctx.get( statement ) ) );
asRawIterator( TokenAccess.RELATIONSHIP_TYPES.inUse( ctx.get( Context.KERNEL_TRANSACTION ).acquireStatement() ) );
return map( ( l) -> new Object[]{l.name()}, types );
}
}

0 comments on commit 5513bae

Please sign in to comment.