Search in sources :

Example 6 with SimpleJdbcCall

use of org.springframework.jdbc.core.simple.SimpleJdbcCall in project ovirt-engine by oVirt.

the class BatchProcedureExecutionConnectionCallback method fillProcMetaData.

private void fillProcMetaData(String procName, Connection con, StoredProcedureMetaData procMetaData) throws SQLException {
    SimpleJdbcCall call = handler.getCall(procName, handler.createCallForModification(procName));
    Map<String, SqlCallParameter> paramOrder = new HashMap<>();
    String procNameFromDB = null;
    String procSchemaFromDB = null;
    StringBuilder params = new StringBuilder();
    try (ResultSet rs2 = con.getMetaData().getProcedureColumns(null, null, call.getProcedureName().toLowerCase(), "%")) {
        int internalCounter = 1;
        while (rs2.next()) {
            ProcData procData = fillProcData(rs2, internalCounter);
            if (procData != null) {
                ++internalCounter;
                paramOrder.put(procData.getColName(), new SqlCallParameter(procData.getOrdinal(), procData.getColName(), procData.getDataType()));
                procNameFromDB = procData.getProcName();
                procSchemaFromDB = procData.getSchemaName();
                params.append("CAST (? AS ").append(procData.getDbTypeName()).append("),");
            }
        }
        if (params.length() > 0) {
            params.deleteCharAt(params.length() - 1);
        }
    } catch (SQLException e) {
        log.error("Can't get procedure '{}' meta data: {}", procName, e.getMessage());
        log.debug("Exception", e);
    }
    procMetaData.setSqlCommand(handler.getDialect().createSqlCallCommand(procSchemaFromDB, procNameFromDB, params.toString()));
    procMetaData.setDbName(procNameFromDB);
    procMetaData.setParamatersMetaData(paramOrder);
    procMetaData.setSchemaName(procSchemaFromDB);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) SimpleJdbcCall(org.springframework.jdbc.core.simple.SimpleJdbcCall)

Example 7 with SimpleJdbcCall

use of org.springframework.jdbc.core.simple.SimpleJdbcCall in project ovirt-engine by oVirt.

the class SimpleJdbcCallsHandler method getCall.

protected <T> SimpleJdbcCall getCall(String procedureName, CallCreator callCreator, RowMapper<T> mapper) {
    SimpleJdbcCall call = callsMap.get(procedureName);
    if (call == null) {
        call = callCreator.createCall();
        call.compile();
        callsMap.putIfAbsent(procedureName, call);
    } else if (mapper != null) {
        call.returningResultSet(RETURN_VALUE_PARAMETER, mapper);
    }
    return call;
}
Also used : SimpleJdbcCall(org.springframework.jdbc.core.simple.SimpleJdbcCall)

Example 8 with SimpleJdbcCall

use of org.springframework.jdbc.core.simple.SimpleJdbcCall in project ovirt-engine by oVirt.

the class VmDeviceDaoImpl method isMemBalloonEnabled.

@Override
public boolean isMemBalloonEnabled(Guid vmId) {
    MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource().addValue("vm_id", vmId);
    Map<String, Object> dbResults = new SimpleJdbcCall(getJdbcTemplate()).withFunctionName("isMemBalloonEnabled").execute(parameterSource);
    String resultKey = getDialect().getFunctionReturnKey();
    return (Boolean) dbResults.getOrDefault(resultKey, false);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SimpleJdbcCall(org.springframework.jdbc.core.simple.SimpleJdbcCall)

Example 9 with SimpleJdbcCall

use of org.springframework.jdbc.core.simple.SimpleJdbcCall in project ovirt-engine by oVirt.

the class QuotaDaoImpl method isQuotaInUse.

@Override
public boolean isQuotaInUse(Quota quota) {
    MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource().addValue("quota_id", quota.getId());
    Map<String, Object> dbResults = new SimpleJdbcCall(getJdbcTemplate()).withFunctionName("IsQuotaInUse").execute(parameterSource);
    String resultKey = getDialect().getFunctionReturnKey();
    return dbResults.get(resultKey) != null && (Boolean) dbResults.get(resultKey);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SimpleJdbcCall(org.springframework.jdbc.core.simple.SimpleJdbcCall)

Example 10 with SimpleJdbcCall

use of org.springframework.jdbc.core.simple.SimpleJdbcCall in project ovirt-engine by oVirt.

the class DbUserDaoImpl method updateLastAdminCheckStatus.

@Override
public void updateLastAdminCheckStatus(Guid... userIds) {
    MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource().addValue("userIds", StringUtils.join(userIds, ","));
    new SimpleJdbcCall(getJdbcTemplate()).withProcedureName("UpdateLastAdminCheckStatus").execute(parameterSource);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) CustomMapSqlParameterSource(org.ovirt.engine.core.dal.dbbroker.CustomMapSqlParameterSource) SimpleJdbcCall(org.springframework.jdbc.core.simple.SimpleJdbcCall)

Aggregations

SimpleJdbcCall (org.springframework.jdbc.core.simple.SimpleJdbcCall)11 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)5 HashMap (java.util.HashMap)2 CustomMapSqlParameterSource (org.ovirt.engine.core.dal.dbbroker.CustomMapSqlParameterSource)2 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 DataSource (javax.sql.DataSource)1 Guid (org.ovirt.engine.core.compat.Guid)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 JdbcOperations (org.springframework.jdbc.core.JdbcOperations)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1 RowMapper (org.springframework.jdbc.core.RowMapper)1 SqlParameter (org.springframework.jdbc.core.SqlParameter)1 NamedParameterJdbcOperations (org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations)1 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)1 SimpleJdbcCallOperations (org.springframework.jdbc.core.simple.SimpleJdbcCallOperations)1 SimpleJdbcInsert (org.springframework.jdbc.core.simple.SimpleJdbcInsert)1 SimpleJdbcInsertOperations (org.springframework.jdbc.core.simple.SimpleJdbcInsertOperations)1