use of org.neo4j.kernel.api.StatementTokenNameLookup in project neo4j by neo4j.
the class RelationshipProxy method getProperty.
@Override
public Object getProperty(String key) {
if (null == key) {
throw new IllegalArgumentException("(null) property key is not allowed");
}
try (Statement statement = actions.statement()) {
try {
int propertyId = statement.readOperations().propertyKeyGetForName(key);
if (propertyId == KeyReadOperations.NO_SUCH_PROPERTY_KEY) {
throw new NotFoundException(String.format("No such property, '%s'.", key));
}
Object value = statement.readOperations().relationshipGetProperty(getId(), propertyId);
if (value == null) {
throw new PropertyNotFoundException(propertyId, EntityType.RELATIONSHIP, getId());
}
return value;
} catch (EntityNotFoundException | PropertyNotFoundException e) {
throw new NotFoundException(e.getUserMessage(new StatementTokenNameLookup(statement.readOperations())), e);
}
}
}
use of org.neo4j.kernel.api.StatementTokenNameLookup in project neo4j by neo4j.
the class NodeProxy method getProperty.
@Override
public Object getProperty(String key) throws NotFoundException {
if (null == key) {
throw new IllegalArgumentException("(null) property key is not allowed");
}
try (Statement statement = actions.statement()) {
try {
int propertyKeyId = statement.readOperations().propertyKeyGetForName(key);
if (propertyKeyId == KeyReadOperations.NO_SUCH_PROPERTY_KEY) {
throw new NotFoundException(format("No such property, '%s'.", key));
}
Object value = statement.readOperations().nodeGetProperty(nodeId, propertyKeyId);
if (value == null) {
throw new PropertyNotFoundException(propertyKeyId, EntityType.NODE, nodeId);
}
return value;
} catch (EntityNotFoundException | PropertyNotFoundException e) {
throw new NotFoundException(e.getUserMessage(new StatementTokenNameLookup(statement.readOperations())), e);
}
}
}
use of org.neo4j.kernel.api.StatementTokenNameLookup in project neo4j by neo4j.
the class MultiIndexPopulationConcurrentUpdatesIT method launchCustomIndexPopulation.
private void launchCustomIndexPopulation(Map<String, Integer> labelNameIdMap, int propertyId, List<NodeUpdates> updates) throws Exception {
NeoStores neoStores = getNeoStores();
LabelScanStore labelScanStore = getLabelScanStore();
ThreadToStatementContextBridge transactionStatementContextBridge = getTransactionStatementContextBridge();
try (Transaction transaction = embeddedDatabase.beginTx()) {
Statement statement = transactionStatementContextBridge.get();
DynamicIndexStoreView storeView = new DynamicIndexStoreViewWrapper(labelScanStore, LockService.NO_LOCK_SERVICE, neoStores, updates);
SchemaIndexProviderMap providerMap = new DefaultSchemaIndexProviderMap(getSchemaIndexProvider());
JobScheduler scheduler = getJobScheduler();
StatementTokenNameLookup tokenNameLookup = new StatementTokenNameLookup(statement.readOperations());
indexService = IndexingServiceFactory.createIndexingService(Config.empty(), scheduler, providerMap, storeView, tokenNameLookup, getIndexRules(neoStores), NullLogProvider.getInstance(), IndexingService.NO_MONITOR, () -> {
});
indexService.start();
IndexRule[] rules = createIndexRules(labelNameIdMap, propertyId);
indexService.createIndexes(rules);
transaction.success();
}
}
use of org.neo4j.kernel.api.StatementTokenNameLookup in project neo4j by neo4j.
the class BuiltInProcedures method listConstraints.
@Description("List all constraints in the database.")
@Procedure(name = "db.constraints", mode = READ)
public Stream<ConstraintResult> listConstraints() {
Statement statement = tx.acquireStatement();
ReadOperations operations = statement.readOperations();
TokenNameLookup tokens = new StatementTokenNameLookup(operations);
return asList(operations.constraintsGetAll()).stream().map((constraint) -> constraint.prettyPrint(tokens)).sorted().map(ConstraintResult::new).onClose(statement::close);
}
use of org.neo4j.kernel.api.StatementTokenNameLookup in project neo4j by neo4j.
the class BuiltInProcedures method listIndexes.
@Description("List all indexes in the database.")
@Procedure(name = "db.indexes", mode = READ)
public Stream<IndexResult> listIndexes() throws ProcedureException {
try (Statement statement = tx.acquireStatement()) {
ReadOperations operations = statement.readOperations();
TokenNameLookup tokens = new StatementTokenNameLookup(operations);
List<NewIndexDescriptor> indexes = asList(operations.indexesGetAll());
Set<NewIndexDescriptor> uniqueIndexes = asSet(operations.uniqueIndexesGetAll());
indexes.addAll(uniqueIndexes);
indexes.sort(Comparator.comparing(a -> a.userDescription(tokens)));
ArrayList<IndexResult> result = new ArrayList<>();
for (NewIndexDescriptor index : indexes) {
try {
String type;
if (uniqueIndexes.contains(index)) {
type = IndexType.NODE_UNIQUE_PROPERTY.typeName();
} else {
type = IndexType.NODE_LABEL_PROPERTY.typeName();
}
result.add(new IndexResult("INDEX ON " + index.schema().userDescription(tokens), operations.indexGetState(index).toString(), type));
} catch (IndexNotFoundKernelException e) {
throw new ProcedureException(Status.Schema.IndexNotFound, e, "No index on ", index.userDescription(tokens));
}
}
return result.stream();
}
}
Aggregations