Search in sources :

Example 1 with EntityInfosCollection

use of org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfosCollection in project jbosstools-hibernate by jbosstools.

the class AllEntitiesProcessor method reCollectModification.

public void reCollectModification(Map<String, EntityInfo> entities) {
    changes.clear();
    final ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
    HashMap<IPath, EntityInfosCollection> modifications = new HashMap<IPath, EntityInfosCollection>();
    Iterator<Map.Entry<String, EntityInfo>> it = entities.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, EntityInfo> entry = it.next();
        if (entry.getValue().isInterfaceFlag()) {
            continue;
        }
        final String javaProjectName = entry.getValue().getJavaProjectName();
        final String fullyQualifiedName = entry.getValue().getFullyQualifiedName();
        IJavaProject javaProject = Utils.findJavaProject(javaProjectName);
        ICompilationUnit icu = Utils.findCompilationUnit(javaProject, fullyQualifiedName);
        if (icu == null) {
            continue;
        }
        org.eclipse.jdt.core.dom.CompilationUnit cu = Utils.getCompilationUnit(icu, true);
        final IPath path = cu.getJavaElement().getPath();
        EntityInfosCollection eiCollection = null;
        if (modifications.containsKey(path)) {
            eiCollection = modifications.get(path);
        } else {
            eiCollection = new EntityInfosCollection();
            eiCollection.setPath(path);
            eiCollection.setICompilationUnit(icu);
            eiCollection.setCompilationUnit(cu);
            modifications.put(path, eiCollection);
            try {
                bufferManager.connect(path, LocationKind.IFILE, null);
            } catch (CoreException e) {
                // $NON-NLS-1$
                HibernateConsolePlugin.getDefault().logErrorMessage("CoreException: ", e);
            }
        }
        final EntityInfo entityInfo = entry.getValue();
        // 
        entityInfo.updateColumnAnnotationImport(defaultStrLength != columnLength);
        entityInfo.updateVersionImport(enableOptLock && entityInfo.isAddVersionFlag());
        // 
        eiCollection.addEntityInfo(entityInfo);
    }
    Iterator<EntityInfosCollection> itEIC = modifications.values().iterator();
    while (itEIC.hasNext()) {
        EntityInfosCollection eic = itEIC.next();
        eic.updateExistingImportSet();
        eic.updateRequiredImportSet();
        collectModification(bufferManager, eic, entities);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) HashMap(java.util.HashMap) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) EntityInfosCollection(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfosCollection) EntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 EntityInfo (org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo)1 EntityInfosCollection (org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfosCollection)1