Example usage for org.hibernate.cfg AvailableSettings DRIVER

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

Introduction

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

Prototype

String DRIVER

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

Click Source Link

Document

Names the JDBC driver class

Usage

From source file:org.jasypt.hibernate4.connectionprovider.EncryptedPasswordC3P0ConnectionProvider.java

License:Apache License

public void configure(final Properties props) {

    final String encryptorRegisteredName = props.getProperty(ParameterNaming.ENCRYPTOR_REGISTERED_NAME);

    final HibernatePBEEncryptorRegistry encryptorRegistry = HibernatePBEEncryptorRegistry.getInstance();
    final PBEStringEncryptor encryptor = encryptorRegistry.getPBEStringEncryptor(encryptorRegisteredName);

    if (encryptor == null) {
        throw new EncryptionInitializationException("No string encryptor registered for hibernate "
                + "with name \"" + encryptorRegisteredName + "\"");
    }//from  w w w .  java 2s  .c o m

    // Get the original values, which may be encrypted
    final String driver = props.getProperty(AvailableSettings.DRIVER);
    final String url = props.getProperty(AvailableSettings.URL);
    final String user = props.getProperty(AvailableSettings.USER);
    final String password = props.getProperty(AvailableSettings.PASS);

    // Perform decryption operations as needed and store the new values
    if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
        props.setProperty(AvailableSettings.DRIVER, PropertyValueEncryptionUtils.decrypt(driver, encryptor));
    }
    if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
        props.setProperty(AvailableSettings.URL, PropertyValueEncryptionUtils.decrypt(url, encryptor));
    }
    if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
        props.setProperty(AvailableSettings.USER, PropertyValueEncryptionUtils.decrypt(user, encryptor));
    }
    if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
        props.setProperty(AvailableSettings.PASS, PropertyValueEncryptionUtils.decrypt(password, encryptor));
    }

    // Let Hibernate do the rest
    super.configure(props);

}

From source file:org.jasypt.hibernate4.connectionprovider.EncryptedPasswordDriverManagerConnectionProvider.java

License:Apache License

public void configure(final Properties props) {

    final String encryptorRegisteredName = props.getProperty(ParameterNaming.ENCRYPTOR_REGISTERED_NAME);

    final HibernatePBEEncryptorRegistry encryptorRegistry = HibernatePBEEncryptorRegistry.getInstance();
    final PBEStringEncryptor encryptor = encryptorRegistry.getPBEStringEncryptor(encryptorRegisteredName);

    if (encryptor == null) {
        throw new EncryptionInitializationException("No string encryptor registered for hibernate "
                + "with name \"" + encryptorRegisteredName + "\"");
    }//from   w ww. j a  v  a  2 s. c o m

    // Get the original values, which may be encrypted
    final String driver = props.getProperty(AvailableSettings.DRIVER);
    final String url = props.getProperty(AvailableSettings.URL);
    final String user = props.getProperty(AvailableSettings.USER);
    final String password = props.getProperty(AvailableSettings.PASS);

    // Perform decryption operations as needed and store the new values
    if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
        props.setProperty(AvailableSettings.DRIVER, PropertyValueEncryptionUtils.decrypt(driver, encryptor));
    }
    if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
        props.setProperty(AvailableSettings.URL, PropertyValueEncryptionUtils.decrypt(url, encryptor));
    }
    if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
        props.setProperty(AvailableSettings.USER, PropertyValueEncryptionUtils.decrypt(user, encryptor));
    }
    if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
        props.setProperty(AvailableSettings.PASS, PropertyValueEncryptionUtils.decrypt(password, encryptor));
    }

    // Let Hibernate process
    super.configure(props);

}

From source file:org.web4thejob.module.JobletInstallerImpl.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public <E extends Exception> List<E> install(List<Joblet> joblets) {
    List<E> exceptions = new ArrayList<E>();

    try {/*from   w w w  .  j a  v  a2 s .  c om*/

        final Configuration configuration = new Configuration();
        configuration.setProperty(AvailableSettings.DIALECT,
                connInfo.getProperty(DatasourceProperties.DIALECT));
        configuration.setProperty(AvailableSettings.DRIVER, connInfo.getProperty(DatasourceProperties.DRIVER));
        configuration.setProperty(AvailableSettings.URL, connInfo.getProperty(DatasourceProperties.URL));
        configuration.setProperty(AvailableSettings.USER, connInfo.getProperty(DatasourceProperties.USER));
        configuration.setProperty(AvailableSettings.PASS, connInfo.getProperty(DatasourceProperties.PASSWORD));

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

        if (StringUtils.hasText(connInfo.getProperty(DatasourceProperties.SCHEMA_SYNTAX))) {
            String schemaSyntax = connInfo.getProperty(DatasourceProperties.SCHEMA_SYNTAX);
            Connection connection = serviceRegistry.getService(ConnectionProvider.class).getConnection();

            for (Joblet joblet : joblets) {
                for (String schema : joblet.getSchemas()) {
                    Statement statement = connection.createStatement();
                    statement.executeUpdate(schemaSyntax.replace("%s", schema));
                    statement.close();
                }
            }

            if (!connection.getAutoCommit()) {
                connection.commit();
            }
        }

        for (Joblet joblet : joblets) {
            for (Resource resource : joblet.getResources()) {
                configuration.addInputStream(resource.getInputStream());
            }
        }

        SchemaExport schemaExport = new SchemaExport(serviceRegistry, configuration);
        schemaExport.execute(Target.EXPORT, SchemaExport.Type.CREATE);
        exceptions.addAll(schemaExport.getExceptions());

    } catch (Exception e) {
        exceptions.add((E) e);
    }

    return exceptions;

}

From source file:org.web4thejob.orm.CreateSchemaTest.java

License:Open Source License

@Test
public void schemaExportTest() throws IOException, SQLException {

    Log4jConfigurer.initLogging("classpath:org/web4thejob/conf/log4j.xml");

    Properties datasource = new Properties();
    datasource.load(new ClassPathResource(DatasourceProperties.PATH).getInputStream());

    final Configuration configuration = new Configuration();
    configuration.setProperty(AvailableSettings.DIALECT, datasource.getProperty(DatasourceProperties.DIALECT));
    configuration.setProperty(AvailableSettings.DRIVER, datasource.getProperty(DatasourceProperties.DRIVER));
    configuration.setProperty(AvailableSettings.URL, "jdbc:hsqldb:mem:mydb");
    configuration.setProperty(AvailableSettings.USER, datasource.getProperty(DatasourceProperties.USER));
    configuration.setProperty(AvailableSettings.PASS, datasource.getProperty(DatasourceProperties.PASSWORD));

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

    Connection connection = serviceRegistry.getService(ConnectionProvider.class).getConnection();
    Statement statement = connection.createStatement();
    statement.executeUpdate("CREATE SCHEMA w4tj;");
    statement.close();//from  w  w  w. j  a  va 2s  .c o m

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    try {
        for (Resource resource : resolver.getResources("classpath*:org/web4thejob/orm/**/*.hbm.xml")) {

            if (resource.getFile().getName().equals("AuxiliaryDatabaseObjects.hbm.xml"))
                continue;

            configuration.addFile(resource.getFile());
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }

    SchemaExport schemaExport = new SchemaExport(serviceRegistry, configuration);
    schemaExport.execute(Target.EXPORT, SchemaExport.Type.CREATE);

    if (!schemaExport.getExceptions().isEmpty()) {
        throw new RuntimeException((Throwable) schemaExport.getExceptions().get(0));
    }

}