@Test public void testDaoClassGenericDaoMethod() throws Exception { GenericDao<GenericBaz, String> bazdao = DaoManager.createDao(connectionSource, GenericBaz.class); assertSame(GenericBaz.class.getName(), bazdao.doGenericAction()); GenericDao<GenericBar, Void> bardao = DaoManager.createDao(connectionSource, GenericBar.class); assertSame(GenericBar.class.getName(), bardao.doGenericAction()); }
public synchronized static <D extends Dao<T, ?>, T> D createDao(ConnectionSource connectionSource, Class<T> clazz) throws SQLException { if (connectionSource == null) { throw new IllegalArgumentException("connectionSource argument cannot be null"); } ClassConnectionSource key = new ClassConnectionSource(connectionSource, clazz); Dao<?, ?> dao = lookupDao(key); if (dao != null) { @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; } dao = createDaoFromConfig(connectionSource, clazz); if (dao != null) { @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; } DatabaseTable databaseTable = clazz.getAnnotation(DatabaseTable.class); if (databaseTable == null || databaseTable.daoClass() == Void.class || databaseTable.daoClass() == BaseDaoImpl.class) { DatabaseType databaseType = connectionSource.getDatabaseType(); DatabaseTableConfig<T> config = databaseType.extractDatabaseTableConfig(connectionSource, clazz); Dao<T, ?> daoTmp; if (config == null) { daoTmp = BaseDaoImpl.createDao(connectionSource, clazz); } else { daoTmp = BaseDaoImpl.createDao(connectionSource, config); } dao = daoTmp; logger.debug("created dao for class {} with reflection", clazz); } else { Class<?> daoClass = databaseTable.daoClass(); Object[] arguments = new Object[] { connectionSource, clazz }; Constructor<?> daoConstructor = findConstructor(daoClass, arguments); if (daoConstructor == null) { arguments = new Object[] { connectionSource }; daoConstructor = findConstructor(daoClass, arguments); if (daoConstructor == null) { throw new SQLException( "Could not find public constructor with ConnectionSource and optional Class parameters " + daoClass + ". Missing static on class?"); } } try { dao = (Dao<?, ?>) daoConstructor.newInstance(arguments); logger.debug("created dao for class {} from constructor", clazz); } catch (Exception e) { throw SqlExceptionUtil.create("Could not call the constructor in class " + daoClass, e); } } registerDao(connectionSource, dao); @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; }
DaoManager { public synchronized static <D extends Dao<T, ?>, T> D createDao(ConnectionSource connectionSource, Class<T> clazz) throws SQLException { if (connectionSource == null) { throw new IllegalArgumentException("connectionSource argument cannot be null"); } ClassConnectionSource key = new ClassConnectionSource(connectionSource, clazz); Dao<?, ?> dao = lookupDao(key); if (dao != null) { @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; } dao = createDaoFromConfig(connectionSource, clazz); if (dao != null) { @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; } DatabaseTable databaseTable = clazz.getAnnotation(DatabaseTable.class); if (databaseTable == null || databaseTable.daoClass() == Void.class || databaseTable.daoClass() == BaseDaoImpl.class) { DatabaseType databaseType = connectionSource.getDatabaseType(); DatabaseTableConfig<T> config = databaseType.extractDatabaseTableConfig(connectionSource, clazz); Dao<T, ?> daoTmp; if (config == null) { daoTmp = BaseDaoImpl.createDao(connectionSource, clazz); } else { daoTmp = BaseDaoImpl.createDao(connectionSource, config); } dao = daoTmp; logger.debug("created dao for class {} with reflection", clazz); } else { Class<?> daoClass = databaseTable.daoClass(); Object[] arguments = new Object[] { connectionSource, clazz }; Constructor<?> daoConstructor = findConstructor(daoClass, arguments); if (daoConstructor == null) { arguments = new Object[] { connectionSource }; daoConstructor = findConstructor(daoClass, arguments); if (daoConstructor == null) { throw new SQLException( "Could not find public constructor with ConnectionSource and optional Class parameters " + daoClass + ". Missing static on class?"); } } try { dao = (Dao<?, ?>) daoConstructor.newInstance(arguments); logger.debug("created dao for class {} from constructor", clazz); } catch (Exception e) { throw SqlExceptionUtil.create("Could not call the constructor in class " + daoClass, e); } } registerDao(connectionSource, dao); @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; } }
DaoManager { public synchronized static <D extends Dao<T, ?>, T> D createDao(ConnectionSource connectionSource, Class<T> clazz) throws SQLException { if (connectionSource == null) { throw new IllegalArgumentException("connectionSource argument cannot be null"); } ClassConnectionSource key = new ClassConnectionSource(connectionSource, clazz); Dao<?, ?> dao = lookupDao(key); if (dao != null) { @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; } dao = createDaoFromConfig(connectionSource, clazz); if (dao != null) { @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; } DatabaseTable databaseTable = clazz.getAnnotation(DatabaseTable.class); if (databaseTable == null || databaseTable.daoClass() == Void.class || databaseTable.daoClass() == BaseDaoImpl.class) { DatabaseType databaseType = connectionSource.getDatabaseType(); DatabaseTableConfig<T> config = databaseType.extractDatabaseTableConfig(connectionSource, clazz); Dao<T, ?> daoTmp; if (config == null) { daoTmp = BaseDaoImpl.createDao(connectionSource, clazz); } else { daoTmp = BaseDaoImpl.createDao(connectionSource, config); } dao = daoTmp; logger.debug("created dao for class {} with reflection", clazz); } else { Class<?> daoClass = databaseTable.daoClass(); Object[] arguments = new Object[] { connectionSource, clazz }; Constructor<?> daoConstructor = findConstructor(daoClass, arguments); if (daoConstructor == null) { arguments = new Object[] { connectionSource }; daoConstructor = findConstructor(daoClass, arguments); if (daoConstructor == null) { throw new SQLException( "Could not find public constructor with ConnectionSource and optional Class parameters " + daoClass + ". Missing static on class?"); } } try { dao = (Dao<?, ?>) daoConstructor.newInstance(arguments); logger.debug("created dao for class {} from constructor", clazz); } catch (Exception e) { throw SqlExceptionUtil.create("Could not call the constructor in class " + daoClass, e); } } registerDao(connectionSource, dao); @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; }  }
DaoManager { public synchronized static <D extends Dao<T, ?>, T> D createDao(ConnectionSource connectionSource, Class<T> clazz) throws SQLException { if (connectionSource == null) { throw new IllegalArgumentException("connectionSource argument cannot be null"); } ClassConnectionSource key = new ClassConnectionSource(connectionSource, clazz); Dao<?, ?> dao = lookupDao(key); if (dao != null) { @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; } dao = createDaoFromConfig(connectionSource, clazz); if (dao != null) { @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; } DatabaseTable databaseTable = clazz.getAnnotation(DatabaseTable.class); if (databaseTable == null || databaseTable.daoClass() == Void.class || databaseTable.daoClass() == BaseDaoImpl.class) { DatabaseType databaseType = connectionSource.getDatabaseType(); DatabaseTableConfig<T> config = databaseType.extractDatabaseTableConfig(connectionSource, clazz); Dao<T, ?> daoTmp; if (config == null) { daoTmp = BaseDaoImpl.createDao(connectionSource, clazz); } else { daoTmp = BaseDaoImpl.createDao(connectionSource, config); } dao = daoTmp; logger.debug("created dao for class {} with reflection", clazz); } else { Class<?> daoClass = databaseTable.daoClass(); Object[] arguments = new Object[] { connectionSource, clazz }; Constructor<?> daoConstructor = findConstructor(daoClass, arguments); if (daoConstructor == null) { arguments = new Object[] { connectionSource }; daoConstructor = findConstructor(daoClass, arguments); if (daoConstructor == null) { throw new SQLException( "Could not find public constructor with ConnectionSource and optional Class parameters " + daoClass + ". Missing static on class?"); } } try { dao = (Dao<?, ?>) daoConstructor.newInstance(arguments); logger.debug("created dao for class {} from constructor", clazz); } catch (Exception e) { throw SqlExceptionUtil.create("Could not call the constructor in class " + daoClass, e); } } registerDao(connectionSource, dao); @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; }  synchronized static D createDao(ConnectionSource connectionSource, Class<T> clazz); synchronized static D lookupDao(ConnectionSource connectionSource, Class<T> clazz); synchronized static D createDao(ConnectionSource connectionSource,
			DatabaseTableConfig<T> tableConfig); synchronized static D lookupDao(ConnectionSource connectionSource,
			DatabaseTableConfig<T> tableConfig); static synchronized void registerDao(ConnectionSource connectionSource, Dao<?, ?> dao); static synchronized void unregisterDao(ConnectionSource connectionSource, Dao<?, ?> dao); static synchronized void registerDaoWithTableConfig(ConnectionSource connectionSource, Dao<?, ?> dao); static synchronized void clearCache(); static synchronized void clearDaoCache(); static synchronized void addCachedDatabaseConfigs(Collection<DatabaseTableConfig<?>> configs); }
DaoManager { public synchronized static <D extends Dao<T, ?>, T> D createDao(ConnectionSource connectionSource, Class<T> clazz) throws SQLException { if (connectionSource == null) { throw new IllegalArgumentException("connectionSource argument cannot be null"); } ClassConnectionSource key = new ClassConnectionSource(connectionSource, clazz); Dao<?, ?> dao = lookupDao(key); if (dao != null) { @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; } dao = createDaoFromConfig(connectionSource, clazz); if (dao != null) { @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; } DatabaseTable databaseTable = clazz.getAnnotation(DatabaseTable.class); if (databaseTable == null || databaseTable.daoClass() == Void.class || databaseTable.daoClass() == BaseDaoImpl.class) { DatabaseType databaseType = connectionSource.getDatabaseType(); DatabaseTableConfig<T> config = databaseType.extractDatabaseTableConfig(connectionSource, clazz); Dao<T, ?> daoTmp; if (config == null) { daoTmp = BaseDaoImpl.createDao(connectionSource, clazz); } else { daoTmp = BaseDaoImpl.createDao(connectionSource, config); } dao = daoTmp; logger.debug("created dao for class {} with reflection", clazz); } else { Class<?> daoClass = databaseTable.daoClass(); Object[] arguments = new Object[] { connectionSource, clazz }; Constructor<?> daoConstructor = findConstructor(daoClass, arguments); if (daoConstructor == null) { arguments = new Object[] { connectionSource }; daoConstructor = findConstructor(daoClass, arguments); if (daoConstructor == null) { throw new SQLException( "Could not find public constructor with ConnectionSource and optional Class parameters " + daoClass + ". Missing static on class?"); } } try { dao = (Dao<?, ?>) daoConstructor.newInstance(arguments); logger.debug("created dao for class {} from constructor", clazz); } catch (Exception e) { throw SqlExceptionUtil.create("Could not call the constructor in class " + daoClass, e); } } registerDao(connectionSource, dao); @SuppressWarnings("unchecked") D castDao = (D) dao; return castDao; }  synchronized static D createDao(ConnectionSource connectionSource, Class<T> clazz); synchronized static D lookupDao(ConnectionSource connectionSource, Class<T> clazz); synchronized static D createDao(ConnectionSource connectionSource,
			DatabaseTableConfig<T> tableConfig); synchronized static D lookupDao(ConnectionSource connectionSource,
			DatabaseTableConfig<T> tableConfig); static synchronized void registerDao(ConnectionSource connectionSource, Dao<?, ?> dao); static synchronized void unregisterDao(ConnectionSource connectionSource, Dao<?, ?> dao); static synchronized void registerDaoWithTableConfig(ConnectionSource connectionSource, Dao<?, ?> dao); static synchronized void clearCache(); static synchronized void clearDaoCache(); static synchronized void addCachedDatabaseConfigs(Collection<DatabaseTableConfig<?>> configs);  }