/** * This method executes adds new user query on the azure SQL user table. * * @return userEntity */ public UserEntity saveNewUser(UserEntity user) throws Exception { LOGGER.info("[UserDAOImpl][saveNewUser] start "); int userId = 0; Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { connection = AzureChatUtils.getConnection(AzureChatUtils.buildConnectionString()); preparedStatement = connection.prepareStatement( AzureChatSQLConstants.SAVE_NEW_USER, Statement.RETURN_GENERATED_KEYS); preparedStatement = generatePreparedStatement(preparedStatement, user); preparedStatement.executeUpdate(); resultSet = preparedStatement.getGeneratedKeys(); if (resultSet.next()) { userId = resultSet.getInt(1); } } catch (Exception e) { LOGGER.error( "Exception occurred while executing save user query on azure SQL table. Exception Message : " + e.getMessage()); throw new AzureChatSystemException( "Exception occurred while executing save user query on azure SQL table. Exception Message : " + e.getMessage()); } finally { AzureChatUtils.closeDatabaseResources(preparedStatement, resultSet, connection); } user.setUserID(userId); LOGGER.info("[UserDAOImpl][saveNewUser] end "); return user; }
/** * This method populates userEntity from the result set object. * * @param resultSet * @return * @throws SQLException */ public UserEntity generateUserObject(ResultSet resultSet) throws SQLException { UserEntity user = new UserEntity(); user.setUserID(resultSet.getInt(1)); user.setNameId(resultSet.getString(2)); user.setIdentityProvider(resultSet.getString(3)); user.setFirstName(resultSet.getString(4)); user.setLastName(resultSet.getString(5)); user.setPhotoBlobUrl(resultSet.getString(6)); user.setEmailAddress(resultSet.getString(7)); user.setPhoneCountryCode(resultSet.getInt(8)); user.setPhoneNumber(resultSet.getLong(9)); user.setDateCreated(resultSet.getDate(10)); user.setCreatedBy(resultSet.getDate(11)); user.setDateModified(resultSet.getDate(12)); user.setModifiedBy(resultSet.getDate(13)); return user; }