Example usage for org.springframework.jdbc.object SqlUpdate setGeneratedKeysColumnNames

List of usage examples for org.springframework.jdbc.object SqlUpdate setGeneratedKeysColumnNames

Introduction

In this page you can find the example usage for org.springframework.jdbc.object SqlUpdate setGeneratedKeysColumnNames.

Prototype

public void setGeneratedKeysColumnNames(@Nullable String... names) 

Source Link

Document

Set the column names of the auto-generated keys.

Usage

From source file:org.agnitas.dao.impl.ImportProfileDaoImpl.java

public int insertImportProfile(ImportProfile importProfile) {
    int profileId;
    if (AgnUtils.isOracleDB()) {
        logSqlStatement(logger, SELECT_NEXT_PROFILEID);
        profileId = getSimpleJdbcTemplate().queryForInt(SELECT_NEXT_PROFILEID);

        logSqlStatement(logger, INSERT_ORACLE);
        getSimpleJdbcTemplate().update(INSERT_ORACLE, profileId, importProfile.getCompanyId(),
                importProfile.getAdminId(), importProfile.getName(), importProfile.getSeparator(),
                importProfile.getTextRecognitionChar(), importProfile.getCharset(),
                importProfile.getDateFormat(), importProfile.getImportMode(),
                importProfile.getNullValuesAction(), importProfile.getKeyColumn(),
                ImportUtils.getBooleanAsInt(importProfile.getExtendedEmailCheck()),
                importProfile.getMailForReport(), importProfile.getCheckForDuplicates(),
                importProfile.getDefaultMailType(),
                ImportUtils.getBooleanAsInt(importProfile.getUpdateAllDuplicates()));
    } else {/* w ww  . ja v  a 2s .co m*/
        logSqlStatement(logger, INSERT_MYSQL);
        SqlUpdate sqlUpdate = new SqlUpdate(getDataSource(), INSERT_MYSQL,
                new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
                        Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR,
                        Types.BOOLEAN, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.BOOLEAN });
        sqlUpdate.setReturnGeneratedKeys(true);
        sqlUpdate.setGeneratedKeysColumnNames(new String[] { FIELD_ID });
        sqlUpdate.compile();
        GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();
        Object[] values = new Object[] { importProfile.getCompanyId(), importProfile.getAdminId(),
                importProfile.getName(), importProfile.getSeparator(), importProfile.getTextRecognitionChar(),
                importProfile.getCharset(), importProfile.getDateFormat(), importProfile.getImportMode(),
                importProfile.getNullValuesAction(), importProfile.getKeyColumn(),
                ImportUtils.getBooleanAsInt(importProfile.getExtendedEmailCheck()),
                importProfile.getMailForReport(), importProfile.getCheckForDuplicates(),
                importProfile.getDefaultMailType(),
                ImportUtils.getBooleanAsInt(importProfile.getUpdateAllDuplicates()) };
        sqlUpdate.update(values, generatedKeyHolder);
        profileId = generatedKeyHolder.getKey().intValue();
    }

    importProfile.setId(profileId);
    insertColumnMappings(importProfile.getColumnMapping(), importProfile.getId());
    insertGenderMappings(importProfile.getGenderMapping(), importProfile.getId());

    return importProfile.getId();
}