Example usage for org.hibernate.cfg AvailableSettings SHOW_SQL

List of usage examples for org.hibernate.cfg AvailableSettings SHOW_SQL

Introduction

In this page you can find the example usage for org.hibernate.cfg AvailableSettings SHOW_SQL.

Prototype

String SHOW_SQL

To view the source code for org.hibernate.cfg AvailableSettings SHOW_SQL.

Click Source Link

Document

Enable logging of generated SQL to the console

Usage

From source file:com.vmware.photon.controller.apife.db.HibernateTestModule.java

License:Open Source License

@Provides
@Singleton/*from  w ww. ja  v  a 2  s . com*/
public SessionFactory getSessionFactory() {
    Configuration configuration = new Configuration();

    Reflections reflections = new Reflections("com.vmware.photon.controller.apife.entities");
    Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Entity.class);

    Reflections baseReflections = new Reflections("com.vmware.photon.controller.apife.entities.base");
    classes.addAll(baseReflections.getTypesAnnotatedWith(Entity.class));

    Reflections commonReflections = new Reflections("com.vmware.photon.controller.api.common");
    classes.addAll(commonReflections.getTypesAnnotatedWith(Entity.class));

    for (final Class<?> clazz : classes) {
        configuration.addAnnotatedClass(clazz);
    }

    configuration.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "managed");
    configuration.setProperty(AvailableSettings.DIALECT, CustomH2Dialect.class.getName());
    configuration.setProperty(AvailableSettings.DRIVER, "org.h2.Driver");
    // in memory DB, wait up to 10 seconds after last connection closed before deleting data
    configuration.setProperty(AvailableSettings.URL, "jdbc:h2:mem:test;DB_CLOSE_DELAY=10");
    configuration.setProperty(AvailableSettings.HBM2DDL_AUTO, "create");
    configuration.setProperty(AvailableSettings.SHOW_SQL, "true");
    configuration.setNamingStrategy(ImprovedNamingStrategy.INSTANCE);

    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties())
            .build();

    return configuration.buildSessionFactory(serviceRegistry);
}

From source file:de.kaiserpfalzEdv.infopir.backend.db.PersistenceConfiguration.java

License:Apache License

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
    entityManagerFactoryBean/* ww w.  ja  va2s  . c  o  m*/
            .setPackagesToScan(env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));

    Properties hibProperties = hibProperties();
    entityManagerFactoryBean.setJpaProperties(hibProperties);

    LOG.debug("Packages to scan: {}", env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));
    LOG.debug("Data Source: {}", dataSource());
    LOG.debug("Persistent Provider: {}", HibernatePersistenceProvider.class.getCanonicalName());
    LOG.trace("HBM2DDL Auto Setting: {}", hibProperties.getProperty(AvailableSettings.HBM2DDL_AUTO));
    LOG.trace("Hibernate Dialect: {}", hibProperties.getProperty(AvailableSettings.DIALECT));
    LOG.trace("Show SQL: {}", hibProperties.get(AvailableSettings.SHOW_SQL));
    return entityManagerFactoryBean;
}

From source file:de.kaiserpfalzEdv.infopir.backend.db.PersistenceConfiguration.java

License:Apache License

private Properties hibProperties() {
    Properties properties = new Properties();
    properties.put(AvailableSettings.HBM2DDL_AUTO, env.getRequiredProperty(AvailableSettings.HBM2DDL_AUTO));
    properties.put(AvailableSettings.DIALECT, env.getRequiredProperty(AvailableSettings.DIALECT));
    properties.put(AvailableSettings.SHOW_SQL, env.getRequiredProperty(AvailableSettings.SHOW_SQL));
    return properties;
}

From source file:de.kaiserpfalzEdv.piracc.backend.db.PersistenceConfiguration.java

License:Apache License

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);

    String[] packages = env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN).split(",");
    entityManagerFactoryBean.setPackagesToScan(packages);

    Properties hibProperties = hibProperties();
    entityManagerFactoryBean.setJpaProperties(hibProperties);

    LOG.debug("Packages to scan: {}", env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));
    LOG.debug("Data Source: {}", dataSource());
    LOG.debug("Persistent Provider: {}", HibernatePersistenceProvider.class.getCanonicalName());
    LOG.trace("HBM2DDL Auto Setting: {}", hibProperties.getProperty(AvailableSettings.HBM2DDL_AUTO));
    LOG.trace("Hibernate Dialect: {}", hibProperties.getProperty(AvailableSettings.DIALECT));
    LOG.trace("Show SQL: {}", hibProperties.get(AvailableSettings.SHOW_SQL));
    return entityManagerFactoryBean;
}

From source file:debop4k.data.orm.spring.boot.autoconfigure.HibernateProperties.java

License:Apache License

@SneakyThrows({ IOException.class })
public Properties toProperties() {
    Properties props = new Properties();

    props.put(AvailableSettings.DIALECT, dialect);

    props.put(AvailableSettings.HBM2DDL_AUTO, hbm2ddl);
    props.put(AvailableSettings.SHOW_SQL, showSql);
    props.put(AvailableSettings.FORMAT_SQL, formatSql);

    props.put(AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, batchFetchSize);

    if (Stringx.isNotEmpty(isolation)) {
        props.put(AvailableSettings.ISOLATION, isolation);
    }//from ww  w  .  j  a v a 2s .c o m
    props.put(AvailableSettings.AUTOCOMMIT, autoCommit);
    props.put(AvailableSettings.RELEASE_CONNECTIONS, releaseMode);

    props.put(AvailableSettings.USE_SECOND_LEVEL_CACHE, useSecondCache);
    props.put(AvailableSettings.CACHE_PROVIDER_CONFIG, cacheProviderConfig.getFile().getAbsolutePath());

    return props;
}

From source file:org.efaps.bpm.BPM.java

License:Apache License

/**
 * Initialize BPM./* w  w  w  .  j  a v a 2 s  .  co m*/
 *
 * @throws EFapsException on error
 */
public static void initialize() throws EFapsException {
    final SystemConfiguration config = EFapsSystemConfiguration.get();
    final boolean active = config != null ? config.getAttributeValueAsBoolean(KernelSettings.ACTIVATE_BPM)
            : false;
    if (active) {

        if (BPM.PMANAGER != null) {
            BPM.PMANAGER.close();
            BPM.PMANAGER = null;
        }
        if (BPM.SMANAGER != null) {
            BPM.SMANAGER.close();
            BPM.SMANAGER = null;
        }

        UserTransaction userTrans = null;
        InitialContext context = null;
        try {
            context = new InitialContext();
            userTrans = TransactionHelper.findUserTransaction();
            Object object = null;
            try {
                object = context.lookup(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME);
            } catch (final NamingException ex) {
                BPM.LOG.info("Checked for JtaTransactionManager");
            }
            if (object == null) {
                context.bind(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME, userTrans);
                context.bind(JtaTransactionManager.FALLBACK_TRANSACTION_MANAGER_NAMES[0],
                        TransactionHelper.findTransactionManager());
            }
        } catch (final NamingException ex) {
            BPM.LOG.error("Could not initialise JNDI InitialContext", ex);
        }

        // register our own KnowledgeBuilderFactoryService
        ServiceRegistryImpl.getInstance().addDefault(KnowledgeBuilderFactoryService.class,
                KnowledgeBuilderFactoryServiceImpl.class.getName());

        final RegisterableItemsFactoryImpl itemsFactory = new RegisterableItemsFactoryImpl();
        itemsFactory.addWorkItemHandler("Manual Task", ManualTaskItemHandler.class);
        itemsFactory.addProcessListener(WorkingMemoryLogListener.class);

        final Map<String, String> properties = new HashMap<String, String>();
        properties.put(AvailableSettings.DIALECT, Context.getDbType().getHibernateDialect());
        properties.put(AvailableSettings.SHOW_SQL, String.valueOf(BPM.LOG.isDebugEnabled()));
        properties.put(AvailableSettings.FORMAT_SQL, "true");
        properties.put(AvailableSettings.RELEASE_CONNECTIONS, "after_transaction");
        properties.put(AvailableSettings.CONNECTION_PROVIDER, ConnectionProvider.class.getName());
        properties.put(org.hibernate.jpa.AvailableSettings.NAMING_STRATEGY, NamingStrategy.class.getName());

        final EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa",
                properties);

        final RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.getDefault()
                .classLoader(EFapsClassLoader.getInstance()).userGroupCallback(new UserGroupCallbackImpl())
                .entityManagerFactory(emf).registerableItemsFactory(itemsFactory).persistence(true)
                .addEnvironmentEntry("TRANSACTION_LOCK_ENABLED", "false");

        BPM.add2EnvironmentBuilder(builder);

        final RuntimeEnvironment environment = builder.get();
        final ManagerFactoryImpl factory = new ManagerFactoryImpl();

        BPM.PMANAGER = factory.newPerProcessInstanceRuntimeManager(environment);
        BPM.SMANAGER = factory.newSingletonRuntimeManager(environment);
    }
}