001package io.ebean;
002
003import io.ebean.config.ContainerConfig;
004import io.ebean.config.ServerConfig;
005import io.ebean.service.SpiContainer;
006import io.ebean.service.SpiContainerFactory;
007
008import javax.persistence.PersistenceException;
009import java.util.Iterator;
010import java.util.Properties;
011import java.util.ServiceLoader;
012
013/**
014 * Deprecated - please migrate to DatabaseFactory.
015 * <p>
016 * Creates EbeanServer instances.
017 * <p>
018 * This uses either a ServerConfig or properties in the ebean.properties file to
019 * configure and create a EbeanServer instance.
020 * </p>
021 * <p>
022 * The EbeanServer instance can either be registered with the Ebean singleton or
023 * not. The Ebean singleton effectively holds a map of EbeanServers by a name.
024 * If the EbeanServer is registered with the Ebean singleton you can retrieve it
025 * later via {@link Ebean#getServer(String)}.
026 * </p>
027 * <p>
028 * One EbeanServer can be nominated as the 'default/primary' EbeanServer. Many
029 * methods on the Ebean singleton such as {@link Ebean#find(Class)} are just a
030 * convenient way of using the 'default/primary' EbeanServer.
031 * </p>
032 */
033@Deprecated
034public class EbeanServerFactory {
035
036  /**
037   * Initialise the container with clustering configuration.
038   * <p>
039   * Call this prior to creating any EbeanServer instances or alternatively set the
040   * ContainerConfig on the ServerConfig when creating the first EbeanServer instance.
041   */
042  public static void initialiseContainer(ContainerConfig containerConfig) {
043    DatabaseFactory.initialiseContainer(containerConfig);
044  }
045
046  /**
047   * Create using ebean.properties to configure the database.
048   */
049  public static EbeanServer create(String name) {
050    return (EbeanServer)DatabaseFactory.create(name);
051  }
052
053  /**
054   * Create using the ServerConfig object to configure the database.
055   */
056  public static EbeanServer create(ServerConfig config) {
057    return (EbeanServer)DatabaseFactory.create(config);
058  }
059
060  /**
061   * Create using the ServerConfig additionally specifying a classLoader to use as the context class loader.
062   */
063  public static EbeanServer createWithContextClassLoader(ServerConfig config, ClassLoader classLoader) {
064    return (EbeanServer)DatabaseFactory.createWithContextClassLoader(config, classLoader);
065  }
066
067  /**
068   * Shutdown gracefully all EbeanServers cleaning up any resources as required.
069   * <p>
070   * This is typically invoked via JVM shutdown hook and not explicitly called.
071   * </p>
072   */
073  public static void shutdown() {
074    DatabaseFactory.shutdown();
075  }
076
077}