use of org.jboss.tools.hibernate.runtime.spi.IConfiguration 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.IConfiguration in project jbosstools-hibernate by jbosstools.
the class ConsoleExtension 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;
return (IArtifactCollector) cc.execute(new Command() {
public Object execute() {
IArtifactCollector artifactCollector = hibernateExtension.getHibernateService().newArtifactCollector();
// Global properties
Properties props = new Properties();
props.put(CodeGenerationStrings.EJB3, // $NON-NLS-1$
"" + attributes.isEJB3Enabled());
props.put(CodeGenerationStrings.JDK5, // $NON-NLS-1$
"" + 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, hibernateExtension.getHibernateService());
} 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.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class HibernateExtension method buildWith.
public IConfiguration buildWith(final IConfiguration cfg, final boolean includeMappings) {
reinitClassLoader();
// TODO handle user libraries here
executionContext = new DefaultExecutionContext(prefs.getName(), classLoader);
IConfiguration result = (IConfiguration) execute(new Command() {
public Object execute() {
ConfigurationFactory cf = new ConfigurationFactory(prefs, fakeDrivers);
return cf.createConfiguration(cfg, includeMappings);
}
});
return result;
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class ConfigurationFactory method buildConfiguration.
// TODO: delegate to some extension point
private IConfiguration buildConfiguration(Properties properties, boolean includeMappings) {
IConfiguration localCfg = null;
if (prefs.getConfigurationMode().equals(ConfigurationMode.ANNOTATIONS)) {
try {
localCfg = buildAnnotationConfiguration();
localCfg = configureStandardConfiguration(includeMappings, localCfg, properties);
} catch (HibernateConsoleRuntimeException he) {
throw he;
} catch (Exception e) {
throw new HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_could_not_load_annotationconfiguration, e);
}
} else if (prefs.getConfigurationMode().equals(ConfigurationMode.JPA)) {
try {
localCfg = buildJPAConfiguration(getPreferences().getPersistenceUnitName(), properties, prefs.getEntityResolverName(), includeMappings);
} catch (HibernateConsoleRuntimeException he) {
throw he;
} catch (Exception e) {
throw new HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_could_not_load_jpa_configuration, e);
}
} else {
localCfg = service.newDefaultConfiguration();
localCfg = configureStandardConfiguration(includeMappings, localCfg, properties);
}
return localCfg;
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class ColumnFacadeImpl method getSqlType.
@Override
public String getSqlType(IConfiguration configuration) {
Column targetColumn = (Column) getTarget();
Configuration configurationTarget = (Configuration) ((IFacade) configuration).getTarget();
Properties properties = configurationTarget.getProperties();
ServiceRegistryBuilder ssrb = new ServiceRegistryBuilder();
ssrb.applySettings(properties);
ServiceRegistry ssr = ssrb.buildServiceRegistry();
DialectFactory df = ssr.getService(DialectFactory.class);
Dialect dialectTarget = df.buildDialect(properties, null);
return targetColumn.getSqlType(dialectTarget, configurationTarget.buildMapping());
}
Aggregations