use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class ConfigurationFactory method buildJPAConfiguration.
private IConfiguration buildJPAConfiguration(String persistenceUnit, Properties properties, String entityResolver, boolean includeMappings) {
if (StringHelper.isEmpty(persistenceUnit)) {
persistenceUnit = null;
}
try {
Map<Object, Object> overrides = new HashMap<Object, Object>();
if (properties != null) {
overrides.putAll(properties);
}
if (StringHelper.isNotEmpty(prefs.getNamingStrategy())) {
// $NON-NLS-1$
overrides.put("hibernate.ejb.naming_strategy", prefs.getNamingStrategy());
}
if (StringHelper.isNotEmpty(prefs.getDialectName())) {
overrides.put(environment.getDialect(), prefs.getDialectName());
}
if (!includeMappings) {
// $NON-NLS-1$//$NON-NLS-2$
overrides.put("hibernate.archive.autodetection", "none");
}
if (StringHelper.isEmpty((String) overrides.get("javax.persistence.validation.mode"))) {
// $NON-NLS-1$
// $NON-NLS-1$//$NON-NLS-2$
overrides.put("javax.persistence.validation.mode", "none");
}
IConfiguration invoke = service.newJpaConfiguration(entityResolver, persistenceUnit, overrides);
changeDatasourceProperties(invoke);
invoke = configureConnectionProfile(invoke);
return invoke;
// Class hibernatePersistanceProviderClass = ReflectHelper.classForName("org.hibernate.jpa.HibernatePersistenceProvider", ConsoleConfiguration.class);
// Object hibernatePersistanceProvider = hibernatePersistanceProviderClass.newInstance();
//
// Method getEntityManagerFactoryBuilderOrNull = hibernatePersistanceProviderClass.getDeclaredMethod(
// "getEntityManagerFactoryBuilderOrNull",
// new Class[] { String.class, Map.class });
// getEntityManagerFactoryBuilderOrNull.setAccessible(true);
// Object entityManagerFactoryBuilder =
// getEntityManagerFactoryBuilderOrNull.invoke(
// hibernatePersistanceProvider,
// new Object[] { persistenceUnit, overrides});
//
// if (entityManagerFactoryBuilder == null) {
// throw new HibernateConsoleRuntimeException(
// "Persistence unit not found: '" +
// persistenceUnit +
// "'.");
// }
//
// Method build =
// entityManagerFactoryBuilder.getClass().getMethod(
// "build", new Class[0]);
// build.invoke(entityManagerFactoryBuilder, null);
//
// Method getHibernateConfiguration =
// entityManagerFactoryBuilder.getClass().getMethod(
// "getHibernateConfiguration", new Class[0]);
// return (Configuration)getHibernateConfiguration.invoke(
// entityManagerFactoryBuilder, null);
} catch (HibernateConsoleRuntimeException he) {
throw he;
} catch (Exception e) {
throw new HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_could_not_create_jpa_based_configuration, e);
}
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class HibernateJpaProject method getDefaultSchema.
/*
* The sequence is(from biggest priority to lowest):
* 1) Configuration.getProperty() (if cc.hasConfiguration())
* 2) ConsoleConfiguration.getPreference().getProperty()-uses hibernate.properties
* 3) JpaProject user overrides
* 4) persistence.xml
* 5) logic from superclass
*/
@Override
public String getDefaultSchema() {
String schema = null;
ConsoleConfiguration cc = getDefaultConsoleConfiguration();
if (cc != null) {
if (cc.hasConfiguration()) {
// was not build yet
IConfiguration configuration = cc.getConfiguration();
if (configuration.getProperties().containsKey(getEnvironment().getDefaultSchema())) {
schema = configuration.getProperty(getEnvironment().getDefaultSchema());
}
}
Properties properties = cc.getPreferences().getProperties();
if (properties != null && properties.containsKey(getEnvironment().getDefaultSchema())) {
schema = properties.getProperty(getEnvironment().getDefaultSchema());
}
}
if (schema == null) {
BasicHibernateProperties prop = getBasicHibernateProperties();
if (getUserOverrideDefaultSchema() != null) {
schema = getUserOverrideDefaultSchema();
} else if (prop != null && prop.getSchemaDefault() != null) {
schema = prop.getSchemaDefault();
}
}
return schema != null ? schema : super.getDefaultSchema();
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class HibernateJpaProject method getDefaultCatalog.
/*
* The sequence is(from biggest priority to lowest):
* 1) Configuration.getProperty() (if cc.hasConfiguration())
* 2) ConsoleConfiguration.getPreference().getProperty()-uses hibernate.properties
* 3) JpaProject user overrides
* 4) persistence.xml
* 5) logic from superclass
*/
@Override
public String getDefaultCatalog() {
String catalog = null;
BasicHibernateProperties prop = getBasicHibernateProperties();
ConsoleConfiguration cc = getDefaultConsoleConfiguration();
if (cc != null) {
if (cc.hasConfiguration()) {
// was not build yet
IConfiguration configuration = cc.getConfiguration();
if (configuration.getProperties().containsKey(getEnvironment().getDefaultCatalog())) {
catalog = configuration.getProperty(getEnvironment().getDefaultCatalog());
}
}
Properties properties = cc.getPreferences().getProperties();
if (properties != null && properties.containsKey(getEnvironment().getDefaultCatalog())) {
catalog = properties.getProperty(getEnvironment().getDefaultCatalog());
}
}
if (catalog == null) {
if (getUserOverrideDefaultCatalog() != null) {
catalog = getUserOverrideDefaultCatalog();
} else if (prop != null && prop.getCatalogDefault() != null) {
catalog = prop.getCatalogDefault();
}
}
return catalog != null ? catalog : super.getDefaultCatalog();
}
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.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 newDefaultConfiguration.
@Override
public IConfiguration newDefaultConfiguration() {
getUsageTracker().trackNewConfigurationEvent(HIBERNATE_VERSION);
Configuration target = new Configuration();
target.setProperty("hibernate.validator.autoregister_listeners", "false");
target.setProperty("hibernate.validator.apply_to_ddl", "false");
return facadeFactory.createConfiguration(target);
}
Aggregations