Search in sources :

Example 21 with AnyValue

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);
        }
    }
}
Also used : AnyValue(org.neo4j.values.AnyValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) CalledFromGeneratedCode(org.neo4j.util.CalledFromGeneratedCode)

Example 22 with AnyValue

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);
    }
}
Also used : AnyValue(org.neo4j.values.AnyValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) CalledFromGeneratedCode(org.neo4j.util.CalledFromGeneratedCode)

Example 23 with AnyValue

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();
}
Also used : RuntimeMBeanException(javax.management.RuntimeMBeanException) MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) AnyValue(org.neo4j.values.AnyValue)

Example 24 with AnyValue

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));
        }
    };
}
Also used : LocalDateTime(java.time.LocalDateTime) InvalidArgumentException(org.neo4j.exceptions.InvalidArgumentException) LocalTime(java.time.LocalTime) AnyValue(org.neo4j.values.AnyValue) LocalDate(java.time.LocalDate)

Example 25 with AnyValue

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();
        }
    });
}
Also used : Context(org.neo4j.kernel.api.procedure.Context) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) ResourceTracker(org.neo4j.kernel.api.ResourceTracker) AnyValue(org.neo4j.values.AnyValue) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) RawIterator(org.neo4j.collection.RawIterator) GlobalProcedures(org.neo4j.kernel.api.procedure.GlobalProcedures)

Aggregations

AnyValue (org.neo4j.values.AnyValue)95 Test (org.junit.jupiter.api.Test)58 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)19 ListValue (org.neo4j.values.virtual.ListValue)14 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)11 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)11 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)10 List (java.util.List)9 TextValue (org.neo4j.values.storable.TextValue)9 RawIterator (org.neo4j.collection.RawIterator)8 MapValue (org.neo4j.values.virtual.MapValue)8 Context (org.neo4j.kernel.api.procedure.Context)7 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)7 ArrayList (java.util.ArrayList)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Values.stringValue (org.neo4j.values.storable.Values.stringValue)6 LocalDate (java.time.LocalDate)5 LocalTime (java.time.LocalTime)5 ZonedDateTime (java.time.ZonedDateTime)5 Arrays (java.util.Arrays)5