Examples of DatabaseType


Examples of org.rhq.core.db.DatabaseType

        return result;
    }

    public static void persistStorageClusterSettingsIfNecessary(HashMap<String, String> serverProperties,
        String password) throws Exception {
        DatabaseType db = null;
        Connection connection = null;
        PreparedStatement updateClusterSetting = null;

        try {
            String dbUrl = serverProperties.get(ServerProperties.PROP_DATABASE_CONNECTION_URL);
            String userName = serverProperties.get(ServerProperties.PROP_DATABASE_USERNAME);
            connection = getDatabaseConnection(dbUrl, userName, password);
            db = DatabaseTypeFactory.getDatabaseType(connection);

            if (!(db instanceof PostgresqlDatabaseType || db instanceof OracleDatabaseType)) {
                throw new IllegalArgumentException("Unknown database type, can't continue: " + db);
            }

            connection = getDatabaseConnection(dbUrl, userName, password);
            connection.setAutoCommit(false);

            updateClusterSetting = connection.prepareStatement("" //
                + "UPDATE rhq_system_config " //
                + "   SET property_value = ?, default_property_value = ? " //
                + " WHERE property_key = ? " //
                + "   AND ( property_value IS NULL OR property_value = '' OR property_value = 'UNSET' ) ");

            updateClusterSetting.setString(1, serverProperties.get(ServerProperties.PROP_STORAGE_USERNAME));
            updateClusterSetting.setString(2, serverProperties.get(ServerProperties.PROP_STORAGE_USERNAME));
            updateClusterSetting.setString(3, "STORAGE_USERNAME");
            updateClusterSetting.executeUpdate();

            updateClusterSetting.setString(1, serverProperties.get(ServerProperties.PROP_STORAGE_PASSWORD));
            updateClusterSetting.setString(2, serverProperties.get(ServerProperties.PROP_STORAGE_PASSWORD));
            updateClusterSetting.setString(3, "STORAGE_PASSWORD");
            updateClusterSetting.executeUpdate();

            updateClusterSetting.setString(1, serverProperties.get(ServerProperties.PROP_STORAGE_CQL_PORT));
            updateClusterSetting.setString(2, serverProperties.get(ServerProperties.PROP_STORAGE_CQL_PORT));
            updateClusterSetting.setString(3, "STORAGE_CQL_PORT");
            updateClusterSetting.executeUpdate();

            updateClusterSetting.setString(1, serverProperties.get(ServerProperties.PROP_STORAGE_GOSSIP_PORT));
            updateClusterSetting.setString(2, serverProperties.get(ServerProperties.PROP_STORAGE_GOSSIP_PORT));
            updateClusterSetting.setString(3, "STORAGE_GOSSIP_PORT");
            updateClusterSetting.executeUpdate();

            connection.commit();
        } catch (SQLException e) {
            LOG.error("Failed to initialize storage cluster settings. Transaction will be rolled back.", e);
            connection.rollback();
            throw e;
        } finally {
            if (db != null) {
                db.closeStatement(updateClusterSetting);
                db.closeConnection(connection);
            }
        }
    }
View Full Code Here

Examples of org.rhq.core.db.DatabaseType

     * @throws Exception
     */
    public static void storeServerDetails(HashMap<String, String> serverProperties, String password,
        ServerDetails serverDetails) throws Exception {

        DatabaseType db = null;
        Connection conn = null;

        try {
            String dbUrl = serverProperties.get(ServerProperties.PROP_DATABASE_CONNECTION_URL);
            String userName = serverProperties.get(ServerProperties.PROP_DATABASE_USERNAME);
            conn = getDatabaseConnection(dbUrl, userName, password);
            db = DatabaseTypeFactory.getDatabaseType(conn);

            updateOrInsertServer(db, conn, serverDetails);

        } catch (SQLException e) {
            // TODO: should we throw an exception here? This would abort the rest of the installation
            LOG.info("Unable to store server entry in the database: " + ThrowableUtil.getAllMessages(e));
        } finally {
            if (null != db) {
                db.closeConnection(conn);
            }
        }
    }
View Full Code Here

Examples of org.rhq.core.db.DatabaseType

     *
     * @throws Exception if failed to communicate with the database
     */
    public static LinkedHashMap<String, String> getServerVersions(String connectionUrl, String username, String password)
        throws Exception {
        DatabaseType db = null;
        Connection conn = null;
        Statement stm = null;
        ResultSet rs = null;
        LinkedHashMap<String, String> result = null;

        try {
            conn = getDatabaseConnection(connectionUrl, username, password);
            db = DatabaseTypeFactory.getDatabaseType(conn);

            if (db.checkColumnExists(conn, "rhq_server", "version")) {

                stm = conn.createStatement();
                rs = stm.executeQuery("SELECT name, version FROM rhq_server ORDER BY name asc");

                result = new LinkedHashMap<String, String>();

                while (rs.next()) {
                    result.put(rs.getString(1), rs.getString(2));
                }
            }
        } catch (IllegalStateException e) {
            // column does not exist
        } catch (SQLException e) {
            LOG.info("Unable to fetch server version info: " + e.getMessage());
        } finally {
            if (null != db) {
                db.closeJDBCObjects(conn, stm, rs);
            }
        }

        return result;
    }
View Full Code Here

Examples of org.rhq.core.db.DatabaseType

     *
     * @throws Exception if failed to communicate with the database
     */
    public static LinkedHashMap<String, String> getStorageNodeVersions(String connectionUrl, String username,
        String password) throws Exception {
        DatabaseType db = null;
        Connection conn = null;
        Statement stm = null;
        ResultSet rs = null;
        LinkedHashMap<String, String> result = null;

        try {
            conn = getDatabaseConnection(connectionUrl, username, password);
            db = DatabaseTypeFactory.getDatabaseType(conn);

            if (db.checkColumnExists(conn, "rhq_storage_node", "version")) {

                stm = conn.createStatement();
                rs = stm.executeQuery("SELECT address, version FROM rhq_storage_node ORDER BY address asc");

                result = new LinkedHashMap<String, String>();

                while (rs.next()) {
                    result.put(rs.getString(1), rs.getString(2));
                }
            }
        } catch (IllegalStateException e) {
            // column does not exist
        } catch (SQLException e) {
            LOG.info("Unable to fetch storage node version info: " + e.getMessage());
        } finally {
            if (null != db) {
                db.closeJDBCObjects(conn, stm, rs);
            }
        }

        return result;
    }
View Full Code Here

Examples of org.rhq.core.db.DatabaseType

        List<Long> timings = new ArrayList<Long>();

        try {
            log.info("Calculating OOBs for hour starting at " + new Date(begin));
            conn = rhqDs.getConnection();
            DatabaseType dbType = DatabaseTypeFactory.getDefaultDatabaseType();

            long t0 = System.currentTimeMillis();
            long tstart = t0;

            // first truncate tmp table
View Full Code Here

Examples of org.rhq.core.db.DatabaseType

        if (null == alert) {
            throw new ApplicationException("Alert not found with id [" + alertId + "].");
        }

        // make sure we don't exceed the max message length for the db vendor
        DatabaseType dbType = DatabaseTypeFactory.getDefaultDatabaseType();
        String message = dbType.getString(notificationLog.getMessage(), AlertNotificationLog.MESSAGE_MAX_LENGTH);

        if (null != message && !message.equals(notificationLog.getMessage())) {
            notificationLog = new AlertNotificationLog(notificationLog.getAlert(), notificationLog.getSender(),
                notificationLog.getResultState(), message);
        }
View Full Code Here

Examples of org.rhq.core.db.DatabaseType

        PreparedStatement ps = null;
        Connection conn = null;

        try {
            conn = rhqDs.getConnection();
            DatabaseType dbType = DatabaseTypeFactory.getDefaultDatabaseType();

            if (dbType instanceof Postgresql83DatabaseType) {
                Statement st = null;
                try {
                    // Take advantage of async commit here
                    st = conn.createStatement();
                    st.execute("SET synchronous_commit = off");
                } finally {
                    JDBCUtil.safeClose(st);
                }
            }

            if (dbType instanceof PostgresqlDatabaseType || dbType instanceof OracleDatabaseType
                || dbType instanceof H2DatabaseType) {
                String keyNextvalSql = JDBCUtil.getNextValSql(conn, "RHQ_calltime_data_key");
                insertKeySql = String.format(CALLTIME_KEY_INSERT_STATEMENT, keyNextvalSql);
            } else if (dbType instanceof SQLServerDatabaseType) {
                insertKeySql = CALLTIME_KEY_INSERT_STATEMENT_AUTOINC;
            } else {
                throw new IllegalArgumentException("Unknown database type, can't continue: " + dbType);
            }

            ps = conn.prepareStatement(insertKeySql);
            for (CallTimeData callTimeData : callTimeDataSet) {
                ps.setInt(1, callTimeData.getScheduleId());
                ps.setInt(3, callTimeData.getScheduleId());
                Set<String> callDestinations = callTimeData.getValues().keySet();
                for (String callDestination : callDestinations) {
                    // make sure the destination string is safe for storage, clip as needed
                    String safeCallDestination = dbType.getString(callDestination,
                        CallTimeDataKey.DESTINATION_MAX_LENGTH);
                    ps.setString(2, safeCallDestination);
                    ps.setString(4, safeCallDestination);
                    ps.addBatch();
                }
View Full Code Here

Examples of org.rhq.core.db.DatabaseType

        PreparedStatement ps = null;
        Connection conn = null;

        try {
            conn = rhqDs.getConnection();
            DatabaseType dbType = DatabaseTypeFactory.getDatabaseType(conn);

            if (dbType instanceof Postgresql83DatabaseType) {
                Statement st = null;
                try {
                    // Take advantage of async commit here
                    st = conn.createStatement();
                    st.execute("SET synchronous_commit = off");
                } finally {
                    JDBCUtil.safeClose(st);
                }
            }

            if (dbType instanceof PostgresqlDatabaseType || dbType instanceof OracleDatabaseType
                || dbType instanceof H2DatabaseType) {
                String valueNextvalSql = JDBCUtil.getNextValSql(conn, "RHQ_calltime_data_value");
                insertValueSql = String.format(CALLTIME_VALUE_INSERT_STATEMENT, valueNextvalSql);
            } else if (dbType instanceof SQLServerDatabaseType) {
                insertValueSql = CALLTIME_VALUE_INSERT_STATEMENT_AUTOINC;
            } else {
                throw new IllegalArgumentException("Unknown database type, can't continue: " + dbType);
            }

            ps = conn.prepareStatement(insertValueSql);
            for (CallTimeData callTimeData : callTimeDataSet) {
                ps.setInt(7, callTimeData.getScheduleId());
                Set<String> callDestinations = callTimeData.getValues().keySet();
                for (String callDestination : callDestinations) {
                    CallTimeDataValue callTimeDataValue = callTimeData.getValues().get(callDestination);
                    ps.setLong(1, callTimeDataValue.getBeginTime());
                    ps.setLong(2, callTimeDataValue.getEndTime());
                    ps.setDouble(3, callTimeDataValue.getMinimum());
                    ps.setDouble(4, callTimeDataValue.getMaximum());
                    ps.setDouble(5, callTimeDataValue.getTotal());
                    ps.setLong(6, callTimeDataValue.getCount());
                    // make sure the destination string is safe for storage, clip as needed
                    String safeCallDestination = dbType.getString(callDestination,
                        CallTimeDataKey.DESTINATION_MAX_LENGTH);
                    ps.setString(8, safeCallDestination);
                    ps.addBatch();
                }
            }
View Full Code Here

Examples of org.rhq.core.db.DatabaseType

        // letting hibernate grab the whole hierarchy via eager fetch of children...
        Query query;
        Collection<ResourceSyncInfo> result;
        boolean isNative = true;

        DatabaseType dbType = DatabaseTypeFactory.getDefaultDatabaseType();
        if (DatabaseTypeFactory.isOracle(dbType)) {
            query = entityManager.createNativeQuery(ResourceSyncInfo.QUERY_NATIVE_QUERY_TOP_LEVEL_SERVER_ORACLE);

        } else if (DatabaseTypeFactory.isPostgres(dbType)) {
            query = entityManager.createNativeQuery(ResourceSyncInfo.QUERY_NATIVE_QUERY_TOP_LEVEL_SERVER_POSTGRES);

        } else {
            isNative = false;
            query = entityManager.createNamedQuery(ResourceSyncInfo.QUERY_TOP_LEVEL_SERVER);
        }

        query.setParameter("resourceId", resourceId);

        if (isNative) {
            List<Object[]> rows = query.getResultList();
            result = new ArrayList<ResourceSyncInfo>(rows.size());
            for (Object[] row : rows) {
                int id = dbType.getInteger(row[0]);
                String uuid = (String) row[1];
                long mtime = dbType.getLong(row[2]);
                InventoryStatus status = InventoryStatus.valueOf((String) row[3]);
                result.add(new ResourceSyncInfo(id, uuid, mtime, status));
            }
        } else {
            result = query.getResultList();
View Full Code Here

Examples of org.rhq.core.db.DatabaseType

    @Override
    @RequiredPermission(Permission.MANAGE_SETTINGS)
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public long analyze(Subject whoami) {
        Connection conn = null;
        DatabaseType dbtype = null;
        try {
            conn = dataSource.getConnection();
            dbtype = DatabaseTypeFactory.getDefaultDatabaseType();
            if (!DatabaseTypeFactory.isPostgres(dbtype)) {
                return -1;
            }

            long duration = doCommand(dbtype, conn, SQL_ANALYZE, null);
            return duration;
        } catch (Exception e) {
            LOG.error("Error analyzing database", e);
            throw new RuntimeException("Error analyzing database", e);
        } finally {
            if (dbtype != null) {
                dbtype.closeConnection(conn);
            }
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.