use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class ElementsFactory method getOrCreateDatabaseTable.
@SuppressWarnings("rawtypes")
protected OrmShape getOrCreateDatabaseTable(ITable databaseTable) {
OrmShape tableShape = null;
if (databaseTable != null) {
tableShape = getShape(databaseTable);
if (tableShape == null) {
tableShape = createShape(databaseTable);
final IConfiguration config = getConfig();
if (config != null) {
Iterator iterator = config.getClassMappings();
while (iterator.hasNext()) {
Object clazz = iterator.next();
if (clazz instanceof IPersistentClass && ((IPersistentClass) clazz).isInstanceOfRootClass()) {
IPersistentClass cls = (IPersistentClass) clazz;
if (databaseTable.equals(cls.getTable())) {
// create persistent class shape only for RootClass,
// which has same table reference
getOrCreatePersistentClass(cls, null);
}
}
}
}
}
}
return tableShape;
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class OrmDiagram method recreateChildren.
public void recreateChildren() {
deleteChildren();
elements.clear();
connections.clear();
StringBuilder errorMessage = new StringBuilder();
IConfiguration config = getConfig(errorMessage);
final ElementsFactory factory = new ElementsFactory(consoleConfigName, elements, connections);
for (int i = 0; i < roots.size(); i++) {
IPersistentClass rc = roots.get(i);
if (rc != null) {
factory.getOrCreatePersistentClass(rc, null);
}
}
updateChildrenList();
factory.createChildren(this);
factory.createForeingKeyConnections();
updateChildrenList();
if (getChildrenNumber() == 0) {
String error = DiagramViewerMessages.MessageShape_warning;
if (config != null) {
if (consoleConfigName != null && consoleConfigName.length() > 0) {
error = consoleConfigName;
// $NON-NLS-1$
error += ": ";
error += DiagramViewerMessages.Diagram_no_items_or_incorrect_state;
}
}
if (errorMessage.length() > 0) {
error = errorMessage.toString();
}
addChild(new MessageShape(error, getConsoleConfigName()));
}
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class OpenDiagramActionDelegate method run.
public void run(IAction action) {
ObjectPluginAction objectPluginAction = (ObjectPluginAction) action;
Map<ConsoleConfiguration, Set<IPersistentClass>> mapCC_PCs = new HashMap<ConsoleConfiguration, Set<IPersistentClass>>();
TreePath[] paths = ((TreeSelection) objectPluginAction.getSelection()).getPaths();
for (int i = 0; i < paths.length; i++) {
final Object firstSegment = paths[i].getFirstSegment();
if (!(firstSegment instanceof ConsoleConfiguration)) {
continue;
}
final ConsoleConfiguration consoleConfig = (ConsoleConfiguration) (firstSegment);
Set<IPersistentClass> setPC = mapCC_PCs.get(consoleConfig);
if (null == setPC) {
setPC = new HashSet<IPersistentClass>();
mapCC_PCs.put(consoleConfig, setPC);
}
Object last_el = paths[i].getLastSegment();
if (last_el instanceof IPersistentClass) {
IPersistentClass persClass = (IPersistentClass) last_el;
setPC.add(persClass);
} else if (last_el instanceof IConfiguration) {
IConfiguration config = (IConfiguration) last_el;
Iterator<IPersistentClass> it = config.getClassMappings();
while (it.hasNext()) {
setPC.add(it.next());
}
} else if (last_el instanceof ConsoleConfiguration) {
IConfiguration config = consoleConfig.getConfiguration();
if (config == null) {
try {
consoleConfig.build();
} catch (Exception he) {
HibernateConsolePlugin.getDefault().showError(HibernateConsolePlugin.getShell(), DiagramViewerMessages.OpenDiagramActionDelegate_could_not_load_configuration + ' ' + consoleConfig.getName(), he);
}
if (consoleConfig.hasConfiguration()) {
consoleConfig.buildMappings();
}
config = consoleConfig.getConfiguration();
}
if (config != null) {
Iterator<IPersistentClass> it = config.getClassMappings();
while (it.hasNext()) {
setPC.add(it.next());
}
}
}
}
for (Iterator<ConsoleConfiguration> it = mapCC_PCs.keySet().iterator(); it.hasNext(); ) {
ConsoleConfiguration consoleConfiguration = it.next();
Set<IPersistentClass> setPC = mapCC_PCs.get(consoleConfiguration);
try {
openEditor(setPC, consoleConfiguration);
} catch (PartInitException e) {
// $NON-NLS-1$
HibernateConsolePlugin.getDefault().logErrorMessage("Can't open mapping view.", e);
}
}
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class OrmLabelProvider method updateColumnSqlType.
/**
* For correct label creation should update column sql type.
* @param column
* @return
*/
public boolean updateColumnSqlType(final IColumn column) {
String sqlType = column.getSqlType();
if (sqlType != null) {
return false;
}
final IConfiguration config = getConfig();
if (config != null) {
final ConsoleConfiguration consoleConfig = getConsoleConfig();
try {
sqlType = (String) consoleConfig.execute(new ExecutionContext.Command() {
public Object execute() {
return column.getSqlType(config);
}
});
} catch (Exception e) {
// do not ignore it - print in Error Log
// $NON-NLS-1$
HibernateConsolePlugin.getDefault().logErrorMessage("Exception: ", e);
}
}
if (sqlType != null) {
column.setSqlType(sqlType);
return true;
}
return false;
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class WripperException method testHbmExportExceptionTest.
public void testHbmExportExceptionTest() throws Exception {
try {
Object[] persClassesInit = getPersistenceClasses(false);
final ConsoleConfiguration consCFG = getConsoleConfig();
IConfiguration config = consCFG.getConfiguration();
// delete old hbm files
assertNotNull(testPackage);
int nDeleted = 0;
if (testPackage.getNonJavaResources().length > 0) {
Object[] ress = testPackage.getNonJavaResources();
for (int i = 0; i < ress.length; i++) {
if (ress[i] instanceof IFile) {
IFile res = (IFile) ress[i];
if (res.getName().endsWith(".hbm.xml")) {
// $NON-NLS-1$
res.delete(true, false, null);
nDeleted++;
}
}
}
}
IHibernateMappingExporter hce = service.newHibernateMappingExporter(config, getSrcFolder());
try {
hce.start();
IArtifactCollector collector = service.newArtifactCollector();
collector.formatFiles();
try {
// build generated configuration
testPackage.getResource().refreshLocal(IResource.DEPTH_INFINITE, null);
testPackage.getJavaProject().getProject().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
ConsoleConfigUtils.customizeCfgXmlForPack(testPackage);
assertNotNull(consCFG);
consCFG.reset();
consCFG.build();
assertTrue(consCFG.hasConfiguration());
consCFG.getConfiguration().buildMappings();
config = consCFG.getConfiguration();
} catch (CoreException e) {
String out = NLS.bind(ConsoleTestMessages.UpdateConfigurationTest_error_customising_file_for_package, new Object[] { ConsoleConfigUtils.CFG_FILE_NAME, testPackage.getPath(), e.getMessage() });
fail(out);
}
} catch (Exception e) {
throw (Exception) e.getCause();
}
//
Object[] persClassesReInit = getPersistenceClasses(false);
//
int nCreated = 0;
if (testPackage.getNonJavaResources().length > 0) {
Object[] ress = testPackage.getNonJavaResources();
for (int i = 0; i < ress.length; i++) {
if (ress[i] instanceof IFile) {
IFile res = (IFile) ress[i];
if (res.getName().endsWith(".hbm.xml")) {
// $NON-NLS-1$
nCreated++;
}
}
}
}
//
assertTrue(persClassesInit.length == persClassesReInit.length);
assertTrue(nCreated > 0);
assertTrue(nDeleted >= 0 && persClassesInit.length > 0);
assertTrue(nCreated <= persClassesInit.length);
} catch (Exception e) {
// $NON-NLS-1$ //$NON-NLS-2$
String newMessage = "\nPackage " + testPackage.getElementName() + ":";
throw new WripperException(newMessage, e);
}
}
Aggregations