use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeImpl method configure.
@Override
public IConfiguration configure(Document document) {
File tempFile = null;
IConfiguration result = null;
try {
tempFile = File.createTempFile(document.toString(), "cfg.xml");
DOMSource domSource = new DOMSource(document);
StringWriter stringWriter = new StringWriter();
StreamResult stream = new StreamResult(stringWriter);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, stream);
FileWriter fileWriter = new FileWriter(tempFile);
fileWriter.write(stringWriter.toString());
fileWriter.close();
result = configure(tempFile);
} catch (IOException | TransformerException e) {
throw new RuntimeException("Problem while configuring", e);
} finally {
tempFile.delete();
}
return result;
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class ServiceImpl method newJpaConfiguration.
@Override
public IConfiguration newJpaConfiguration(String entityResolver, String persistenceUnit, Map<Object, Object> overrides) {
getUsageTracker().trackNewConfigurationEvent(HIBERNATE_VERSION);
Ejb3Configuration ejb3Configuration = new Ejb3Configuration();
if (StringHelper.isNotEmpty(entityResolver)) {
try {
Class<?> resolver = ReflectHelper.classForName(entityResolver, this.getClass());
Object object = resolver.newInstance();
ejb3Configuration.setEntityResolver((EntityResolver) object);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new HibernateConsoleRuntimeException(e);
}
}
ejb3Configuration.setProperty("hibernate.validator.autoregister_listeners", "false");
ejb3Configuration.setProperty("hibernate.validator.apply_to_ddl", "false");
ejb3Configuration.configure(persistenceUnit, overrides);
Configuration configuration = ejb3Configuration.getHibernateConfiguration();
return facadeFactory.createConfiguration(configuration);
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class ServiceImpl method newAnnotationConfiguration.
@Override
public IConfiguration newAnnotationConfiguration() {
getUsageTracker().trackNewConfigurationEvent(HIBERNATE_VERSION);
Configuration configuration = new Configuration();
configuration.setProperty("hibernate.validator.autoregister_listeners", "false");
configuration.setProperty("hibernate.validator.apply_to_ddl", "false");
return facadeFactory.createConfiguration(configuration);
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class ElementsFactory method getConfig.
public IConfiguration getConfig() {
IConfiguration config = null;
final ConsoleConfiguration consoleConfig = getConsoleConfig();
if (consoleConfig != null) {
config = consoleConfig.getConfiguration();
}
return config;
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class ElementsFactory method processExpand.
protected void processExpand(ExpandableShape shape) {
Object element = shape.getOrmElement();
if (!(element instanceof IProperty)) {
return;
}
OrmShape s = null;
IProperty property = (IProperty) element;
if (!property.isComposite()) {
final IConfiguration config = getConfig();
//
IValue v = property.getValue();
IType type = UtilTypeExtract.getTypeUsingExecContext(v, getConsoleConfig());
if (type != null && type.isEntityType()) {
Object clazz = config != null ? config.getClassMapping(type.getAssociatedEntityName()) : null;
if (clazz instanceof IPersistentClass && ((IPersistentClass) clazz).isInstanceOfRootClass()) {
IPersistentClass rootClass = (IPersistentClass) clazz;
s = getOrCreatePersistentClass(rootClass, null);
if (shouldCreateConnection(shape, s)) {
connections.add(new Connection(shape, s));
}
} else if (clazz instanceof IPersistentClass && ((IPersistentClass) clazz).isInstanceOfSubclass()) {
s = getOrCreatePersistentClass(((IPersistentClass) clazz).getRootClass(), null);
}
}
} else {
s = getOrCreatePersistentClass(getService().newSpecialRootClass(property), null);
if (shouldCreateConnection(shape, s)) {
connections.add(new Connection(shape, s));
}
createConnections(s, getOrCreateDatabaseTable(property.getValue().getTable()));
}
}
Aggregations