All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.neo4j.graphdb.Entity Maven / Gradle / Ivy

There is a newer version: 5.25.1
Show newest version
/*
 * Copyright (c) "Neo4j"
 * Neo4j Sweden AB [https://neo4j.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 .
 */
package org.neo4j.graphdb;

import java.util.Map;
import org.neo4j.annotations.api.PublicApi;

/**
 * An Entity is a {@link Entity} that is persisted in the database, and identified by an {@link #getElementId()} element id}.
 * 

* {@link Node Nodes} and {@link Relationship Relationships} are Entities. * * Entities are attached to transaction in which they were accessed. Outside of transaction it's possible only to access an entity's element id. * All other methods should be called only in the scope of the owning transaction. * * Defines a common API for handling properties on both {@link Node nodes} and * {@link Relationship relationships}. *

* Properties are key-value pairs. The keys are always strings. Valid property * value types are all the Java primitives (int, byte, * float, etc), java.lang.Strings, the Spatial * and Temporal types and arrays of any of these. *

* The complete list of currently supported property types is: *

    *
  • boolean
  • *
  • byte
  • *
  • short
  • *
  • int
  • *
  • long
  • *
  • float
  • *
  • double
  • *
  • char
  • *
  • java.lang.String
  • *
  • org.neo4j.graphdb.spatial.Point
  • *
  • java.time.LocalDate
  • *
  • java.time.OffsetTime
  • *
  • java.time.LocalTime
  • *
  • java.time.ZonedDateTime
    *
    It is also possible to use java.time.OffsetDateTime and it will * be converted to a ZonedDateTime internally.
    *
  • *
  • java.time.LocalDateTime
  • *
  • java.time.temporal.TemporalAmount
    *
    There are two concrete implementations of this interface, java.time.Duration * and java.time.Period which will be converted to a single Neo4j Duration * type. This means loss of type information, so properties of this type, when read back using * {@link #getProperty(String) getProperty} will be only of type java.time.temporal.TemporalAmount.
    *
  • *
  • Arrays of any of the above types, for example int[], String[] or LocalTime[]
  • *
*

* Please note that Neo4j does NOT accept arbitrary objects as property * values. {@link #setProperty(String, Object) setProperty()} takes a * java.lang.Object only to avoid an explosion of overloaded * setProperty() methods. **/ @PublicApi public interface Entity { /** * Returns the unique id of this entity. Id's are reused over time so they are only guaranteed to be unique * during a specific transaction: if the entity is deleted, it is * likely that some new entity will reuse this id at some point. * * @return The id of this Entity. * @deprecated in favor of {@link #getElementId()}. */ @Deprecated(since = "5.0", forRemoval = true) long getId(); /** * Returns the unique element id of this entity. Id's are reused over time so they are only guaranteed to be unique * during a specific transaction: if the entity is deleted, it is * likely that some new entity will reuse this id at some point. * * @return The element id of this Entity. */ String getElementId(); /** * Returns true if this property container has a property * accessible through the given key, false otherwise. If key is * null, this method returns false. * * @param key the property key * @return true if this property container has a property * accessible through the given key, false otherwise */ boolean hasProperty(String key); /** * Returns the property value associated with the given key. The value is of * one of the valid property types, i.e. a Java primitive, * a {@link String String}, a {@link org.neo4j.graphdb.spatial.Point Point}, * a valid temporal type, or an array of any of the valid types. * See the {@link Entity the class description} * for a full list of known types. *

* If there's no property associated with key an unchecked * exception is raised. The idiomatic way to avoid an exception for an * unknown key and instead get null back is to use a default * value: {@link #getProperty(String, Object) Object valueOrNull = * nodeOrRel.getProperty( key, null )} * * @param key the property key * @return the property value associated with the given key * @throws NotFoundException if there's no property associated with * key */ Object getProperty(String key); /** * Returns the property value associated with the given key, or a default * value. The value is of one of the valid property types, i.e. a Java primitive, * a {@link String String}, a {@link org.neo4j.graphdb.spatial.Point Point}, * a valid temporal type, or an array of any of the valid types. * See the {@link Entity the class description} * for a full list of known types. * * @param key the property key * @param defaultValue the default value that will be returned if no * property value was associated with the given key * @return the property value associated with the given key */ Object getProperty(String key, Object defaultValue); /** * Sets the property value for the given key to value. The * property value must be one of the valid property types, i.e. a Java primitive, * a {@link String String}, a {@link org.neo4j.graphdb.spatial.Point Point}, * a valid temporal type, or an array of any of the valid types. * See the {@link Entity the class description} * for a full list of known types. *

* This means that null is not an accepted property value. * * @param key the key with which the new property value will be associated * @param value the new property value, of one of the valid property types * @throws IllegalArgumentException if value is of an * unsupported type (including null) */ void setProperty(String key, Object value); /** * Removes the property associated with the given key and returns the old * value. If there's no property associated with the key, null * will be returned. * * @param key the property key * @return the property value that used to be associated with the given key */ Object removeProperty(String key); /** * Returns all existing property keys, or an empty iterable if this property * container has no properties. * * @return all property keys on this property container */ Iterable getPropertyKeys(); /** * Returns specified existing properties. The collection is mutable, * but changing it has no impact on the graph as the data is detached. * * @param keys the property keys to return * @return specified properties on this property container * @throws NullPointerException if the array of keys or any key is null */ Map getProperties(String... keys); /** * Returns all existing properties. * * @return all properties on this property container */ Map getAllProperties(); /** * Deletes this entity. * * @throws NotFoundException if any methods are invoked on this entity after {@code delete()} */ void delete(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy