Search in sources :

Example 1 with Persistence

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

the class HibernateJpaProject method getBasicHibernateProperties.

public BasicHibernateProperties getBasicHibernateProperties() {
    if (getContextRoot() != null) {
        PersistenceXml persistenceXml = getContextRoot().getPersistenceXml();
        Persistence persistence = persistenceXml.getRoot();
        if (persistence.getPersistenceUnitsSize() > 0) {
            PersistenceUnit persistenceUnit = persistence.getPersistenceUnit(0);
            if (persistenceUnit instanceof HibernatePersistenceUnit) {
                return ((HibernatePersistenceUnit) persistenceUnit).getHibernatePersistenceUnitProperties();
            }
        }
    }
    return null;
}
Also used : Persistence(org.eclipse.jpt.jpa.core.context.persistence.Persistence) PersistenceXml(org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml) HibernatePersistenceUnit(org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit) PersistenceUnit(org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit) HibernatePersistenceUnit(org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit)

Example 2 with Persistence

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

the class HibernateJpaOrmModelTests 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());
    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<MappingFileRef> mfrs = IterableTools.list(hpu.getMappingFileRefs());
    assertTrue(mfrs.size() == 1);
    assertTrue(mfrs.get(0).getMappingFile() instanceof GenericOrmXml);
    GenericOrmXml orm = (GenericOrmXml) mfrs.get(0).getMappingFile();
    checkManyToMany1NS(orm.getRoot().getPersistentType("entity.ManyToMany1"));
    checkManyToMany2NS(orm.getRoot().getPersistentType("entity.ManyToMany2"));
    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) GenericOrmXml(org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.GenericOrmXml) HibernatePersistenceUnit(org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit) MappingFileRef(org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef) Test(org.junit.Test)

Example 3 with Persistence

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

the class HibernateJpaOrmModelTests method testDefaultMapping.

@Test
public void testDefaultMapping() {
    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<MappingFileRef> mfrs = IterableTools.list(hpu.getMappingFileRefs());
    assertTrue(mfrs.size() == 1);
    assertTrue(mfrs.get(0).getMappingFile() instanceof GenericOrmXml);
    GenericOrmXml orm = (GenericOrmXml) mfrs.get(0).getMappingFile();
    List<OrmPersistentType> pTypes = IterableTools.list(orm.getRoot().getPersistentTypes());
    assertTrue(pTypes.size() == 3);
    checkManyToMany1(orm.getRoot().getPersistentType("entity.ManyToMany1"));
    checkManyToMany2(orm.getRoot().getPersistentType("entity.ManyToMany2"));
}
Also used : JpaContextRoot(org.eclipse.jpt.jpa.core.context.JpaContextRoot) Persistence(org.eclipse.jpt.jpa.core.context.persistence.Persistence) OrmPersistentType(org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType) GenericOrmXml(org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.GenericOrmXml) HibernatePersistenceUnit(org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit) MappingFileRef(org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef) Test(org.junit.Test)

Example 4 with Persistence

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

the class AddGeneratedClassesJob method mappingFileContains.

boolean mappingFileContains(JpaProject jpaProject, String fullyQualifiedTypeName) {
    PersistenceXml persistenceXml = jpaProject.getContextRoot().getPersistenceXml();
    if (persistenceXml == null) {
        return false;
    }
    Persistence persistence = persistenceXml.getRoot();
    if (persistence == null) {
        return false;
    }
    if (persistence.getPersistenceUnitsSize() == 0) {
        return false;
    }
    PersistenceUnit persistenceUnit = persistence.getPersistenceUnit(0);
    for (MappingFileRef mappingFileRef : persistenceUnit.getMappingFileRefs()) {
        if (mappingFileRef.getPersistentType(fullyQualifiedTypeName) != null) {
            return true;
        }
    }
    return false;
}
Also used : Persistence(org.eclipse.jpt.jpa.core.context.persistence.Persistence) XmlPersistence(org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistence) PersistenceXml(org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml) PersistenceUnit(org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit) XmlPersistenceUnit(org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistenceUnit) MappingFileRef(org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef)

Example 5 with Persistence

use of org.eclipse.jpt.jpa.core.context.persistence.Persistence 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)

Aggregations

Persistence (org.eclipse.jpt.jpa.core.context.persistence.Persistence)6 HibernatePersistenceUnit (org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit)5 JpaContextRoot (org.eclipse.jpt.jpa.core.context.JpaContextRoot)4 Test (org.junit.Test)4 MappingFileRef (org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef)3 ClassRef (org.eclipse.jpt.jpa.core.context.persistence.ClassRef)2 PersistenceUnit (org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit)2 PersistenceXml (org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml)2 GenericOrmXml (org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.GenericOrmXml)2 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)2 OrmPersistentType (org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType)1 XmlPersistence (org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistence)1 XmlPersistenceUnit (org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistenceUnit)1 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)1