use of org.jboss.tools.hibernate.runtime.spi.IService in project jbosstools-hibernate by jbosstools.
the class ConsoleExtension method buildConfiguration.
private IConfiguration buildConfiguration(final ExporterAttributes attributes, ConsoleConfiguration cc, IWorkspaceRoot root) {
final boolean reveng = attributes.isReverseEngineer();
final String reverseEngineeringStrategy = attributes.getRevengStrategy();
final boolean preferBasicCompositeids = attributes.isPreferBasicCompositeIds();
final IResource revengres = PathHelper.findMember(root, attributes.getRevengSettings());
if (reveng) {
IConfiguration configuration = null;
if (cc.hasConfiguration()) {
configuration = cc.getConfiguration();
} else {
configuration = cc.buildWith(null, false);
}
final IConfiguration cfg = hibernateExtension.getHibernateService().newJDBCMetaDataConfiguration();
// final JDBCMetaDataConfiguration cfg = new
// JDBCMetaDataConfiguration();
Properties properties = configuration.getProperties();
cfg.setProperties(properties);
cc.buildWith(cfg, false);
cfg.setPreferBasicCompositeIds(preferBasicCompositeids);
cc.execute(new // need to execute in the
Command() {
// consoleconfiguration to let it handle
// classpath stuff!
public Object execute() {
// todo: factor this setup of revengstrategy to core
IService service = hibernateExtension.getHibernateService();
IReverseEngineeringStrategy res = service.newDefaultReverseEngineeringStrategy();
IOverrideRepository repository = null;
if (revengres != null) {
File file = PathHelper.getLocation(revengres).toFile();
repository = service.newOverrideRepository();
repository.addFile(file);
}
if (repository != null) {
res = repository.getReverseEngineeringStrategy(res);
}
if (reverseEngineeringStrategy != null && reverseEngineeringStrategy.trim().length() > 0) {
res = service.newReverseEngineeringStrategy(reverseEngineeringStrategy, res);
}
IReverseEngineeringSettings qqsettings = service.newReverseEngineeringSettings(res).setDefaultPackageName(attributes.getPackageName()).setDetectManyToMany(attributes.detectManyToMany()).setDetectOneToOne(attributes.detectOneToOne()).setDetectOptimisticLock(attributes.detectOptimisticLock());
res.setSettings(qqsettings);
cfg.setReverseEngineeringStrategy(res);
cfg.readFromJDBC();
cfg.buildMappings();
return null;
}
});
return cfg;
} else {
cc.build();
cc.buildMappings();
return cc.getConfiguration();
}
}
use of org.jboss.tools.hibernate.runtime.spi.IService in project jbosstools-hibernate by jbosstools.
the class ReverseEngineeringEditor method getLazyDatabaseSchema.
public LazyDatabaseSchema getLazyDatabaseSchema() {
try {
ConsoleConfiguration configuration = KnownConfigurations.getInstance().find(getConsoleConfigurationName());
if (configuration == null) {
configuration = askForConsoleConfiguration();
if (configuration == null) {
return null;
} else {
setConsoleConfigurationName(configuration.getName());
}
}
org.hibernate.eclipse.console.model.ITableFilter[] tableFilters = getReverseEngineeringDefinition().getTableFilters();
IService service = configuration.getHibernateExtension().getHibernateService();
IOverrideRepository repository = service.newOverrideRepository();
boolean hasIncludes = false;
for (int i = 0; i < tableFilters.length; i++) {
org.hibernate.eclipse.console.model.ITableFilter filter = tableFilters[i];
ITableFilter tf = service.newTableFilter();
tf.setExclude(filter.getExclude());
if (filter.getExclude() != null && !filter.getExclude().booleanValue()) {
hasIncludes = true;
}
tf.setMatchCatalog(filter.getMatchCatalog());
tf.setMatchName(filter.getMatchName());
tf.setMatchSchema(filter.getMatchSchema());
repository.addTableFilter(tf);
}
ITableFilter tf = service.newTableFilter();
tf.setExclude(Boolean.FALSE);
// $NON-NLS-1$
tf.setMatchCatalog(".*");
// $NON-NLS-1$
tf.setMatchSchema(".*");
// $NON-NLS-1$
tf.setMatchName(".*");
repository.addTableFilter(tf);
String dialogId = ReverseEngineeringEditor.class.getName();
if (tableFilters.length == 0 && OptionalMessageDialog.isDialogEnabled(dialogId)) {
int returnCode = OptionalMessageDialog.open(dialogId, getContainer().getShell(), MapperMessages.ReverseEngineeringEditor_no_filters_defined, null, MapperMessages.ReverseEngineeringEditor_no_filters_has_been_defined, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
if (returnCode == Window.CANCEL)
return null;
}
LazyDatabaseSchema lazyDatabaseSchema = new LazyDatabaseSchema(configuration, repository.getReverseEngineeringStrategy(service.newDefaultReverseEngineeringStrategy()));
return lazyDatabaseSchema;
} catch (Exception he) {
HibernateConsolePlugin.getDefault().showError(getContainer().getShell(), MapperMessages.ReverseEngineeringEditor_error_while_refreshing_databasetree, he);
return null;
}
}
use of org.jboss.tools.hibernate.runtime.spi.IService in project jbosstools-hibernate by jbosstools.
the class JPAPostInstallFasetListener method getConnectionProperties.
public Properties getConnectionProperties(IProject project) {
IJavaProject javaProject = JavaCore.create(project);
IService service = null;
if (javaProject != null) {
HibernateNature hibNat = HibernateNature.getHibernateNature(javaProject);
if (hibNat != null) {
ConsoleConfiguration cc = hibNat.getDefaultConsoleConfiguration();
if (cc != null) {
service = cc.getHibernateExtension().getHibernateService();
}
}
}
String cpName = HibernateEclipseUtils.getConnectionProfileName(project);
if (cpName != null && service != null) {
return ConnectionProfileUtil.getHibernateConnectionProperties(service, ProfileManager.getInstance().getProfileByName(cpName));
}
return new Properties();
}
use of org.jboss.tools.hibernate.runtime.spi.IService in project jbosstools-hibernate by jbosstools.
the class ServiceLookupTest method testGetDefault.
@Test
public void testGetDefault() {
IService service = ServiceLookup.getDefault();
Assert.assertSame(ServiceLookup.findService("0.0.0.Test"), service);
}
use of org.jboss.tools.hibernate.runtime.spi.IService 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;
}
});
}
Aggregations