EOModelGroup modelGroup = EOModelGroup.defaultGroup();
Enumeration modelNamesEnum = modelNames.objectEnumerator();
while (modelNamesEnum.hasMoreElements()) {
String modelName = (String) modelNamesEnum.nextElement();
if (!skipModelNames.containsObject(modelName)) {
EOModel model = modelGroup.modelNamed(modelName);
if (model == null) {
throw new IllegalArgumentException("There is no model named '" + modelName + "' in this model group.");
}
_buildDependenciesForModel(model, ERXMigrator.LATEST_VERSION, versions, migrations);
}
}
Set<String> processedModelNames = new HashSet<String>();
Set<String> pendingModelNames = new HashSet<String>(versions.keySet());
while (!pendingModelNames.isEmpty()) {
Iterator<String> modelNamesIter = pendingModelNames.iterator();
while (modelNamesIter.hasNext()) {
String modelName = modelNamesIter.next();
EOModel model = modelGroup.modelNamed(modelName);
Enumeration entitiesEnum = model.entities().objectEnumerator();
while (entitiesEnum.hasMoreElements()) {
EOEntity entity = (EOEntity) entitiesEnum.nextElement();
EOEntity parentEntity = entity.parentEntity();
if (parentEntity != null && !parentEntity.model().equals(model)) {
EOModel parentModel = parentEntity.model();
_buildDependenciesForModel(parentModel, LATEST_VERSION, versions, migrations);
}
Enumeration relationshipsEnum = entity.relationships().objectEnumerator();
while (relationshipsEnum.hasMoreElements()) {
EORelationship relationship = (EORelationship) relationshipsEnum.nextElement();
EOEntity destinationEntity = relationship.destinationEntity();
if (destinationEntity != null && !destinationEntity.model().equals(model)) {
EOModel destinationModel = destinationEntity.model();
_buildDependenciesForModel(destinationModel, LATEST_VERSION, versions, migrations);
}
}
}
_buildDependenciesForModel(model, LATEST_VERSION, versions, migrations);