Package org.hibernate.persister.internal

Source Code of org.hibernate.persister.internal.StandardPersisterClassResolver

/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors.  All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA  02110-1301  USA
*/
package org.hibernate.persister.internal;

import org.hibernate.mapping.Collection;
import org.hibernate.mapping.JoinedSubclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.UnionSubclass;
import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.persister.collection.BasicCollectionPersister;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.collection.OneToManyPersister;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.JoinedSubclassEntityPersister;
import org.hibernate.persister.entity.SingleTableEntityPersister;
import org.hibernate.persister.entity.UnionSubclassEntityPersister;
import org.hibernate.persister.spi.PersisterClassResolver;
import org.hibernate.persister.spi.UnknownPersisterException;

/**
* @author Steve Ebersole
*/
public class StandardPersisterClassResolver implements PersisterClassResolver {

  public Class<? extends EntityPersister> getEntityPersisterClass(EntityBinding metadata) {
    // todo : make sure this is based on an attribute kept on the metamodel in the new code, not the concrete PersistentClass impl found!

    if ( metadata.isRoot() ) {
      return singleTableEntityPersister(); // EARLY RETURN!
    }
    switch ( metadata.getInheritanceType() ) {
      case JOINED: {
        return joinedSubclassEntityPersister();
      }
      case SINGLE_TABLE: {
        return singleTableEntityPersister();
      }
      case TABLE_PER_CLASS: {
        return unionSubclassEntityPersister();
      }
      default: {
        throw new UnknownPersisterException(
            "Could not determine persister implementation for entity [" + metadata.getEntity().getName() + "]"
        );
      }

    }
  }

  @Override
  public Class<? extends EntityPersister> getEntityPersisterClass(PersistentClass metadata) {
    // todo : make sure this is based on an attribute kept on the metamodel in the new code, not the concrete PersistentClass impl found!
    if ( RootClass.class.isInstance( metadata ) ) {
      return singleTableEntityPersister();
    }
    else if ( JoinedSubclass.class.isInstance( metadata ) ) {
      return joinedSubclassEntityPersister();
    }
    else if ( UnionSubclass.class.isInstance( metadata ) ) {
      return unionSubclassEntityPersister();
    }
    else {
      throw new UnknownPersisterException(
          "Could not determine persister implementation for entity [" + metadata.getEntityName() + "]"
      );
    }
  }

  public Class<? extends EntityPersister> singleTableEntityPersister() {
    return SingleTableEntityPersister.class;
  }

  public Class<? extends EntityPersister> joinedSubclassEntityPersister() {
    return JoinedSubclassEntityPersister.class;
  }

  public Class<? extends EntityPersister> unionSubclassEntityPersister() {
    return UnionSubclassEntityPersister.class;
  }

  @Override
  public Class<? extends CollectionPersister> getCollectionPersisterClass(Collection metadata) {
    return metadata.isOneToMany() ? oneToManyPersister() : basicCollectionPersister();
  }

  @Override
  public Class<? extends CollectionPersister> getCollectionPersisterClass(PluralAttributeBinding metadata) {
    return metadata.getCollectionElement().isOneToMany() ? oneToManyPersister() : basicCollectionPersister();
  }

  private Class<OneToManyPersister> oneToManyPersister() {
    return OneToManyPersister.class;
  }

  private Class<BasicCollectionPersister> basicCollectionPersister() {
    return BasicCollectionPersister.class;
  }
}
TOP

Related Classes of org.hibernate.persister.internal.StandardPersisterClassResolver

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.