001/*
002 * Copyright (c) 2008, 2009, 2011 Oracle, Inc. All rights reserved.
003 *
004 * This program and the accompanying materials are made available under the
005 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
006 * which accompanies this distribution.  The Eclipse Public License is available
007 * at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License
008 * is available at http://www.eclipse.org/org/documents/edl-v10.php.
009 */
010package javax.persistence;
011
012/**
013 * Utility interface between the application and the persistence provider managing the persistence unit.
014 * <p>
015 * The methods of this interface should only be invoked on entity instances obtained from or managed by entity
016 * managers for this persistence unit or on new entity instances.
017 *
018 * @since Java Persistence 2.0
019 */
020public interface PersistenceUnitUtil extends PersistenceUtil {
021  /**
022   * Determine the load state of a given persistent attribute of an entity belonging to the persistence
023   * unit.
024   *
025   * @param entity        entity instance containing the attribute
026   * @param attributeName name of attribute whose load state is to be determined
027   * @return false if entity's state has not been loaded or if the attribute state has not been loaded, else
028   * true
029   */
030  public boolean isLoaded(Object entity, String attributeName);
031
032  /**
033   * Determine the load state of an entity belonging to the persistence unit. This method can be used to
034   * determine the load state of an entity passed as a reference. An entity is considered loaded if all
035   * attributes for which <code>FetchType.EAGER</code> has been specified have been loaded.
036   * <p>
037   * The <code>isLoaded(Object, String)</code> method should be used to determine the load state of an
038   * attribute. Not doing so might lead to unintended loading of state.
039   *
040   * @param entity entity instance whose load state is to be determined
041   * @return false if the entity has not been loaded, else true
042   */
043  public boolean isLoaded(Object entity);
044
045  /**
046   * Return the id of the entity. A generated id is not guaranteed to be available until after the database
047   * insert has occurred. Returns null if the entity does not yet have an id.
048   *
049   * @param entity entity instance
050   * @return id of the entity
051   * @throws IllegalArgumentException if the object is found not to be an entity
052   */
053  public Object getIdentifier(Object entity);
054}