Search in sources :

Example 1 with ClassRef

use of org.eclipse.jpt.jpa.core.context.persistence.ClassRef in project jbosstools-hibernate by jbosstools.

the class HibernatePersistenceUnitClassesComposite method buildLabelProvider.

private ILabelProvider buildLabelProvider() {
    return new LabelProvider() {

        @Override
        public Image getImage(Object element) {
            Image image = null;
            if (element instanceof ClassRef) {
                ClassRef classRef = (ClassRef) element;
                JavaPersistentType persistentType = classRef.getJavaPersistentType();
                if (persistentType != null) {
                    image = this.getImage(persistentType);
                // image = JpaMappingImageHelper.imageForTypeMapping(persistentType.getMappingKey());
                } else if (classRef instanceof PackageInfoRef) {
                    PackageInfoRef packageInfoRef = (PackageInfoRef) classRef;
                    if (packageInfoRef.getJavaPackageInfo() != null) {
                        image = JavaPlugin.getImageDescriptorRegistry().get(JavaPluginImages.DESC_OBJS_PACKAGE);
                    }
                }
            }
            if (image != null) {
                return image;
            }
            return HibernateJptUIPlugin.getDefault().getImage("warning");
        }

        @Override
        public String getText(Object element) {
            ClassRef classRef = (ClassRef) element;
            String name = classRef.getClassName();
            if (name == null) {
                name = JptJpaUiPersistenceMessages.PERSISTENCE_UNIT_CLASSES_COMPOSITE_CLASS_REF_NO_NAME;
            }
            return name;
        }
    };
}
Also used : PackageInfoRef(org.jboss.tools.hibernate.jpt.core.internal.context.persistence.PackageInfoRef) ClassRef(org.eclipse.jpt.jpa.core.context.persistence.ClassRef) JavaPersistentType(org.eclipse.jpt.jpa.core.context.java.JavaPersistentType) Image(org.eclipse.swt.graphics.Image) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 2 with ClassRef

use of org.eclipse.jpt.jpa.core.context.persistence.ClassRef in project jbosstools-hibernate by jbosstools.

the class HibernatePersistenceUnitClassesComposite method addMappedClass.

// private void addMappedClass(ObjectListSelectionModel listSelectionModel) {
// IType type = chooseType();
// 
// if (type != null) {
// String className = type.getFullyQualifiedName('$');
// if(classRefExists(className)) {
// return;
// }
// ClassRef classRef = getSubject().addSpecifiedClassRef(className);
// listSelectionModel.setSelectedValue(classRef);
// }
// }
private ClassRef addMappedClass() {
    IType type = chooseType();
    ClassRef result = null;
    if (type != null) {
        String className = type.getFullyQualifiedName('$');
        result = getClassRef(className);
        if (result == null) {
            result = getSubject().addSpecifiedClassRef(className);
        }
    }
    return result;
}
Also used : ClassRef(org.eclipse.jpt.jpa.core.context.persistence.ClassRef) IType(org.eclipse.jdt.core.IType)

Example 3 with ClassRef

use of org.eclipse.jpt.jpa.core.context.persistence.ClassRef in project jbosstools-hibernate by jbosstools.

the class HibernatePersistenceUnitClassesComposite method addMappedPackage.

// private void addMappedPackage(ObjectListSelectionModel listSelectionModel) {
// IPackageFragment pack = choosePackage();
// 
// if (pack != null) {
// if(classRefExists(pack.getElementName())) {
// return;
// }
// ClassRef classRef = getSubject().addSpecifiedClassRef(pack.getElementName());
// listSelectionModel.setSelectedValue(classRef);
// }
// }
private ClassRef addMappedPackage() {
    IPackageFragment pack = choosePackage();
    ClassRef result = null;
    if (pack != null) {
        result = getClassRef(pack.getElementName());
        if (result == null) {
            result = getSubject().addSpecifiedClassRef(pack.getElementName());
        }
    }
    return result;
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ClassRef(org.eclipse.jpt.jpa.core.context.persistence.ClassRef)

Example 4 with ClassRef

use of org.eclipse.jpt.jpa.core.context.persistence.ClassRef in project jbosstools-hibernate by jbosstools.

the class HibernateJpaModelTests method testNamigStrategyMapping.

@Test
public void testNamigStrategyMapping() {
    ConsoleConfiguration cc = KnownConfigurations.getInstance().find(PROJECT_NAME);
    assertNotNull("Console configuration not found for project " + PROJECT_NAME, cc);
    cc.build();
    assertNotNull("Console configuration build problem", cc.getConfiguration());
    IConfiguration configuration = cc.getConfiguration();
    assertNotNull("Naming Strategy not found", cc.getConfiguration().getNamingStrategy());
    assertEquals("ns.NamingStrategy", cc.getConfiguration().getNamingStrategy().getStrategyClassName());
    try {
        jpaProject = ((Reference) project.getAdapter(Reference.class)).getValue();
    } catch (InterruptedException e) {
        fail(e.getMessage());
    }
    assertNotNull(jpaProject);
    JpaContextRoot rootContextNode = jpaProject.getContextRoot();
    Persistence p = rootContextNode.getPersistenceXml().getRoot();
    assertTrue(p.getPersistenceUnits().iterator().hasNext());
    assertTrue(p.getPersistenceUnits().iterator().next() instanceof HibernatePersistenceUnit);
    HibernatePersistenceUnit hpu = (HibernatePersistenceUnit) p.getPersistenceUnits().iterator().next();
    List<ClassRef> crs = IterableTools.list(hpu.getClassRefs());
    assertTrue(crs.size() == 2);
    if (crs.get(0).isFor("entity.ManyToMany1")) {
        checkManyToManyNS1(crs.get(0));
        checkManyToManyNS2(crs.get(1));
    } else {
        checkManyToManyNS1(crs.get(1));
        checkManyToManyNS2(crs.get(0));
    }
    cc.reset();
}
Also used : JpaContextRoot(org.eclipse.jpt.jpa.core.context.JpaContextRoot) Persistence(org.eclipse.jpt.jpa.core.context.persistence.Persistence) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ClassRef(org.eclipse.jpt.jpa.core.context.persistence.ClassRef) HibernatePersistenceUnit(org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Test(org.junit.Test)

Example 5 with ClassRef

use of org.eclipse.jpt.jpa.core.context.persistence.ClassRef in project jbosstools-hibernate by jbosstools.

the class HibernateJpaModelTests method testDefaultMapping.

@Test
public void testDefaultMapping() {
    assertNotNull(jpaProject);
    JpaContextRoot rootContextNode = jpaProject.getContextRoot();
    Persistence p = rootContextNode.getPersistenceXml().getRoot();
    assertTrue(p.getPersistenceUnitsSize() > 0);
    assertTrue(p.getPersistenceUnits().iterator().next() instanceof HibernatePersistenceUnit);
    HibernatePersistenceUnit hpu = (HibernatePersistenceUnit) p.getPersistenceUnits().iterator().next();
    List<ClassRef> crs = IterableTools.list(hpu.getClassRefs());
    assertTrue(crs.size() == 2);
    if (crs.get(0).isFor("entity.ManyToMany1")) {
        checkManyToMany1(crs.get(0));
        checkManyToMany2(crs.get(1));
    } else {
        checkManyToMany1(crs.get(1));
        checkManyToMany2(crs.get(0));
    }
}
Also used : JpaContextRoot(org.eclipse.jpt.jpa.core.context.JpaContextRoot) Persistence(org.eclipse.jpt.jpa.core.context.persistence.Persistence) ClassRef(org.eclipse.jpt.jpa.core.context.persistence.ClassRef) HibernatePersistenceUnit(org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit) Test(org.junit.Test)

Aggregations

ClassRef (org.eclipse.jpt.jpa.core.context.persistence.ClassRef)5 JpaContextRoot (org.eclipse.jpt.jpa.core.context.JpaContextRoot)2 Persistence (org.eclipse.jpt.jpa.core.context.persistence.Persistence)2 HibernatePersistenceUnit (org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit)2 Test (org.junit.Test)2 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 IType (org.eclipse.jdt.core.IType)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 JavaPersistentType (org.eclipse.jpt.jpa.core.context.java.JavaPersistentType)1 Image (org.eclipse.swt.graphics.Image)1 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)1 PackageInfoRef (org.jboss.tools.hibernate.jpt.core.internal.context.persistence.PackageInfoRef)1 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)1