use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class KnownConfigurationsTest method testKnownConfigurations.
@Test
public void testKnownConfigurations() {
KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
ConsoleConfiguration[] configurations = knownConfigurations.getConfigurations();
Assert.assertEquals(0, configurations.length);
CCListener listener = new CCListener();
try {
knownConfigurations.addConsoleConfigurationListener(listener);
Assert.assertEquals(0, listener.added.size());
ConsoleConfigurationPreferences preferences = new ConsoleConfigurationPreferences() {
public void setName(String name) {
}
public void readStateFrom(Element element) {
}
public void writeStateTo(Element node) {
}
public File getPropertyFile() {
return null;
}
public File getConfigXMLFile() {
return null;
}
public Properties getProperties() {
return null;
}
public File[] getMappingFiles() {
return null;
}
public URL[] getCustomClassPathURLS() {
return null;
}
public String getName() {
return TestConsoleMessages.KnownConfigurationsTest_fake_prefs;
}
public String getEntityResolverName() {
return null;
}
public ConfigurationMode getConfigurationMode() {
return null;
}
public String getNamingStrategy() {
return null;
}
public String getPersistenceUnitName() {
return null;
}
public String getConnectionProfileName() {
return null;
}
public String getDialectName() {
return null;
}
public String getHibernateVersion() {
return null;
}
};
ConsoleConfigurationPreferences preferences2 = new ConsoleConfigurationPreferences() {
String name = TestConsoleMessages.KnownConfigurationsTest_new_test;
public void setName(String name) {
this.name = name;
}
public void readStateFrom(Element element) {
}
public void writeStateTo(Element node) {
}
public File getPropertyFile() {
return null;
}
public File getConfigXMLFile() {
return null;
}
public Properties getProperties() {
return null;
}
public File[] getMappingFiles() {
return null;
}
public URL[] getCustomClassPathURLS() {
return null;
}
public String getName() {
return name;
}
public String getEntityResolverName() {
return null;
}
public ConfigurationMode getConfigurationMode() {
return null;
}
public String getNamingStrategy() {
return null;
}
public String getPersistenceUnitName() {
return null;
}
public String getConnectionProfileName() {
return null;
}
public String getDialectName() {
return null;
}
public String getHibernateVersion() {
return null;
}
};
ConsoleConfiguration configuration = new ConsoleConfiguration(preferences);
ConsoleConfiguration configuration2 = new ConsoleConfiguration(preferences2);
knownConfigurations.addConfiguration(configuration, false);
knownConfigurations.addConfiguration(configuration2, false);
configurations = knownConfigurations.getConfigurations();
Assert.assertEquals(2, configurations.length);
Assert.assertEquals(listener.added.size(), 0);
knownConfigurations.addConfiguration(configuration, true);
knownConfigurations.addConfiguration(configuration2, true);
configurations = knownConfigurations.getConfigurations();
Assert.assertEquals(2, configurations.length);
Assert.assertEquals(listener.added.size(), 2);
knownConfigurations.removeConfiguration(configuration, false);
knownConfigurations.removeConfiguration(configuration2, false);
configurations = knownConfigurations.getConfigurations();
Assert.assertEquals(0, configurations.length);
Assert.assertEquals(listener.added.size(), 0);
} finally {
KnownConfigurations.getInstance().removeConfigurationListener(listener);
}
}
use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class OrmDiagramTest method testLoadAndSave.
public void testLoadAndSave() {
final ConsoleConfiguration consoleConfig = context.mock(ConsoleConfiguration.class);
final IConfiguration config = context.mock(IConfiguration.class);
final IPersistentClass ioe = context.mock(IPersistentClass.class);
ArrayList<IPersistentClass> rts = new ArrayList<IPersistentClass>();
rts.add(ioe);
final List<Object> emptyList = new ArrayList<Object>();
final Iterator<Object> emptyListIterator = emptyList.iterator();
// see https://jira.jboss.org/jira/browse/JBIDE-6186
final String innerIntricateName = "myInner$Id";
context.checking(new Expectations() {
{
oneOf(ioe).getEntityName();
will(returnValue(innerIntricateName));
allowing(consoleConfig).getConfiguration();
will(returnValue(config));
allowing(consoleConfig).hasConfiguration();
will(returnValue(true));
oneOf(ioe).getEntityName();
will(returnValue(innerIntricateName));
oneOf(ioe).getEntityName();
will(returnValue(innerIntricateName));
oneOf(ioe).isInstanceOfRootClass();
will(returnValue(true));
oneOf(ioe).getIdentifierProperty();
will(returnValue(null));
oneOf(ioe).getIdentifier();
will(returnValue(null));
oneOf(ioe).getPropertyIterator();
will(returnValue(emptyListIterator));
oneOf(ioe).getTable();
will(returnValue(null));
oneOf(ioe).getSubclassIterator();
will(returnValue(emptyListIterator));
oneOf(ioe).getIdentifier();
will(returnValue(null));
oneOf(ioe).getJoinIterator();
will(returnValue(emptyListIterator));
allowing(ioe).getClassName();
// $NON-NLS-1$
will(returnValue("ClassName"));
allowing(consoleConfig).getName();
// $NON-NLS-1$
will(returnValue("CCName"));
allowing(ioe).getEntityName();
will(returnValue(innerIntricateName));
}
});
final OrmDiagram ormDiagram = new // $NON-NLS-1$
OrmDiagram(// $NON-NLS-1$
"", // $NON-NLS-1$
rts) {
public ConsoleConfiguration getConsoleConfig() {
return consoleConfig;
}
};
ormDiagram.saveInXmlFile();
// test is the folder created
File folder = new File(ormDiagram.getStoreFolderPath().toOSString());
assertTrue(folder.exists() && folder.isDirectory());
// test is the file created
File file = new File(ormDiagram.getStoreFilePath().toOSString());
assertTrue(file.exists() && file.isFile());
//
boolean res = file.delete();
assertTrue(res);
//
res = folder.delete();
assertTrue(res);
// GENERAL TEST:
// check for all expectations
context.assertIsSatisfied();
}
use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class LaunchHelper method findFilteredSortedConsoleConfigs.
/**
* UI elements should use this method as it does filtering of console configuration related
* to deleted or closed projects if the settings are set.
* @return
* @throws CoreException
*/
public static ConsoleConfiguration[] findFilteredSortedConsoleConfigs() {
ConsoleConfiguration[] ccs = KnownConfigurations.getInstance().getConfigurationsSortedByName();
List<ConsoleConfiguration> consoleConfigurations = new ArrayList<ConsoleConfiguration>();
for (ConsoleConfiguration cc : ccs) {
boolean isAccepted = true;
try {
ILaunchConfiguration config = LaunchHelper.findHibernateLaunchConfig(cc.getName());
if (config != null) {
isAccepted = DebugUIPlugin.doLaunchConfigurationFiltering(config);
}
} catch (CoreException e) {
HibernateConsolePlugin.getDefault().showError(null, e.getLocalizedMessage(), e);
}
if (isAccepted) {
consoleConfigurations.add(cc);
}
}
return consoleConfigurations.toArray(new ConsoleConfiguration[consoleConfigurations.size()]);
}
use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class OpenMappingUtils method searchInEjb3MappingFiles.
/**
* Trying to find hibernate console config ejb3 mapping file,
* which is corresponding to provided element.
*
* @param consoleConfig
* @param element
* @return
*/
@SuppressWarnings("unchecked")
public static IFile searchInEjb3MappingFiles(ConsoleConfiguration consoleConfig, Object element) {
IFile file = null;
if (consoleConfig == null) {
return file;
}
final ConsoleConfiguration cc2 = consoleConfig;
List<String> documentPaths = (List<String>) consoleConfig.execute(new ExecutionContext.Command() {
public Object execute() {
String persistenceUnitName = cc2.getPreferences().getPersistenceUnitName();
EntityResolver entityResolver = cc2.getConfiguration().getEntityResolver();
IService service = cc2.getHibernateExtension().getHibernateService();
return service.getJPAMappingFilePaths(persistenceUnitName, entityResolver);
}
});
if (documentPaths == null) {
return file;
}
IJavaProject[] projs = ProjectUtils.findJavaProjects(consoleConfig);
ArrayList<IPath> pathsSrc = new ArrayList<IPath>();
ArrayList<IPath> pathsOut = new ArrayList<IPath>();
ArrayList<IPath> pathsFull = new ArrayList<IPath>();
for (int i = 0; i < projs.length; i++) {
IJavaProject proj = projs[i];
IPath projPathFull = proj.getResource().getLocation();
IPath projPath = proj.getPath();
IPath projPathOut = null;
try {
projPathOut = proj.getOutputLocation();
projPathOut = projPathOut.makeRelativeTo(projPath);
} catch (JavaModelException e) {
// just ignore
}
IPackageFragmentRoot[] pfrs = new IPackageFragmentRoot[0];
try {
pfrs = proj.getAllPackageFragmentRoots();
} catch (JavaModelException e) {
// just ignore
}
for (int j = 0; j < pfrs.length; j++) {
// TODO: think about possibility to open resources from jar files
if (pfrs[j].isArchive() || pfrs[j].isExternal()) {
continue;
}
final IPath pathSrc = pfrs[j].getPath();
final IPath pathOut = projPathOut;
final IPath pathFull = projPathFull;
pathsSrc.add(pathSrc);
pathsOut.add(pathOut);
pathsFull.add(pathFull);
}
}
int scanSize = Math.min(pathsSrc.size(), pathsOut.size());
scanSize = Math.min(pathsFull.size(), scanSize);
for (int i = 0; i < scanSize && file == null; i++) {
final IPath pathSrc = pathsSrc.get(i);
final IPath pathOut = pathsOut.get(i);
final IPath pathFull = pathsFull.get(i);
Iterator<String> it = documentPaths.iterator();
while (it.hasNext() && file == null) {
String docPath = it.next();
IPath path2DocFull = Path.fromOSString(docPath);
IPath resPath = path2DocFull.makeRelativeTo(pathFull);
if (pathOut != null) {
resPath = resPath.makeRelativeTo(pathOut);
}
resPath = pathSrc.append(resPath);
file = ResourcesPlugin.getWorkspace().getRoot().getFile(resPath);
if (file == null || !file.exists()) {
file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(resPath);
}
if (file != null && file.exists()) {
if (elementInFile(consoleConfig, file, element)) {
break;
}
}
file = null;
}
}
return file;
}
use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class ConfigurationsViewActionGroup method fillContextMenu.
public void fillContextMenu(IMenuManager menu) {
if (getContext() == null) {
return;
}
IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
if (selection == null) {
return;
}
Object first = selection.getFirstElement();
menu.add(new Separator(GROUP_PRIMAL_EDITORS));
menu.appendToGroup(GROUP_PRIMAL_EDITORS, hqlEditorAction);
menu.appendToGroup(GROUP_PRIMAL_EDITORS, criteriaEditorAction);
menu.add(new GroupMarker(GROUP_PRIMAL_EDITORS_LAST));
menu.add(new Separator(GROUP_CONSOLE_CONFIG));
menu.appendToGroup(GROUP_CONSOLE_CONFIG, addConfigurationAction);
if (first instanceof ConsoleConfiguration) {
menu.appendToGroup(GROUP_CONSOLE_CONFIG, reloadConfigurationAction);
menu.appendToGroup(GROUP_CONSOLE_CONFIG, editConfigurationAction);
menu.appendToGroup(GROUP_CONSOLE_CONFIG, closeConfigAction);
menu.appendToGroup(GROUP_CONSOLE_CONFIG, deleteConfigurationAction);
}
menu.add(new GroupMarker(GROUP_CONSOLE_CONFIG_LAST));
menu.add(new Separator(GROUP_ADDITION));
menu.appendToGroup(GROUP_ADDITION, refreshAction);
if (first instanceof ConsoleConfiguration) {
menu.appendToGroup(GROUP_ADDITION, schemaExportAction);
}
menu.add(new GroupMarker(GROUP_ADDITION_LAST));
menu.add(new Separator(GROUP_OTHER_EDITORS));
// TODO: shouldn't these and maybe the others not be defined via menu extension points ?
if (first != null && (first instanceof IPersistentClass || (first instanceof IProperty && ((IProperty) first).classIsPropertyClass()))) {
menu.appendToGroup(GROUP_OTHER_EDITORS, openSourceAction);
menu.appendToGroup(GROUP_OTHER_EDITORS, openMappingAction);
}
menu.add(new GroupMarker(GROUP_OTHER_EDITORS_LAST));
}
Aggregations