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

com.digitolio.jdbi.table.TableRegistry Maven / Gradle / Ivy

There is a newer version: 0.6.8.2
Show newest version
package com.digitolio.jdbi.table;

import com.digitolio.jdbi.strategy.TranslatingStrategyAware;

import java.sql.Connection;
import java.util.concurrent.ConcurrentHashMap;

public class TableRegistry {

    private final static TableRegistry SINGLETON = new TableRegistry();

    private final TableFactory tableFactory = new TableFactory();

    private final ConcurrentHashMap tables = new ConcurrentHashMap();

    private TableRegistry() { }

    public static TableRegistry getInstance() {
        return SINGLETON;
    }

    public Table getTable(Connection con, Class type, TranslatingStrategyAware translater) {
        TranslateTablePair key = new TranslateTablePair(type, translater);
        return getTable(con, key);
    }

    public Table getTable(Connection con, TranslateTablePair key) {
        if (tables.containsKey(key)) {
            return tables.get(key);
        } else {
            Table table = tableFactory.newInstance(con, key);
            tables.put(key, table);
            return table;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy