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

com.cedarsoft.gdao.hibernate.HibernateDaoFactory Maven / Gradle / Ivy

There is a newer version: 1.6.3
Show newest version
package com.cedarsoft.gdao.hibernate;

import com.cedarsoft.gdao.DaoTypeDescriptor;
import com.cedarsoft.gdao.GenericDao;
import com.cedarsoft.utils.Cache;
import org.hibernate.SessionFactory;
import org.jetbrains.annotations.NotNull;

/**
 * Creates Hibernate DAOs if needed.
 */
public class HibernateDaoFactory implements Cache.Factory, GenericDao> {
  @NotNull
  private final SessionFactory sessionFactory;

  /**
   * Creates a new factory for the given session factory
   *
   * @param sessionFactory the session factory
   */
  public HibernateDaoFactory( @NotNull SessionFactory sessionFactory ) {
    this.sessionFactory = sessionFactory;
  }

  @NotNull
  public GenericDao create( @NotNull DaoTypeDescriptor key ) {
    return new HibernateDao( sessionFactory, key.getType(), key.getLockProvider() );
  }
}