use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class PathValueBuilder method addMultipleIncoming.
/**
* Adds multiple incoming relationships to the path
*
* @param relationships the incoming relationships to add
*/
@CalledFromGeneratedCode
public void addMultipleIncoming(ListValue relationships) {
for (AnyValue value : relationships) {
if (notNoValue(value)) {
// we know these relationships have already loaded start and end relationship
// so we should not use CypherFunctions::[start,end]Node to look them up
RelationshipValue relationship = (RelationshipValue) value;
nodes.add(relationship.startNode());
rels.add(relationship);
}
}
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class PathValueBuilder method addMultipleOutgoing.
/**
* Adds multiple outgoing relationships to the path
*
* @param relationships the outgoing relationships to add
* @param target the final target node of the path
*/
@CalledFromGeneratedCode
public void addMultipleOutgoing(ListValue relationships, NodeValue target) {
if (relationships.isEmpty()) {
// nothing to do here
return;
}
int i;
for (i = 0; i < relationships.size() - 1; i++) {
AnyValue value = relationships.value(i);
if (notNoValue(value)) {
// we know these relationships have already loaded start and end relationship
// so we should not use CypherFunctions::[start,end]Node to look them up
RelationshipValue relationship = (RelationshipValue) value;
nodes.add(relationship.endNode());
rels.add(relationship);
}
}
AnyValue last = relationships.value(i);
if (notNoValue(last)) {
rels.add((RelationshipValue) last);
nodes.add(target);
}
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class JmxQueryProcedure method toNeo4jValue.
private MapValue toNeo4jValue(ObjectName name, MBeanAttributeInfo attribute) throws JMException {
AnyValue value;
try {
value = toNeo4jValue(jmxServer.getAttribute(name, attribute.getName()));
} catch (RuntimeMBeanException e) {
if (e.getCause() != null && e.getCause() instanceof UnsupportedOperationException) {
// We include the name and description of this attribute still - but the value of it is
// unknown. We do this rather than rethrow the exception, because several MBeans built into
// the JVM will throw exception on attribute access depending on their runtime state, even
// if the attribute is marked as readable. Notably the GC beans do this.
value = NO_VALUE;
} else {
throw e;
}
}
MapValueBuilder builder = new MapValueBuilder(2);
builder.add("description", stringValue(attribute.getDescription()));
builder.add("value", value);
return builder.build();
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class LocalDateTimeValue method builder.
private static DateTimeValue.DateTimeBuilder<LocalDateTimeValue> builder(Supplier<ZoneId> defaultZone) {
return new DateTimeValue.DateTimeBuilder<>(defaultZone) {
@Override
protected boolean supportsTimeZone() {
return false;
}
@Override
protected boolean supportsEpoch() {
return false;
}
@Override
public LocalDateTimeValue buildInternal() {
boolean selectingDate = fields.containsKey(TemporalFields.date);
boolean selectingTime = fields.containsKey(TemporalFields.time);
boolean selectingDateTime = fields.containsKey(TemporalFields.datetime);
LocalDateTime result;
if (selectingDateTime) {
AnyValue dtField = fields.get(TemporalFields.datetime);
if (!(dtField instanceof TemporalValue)) {
throw new InvalidArgumentException(String.format("Cannot construct local date time from: %s", dtField));
}
TemporalValue dt = (TemporalValue) dtField;
result = LocalDateTime.of(dt.getDatePart(), dt.getLocalTimePart());
} else if (selectingTime || selectingDate) {
LocalTime time;
if (selectingTime) {
AnyValue timeField = fields.get(TemporalFields.time);
if (!(timeField instanceof TemporalValue)) {
throw new InvalidArgumentException(String.format("Cannot construct local time from: %s", timeField));
}
TemporalValue t = (TemporalValue) timeField;
time = t.getLocalTimePart();
} else {
time = LocalTimeValue.DEFAULT_LOCAL_TIME;
}
LocalDate date;
if (selectingDate) {
AnyValue dateField = fields.get(TemporalFields.date);
if (!(dateField instanceof TemporalValue)) {
throw new InvalidArgumentException(String.format("Cannot construct date from: %s", dateField));
}
TemporalValue t = (TemporalValue) dateField;
date = t.getDatePart();
} else {
date = DateValue.DEFAULT_CALENDER_DATE;
}
result = LocalDateTime.of(date, time);
} else {
result = DEFAULT_LOCAL_DATE_TIME;
}
if (fields.containsKey(TemporalFields.week) && !selectingDate && !selectingDateTime) {
// Be sure to be in the start of the week based year (which can be later than 1st Jan)
result = result.with(IsoFields.WEEK_BASED_YEAR, safeCastIntegral(TemporalFields.year.name(), fields.get(TemporalFields.year), TemporalFields.year.defaultValue)).with(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 1).with(ChronoField.DAY_OF_WEEK, 1);
}
result = assignAllFields(result);
return localDateTime(result);
}
private LocalDateTime getLocalDateTimeOf(AnyValue temporal) {
if (temporal instanceof TemporalValue) {
TemporalValue v = (TemporalValue) temporal;
LocalDate datePart = v.getDatePart();
LocalTime timePart = v.getLocalTimePart();
return LocalDateTime.of(datePart, timePart);
}
throw new InvalidArgumentException(String.format("Cannot construct date from: %s", temporal));
}
@Override
protected LocalDateTimeValue selectDateTime(AnyValue datetime) {
if (datetime instanceof LocalDateTimeValue) {
return (LocalDateTimeValue) datetime;
}
return localDateTime(getLocalDateTimeOf(datetime));
}
};
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class BoltKeepAliveSchedulingIT method installSleepProcedure.
private static void installSleepProcedure(GraphDatabaseService db) throws ProcedureException {
GraphDatabaseAPI dbApi = (GraphDatabaseAPI) db;
dbApi.getDependencyResolver().resolveDependency(GlobalProcedures.class).register(new CallableProcedure.BasicProcedure(procedureSignature("boltissue", "sleep").out(ProcedureSignature.VOID).build()) {
@Override
public RawIterator<AnyValue[], ProcedureException> apply(Context context, AnyValue[] objects, ResourceTracker resourceTracker) throws ProcedureException {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new ProcedureException(Status.General.UnknownError, e, "Interrupted");
}
return RawIterator.empty();
}
});
}
Aggregations