Example usage for org.springframework.jdbc.support.rowset SqlRowSet next

List of usage examples for org.springframework.jdbc.support.rowset SqlRowSet next

Introduction

In this page you can find the example usage for org.springframework.jdbc.support.rowset SqlRowSet next.

Prototype

boolean next() throws InvalidResultSetAccessException;

Source Link

Document

Move the cursor to the next row.

Usage

From source file:com.hs.mail.imap.dao.MySqlMessageDao.java

public Map<String, String> getHeader(long physMessageID) {
    String sql = "SELECT headername, headervalue FROM headername n, headervalue v WHERE v.physmessageid = ? AND v.headernameid = n.id";
    SqlRowSet rs = getJdbcTemplate().queryForRowSet(sql, new Object[] { new Long(physMessageID) });
    Map<String, String> results = new HashMap<String, String>();
    while (rs.next()) {
        results.put(rs.getString(1), rs.getString(2));
    }// w w w .  j a  v  a2s .com
    return results;
}

From source file:com.ineunet.knife.persist.dao.support.JdbcDaoSupport.java

@Override
public Object[] queryForArray(String sql, int cols, Object... args) {
    SqlRowSet sqlSet = getJdbcTemplate().queryForRowSet(sql, args);
    Object[] array = null;/*from w  ww. j  av  a2 s  .c  o  m*/
    //sqlSet.getRow(): 0
    //sqlSet.isBeforeFirst(): true
    //sqlSet.isFirst(): false
    if (sqlSet.next()) {
        array = new Object[cols];
        for (int i = 0; i < cols; i++) {
            array[i] = sqlSet.getObject(i + 1);
        }
    }
    if (sqlSet.next()) {
        throw new IncorrectResultSizeDataAccessException(1);
    }
    //sqlSet.isFirst(): true
    //sqlSet.isLast(): true
    //sqlSet.isAfterLast(): false
    return array;
}

From source file:nl.surfnet.coin.teams.service.impl.GroupProviderServiceSQLImpl.java

/**
 * Gets the allowed options for a Group Provider
 *
 * @param groupProvider {@link GroupProvider}
 * @return Map with allowed options//from   ww  w.  j av a  2 s  .c o m
 */
private Map<String, Object> getAllowedOptions(GroupProvider groupProvider) {
    Object[] args = { groupProvider.getId() };

    Map<String, Object> options = new HashMap<String, Object>();

    final SqlRowSet sqlRowSet = this.jdbcTemplate.queryForRowSet("SELECT gp_option.name, gp_option.value "
            + "FROM group_provider_option AS gp_option " + "WHERE gp_option.group_provider_id = ?;", args);

    while (sqlRowSet.next()) {
        options.put(sqlRowSet.getString("name"), sqlRowSet.getObject("value"));
    }
    return options;
}

From source file:org.jasig.cas.ticket.registry.support.JdbcLockingStrategy.java

/**
 * @see org.jasig.cas.ticket.registry.support.LockingStrategy#acquire()
 *//*  ww  w  . j  a v a2 s.  c om*/
@Transactional
public boolean acquire() {
    boolean lockAcquired = false;
    if (this.platform == DatabasePlatform.SqlServer) {
        this.jdbcTemplate.execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
    }
    try {
        final SqlRowSet rowSet = (SqlRowSet) this.jdbcTemplate.query(this.selectSql,
                new Object[] { this.applicationId }, new SqlRowSetResultSetExtractor());
        final Timestamp expDate = getExpirationDate();
        if (!rowSet.next()) {
            // No row exists for this applicationId so create it.
            // Row is created with uniqueId of this instance
            // which indicates the lock is initially held by this instance.
            this.jdbcTemplate.update(this.createSql,
                    new Object[] { this.applicationId, this.uniqueId, expDate });
            return true;
        }
        lockAcquired = canAcquire(rowSet);
        if (lockAcquired) {
            // Update unique ID of row to indicate this instance holds lock
            this.jdbcTemplate.update(this.updateAcquireSql,
                    new Object[] { this.uniqueId, expDate, this.applicationId });
        }
    } finally {
        // Always attempt to revert current connection to default isolation
        // level on SQL Server
        if (this.platform == DatabasePlatform.SqlServer) {
            this.jdbcTemplate.execute("SET TRANSACTION ISOLATION LEVEL READ COMMITTED");
        }
    }
    return lockAcquired;
}

From source file:org.restsql.core.impl.AbstractSqlResourceMetaData.java

/** Populates metadata using definition. */
@Override/*from  www .  j ava 2 s .  co  m*/
public void init(final String resName, final SqlResourceDefinition definition, DataSource dataSource)
        throws DataAccessException, SqlResourceException {
    this.resName = resName;
    this.definition = definition;
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    String sql = null;
    SqlResourceDefinitionUtils.validate(definition);

    sql = getSqlMainQuery(definition);
    final SqlRowSet resultSet = this.jdbcTemplate.queryForRowSet(sql);
    resultSet.next();
    buildTablesAndColumns(resultSet);

    buildPrimaryKeys();
    buildInvisibleForeignKeys();
    buildJoinTableMetadata();
    buildSequenceMetaData();

    hierarchical = getChild() != null;
}

From source file:com.emc.vipr.sync.filter.TrackingFilter.java

@Override
public void filter(final SyncObject obj) {
    final String sourceId = obj.getSourceIdentifier();
    boolean statusExists = false;
    final Map<String, String> metaValues = new HashMap<>();

    try {//w  w  w. j  a va  2 s . co m
        SqlRowSet rowSet = time(new Timeable<SqlRowSet>() {
            @Override
            public SqlRowSet call() {
                return template.queryForRowSet(String.format(SQL_STATUS_QUERY, tableName), sourceId);
            }
        }, OPERATION_STATUS_QUERY);
        if (rowSet.next()) {
            // status exists for this object
            statusExists = true;
            String targetId = rowSet.getString("target_id");
            if (targetId != null && targetId.trim().length() > 0)
                obj.setTargetIdentifier(targetId);

            // if the object is already complete, short-circuit the sync here (skip the object)
            if (COMPLETE_STATUS.equals(rowSet.getString("status")) && !processAllObjects) {
                LogMF.debug(l4j, "{0} is marked complete; skipping", sourceId);
                return;
            }
        }

        // get metadata values before processing (what if we're deleting the object?)
        for (String name : metaTags) {
            String metaValue = obj.getMetadata().getUserMetadataValue(name);
            if (metaValue == null && obj.getMetadata() instanceof AtmosMetadata) // try system meta too
                metaValue = ((AtmosMetadata) obj.getMetadata()).getSystemMetadataValue(name);
            if (metaValue != null)
                metaValues.put(name, metaValue);
        }

        // process object
        getNext().filter(obj);

        // sync completed successfully; update tracking table
        final boolean finalStatusExists = statusExists;
        time(new Timeable<Void>() {
            @Override
            public Void call() {
                template.update(finalStatusExists ? createStatusUpdateSql() : createStatusInsertSql(),
                        createStatusParameters(obj, metaValues, COMPLETE_STATUS, null));
                return null;
            }
        }, OPERATION_STATUS_UPDATE);

    } catch (final Throwable t) {

        // sync failed; update tracking table
        final boolean finalStatusExists = statusExists;
        time(new Timeable<Void>() {
            @Override
            public Void call() {
                template.update(finalStatusExists ? createStatusUpdateSql() : createStatusInsertSql(),
                        createStatusParameters(obj, metaValues, ERROR_STATUS, t.getMessage()));
                return null;
            }
        }, OPERATION_STATUS_UPDATE);

        throw t;
    }
}

From source file:net.freechoice.dao.impl.DaoUser.java

@Warning(values = { "injection" })
@Deprecated/*from  ww w  .j a  v a 2  s  .c om*/
@Override
public AvgUser getRoleByEmail(final String email) {

    AvgUser role = null;

    SqlRowSet rowSet = getJdbcTemplate().queryForRowSet("select U.id, U.password, U.name_login, M.value "
            + " from FC_User as U left outer join FC_User_Meta as M " + " on U.id = M.id_user_ "
            + " where U.is_valid = true and email = " + quote(email) + " and M.key = " + SuperUser.TIME_EXPIRE);
    if (rowSet.next()) {
        if (rowSet.isLast()) {
            /**
             * only super user have expire time
             */
            String timeExpire = rowSet.getString(4);
            if (timeExpire == null || (timeExpire != null && DateUtil.hasExpired(timeExpire))) {

                role = new AvgUser();
            } else {
                role = new SuperUser();
            }
            role.id = rowSet.getInt(1);
            role.hashedPswWithSalt = rowSet.getString(2);
            role.name_login = rowSet.getString(3);
            role.email = email;
        } else {
            throw new RuntimeException("multiple user found, should be one only");
        }
    }
    return role;
}

From source file:org.restsql.core.impl.AbstractSqlResourceMetaData.java

private void buildJoinTableMetadata() {
    // Join table could have been identified in buildTablesAndColumns(), but
    // not always
    final Table joinDef = SqlResourceDefinitionUtils.getTable(definition, TableRole.Join);
    if (joinDef != null && joinTable == null) {
        // Determine table and database name
        String tableName, databaseName;
        final String possiblyQualifiedTableName = joinDef.getName();
        final int dotIndex = possiblyQualifiedTableName.indexOf('.');
        if (dotIndex > 0) {
            tableName = possiblyQualifiedTableName.substring(0, dotIndex);
            databaseName = possiblyQualifiedTableName.substring(dotIndex + 1);
        } else {//from  ww w. j a va2  s .  c  o m
            tableName = possiblyQualifiedTableName;
            databaseName = SqlResourceDefinitionUtils.getDefaultDatabase(definition);
        }

        final String qualifiedTableName = getQualifiedTableName(databaseName, tableName);

        // Create table and add to special lists
        joinTable = new TableMetaDataImpl(tableName, qualifiedTableName, databaseName, TableRole.Join);
        tableMap.put(joinTable.getQualifiedTableName(), joinTable);
        tables.add(joinTable);
        joinList = new ArrayList<TableMetaData>(1);
        joinList.add(joinTable);

        // Execute metadata query and populate metadata structure

        SqlRowSet resultSet = null;

        resultSet = this.jdbcTemplate.queryForRowSet(getSqlColumnsQuery(), databaseName, tableName);
        while (resultSet.next()) {
            final String columnName = resultSet.getString(1);
            final ColumnMetaDataImpl column = new ColumnMetaDataImpl(databaseName, qualifiedTableName,
                    tableName, TableRole.Join, columnName, columnName, resultSet.getString(2), this);
            ((TableMetaDataImpl) joinTable).addColumn(column);
        }

    }
}

From source file:nl.surfnet.coin.teams.service.impl.GroupProviderServiceSQLImpl.java

private List<ConversionRule> getIdConverters(SqlRowSet sqlRowSet) {
    Map<Integer, ConversionRule> idConverterMap = new HashMap<Integer, ConversionRule>();
    ConversionRule converter;/* w  w  w. j  av a 2  s .co  m*/
    Integer ruleId;

    final String id = "id";
    final String nameCol = "name";
    final String valueCol = "value";
    final String name_search = "search";
    final String name_replace = "replace";
    final String name_property = "property";

    while (sqlRowSet.next()) {
        ruleId = sqlRowSet.getInt(id);

        if (idConverterMap.containsKey(ruleId)) {
            converter = idConverterMap.get(ruleId);
        } else {
            converter = new ConversionRule();
            converter.setPropertyName(id);
        }

        final String name = sqlRowSet.getString(nameCol);
        final String value = sqlRowSet.getString(valueCol);
        if (name_search.equals(name)) {
            converter.setSearchPattern(value);
        }
        if (name_replace.equals(name)) {
            converter.setReplaceWith(value);
        }
        if (name_property.equals(name)) {
            converter.setPropertyName(value);
        }
        idConverterMap.put(ruleId, converter);
    }
    return new ArrayList<ConversionRule>(idConverterMap.values());
}