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;
}
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());
}
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();
}
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
}
}
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;
}
Aggregations