use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class ConsoleConfigurationTest method testHQLComments.
@Test
public void testHQLComments() {
consoleCfg.build();
consoleCfg.buildSessionFactory();
try {
consoleCfg.buildSessionFactory();
Assert.fail(TestConsoleMessages.ConsoleConfigurationTest_factory_already_exists);
} catch (HibernateConsoleRuntimeException hcre) {
}
// $NON-NLS-1$
QueryPage qp = consoleCfg.executeHQLQuery("from java.lang.Object --this is my comment");
Assert.assertNotNull(qp);
}
use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class CodeGenerationLaunchDelegate method runExporters.
private IArtifactCollector runExporters(final ExporterAttributes attributes, final ExporterFactory[] exporterFactories, final Set<String> outputDirectories, final IProgressMonitor monitor) throws CoreException {
monitor.beginTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_generating_code_for + attributes.getConsoleConfigurationName(), exporterFactories.length + 1);
if (monitor.isCanceled())
return null;
ConsoleConfiguration cc = KnownConfigurations.getInstance().find(attributes.getConsoleConfigurationName());
if (attributes.isReverseEngineer()) {
monitor.subTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_reading_jdbc_metadata);
}
final IConfiguration cfg = buildConfiguration(attributes, cc, ResourcesPlugin.getWorkspace().getRoot());
monitor.worked(1);
if (monitor.isCanceled())
return null;
final IService service = cc.getHibernateExtension().getHibernateService();
return (IArtifactCollector) cc.execute(new Command() {
public Object execute() {
IArtifactCollector artifactCollector = service.newArtifactCollector();
// Global properties
Properties props = new Properties();
// $NON-NLS-1$
props.put(CodeGenerationStrings.EJB3, "" + attributes.isEJB3Enabled());
// $NON-NLS-1$
props.put(CodeGenerationStrings.JDK5, "" + attributes.isJDK5Enabled());
for (int i = 0; i < exporterFactories.length; i++) {
monitor.subTask(exporterFactories[i].getExporterDefinition().getDescription());
Properties globalProperties = new Properties();
globalProperties.putAll(props);
IExporter exporter;
try {
exporter = exporterFactories[i].createConfiguredExporter(cfg, attributes.getOutputPath(), attributes.getTemplatePath(), globalProperties, outputDirectories, artifactCollector, service);
} catch (CoreException e) {
throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_setting_up + exporterFactories[i].getExporterDefinition(), e);
}
try {
exporter.start();
} catch (HibernateException he) {
throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_running + exporterFactories[i].getExporterDefinition().getDescription(), he);
}
monitor.worked(1);
}
return artifactCollector;
}
});
}
use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class ConsoleConfigurationJavaClasspathTab method isValid.
public boolean isValid(ILaunchConfiguration launchConfig) {
if (!super.isValid(launchConfig)) {
return false;
}
if (lastValidatedLaunchConfig != null && lastValidatedLaunchConfig.contentsEqual(launchConfig)) {
setErrorMessage(lastErrorMessage);
return lastRes;
}
setErrorMessage(null);
setMessage(null);
boolean resUserClasses = false, resExistArchive = true;
IRuntimeClasspathEntry[] entries;
try {
entries = JavaRuntime.computeUnresolvedRuntimeClasspath(launchConfig);
for (int i = 0; i < entries.length; i++) {
IRuntimeClasspathEntry entry = entries[i];
if (entry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) {
resUserClasses = true;
if (entry.getType() == IRuntimeClasspathEntry.ARCHIVE) {
if (!entry.getPath().toFile().exists()) {
resExistArchive = false;
String out = NLS.bind(HibernateConsoleMessages.ConsoleConfigurationTabGroup_archive_classpath_entry_does_not_exist, entry.getPath().toString());
setErrorMessage(out);
}
}
}
}
} catch (CoreException e) {
// Ignore as the exception occurs if the selected project is not java project
// We'll show warning to the user later
}
if (!resUserClasses) {
setErrorMessage(HibernateConsoleMessages.ConsoleConfigurationTabGroup_classpath_must_be_set_or_restored_to_default);
}
if (resUserClasses && resExistArchive) {
boolean flagTryToBuild = true;
final ConsoleConfiguration ccTest = new ConsoleConfiguration(new EclipseLaunchConsoleConfigurationPreferences(launchConfig));
if (configurationFileWillBeCreated) {
// exception to resolve the file
try {
ccTest.getConfigXMLFile();
} catch (HibernateConsoleRuntimeException ex) {
flagTryToBuild = false;
}
}
if (flagTryToBuild) {
try {
ccTest.buildWith(null, false);
} catch (Exception ex) {
resUserClasses = false;
setErrorMessage(ex.getMessage());
}
// accurate reset for ccTest after buildWith, should avoid possible "leaks"
try {
ccTest.reset();
} catch (Exception ex) {
if (resUserClasses) {
resUserClasses = false;
setErrorMessage(ex.getMessage());
}
}
try {
lastValidatedLaunchConfig = launchConfig.getWorkingCopy();
} catch (CoreException e1) {
lastValidatedLaunchConfig = null;
}
}
}
final boolean res = resUserClasses && resExistArchive;
if (lastValidatedLaunchConfig != null) {
lastErrorMessage = getErrorMessage();
lastRes = res;
}
return res;
}
use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class EclipseLaunchConsoleConfigurationPreferences method getCustomClassPathURLS.
public URL[] getCustomClassPathURLS() {
try {
String[] classpath = ClassLoaderHelper.getClasspath(launchConfiguration);
URL[] cp = new URL[classpath.length];
for (int i = 0; i < classpath.length; i++) {
String str = classpath[i];
cp[i] = new File(str).toURI().toURL();
}
return cp;
} catch (CoreException e) {
throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.EclipseLaunchConsoleConfigurationPreferences_could_not_compute_classpath, e);
} catch (MalformedURLException e) {
throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.EclipseLaunchConsoleConfigurationPreferences_could_not_compute_classpath, e);
}
}
use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class EclipseLaunchConsoleConfigurationPreferences method getMappingFiles.
@SuppressWarnings("unchecked")
public File[] getMappingFiles() {
try {
List<String> mappings = launchConfiguration.getAttribute(IConsoleConfigurationLaunchConstants.FILE_MAPPINGS, Collections.EMPTY_LIST);
File[] result = new File[mappings.size()];
int i = 0;
for (String element : mappings) {
result[i++] = strToFile(element);
}
return result;
} catch (CoreException e) {
throw new HibernateConsoleRuntimeException(e);
}
}
Aggregations