Search in sources :

Example 96 with IConfiguration

use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.

the class HbmExporterTest method getConfigurationFor.

/**
 * Method returns Configuration object for selected ICompilationUnits.
 * Fails if configuration is null.
 * @return
 */
protected IConfiguration getConfigurationFor(String... cuNames) {
    Set<ICompilationUnit> selectionCU = new HashSet<ICompilationUnit>();
    for (int i = 0; i < cuNames.length; i++) {
        ICompilationUnit icu = Utils.findCompilationUnit(project.getIJavaProject(), cuNames[i]);
        assertNotNull(icu);
        selectionCU.add(icu);
    }
    ConfigurationActor actor = new ConfigurationActor(selectionCU);
    Map<IJavaProject, IConfiguration> configurations = actor.createConfigurations(Integer.MAX_VALUE);
    assertEquals(1, configurations.size());
    IConfiguration config = configurations.get(project.getIJavaProject());
    assertNotNull(config);
    return config;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaProject(org.eclipse.jdt.core.IJavaProject) ConfigurationActor(org.hibernate.eclipse.jdt.ui.wizards.ConfigurationActor) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) HashSet(java.util.HashSet)

Example 97 with IConfiguration

use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.

the class HbmExporterTest method testArray.

public void testArray() {
    // $NON-NLS-1$
    IConfiguration config = getConfigurationFor("pack.A");
    // $NON-NLS-1$ //$NON-NLS-2$
    checkClassesMaped(config, "pack.A", "pack.B");
    // $NON-NLS-1$
    IPersistentClass a = config.getClassMapping("pack.A");
    // $NON-NLS-1$
    IPersistentClass b = config.getClassMapping("pack.B");
    // $NON-NLS-1$
    IProperty bs = a.getProperty("bs");
    assertNotNull(bs.getValue());
    IValue value = bs.getValue();
    assertTrue("Expected to get Array-type mapping", value.isArray());
    // $NON-NLS-1$
    assertEquals("pack.B", value.getElementClassName());
    assertTrue(// $NON-NLS-1$
    "Expected to get one-to-many array's element type", value.getCollectionElement().isOneToMany());
    // $NON-NLS-1$
    IProperty testIntArray = b.getProperty("testIntArray");
    assertNotNull(testIntArray);
    value = testIntArray.getValue();
    assertNotNull(value);
    assertTrue(// $NON-NLS-1$
    "Expected to get PrimitiveArray-type mapping", value.isPrimitiveArray());
    assertNotNull(value.getCollectionElement());
    // $NON-NLS-1$
    assertTrue("Expected to get int-type primitive array", value.getCollectionElement().getType().isIntegerType());
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 98 with IConfiguration

use of org.jboss.tools.hibernate.runtime.spi.IConfiguration 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 99 with IConfiguration

use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.

the class ConsoleConfigurationTest method testHQLListParameters.

@Test
public void testHQLListParameters() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    // fix for https://issues.jboss.org/browse/JBIDE-9392
    // the view calls jdbc connection
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IViewPart view = activePage.findView(QueryPageTabView.ID);
    if (view != null) {
        activePage.hideView(view);
        view.dispose();
    }
    consoleCfg.build();
    IConfiguration c = consoleCfg.getConfiguration();
    IPersistentClass rc = service.newRootClass();
    rc.setEntityName("java.awt.Button");
    rc.setClassName("java.awt.Button");
    IColumn column = service.newColumn("label");
    ITable table = service.newTable("faketable");
    IPrimaryKey pk = table.getPrimaryKey();
    pk.addColumn(column);
    rc.setTable(table);
    table.addColumn(column);
    IProperty fakeProp = service.newProperty();
    fakeProp.setName("label");
    IValue sv = service.newSimpleValue();
    sv.addColumn(column);
    sv.setTypeName("string");
    sv.setTable(table);
    fakeProp.setValue(sv);
    rc.setIdentifierProperty(fakeProp);
    rc.setIdentifier(fakeProp.getValue());
    c.addClass(rc);
    consoleCfg.buildSessionFactory();
    ConsoleQueryParameter paramA = new ConsoleQueryParameter(service, "a", typeFactory.getIntegerType(), new Integer[] { new Integer(1), new Integer(2) });
    ConsoleQueryParameter paramB = new ConsoleQueryParameter(service, "b", typeFactory.getIntegerType(), new Integer(3));
    ConsoleQueryParameter paramOrdered = new ConsoleQueryParameter(service, "0", typeFactory.getIntegerType(), new Integer(4));
    QueryInputModel model = new QueryInputModel(service);
    model.addParameter(paramA);
    model.addParameter(paramB);
    model.addParameter(paramOrdered);
    // $NON-NLS-1$
    QueryPage qp = consoleCfg.executeHQLQuery("select count(*) from java.awt.Button where 1 in ( ?, :a, :b )", model);
    Assert.assertNotNull(qp);
    try {
        // execute the query
        qp.getList();
    } catch (Exception e) {
    // ignore - there is fake mapping
    }
}
Also used : ConsoleQueryParameter(org.hibernate.console.ConsoleQueryParameter) IViewPart(org.eclipse.ui.IViewPart) QueryPage(org.hibernate.console.QueryPage) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) QueryInputModel(org.hibernate.console.QueryInputModel) IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Test(org.junit.Test)

Example 100 with IConfiguration

use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.

the class CoreMappingTestHelper method getPersistenceClasses.

private Object[] getPersistenceClasses(boolean resetCC) {
    final ConsoleConfiguration consCFG = getConsoleConfig();
    if (resetCC) {
        consCFG.reset();
        consCFG.build();
    }
    Assert.assertTrue(consCFG.hasConfiguration());
    if (resetCC) {
        consCFG.buildMappings();
    }
    Object[] configs = null;
    Object[] persClasses = null;
    try {
        configs = ccWorkbenchAdapter.getChildren(consCFG);
        Assert.assertNotNull(configs);
        Assert.assertEquals(3, configs.length);
        Assert.assertTrue(configs[0] instanceof IConfiguration);
        persClasses = configWorkbenchAdapter.getChildren(configs[0]);
    } catch (Exception ex) {
        String out = NLS.bind(TestConsoleMessages.OpenMappingDiagramTest_mapping_diagrams_for_package_cannot_be_opened, new Object[] { testName.getMethodName(), ex.getMessage() });
        Assert.fail(out);
    }
    return persClasses;
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)137 Test (org.junit.Test)72 Configuration (org.hibernate.cfg.Configuration)65 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)29 JDBCMetaDataConfiguration (org.hibernate.cfg.JDBCMetaDataConfiguration)25 File (java.io.File)19 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)17 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)16 Properties (java.util.Properties)13 CoreException (org.eclipse.core.runtime.CoreException)10 IReverseEngineeringStrategy (org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy)10 IJDBCReader (org.jboss.tools.hibernate.runtime.spi.IJDBCReader)9 FileWriter (java.io.FileWriter)8 IOException (java.io.IOException)8 JDBCReader (org.hibernate.cfg.reveng.JDBCReader)8 SimpleValue (org.hibernate.mapping.SimpleValue)8 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)8 JavaModelException (org.eclipse.jdt.core.JavaModelException)7 PartInitException (org.eclipse.ui.PartInitException)7 Ejb3Configuration (org.hibernate.ejb.Ejb3Configuration)7