/** * Build the AccountSQLCall object * * @return a AccountSQLCall */ public AccountSQLCall build() { final List<SQLParam> sqlParams = new ArrayList<SQLParam>(); // Update the password attribute, if defined and value is present if (resourcePassword != null) { setSqlValue(UNENCRYPT_PWD, resourcePassword); setSqlValue(PWD_DATE, currentDate); } else if (password != null) { setSqlValue(UNENCRYPT_PWD, password); setSqlValue(PWD_DATE, currentDate); } // Check required columns Assertions.nullCheck(sqlParamsMap.get(USER_NAME), Name.NAME); Assertions.nullCheck(sqlParamsMap.get(OWNER), OWNER); if (create) { Assertions.nullCheck(sqlParamsMap.get(UNENCRYPT_PWD), OperationalAttributes.PASSWORD_NAME); } final String fn = (create) ? CREATE_FNC : UPDATE_FNC; log.ok("getUserCallSQL: {0}", fn); StringBuilder body = new StringBuilder(); boolean first = true; for (CallParam par : CALL_PARAMS) { final String columnName = par.name; final String parameterExpress = par.expression; SQLParam val = getSqlParam(columnName); String nullParam = getNullParam(columnName); if (nullParam == null && val == null) { continue; // skip all non setup values } if (!first) body.append(", "); if (val != null) { // exact value has advantage body.append(MessageFormat.format(parameterExpress, Q)); sqlParams.add(val); } else if (nullParam != null) { body.append(MessageFormat.format(parameterExpress, nullParam)); } else { throw new IllegalStateException(); } first = false; } final String sql = createCallSQL(fn, body); log.ok("getUserCallSQL done"); return new AccountSQLCall(sql, sqlParams); }
/** * @param fn * @param body * @return The SQL string */ private String createCallSQL(final String fn, StringBuilder body) { // The SQL call update function SQL template final String FND_USER_CALL = "fnd_user_pkg."; return "{ call " + cfg.app() + FND_USER_CALL + fn + " ( " + body.toString() + " ) }"; }