use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class TypeVisitor method createConfigurations.
/**
* @return different configuration for different projects
*/
public Map<IJavaProject, IConfiguration> createConfigurations(int processDepth) {
Map<IJavaProject, IConfiguration> configs = new HashMap<IJavaProject, IConfiguration>();
if (selectionCU.size() == 0) {
return configs;
}
AllEntitiesInfoCollector collector = new AllEntitiesInfoCollector();
Iterator<ICompilationUnit> it = selectionCU.iterator();
Map<IJavaProject, Set<ICompilationUnit>> mapJP_CUSet = new HashMap<IJavaProject, Set<ICompilationUnit>>();
// separate by parent project
while (it.hasNext()) {
ICompilationUnit cu = it.next();
Set<ICompilationUnit> set = mapJP_CUSet.get(cu.getJavaProject());
if (set == null) {
set = new HashSet<ICompilationUnit>();
mapJP_CUSet.put(cu.getJavaProject(), set);
}
set.add(cu);
}
Iterator<Map.Entry<IJavaProject, Set<ICompilationUnit>>> mapIt = mapJP_CUSet.entrySet().iterator();
while (mapIt.hasNext()) {
Map.Entry<IJavaProject, Set<ICompilationUnit>> entry = mapIt.next();
IJavaProject javaProject = entry.getKey();
Iterator<ICompilationUnit> setIt = entry.getValue().iterator();
collector.initCollector();
while (setIt.hasNext()) {
ICompilationUnit icu = setIt.next();
collector.collect(icu, processDepth);
}
collector.resolveRelations();
// I don't check here if any non abstract class selected
IConfiguration config = createConfiguration(javaProject, collector.getMapCUs_Info());
if (config != null) {
configs.put(javaProject, config);
}
}
return configs;
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class NewHibernateMappingFileWizard method getPlaces2Gen.
protected Map<IJavaProject, IPath> getPlaces2Gen() {
updateCompilationUnits();
Map<IJavaProject, IConfiguration> configs = createConfigurations();
Map<IJavaProject, IPath> places2Gen = new HashMap<IJavaProject, IPath>();
for (Entry<IJavaProject, IConfiguration> entry : configs.entrySet()) {
IConfiguration config = entry.getValue();
IPath place2Gen = previewPage.getRootPlace2Gen().append(entry.getKey().getElementName());
places2Gen.put(entry.getKey(), place2Gen);
File folder2Gen = new File(place2Gen.toOSString());
// cleanup folder before gen info
FileUtils.delete(folder2Gen);
if (!folder2Gen.exists()) {
folder2Gen.mkdirs();
}
HibernateMappingExporterWrapper hce = new HibernateMappingExporterWrapper(entry.getKey(), config, folder2Gen);
try {
hce.start();
} catch (Exception e) {
HibernateConsolePlugin.getDefault().log(e);
}
}
return places2Gen;
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class CodeGenerationLaunchDelegate 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 JDBCMetaDataConfiguration cfg = new JDBCMetaDataConfiguration();
final IService service = cc.getHibernateExtension().getHibernateService();
final IConfiguration cfg = service.newJDBCMetaDataConfiguration();
Properties properties = configuration.getProperties();
cfg.setProperties(properties);
cc.buildWith(cfg, false);
cfg.setPreferBasicCompositeIds(preferBasicCompositeids);
cc.execute(new // need to execute in the consoleconfiguration to let it handle classpath stuff!
Command() {
public Object execute() {
// todo: factor this setup of revengstrategy to core
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 ConsoleConfiguration method buildWith.
/**
* @return
*/
public IConfiguration buildWith(final IConfiguration cfg, final boolean includeMappings) {
reinitClassLoader();
executionContext = new DefaultExecutionContext(getName(), classLoader);
IConfiguration result = (IConfiguration) execute(new Command() {
public Object execute() {
ConfigurationFactory csf = new ConfigurationFactory(prefs, fakeDrivers);
return csf.createConfiguration(cfg, includeMappings);
}
});
return result;
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class ConfigurationFactory method loadConfigurationXML.
@SuppressWarnings("unchecked")
private IConfiguration loadConfigurationXML(IConfiguration localCfg, boolean includeMappings, EntityResolver entityResolver) {
File configXMLFile = prefs.getConfigXMLFile();
if (!includeMappings) {
org.dom4j.Document doc;
XMLHelper xmlHelper = new XMLHelper();
InputStream stream = null;
// $NON-NLS-1$
String resourceName = "<unknown>";
if (configXMLFile != null) {
resourceName = configXMLFile.toString();
try {
stream = new FileInputStream(configXMLFile);
} catch (FileNotFoundException e1) {
throw new HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_could_not_access + configXMLFile, e1);
}
} else {
// $NON-NLS-1$
resourceName = "/hibernate.cfg.xml";
if (checkHibernateResoureExistence(resourceName)) {
// simulate hibernate's
stream = getResourceAsStream(resourceName);
// default look up
} else {
return localCfg;
}
}
try {
List<SAXParseException> errors = new ArrayList<SAXParseException>();
doc = xmlHelper.createSAXReader(resourceName, errors, entityResolver).read(new InputSource(stream));
if (errors.size() != 0) {
throw new MappingException(ConsoleMessages.ConsoleConfiguration_invalid_configuration, errors.get(0));
}
List<Node> list = doc.getRootElement().element("session-factory").elements(// $NON-NLS-1$ //$NON-NLS-2$
"mapping");
for (Node element : list) {
element.getParent().remove(element);
}
DOMWriter dw = new DOMWriter();
Document document = dw.write(doc);
return localCfg.configure(document);
} catch (DocumentException e) {
throw new HibernateException(ConsoleMessages.ConsoleConfiguration_could_not_parse_configuration + resourceName, e);
} finally {
try {
if (stream != null)
stream.close();
} catch (IOException ioe) {
// log.warn( "could not close input stream for: " + resourceName, ioe );
}
}
} else {
if (configXMLFile != null) {
return localCfg.configure(configXMLFile);
} else {
IConfiguration resultCfg = localCfg;
if (checkHibernateResoureExistence("/hibernate.cfg.xml")) {
// $NON-NLS-1$
resultCfg = localCfg.configure();
}
return resultCfg;
}
}
}
Aggregations