private String getNameFromCache() { String result; Set<String> names = producer.getCache().keySet(); if (names.size() > 1) { throw new DemoiselleException( getBundle().getString("more-than-one-datasource-defined", Name.class.getSimpleName())); } else { result = names.iterator().next(); } return result; }
public Connection getConnection(String name) { Connection connection = null; if (cache.containsKey(name)) { connection = cache.get(name); } else { try { connection = producer.create(name).getConnection(); setTransactionIsolationLevel(connection); disableAutoCommit(connection); cache.put(name, connection); statusCache.put(connection, new Status()); getLogger().info(getBundle().getString("connection-was-created", name)); } catch (Exception cause) { throw new DemoiselleException( getBundle().getString("connection-creation-failed", name), cause); } } return connection; }
@PostConstruct public void init() { for (String name : producer.getCache().keySet()) { getConnection(name); } }