// clear out:
installationDao.flushAndClear();
for (int i = 0; i < installations.size(); i++) {
Installation current = installations.get(i);
// let's avoid duplicated tokens/devices per variant
// For devices without a token, let's also not bother the DAO layer to throw BeanValidation exception
if (!existingTokens.contains(current.getDeviceToken()) && hasTokenValue(current)) {
logger.finest("Importing device with token: " + current.getDeviceToken());
// set reference
current.setVariant(variant);
mergeCategories(current);
installationDao.create(current);
// and add a reference to the existing tokens set, to ensure the JSON file contains no duplicates:
existingTokens.add(current.getDeviceToken());
// some tunings, ever 10k devices releasing resources
if (i % 10000 == 0) {
logger.finest("releasing some resources during import");
installationDao.flushAndClear();
}
} else {
// for now, we ignore them.... no update applied!
logger.finest("Device with token '" + current.getDeviceToken() + "' already exists. Ignoring it ");
}
}
// clear out:
installationDao.flushAndClear();
}