Package org.exolab.jms.persistence

Examples of org.exolab.jms.persistence.PersistenceException


    public void migrate() throws PersistenceException {
        Connection connection = _connections.getConnection();

        String fromVersion = SchemaHelper.getSchemaVersion(connection);
        if (fromVersion == null) {
            throw new PersistenceException(
                    "Cannot migrate schema - existing schema version cannot be "
                    + "determined");
        }
        String toVersion = RDBMSAdapter.SCHEMA_VERSION;
        SchemaConverter converter =
                SchemaConverterFactory.create(fromVersion, toVersion,
                                              connection);
        if (converter != null) {
            try {
                _log.info("Migrating schema from version=" +
                          fromVersion + " to version=" + toVersion);
                converter.convert();
                _log.info("Successfully migrated schema");
            } catch (PersistenceException exception) {
                _log.error("Schema migration from version=" + fromVersion +
                           " to version=" + toVersion + " failed",
                           exception);
                throw exception;
            }
        } else {
            throw new PersistenceException(
                    "Incompatible schema types. Expected schema version="
                    + fromVersion + ", but got schema version=" + toVersion);
        }
    }
View Full Code Here


    private void init(Configuration config) throws PersistenceException {
        RdbmsDatabaseConfiguration rdbms =
                config.getDatabaseConfiguration()
                .getRdbmsDatabaseConfiguration();
        if (rdbms == null) {
            throw new PersistenceException(
                    "Configuration not configured to use an RDBMS");
        }
        _connections = new DBCPConnectionManager();
        _connections.setDriver(rdbms.getDriver());
        _connections.setURL(rdbms.getUrl());
View Full Code Here

            result = query.executeQuery();
            if (result.next()) {
                version = result.getString(1);
            }
        } catch (SQLException exception) {
            throw new PersistenceException(
                "Failed to get the schema version", exception);
        } finally {
            SQLHelper.close(result);
            SQLHelper.close(query);
        }
View Full Code Here

        try {
            update = connection.prepareStatement(
                "update system_data set version=? where id = 1");
            update.setString(1, version);
            if (update.executeUpdate() != 1) {
                throw new PersistenceException(
                    "Failed to update system_data.version");
            }
        } catch (SQLException exception) {
            throw new PersistenceException(
                "Failed to update system_data.version", exception);
        } finally {
            SQLHelper.close(update);
        }
    }
View Full Code Here

    public static Database getSchemaFromResource(String path)
        throws PersistenceException {
        Database schema = null;
        InputStream stream = SchemaHelper.class.getResourceAsStream(path);
        if (stream == null) {
            throw new PersistenceException("Cannot locate resource: " +
                path);
        }
        try {
            schema = Database.unmarshal(new InputStreamReader(stream));
        } catch (MarshalException exception) {
            throw new PersistenceException(exception.getMessage());
        } catch (ValidationException exception) {
            throw new PersistenceException(exception.getMessage());
        }
        return schema;
    }
View Full Code Here

        Database schema = null;
        InputStream stream = null;
        try {
            stream = new FileInputStream(path);
        } catch (FileNotFoundException exception) {
            throw new PersistenceException(exception.getMessage(), exception);
        }

        try {
            schema = Database.unmarshal(new InputStreamReader(stream));
        } catch (MarshalException exception) {
            throw new PersistenceException(exception.getMessage());
        } catch (ValidationException exception) {
            throw new PersistenceException(exception.getMessage());
        }
        return schema;
    }
View Full Code Here

    public RDBMSTool(Configuration config) throws PersistenceException {
        RdbmsDatabaseConfiguration rdbms =
                config.getDatabaseConfiguration()
                .getRdbmsDatabaseConfiguration();
        if (rdbms == null) {
            throw new PersistenceException(
                    "Configuration not configured to use an RDBMS");
        }
        Connection connection = null;
        try {
            Class.forName(rdbms.getDriver());
            connection = DriverManager.getConnection(rdbms.getUrl(),
                                                      rdbms.getUser(),
                                                      rdbms.getPassword());
        } catch (SQLException exception) {
            throw new PersistenceException(exception);
        } catch (ClassNotFoundException exception) {
            throw new PersistenceException(exception);
        }
        init(connection);
    }
View Full Code Here

     * @throws PersistenceException if the table exists, or cannot be created
     */
    public void create(Table table) throws PersistenceException {
        String name = table.getName();
        if (_browser.getTableExists(name)) {
            throw new PersistenceException(
                    "An object already exists in the database named " + name);
        }

        StringBuffer sql = new StringBuffer("create table ");
        sql.append(name);
        sql.append(" (");

        _log.debug("Creating table: " + name);
        Attribute[] attributes = table.getAttribute();
        for (int i = 0; i < attributes.length; ++i) {
            if (i > 0) {
                sql.append(", ");
            }
            Attribute attribute = attributes[i];
            sql.append(attribute.getName());
            sql.append(" ");
            sql.append(getSQLType(attribute));
            if (attribute.getNotNull()) {
                sql.append(" not null");
            }
            if (attribute.getPrimaryKey()) {
                sql.append(" primary key");
            }
            if (attribute.getUnique()) {
                sql.append(" unique");
            }
        }
        PrimaryKey key = table.getPrimaryKey();
        if (key != null) {
            sql.append(", primary key (");
            Column[] columns = key.getColumn();
            for (int i = 0; i < columns.length; ++i) {
                if (i > 0) {
                    sql.append(", ");
                }
                sql.append(columns[i].getName());
            }
            sql.append(")");
        }
        sql.append(")");

        _log.debug("SQL=" + sql);
        Statement statement = null;
        try {
            statement = _connection.createStatement();
            statement.executeUpdate(sql.toString());
        } catch (SQLException exception) {
            throw new PersistenceException("Failed to create table=" + name,
                                           exception);
        } finally {
            SQLHelper.close(statement);
        }
        createIndexes(table);
View Full Code Here

    private void init(Connection connection) throws PersistenceException {
        _connection = connection;
        try {
            _connection.setAutoCommit(true);
        } catch (SQLException exception) {
            throw new PersistenceException("Failed to set auto-commit on",
                                           exception);
        }
        _browser = new SchemaBrowser(_connection);
    }
View Full Code Here

            Statement statement = null;
            try {
                statement = _connection.createStatement();
                statement.executeUpdate(sql.toString());
            } catch (SQLException exception) {
                throw new PersistenceException("Failed to create index="
                                               + index.getName()
                                               + " on table "
                                               + table.getName(), exception);
            } finally {
                SQLHelper.close(statement);
View Full Code Here

TOP

Related Classes of org.exolab.jms.persistence.PersistenceException

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.