LOG.info("Injecting standard datasources.");
boolean admin = userService.hasAdministratorAccess();
boolean devMode = userService.isDevMode();
ServletUtils.requireAccess(admin || devMode);
DataSource bugSource = new DataSource();
bugSource.setInternalOnly(true);
bugSource.setName("Bug Database");
bugSource.setParameters(Lists.newArrayList("Path", "Hotlist"));
DataSource testManager = new DataSource();
testManager.setInternalOnly(true);
testManager.setName("Test Database");
testManager.setParameters(Lists.newArrayList("Label", "ProjectID", "SavedSearchID"));
DataSource perforce = new DataSource();
perforce.setInternalOnly(true);
perforce.setName("Perforce");
perforce.setParameters(Lists.newArrayList("Path"));
DataSource issueTracker = new DataSource();
issueTracker.setInternalOnly(false);
issueTracker.setName("Issue Tracker");
issueTracker.setParameters(Lists.newArrayList("Project", "Label", "Owner"));
DataSource other = new DataSource();
other.setInternalOnly(false);
other.setName("Other...");
other.setParameters(new ArrayList<String>());
List<DataSource> all = Lists.newArrayList(
bugSource, testManager, perforce, issueTracker, other);
PersistenceManager pm = pmf.getPersistenceManager();
try {
// Remove any data source from what we will persist if it already exists.
DataSource source;
Iterator<DataSource> i = all.iterator();
while (i.hasNext()) {
source = i.next();
Query query = pm.newQuery(DataSource.class);
query.declareParameters("String nameParam");
query.setFilter("name == nameParam");
if (((List<DataSource>) query.execute(source.getName())).size() > 0) {
i.remove();
}
}
pm.makePersistentAll(all);
} finally {