use of org.apache.cayenne.project.extension.SaverDelegate in project cayenne by apache.
the class FileProjectSaver method save.
void save(Project project, Resource baseResource, boolean deleteOldResources) {
Collection<ConfigurationNode> nodes = project.getRootNode().acceptVisitor(saveableNodesGetter);
Collection<SaveUnit> units = new ArrayList<>(nodes.size());
for (ConfigurationNode node : nodes) {
String targetLocation = nameMapper.configurationLocation(node);
Resource targetResource = baseResource.getRelativeResource(targetLocation);
units.add(createSaveUnit(node, targetResource, null));
for (ProjectExtension extension : extensions) {
ConfigurationNodeVisitor<String> namingDelegate = extension.createNamingDelegate();
SaverDelegate unitSaverDelegate = extension.createSaverDelegate();
String fileName = node.acceptVisitor(namingDelegate);
if (fileName != null) {
// not null means that this should go to a separate file
targetResource = baseResource.getRelativeResource(fileName);
units.add(createSaveUnit(node, targetResource, unitSaverDelegate));
}
}
}
checkAccess(units);
try {
saveToTempFiles(units);
saveCommit(units);
} finally {
clearTempFiles(units);
}
try {
if (deleteOldResources) {
clearRenamedFiles(units);
Collection<URL> unusedResources = project.getUnusedResources();
for (SaveUnit unit : units) {
unusedResources.remove(unit.sourceConfiguration.getURL());
}
deleteUnusedFiles(unusedResources);
}
} catch (IOException ex) {
throw new CayenneRuntimeException(ex);
}
// I guess we should reset projects state regardless of the value of
// 'deleteOldResources'
project.getUnusedResources().clear();
}
Aggregations