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(s).
014 * <p>
015 * The <code>PersistenceUtil</code> interface instance obtained from the {@link Persistence} class is used to
016 * determine the load state of an entity or entity attribute regardless of which persistence provider in the
017 * environment created the entity.
018 *
019 * @since Java Persistence 2.0
020 */
021public interface PersistenceUtil {
022  /**
023   * Determine the load state of a given persistent attribute.
024   *
025   * @param entity        entity 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. This method can be used to determine the load state of an entity
034   * passed as a reference. An entity is considered loaded if all attributes for which
035   * <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 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}