Search in sources :

Example 1 with AllEntitiesInfoCollector

use of org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector in project jbosstools-hibernate by jbosstools.

the class TypeVisitor method createConfigurations.

/**
 * @return different configuration for different projects
 */
public Map<IJavaProject, IConfiguration> createConfigurations(int processDepth) {
    Map<IJavaProject, IConfiguration> configs = new HashMap<IJavaProject, IConfiguration>();
    if (selectionCU.size() == 0) {
        return configs;
    }
    AllEntitiesInfoCollector collector = new AllEntitiesInfoCollector();
    Iterator<ICompilationUnit> it = selectionCU.iterator();
    Map<IJavaProject, Set<ICompilationUnit>> mapJP_CUSet = new HashMap<IJavaProject, Set<ICompilationUnit>>();
    // separate by parent project
    while (it.hasNext()) {
        ICompilationUnit cu = it.next();
        Set<ICompilationUnit> set = mapJP_CUSet.get(cu.getJavaProject());
        if (set == null) {
            set = new HashSet<ICompilationUnit>();
            mapJP_CUSet.put(cu.getJavaProject(), set);
        }
        set.add(cu);
    }
    Iterator<Map.Entry<IJavaProject, Set<ICompilationUnit>>> mapIt = mapJP_CUSet.entrySet().iterator();
    while (mapIt.hasNext()) {
        Map.Entry<IJavaProject, Set<ICompilationUnit>> entry = mapIt.next();
        IJavaProject javaProject = entry.getKey();
        Iterator<ICompilationUnit> setIt = entry.getValue().iterator();
        collector.initCollector();
        while (setIt.hasNext()) {
            ICompilationUnit icu = setIt.next();
            collector.collect(icu, processDepth);
        }
        collector.resolveRelations();
        // I don't check here if any non abstract class selected
        IConfiguration config = createConfiguration(javaProject, collector.getMapCUs_Info());
        if (config != null) {
            configs.put(javaProject, config);
        }
    }
    return configs;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Entry(java.util.Map.Entry) IJavaProject(org.eclipse.jdt.core.IJavaProject) AllEntitiesInfoCollector(org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AllEntitiesInfoCollector

use of org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector in project jbosstools-hibernate by jbosstools.

the class JPAMapMockTests method testJPAMapToolActor.

public void testJPAMapToolActor() {
    final JPAMapToolActor jpaMapToolActor = new JPAMapToolActor();
    final AllEntitiesProcessor allEntitiesProcessor = context.mock(AllEntitiesProcessor.class);
    final AllEntitiesInfoCollector allEntitiesInfoCollector = context.mock(AllEntitiesInfoCollector.class);
    final ISelection selection = context.mock(ISelection.class);
    final ICompilationUnit compilationUnit = context.mock(ICompilationUnit.class);
    final IJavaProject javaProject = context.mock(IJavaProject.class);
    jpaMapToolActor.setAllEntitiesProcessor(allEntitiesProcessor);
    jpaMapToolActor.setAllEntitiesInfoCollector(allEntitiesInfoCollector);
    jpaMapToolActor.setSelection(selection);
    final IStructuredSelection selection2Update = new StructuredSelection();
    context.checking(new Expectations() {

        {
            exactly(1).of(allEntitiesProcessor).modify(new HashMap<String, EntityInfo>(), true, selection2Update);
        }
    });
    jpaMapToolActor.updateSelected(Integer.MAX_VALUE);
    context.assertIsSatisfied();
    jpaMapToolActor.setSelection(null);
    Set<ICompilationUnit> selectionCU = new HashSet<ICompilationUnit>();
    selectionCU.add(compilationUnit);
    jpaMapToolActor.setSelectionCU(selectionCU);
    // $NON-NLS-1$
    final Sequence sequence = context.sequence("updateSelected");
    context.checking(new Expectations() {

        {
            allowing(compilationUnit).getJavaProject();
            inSequence(sequence);
            will(returnValue(javaProject));
            allowing(allEntitiesInfoCollector).initCollector();
            inSequence(sequence);
            allowing(allEntitiesInfoCollector).collect(compilationUnit, Integer.MAX_VALUE);
            inSequence(sequence);
            allowing(allEntitiesInfoCollector).resolveRelations();
            inSequence(sequence);
            allowing(allEntitiesInfoCollector).getNonAbstractCUNumber();
            inSequence(sequence);
            will(returnValue(2));
            allowing(allEntitiesInfoCollector).getNonInterfaceCUNumber();
            inSequence(sequence);
            will(returnValue(2));
            allowing(allEntitiesInfoCollector).getAnnotationStylePreference();
            inSequence(sequence);
            will(returnValue(AnnotStyle.GETTERS));
            allowing(allEntitiesProcessor).setAnnotationStylePreference(AnnotStyle.GETTERS);
            inSequence(sequence);
            allowing(allEntitiesInfoCollector).getMapCUs_Info();
            inSequence(sequence);
            will(returnValue(null));
            allowing(allEntitiesProcessor).modify(null, true, null);
            inSequence(sequence);
            allowing(allEntitiesProcessor).savePreferences();
            inSequence(sequence);
            exactly(1).of(allEntitiesProcessor).modify(null, true, selection2Update);
        }
    });
    jpaMapToolActor.updateSelected(Integer.MAX_VALUE);
    context.assertIsSatisfied();
/**
 * /
 *		jpaMapToolActor.clearSelectionCU();
 *		jpaMapToolActor.addCompilationUnit(compilationUnit);
 *		jpaMapToolActor.addCompilationUnit(compilationUnit);
 *        context.checking(new Expectations() {{
 *        	jpaMapToolActor.expects(once()).method("updateSelectedItems").with(eq(selection));
 *            one(authorizedPurchaserManager).retrievePurchasers(user.getId());
 *            will(returnValue(Collections.emptyList()));
 *
 *            allowing(securityContext).getAuthentication();
 *            will(returnValue(authentication));
 *        }});
 *        jpaMapToolActor.updateOpen();
 *        /*
 */
}
Also used : Expectations(org.jmock.Expectations) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) HashMap(java.util.HashMap) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Sequence(org.jmock.Sequence) JPAMapToolActor(org.hibernate.eclipse.jdt.ui.internal.jpa.actions.JPAMapToolActor) AllEntitiesProcessor(org.hibernate.eclipse.jdt.ui.internal.jpa.process.AllEntitiesProcessor) IJavaProject(org.eclipse.jdt.core.IJavaProject) AllEntitiesInfoCollector(org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector) ISelection(org.eclipse.jface.viewers.ISelection) HashSet(java.util.HashSet)

Example 3 with AllEntitiesInfoCollector

use of org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector in project jbosstools-hibernate by jbosstools.

the class NewHibernateMappingFileWizard method initEntitiesInfo.

protected void initEntitiesInfo() {
    if (selectionCU.size() == 0) {
        return;
    }
    AllEntitiesInfoCollector collector = new AllEntitiesInfoCollector();
    Iterator<ICompilationUnit> it = selectionCU.iterator();
    Map<IJavaProject, Set<ICompilationUnit>> mapJP_CUSet = new HashMap<IJavaProject, Set<ICompilationUnit>>();
    // separate by parent project
    while (it.hasNext()) {
        ICompilationUnit cu = it.next();
        Set<ICompilationUnit> set = mapJP_CUSet.get(cu.getJavaProject());
        if (set == null) {
            set = new HashSet<ICompilationUnit>();
            mapJP_CUSet.put(cu.getJavaProject(), set);
        }
        set.add(cu);
    }
    Iterator<Map.Entry<IJavaProject, Set<ICompilationUnit>>> mapIt = mapJP_CUSet.entrySet().iterator();
    while (mapIt.hasNext()) {
        Map.Entry<IJavaProject, Set<ICompilationUnit>> entry = mapIt.next();
        IJavaProject javaProject = entry.getKey();
        Iterator<ICompilationUnit> setIt = entry.getValue().iterator();
        collector.initCollector();
        while (setIt.hasNext()) {
            ICompilationUnit icu = setIt.next();
            collector.collect(icu, processDepth);
        }
        collector.resolveRelations();
        Collection<EntityInfo> c = new ArrayList<EntityInfo>();
        for (Iterator<EntityInfo> i = collector.getMapCUs_Info().values().iterator(); i.hasNext(); ) {
            c.add(i.next());
        }
        project_infos.put(javaProject, c);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Entry(java.util.Map.Entry) IJavaProject(org.eclipse.jdt.core.IJavaProject) AllEntitiesInfoCollector(org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector) EntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with AllEntitiesInfoCollector

use of org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector in project jbosstools-hibernate by jbosstools.

the class HibernateJPAWizardDataFactory method createHibernateJPAWizardData.

public static IHibernateJPAWizardData createHibernateJPAWizardData(final IStructuredSelection selection2Update, IHibernateJPAWizardParams params, int depth) {
    CompilationUnitCollector compileUnitCollector = new CompilationUnitCollector();
    @SuppressWarnings("rawtypes") Iterator itSelection2Update = selection2Update.iterator();
    while (itSelection2Update.hasNext()) {
        Object obj = itSelection2Update.next();
        compileUnitCollector.processJavaElements(obj, true);
    }
    Iterator<ICompilationUnit> it = compileUnitCollector.setSelectionCUIterator();
    AllEntitiesInfoCollector collector = new AllEntitiesInfoCollector();
    collector.initCollector();
    while (it.hasNext()) {
        ICompilationUnit cu = it.next();
        collector.collect(cu, depth);
    }
    collector.resolveRelations();
    final Map<String, EntityInfo> entities = collector.getMapCUs_Info();
    params.performDisconnect();
    params.reCollectModification(entities);
    final ArrayList<ChangeStructure> changes = params.getChanges();
    IHibernateJPAWizardData data = new IHibernateJPAWizardData() {

        public Map<String, EntityInfo> getEntities() {
            return entities;
        }

        public ArrayList<ChangeStructure> getChanges() {
            return changes;
        }

        public IStructuredSelection getSelection2Update() {
            return selection2Update;
        }
    };
    return data;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnitCollector(org.hibernate.eclipse.jdt.ui.internal.jpa.collect.CompilationUnitCollector) ChangeStructure(org.hibernate.eclipse.jdt.ui.internal.jpa.process.ChangeStructure) AllEntitiesInfoCollector(org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector) EntityInfo(org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo) Iterator(java.util.Iterator)

Aggregations

ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)4 AllEntitiesInfoCollector (org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 EntityInfo (org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 JPAMapToolActor (org.hibernate.eclipse.jdt.ui.internal.jpa.actions.JPAMapToolActor)1 CompilationUnitCollector (org.hibernate.eclipse.jdt.ui.internal.jpa.collect.CompilationUnitCollector)1 AllEntitiesProcessor (org.hibernate.eclipse.jdt.ui.internal.jpa.process.AllEntitiesProcessor)1 ChangeStructure (org.hibernate.eclipse.jdt.ui.internal.jpa.process.ChangeStructure)1 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)1 Expectations (org.jmock.Expectations)1