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

io.github.mmm.orm.jdbc.connection.JdbcConnectionPoolProvider Maven / Gradle / Ivy

The newest version!
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0 */
package io.github.mmm.orm.jdbc.connection;

import javax.sql.DataSource;

import io.github.mmm.base.metainfo.MetaInfo;
import io.github.mmm.orm.connection.DbConnectionPool;
import io.github.mmm.orm.connection.DbConnectionPoolProvider;
import io.github.mmm.orm.dialect.DbDialect;
import io.github.mmm.orm.source.DbSource;

/**
 * Abstract base implementation of {@link DbConnectionPoolProvider} for JDBC.
 *
 * @since 1.0.0
 */
public abstract class JdbcConnectionPoolProvider implements DbConnectionPoolProvider {

  @Override
  public String getKind() {

    return "jdbc";
  }

  @Override
  public DbConnectionPool create(DbSource source, MetaInfo config, DbDialect dialect) {

    DataSource dataSource = createDataSource(config);
    return new JdbcConnectionPool(dataSource, source, dialect, this);
  }

  /**
   * @param config the configuration as {@link MetaInfo}.
   * @return the connection pool as {@link DataSource}.
   */
  protected abstract DataSource createDataSource(MetaInfo config);

  /**
   * @param dataSource the {@link DataSource} that was created by {@link #createDataSource(MetaInfo)} and is now to be
   *        closed to free resources as the connection pool is no longer needed.
   */
  protected abstract void close(DataSource dataSource);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy