Package org.rhq.core.db

Examples of org.rhq.core.db.DatabaseType


    @RequiredPermission(Permission.MANAGE_SETTINGS)
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public long vacuum(Subject whoami, String[] tableNames) {
        long duration = 0;
        Connection conn = null;
        DatabaseType dbtype = null;
        try {
            conn = dataSource.getConnection();
            dbtype = DatabaseTypeFactory.getDefaultDatabaseType();
            if (!DatabaseTypeFactory.isPostgres(dbtype)) {
                return -1;
            }

            if (tableNames == null) // no names given -> operate on all tables.
            {
                tableNames = new String[1];
                tableNames[0] = null;
            }

            for (String tableName : tableNames) {
                duration += doCommand(dbtype, conn, SQL_VACUUM, tableName);
            }

            return duration;
        } catch (Exception e) {
            LOG.error("Error vacuuming database: " + e.getMessage(), e);
            return duration;
        } finally {
            if (dbtype != null) {
                dbtype.closeConnection(conn);
            }
        }
    }
View Full Code Here


    @SuppressWarnings("unchecked")
    private List<Integer> getDescendents(int resourceId) {
        List<Integer> result;
        Query query;

        DatabaseType dbType = DatabaseTypeFactory.getDefaultDatabaseType();
        if (DatabaseTypeFactory.isOracle(dbType)) {
            query = entityManager.createNativeQuery(Resource.QUERY_NATIVE_FIND_DESCENDANTS_ORACLE);

        } else if (DatabaseTypeFactory.isPostgres(dbType)) {
            query = entityManager.createNativeQuery(Resource.QUERY_NATIVE_FIND_DESCENDANTS_POSTGRES);

        } else {
            query = entityManager.createNamedQuery(Resource.QUERY_FIND_DESCENDANTS);
        }

        query.setParameter("resourceId", resourceId);

        if (DatabaseTypeFactory.isOracle(dbType)) {
            List<?> rl = query.getResultList();
            result = new ArrayList<Integer>(rl.size());
            for (Object id : rl) {
                result.add(dbType.getInteger(id));
            }
        } else {
            // native Integer support
            result = query.getResultList();
        }
View Full Code Here

    public List<Integer> getResourceDescendantsByTypeAndName(Subject user, int resourceId, Integer resourceTypeId,
        String name) {

        List<Integer> result;
        Query query;
        DatabaseType dbType = DatabaseTypeFactory.getDefaultDatabaseType();

        if (DatabaseTypeFactory.isOracle(dbType)) {
            query = entityManager.createNativeQuery(Resource.QUERY_NATIVE_FIND_DESCENDANTS_BY_TYPE_AND_NAME_ORACLE);

        } else if (DatabaseTypeFactory.isPostgres(dbType)) {
            query = entityManager.createNativeQuery(Resource.QUERY_NATIVE_FIND_DESCENDANTS_BY_TYPE_AND_NAME_POSTGRES);

        } else {
            query = entityManager.createNamedQuery(Resource.QUERY_FIND_DESCENDANTS_BY_TYPE_AND_NAME);
        }

        query.setParameter("resourceId", resourceId);
        query.setParameter("resourceTypeId", ((null != resourceTypeId) ? resourceTypeId : 0));
        name = QueryUtility.formatSearchParameter(name);
        query.setParameter("resourceName", ((null != name) ? name : "$$$null$$$"));

        if (DatabaseTypeFactory.isOracle(dbType)) {
            List<?> rl = query.getResultList();
            result = new ArrayList<Integer>(rl.size());
            for (Object id : rl) {
                result.add(dbType.getInteger(id));
            }
        } else {
            // native Integer support
            result = query.getResultList();
        }
View Full Code Here

            hasErrors |= resourceManager.bulkNativeQueryDeleteInNewTransaction(overlord, nativeQueryToExecute,
                resourceIds);
        }

        // update the resource type of affected groups by calling setResouceType()
        DatabaseType dbType = DatabaseTypeFactory.getDefaultDatabaseType();
        Integer groupId = null;
        for (int i = 0, size = rs.size(); i < size; ++i) {
            try {
                groupId = dbType.getInteger(rs.get(i));
                resourceGroupManager.setResourceTypeInNewTx(groupId);

            } catch (ResourceGroupDeleteException rgde) {
                LOG.warn("Unable to change resource type for group with id [" + groupId + "]", rgde);
            }
View Full Code Here

        PreparedStatement insertStatement = null;

        int created = -1;
        try {
            conn = dataSource.getConnection();
            DatabaseType dbType = DatabaseTypeFactory.getDefaultDatabaseType();

            String insertQueryString = null;
            if (dbType instanceof PostgresqlDatabaseType) {
                insertQueryString = MeasurementSchedule.NATIVE_QUERY_INSERT_SCHEDULES_POSTGRES;
            } else if (dbType instanceof OracleDatabaseType || dbType instanceof H2DatabaseType) {
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    public Set<Integer> getSchedulesWithoutBaselines() {
        try {
            DatabaseType databaseType = DatabaseTypeFactory.getDefaultDatabaseType();
            final String sql = "" //
                + "SELECT DISTINCT s.id " //
                + "  FROM rhq_measurement_sched s JOIN rhq_measurement_def d ON s.definition = d.id " //
                + " WHERE s.enabled = " + databaseType.getBooleanValue(true) //
                + "   AND d.numeric_type = 0 " //
                + "   AND NOT EXISTS (SELECT * FROM rhq_measurement_bline b WHERE b.schedule_id = s.id)";
            Query query = this.entityManager.createNativeQuery(sql);
            List results = query.getResultList();
            Set<Integer> scheduleIds = new HashSet<Integer>();
            for (Object object : results) {
                scheduleIds.add(databaseType.getInteger(object));
            }
            return scheduleIds;
        } catch (Exception e) {
            throw new RuntimeException(
                "An unexpected error occurred while trying to retrieve schedules without baselines", e);
View Full Code Here

        String statementSql;
        Connection conn = null;
        PreparedStatement ps = null;
        try {
            conn = rhqDs.getConnection();
            DatabaseType dbType = DatabaseTypeFactory.getDefaultDatabaseType();

            if (dbType instanceof PostgresqlDatabaseType || dbType instanceof OracleDatabaseType
                || dbType instanceof H2DatabaseType) {
                String nextvalSql = JDBCUtil.getNextValSql(conn, EventSource.TABLE_NAME);
                statementSql = String.format(EVENT_SOURCE_INSERT_STMT, nextvalSql);
            } else if (dbType instanceof SQLServerDatabaseType) {
                statementSql = EVENT_SOURCE_INSERT_STMT_AUTOINC;
            } else {
                throw new IllegalArgumentException("Unknown database type, can't continue: " + dbType);
            }

            // First insert the "keys" (i.e. the EventSources).
            ps = conn.prepareStatement(statementSql);
            try {
                for (EventSource eventSource : events.keySet()) {
                    int paramIndex = 1;
                    ps.setString(paramIndex++, eventSource.getEventDefinition().getName());
                    ps.setString(paramIndex++, eventSource.getEventDefinition().getResourceType().getName());
                    ps.setString(paramIndex++, eventSource.getEventDefinition().getResourceType().getPlugin());
                    ps.setInt(paramIndex++, eventSource.getResource().getId());
                    ps.setString(paramIndex++, eventSource.getLocation());
                    ps.setString(paramIndex++, eventSource.getEventDefinition().getName());
                    ps.setString(paramIndex++, eventSource.getEventDefinition().getResourceType().getName());
                    ps.setString(paramIndex++, eventSource.getEventDefinition().getResourceType().getPlugin());
                    ps.setInt(paramIndex++, eventSource.getResource().getId());
                    ps.setString(paramIndex++, eventSource.getLocation());

                    ps.addBatch();
                }
                ps.executeBatch();
            } finally {
                JDBCUtil.safeClose(ps);
            }

            if (dbType instanceof PostgresqlDatabaseType || dbType instanceof OracleDatabaseType
                || dbType instanceof H2DatabaseType) {
                String nextvalSql = JDBCUtil.getNextValSql(conn, Event.TABLE_NAME);
                statementSql = String.format(EVENT_INSERT_STMT, nextvalSql);
            } else if (dbType instanceof SQLServerDatabaseType) {
                statementSql = EVENT_INSERT_STMT_AUTOINC;
            } else {
                throw new IllegalArgumentException("Unknown database type, can't continue: " + dbType);
            }

            // Then insert the "values" (i.e. the Events).
            ps = conn.prepareStatement(statementSql);
            try {
                for (EventSource eventSource : events.keySet()) {
                    Set<Event> eventData = events.get(eventSource);
                    for (Event event : eventData) {
                        int paramIndex = 1;
                        ps.setString(paramIndex++, eventSource.getEventDefinition().getName());
                        ps.setString(paramIndex++, eventSource.getEventDefinition().getResourceType().getName());
                        ps.setString(paramIndex++, eventSource.getEventDefinition().getResourceType().getPlugin());
                        ps.setInt(paramIndex++, eventSource.getResource().getId());
                        ps.setString(paramIndex++, eventSource.getLocation());
                        ps.setLong(paramIndex++, event.getTimestamp());
                        ps.setString(paramIndex++, event.getSeverity().toString());
                        String detail = dbType.getString(event.getDetail(), Event.DETAIL_MAX_LENGTH);
                        ps.setString(paramIndex++, detail);
                        ps.addBatch();
                    }

                    // We may have trimmed the event detail for storage reasons, but for alerting use the
View Full Code Here

    @Deprecated
    @NotNull
    public Resource getRootResourceForResource(int resourceId) {
        Query query;
        Resource result;
        DatabaseType dbType = DatabaseTypeFactory.getDefaultDatabaseType();

        if (DatabaseTypeFactory.isOracle(dbType)) {
            query = entityManager.createNativeQuery(Resource.QUERY_NATIVE_FIND_RESOURCE_PLATFORM_ORACLE);

        } else if (DatabaseTypeFactory.isPostgres(dbType)) {
            query = entityManager.createNativeQuery(Resource.QUERY_NATIVE_FIND_RESOURCE_PLATFORM_POSTGRES);

        } else {
            query = entityManager.createNamedQuery(Resource.QUERY_FIND_ROOT_PLATFORM_OF_RESOURCE);
        }

        query.setParameter("resourceId", resourceId);

        Integer platformId;
        if (DatabaseTypeFactory.isOracle(dbType)) {
            platformId = dbType.getInteger(query.getSingleResult());

        } else {
            // native Integer support
            platformId = (Integer) query.getSingleResult();
        }
View Full Code Here

        // make sure the task has been defined properly
        validateAttributes();

        try {
            DatabaseType db_type = getDatabaseType();
            Connection conn = getConnection();

            log(MSG.getMsg(DbAntI18NResourceKeys.DROP_SEQUENCE_EXECUTING, m_name));
            db_type.dropSequence(conn, m_name);
        } catch (Exception e) {
            throw new BuildException(MSG.getMsg(DbAntI18NResourceKeys.SCHEMA_SPEC_TASK_FAILURE, "DropSequence", e), e);
        }

        return;
View Full Code Here

            return;
        }

        validateAttributes();

        DatabaseType db_type = getDatabaseType();
        Connection conn = getConnection();

        try {
            boolean table_exists = db_type.checkTableExists(conn, table);

            if (!table_exists) {
                log(MSG.getMsg(DbAntI18NResourceKeys.DROP_TABLE_TABLE_DOES_NOT_EXIST, table));
                return;
            }

            log(MSG.getMsg(DbAntI18NResourceKeys.DROP_TABLE_EXECUTING, table));
            db_type.dropTable(conn, table);
        } catch (IllegalStateException e) {
            log(MSG.getMsg(DbAntI18NResourceKeys.DROP_TABLE_TABLE_DOES_NOT_EXIST, table));
            // since the semantics demand that we return normally here, we need to rollback the
            // invalidated transaction ourselves.
            if (isIgnoreError()) {
View Full Code Here

TOP

Related Classes of org.rhq.core.db.DatabaseType

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.