本文整理了Java中org.neo4j.function.Factory
类的一些代码示例,展示了Factory
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Factory
类的具体详情如下:
包路径:org.neo4j.function.Factory
类名称:Factory
[英]A generic factory interface for creating instances that do not need any additional dependencies or parameters. If the implementation is not always creating new instances, you should probably use java.util.function.Supplier.
[中]用于创建不需要任何附加依赖项或参数的实例的通用factory接口。如果实现并不总是创建新实例,那么您可能应该使用java。util。作用供应商
代码示例来源:origin: neo4j/neo4j
@SuppressWarnings( "unchecked" )
@Documented( "Get all indexes." )
@Test
@GraphDescription.Graph( nodes = {} )
public void get_indexes() throws Exception
{
data.get();
String labelName1 = labels.newInstance();
String propertyKey1 = properties.newInstance();
String labelName2 = labels.newInstance();
String propertyKey2 = properties.newInstance();
createIndex( labelName1, propertyKey1 );
createIndex( labelName2, propertyKey2 );
List<Map<String,Object>> serializedList = retryOnStillPopulating(
() -> gen.get().expectedStatus( 200 ).get( getSchemaIndexUri() ).entity() );
Map<String,Object> index1 = new HashMap<>();
index1.put( "label", labelName1 );
index1.put( "labels", singletonList( labelName1 ) );
index1.put( "property_keys", singletonList( propertyKey1 ) );
Map<String,Object> index2 = new HashMap<>();
index2.put( "label", labelName2 );
index2.put( "labels", singletonList( labelName2 ) );
index2.put( "property_keys", singletonList( propertyKey2 ) );
assertThat( serializedList, hasItems( index1, index2 ) );
}
代码示例来源:origin: neo4j/neo4j
try ( PrimitiveCollection a = factory.newInstance() )
int o = a.hashCode();
assertThat( "0 elm hashcode equal", o, is( i ) );
assertThat( "1 elm hashcode equal", n, is( j ) );
assertThat( "2 elm hashcode equal", m, is( k ) );
assertThat( "3 elm hashcode distinct", l, not( isOneOf( i, j, k, m, n, o ) ) );
assertThat( "2 elm hashcode distinct", k, not( isOneOf( i, j, l, n, o ) ) );
代码示例来源:origin: neo4j/neo4j
@Documented( "Create index.\n" +
"\n" +
"This will start a background job in the database that will create and populate the index.\n" +
"You can check the status of your index by listing all the indexes for the relevant label." )
@Test
@GraphDescription.Graph( nodes = {} )
public void create_index() throws JsonParseException
{
data.get();
String labelName = labels.newInstance();
String propertyKey = properties.newInstance();
Map<String,Object> definition = map( "property_keys", singletonList( propertyKey ) );
String result = gen.get()
.expectedStatus( 200 )
.payload( createJsonFrom( definition ) )
.post( getSchemaIndexLabelUri( labelName ) )
.entity();
Map<String,Object> serialized = jsonToMap( result );
Map<String,Object> index = new HashMap<>();
index.put( "label", labelName );
index.put( "labels", singletonList( labelName ) );
index.put( "property_keys", singletonList( propertyKey ) );
assertThat( serialized, equalTo( index ) );
}
代码示例来源:origin: neo4j/neo4j
final String index = indexes.newInstance();
String key = "name";
String value = "Peter";
GraphDatabaseService graphdb = graphdb();
helper.createRelationshipIndex( index );
try ( Transaction tx = graphdb.beginTx() )
Node node1 = graphdb.createNode();
Node node2 = graphdb.createNode();
Relationship rel = node1.createRelationshipTo( node2, MyRelationshipTypes.KNOWS );
graphdb.index().forRelationships( index ).add( rel, key, value );
代码示例来源:origin: neo4j/neo4j
@Documented( "List indexes for a label." )
@Test
@GraphDescription.Graph( nodes = {} )
public void get_indexes_for_label() throws Exception
{
data.get();
String labelName = labels.newInstance();
String propertyKey = properties.newInstance();
createIndex( labelName, propertyKey );
Map<String,Object> definition = map( "property_keys", singletonList( propertyKey ) );
List<Map<String,Object>> serializedList = retryOnStillPopulating( () -> gen.get()
.expectedStatus( 200 )
.payload( createJsonFrom( definition ) )
.get( getSchemaIndexLabelUri( labelName ) )
.entity() );
Map<String,Object> index = new HashMap<>();
index.put( "label", labelName );
index.put( "labels", singletonList( labelName ) );
index.put( "property_keys", singletonList( propertyKey ) );
assertThat( serializedList, hasItem( index ) );
}
代码示例来源:origin: neo4j/neo4j
@Documented( "Get a specific uniqueness constraint.\n" +
"Get a specific uniqueness constraint for a label and a property." )
@Test
@GraphDescription.Graph( nodes = {} )
public void getLabelUniquenessPropertyConstraint() throws JsonParseException
{
data.get();
String labelName = labels.newInstance();
String propertyKey = properties.newInstance();
createLabelUniquenessPropertyConstraint( labelName, propertyKey );
String result = gen.get().expectedStatus( 200 ).get(
getSchemaConstraintLabelUniquenessPropertyUri( labelName, propertyKey ) ).entity();
List<Map<String, Object>> serializedList = jsonToList( result );
Map<String, Object> constraint = new HashMap<>( );
constraint.put( "type", ConstraintType.UNIQUENESS.name() );
constraint.put( "label", labelName );
constraint.put( "property_keys", singletonList( propertyKey ) );
assertThat( serializedList, hasItem( constraint ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void get_or_create_node_with_array_properties() throws Exception
{
final String index = indexes.newInstance();
String key = "name";
String value = "Tobias";
helper.createNodeIndex( index );
ResponseEntity response = gen()
.expectedStatus( 201 /* created */ )
.payloadType( MediaType.APPLICATION_JSON_TYPE )
.payload( "{\"key\": \"" + key + "\", \"value\": \"" + value
+ "\", \"properties\": {\"" + key + "\": \"" + value
+ "\", \"array\": [1,2,3]}}" )
.post( functionalTestHelper.nodeIndexUri() + index + "?unique" );
MultivaluedMap<String, String> headers = response.response().getHeaders();
Map<String, Object> result = JsonHelper.jsonToMap( response.entity() );
String location = headers.getFirst("Location");
assertEquals( result.get( "indexed" ), location );
Map<String, Object> data = assertCast( Map.class, result.get( "data" ) );
assertEquals( value, data.get( key ) );
assertEquals(Arrays.asList( 1, 2, 3), data.get( "array" ) );
Node node;
try ( Transaction tx = graphdb().beginTx() )
{
node = graphdb().index().forNodes(index).get(key, value).getSingle();
}
assertThat( node, inTx( graphdb(), hasProperty( key ).withValue( value ) ) );
assertThat( node, inTx( graphdb(), hasProperty( "array" ).withValue( new int[]{1, 2, 3} ) ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void create_compound_schema_index()
{
Map<String,Object> definition = map( "property_keys",
asList( properties.newInstance(), properties.newInstance() ) );
gen.get().expectedStatus( 200 )
.payload( createJsonFrom( definition ) ).post( getSchemaIndexLabelUri( labels.newInstance() ) );
}
代码示例来源:origin: neo4j/neo4j
@Override
public ResourceIterator<Path> iterator()
{
TraverserIterator traverserIterator = traverserIteratorFactory.newInstance();
lastIterator = traverserIterator;
return traverserIterator;
}
代码示例来源:origin: neo4j/neo4j
@Documented( "Create uniqueness constraint.\n" +
"Create a uniqueness constraint on a property." )
@Test
@GraphDescription.Graph( nodes = {} )
public void createPropertyUniquenessConstraint() throws JsonParseException
{
data.get();
String labelName = labels.newInstance();
String propertyKey = properties.newInstance();
Map<String, Object> definition = map( "property_keys", singletonList( propertyKey ) );
String result = gen.get().expectedStatus( 200 ).payload( createJsonFrom( definition ) ).post(
getSchemaConstraintLabelUniquenessUri( labelName ) ).entity();
Map<String, Object> serialized = jsonToMap( result );
Map<String, Object> constraint = new HashMap<>( );
constraint.put( "type", ConstraintType.UNIQUENESS.name() );
constraint.put( "label", labelName );
constraint.put( "property_keys", singletonList( propertyKey ) );
assertThat( serialized, equalTo( constraint ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void already_indexed_relationship_should_not_fail_on_create_or_fail()
{
// Given
final String index = indexes.newInstance();
String key = "name";
String value = "Peter";
GraphDatabaseService graphdb = graphdb();
helper.createRelationshipIndex( index );
Relationship rel;
try ( Transaction tx = graphdb.beginTx() )
{
Node node1 = graphdb.createNode();
Node node2 = graphdb.createNode();
rel = node1.createRelationshipTo( node2, MyRelationshipTypes.KNOWS );
graphdb.index().forRelationships( index ).add( rel, key, value );
tx.success();
}
// When & Then
gen.get()
.expectedStatus( 201 )
.payloadType( MediaType.APPLICATION_JSON_TYPE )
.payload(
"{\"key\": \"" + key + "\", \"value\": \"" + value + "\", \"uri\":\""
+ functionalTestHelper.relationshipUri( rel.getId() ) + "\"}" )
.post( functionalTestHelper.relationshipIndexUri() + index + "?uniqueness=create_or_fail" );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void create_compound_schema_constraint()
{
Map<String,Object> definition = map( "property_keys",
asList( properties.newInstance(), properties.newInstance() ) );
gen.get().expectedStatus( 405 )
.payload( createJsonFrom( definition ) ).post( getSchemaConstraintLabelUri( labels.newInstance() ) );
}
代码示例来源:origin: neo4j/neo4j
protected R create()
{
return factory.newInstance();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void already_indexed_node_should_not_fail_on_create_or_fail()
{
// Given
final String index = indexes.newInstance();
String key = "name";
String value = "Peter";
GraphDatabaseService graphdb = graphdb();
helper.createNodeIndex( index );
Node node;
try ( Transaction tx = graphdb.beginTx() )
{
node = graphdb.createNode();
graphdb.index().forNodes( index ).add( node, key, value );
tx.success();
}
// When & Then
gen.get()
.expectedStatus( 201 )
.payloadType( MediaType.APPLICATION_JSON_TYPE )
.payload(
"{\"key\": \"" + key + "\", \"value\": \"" + value + "\", \"uri\":\""
+ functionalTestHelper.nodeUri( node.getId() ) + "\"}" )
.post( functionalTestHelper.nodeIndexUri() + index + "?uniqueness=create_or_fail" );
}
代码示例来源:origin: neo4j/neo4j
@SuppressWarnings( "unchecked" )
@Documented( "Get all uniqueness constraints for a label." )
@Test
@GraphDescription.Graph( nodes = {} )
public void getLabelUniquenessPropertyConstraints() throws JsonParseException
{
data.get();
String labelName = labels.newInstance();
String propertyKey1 = properties.newInstance();
String propertyKey2 = properties.newInstance();
createLabelUniquenessPropertyConstraint( labelName, propertyKey1 );
createLabelUniquenessPropertyConstraint( labelName, propertyKey2 );
String result = gen.get().expectedStatus( 200 ).get( getSchemaConstraintLabelUniquenessUri( labelName ) ).entity();
List<Map<String, Object>> serializedList = jsonToList( result );
Map<String, Object> constraint1 = new HashMap<>( );
constraint1.put( "type", ConstraintType.UNIQUENESS.name() );
constraint1.put( "label", labelName );
constraint1.put( "property_keys", singletonList( propertyKey1 ) );
Map<String, Object> constraint2 = new HashMap<>( );
constraint2.put( "type", ConstraintType.UNIQUENESS.name() );
constraint2.put( "label", labelName );
constraint2.put( "property_keys", singletonList( propertyKey2 ) );
assertThat( serializedList, hasItems( constraint1, constraint2 ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void create_compound_index()
{
Map<String,Object> definition = map( "property_keys", asList( properties.newInstance(), properties.newInstance()) );
gen.get()
.expectedStatus( 200 )
.payload( createJsonFrom( definition ) )
.post( getSchemaIndexLabelUri( labels.newInstance() ) );
}
代码示例来源:origin: neo4j/neo4j
@Override
public AbstractIndexPartition createPartition( File partitionFolder, Directory directory ) throws IOException
{
return new WritableIndexPartition( partitionFolder, directory, writerConfigFactory.newInstance() );
}
}
代码示例来源:origin: neo4j/neo4j
public void get_or_create_unique_node_if_already_existing() throws Exception
final String index = indexes.newInstance();
String key = "name";
String value = "Peter";
try ( Transaction tx = graphdb().beginTx() )
Node peter = graphdb.createNode();
peter.setProperty( key, value );
peter.setProperty( "sequence", 1 );
graphdb.index().forNodes( index ).add( peter, key, value );
代码示例来源:origin: neo4j/neo4j
@SuppressWarnings( "unchecked" )
@Documented( "Get all constraints for a label." )
@Test
@GraphDescription.Graph( nodes = {} )
public void getLabelPropertyConstraints() throws JsonParseException
{
data.get();
String labelName = labels.newInstance();
String propertyKey1 = properties.newInstance();
createLabelUniquenessPropertyConstraint( labelName, propertyKey1 );
String result = gen.get().expectedStatus( 200 ).get( getSchemaConstraintLabelUri( labelName ) ).entity();
List<Map<String, Object>> serializedList = jsonToList( result );
Map<String, Object> constraint1 = new HashMap<>( );
constraint1.put( "type", ConstraintType.UNIQUENESS.name() );
constraint1.put( "label", labelName );
constraint1.put( "property_keys", singletonList( propertyKey1 ) );
assertThat( serializedList, hasItems( constraint1 ) );
}
代码示例来源:origin: neo4j/neo4j
/**
* Create an index for a label and property key which already exists.
*/
@Test
public void create_existing_index()
{
String labelName = labels.newInstance();
String propertyKey = properties.newInstance();
createIndex( labelName, propertyKey );
Map<String,Object> definition = map( "property_keys", singletonList( propertyKey ) );
gen.get()
.expectedStatus( 409 )
.payload( createJsonFrom( definition ) )
.post( getSchemaIndexLabelUri( labelName ) );
}
内容来源于网络,如有侵权,请联系作者删除!