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 SchemaExportFacadeImpl method setConfiguration.
public void setConfiguration(IConfiguration configuration) {
Configuration configurationTarget = (Configuration) ((IFacade) configuration).getTarget();
this.metadata = MetadataHelper.getMetadata(configurationTarget);
}
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();
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
ssrb.applySettings(properties);
StandardServiceRegistry ssr = ssrb.build();
DialectFactory df = ssr.getService(DialectFactory.class);
Dialect dialectTarget = df.buildDialect(properties, null);
return targetColumn.getSqlType(dialectTarget, MetadataHelper.getMetadata(configurationTarget));
}
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);
IConfiguration result = null;
try {
HibernatePersistenceProvider hibernatePersistenceProvider = new HibernatePersistenceProvider();
Method getEntityManagerFactoryBuilderOrNull = hibernatePersistenceProvider.getClass().getDeclaredMethod("getEntityManagerFactoryBuilderOrNull", new Class[] { String.class, Map.class });
getEntityManagerFactoryBuilderOrNull.setAccessible(true);
Object entityManagerFactoryBuilder = getEntityManagerFactoryBuilderOrNull.invoke(hibernatePersistenceProvider, new Object[] { persistenceUnit, overrides });
if (entityManagerFactoryBuilder == null) {
throw new HibernateConsoleRuntimeException("Persistence unit not found: '" + persistenceUnit + "'.");
}
Method buildServiceRegistry = entityManagerFactoryBuilder.getClass().getMethod("buildServiceRegistry", new Class[0]);
Object serviceRegistry = buildServiceRegistry.invoke(entityManagerFactoryBuilder, (Object[]) null);
Class<?> serviceRegistryClass = StandardClassLoaderDelegateImpl.INSTANCE.classForName("org.hibernate.service.ServiceRegistry");
Method buildHibernateConfiguration = entityManagerFactoryBuilder.getClass().getMethod("buildHibernateConfiguration", new Class[] { serviceRegistryClass });
Configuration configuration = (Configuration) buildHibernateConfiguration.invoke(entityManagerFactoryBuilder, new Object[] { serviceRegistry });
result = facadeFactory.createConfiguration(configuration);
} catch (SecurityException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new HibernateConsoleRuntimeException(e);
}
return result;
}
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 AnnotationConfiguration();
return facadeFactory.createConfiguration(configuration);
}
Aggregations