Package net.sf.hibernate.connection

Examples of net.sf.hibernate.connection.ConnectionProvider


   * @see net.sf.hibernate.engine.SessionFactoryImplementor#getConnectionProvider
   * @see LocalDataSourceConnectionProvider
   */
  public static DataSource getDataSource(SessionFactory sessionFactory) {
    if (sessionFactory instanceof SessionFactoryImplementor) {
      ConnectionProvider cp = ((SessionFactoryImplementor) sessionFactory).getConnectionProvider();
      if (cp instanceof LocalDataSourceConnectionProvider) {
        return ((LocalDataSourceConnectionProvider) cp).getDataSource();
      }
    }
    return null;
View Full Code Here


        log.info("Running hbm2ddl schema export");

        Connection connection = null;
        FileWriter fileOutput = null;
        ConnectionProvider connectionProvider = null;
        Statement statement = null;

        Properties props = new Properties();
        props.putAll(dialect.getDefaultProperties());
        props.putAll(connectionProperties);

        try {

            if (outputFile != null) {
                log.info("writing generated schema to file: " + outputFile);
                fileOutput = new FileWriter(outputFile);
            }

            if (export) {
                log.info("exporting generated schema to database");
                connectionProvider = ConnectionProviderFactory.newConnectionProvider(props);
                connection = connectionProvider.getConnection();
                if (!connection.getAutoCommit()) {
                    connection.commit();
                    connection.setAutoCommit(true);
                }
                statement = connection.createStatement();
            }

            for (int i = 0; i < dropSQL.length; i++) {
                try {
                    String formatted = dropSQL[i];
                    formatted = customModify(formatted);
                    if (delimiter != null) formatted += delimiter;
                    if (script) System.out.println(formatted);
                    log.debug(formatted);
                    if (outputFile != null) fileOutput.write(formatted + "\n");
                    if (export) statement.executeUpdate(dropSQL[i]);
                } catch (SQLException e) {
                    log.debug("Unsuccessful: " + dropSQL[i]);
                    log.debug(e.getMessage());
                }

            }

            if (!justDrop) {
                for (int j = 0; j < createSQL.length; j++) {
                    try {
                        String line = createSQL[j];
                        line = customModify(line);
                        String formatted = format ? format(line) : line;
                        if (delimiter != null) formatted += delimiter;
                        if (script) System.out.println(formatted);
                        log.debug(formatted);
                        if (outputFile != null) fileOutput.write(formatted + "\n");
                        if (export) statement.executeUpdate(createSQL[j]);
                    } catch (SQLException e) {
                        log.error("Unsuccessful: " + createSQL[j]);
                        log.error(e.getMessage());
                    }
                }
            }

            log.info("schema export complete");

        } catch (Exception e) {
            log.error("schema export unsuccessful", e);
        } finally {

            try {
                if (statement != null) statement.close();
                if (connection != null) {
                    JDBCExceptionReporter.logWarnings(connection.getWarnings());
                    connection.clearWarnings();
                    connectionProvider.closeConnection(connection);
                    connectionProvider.close();
                }
            } catch (Exception e) {
                log.error("Could not close connection", e);
            }
View Full Code Here

TOP

Related Classes of net.sf.hibernate.connection.ConnectionProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.