use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project perun by CESNET.
the class UsersManagerImpl method getUsersByAttributeValue.
public List<User> getUsersByAttributeValue(PerunSession sess, AttributeDefinition attributeDefinition, String attributeValue) throws InternalErrorException {
String value = "";
String operator = "=";
if (attributeDefinition.getType().equals(String.class.getName())) {
value = attributeValue.trim();
operator = "=";
} else if (attributeDefinition.getType().equals(Integer.class.getName())) {
value = attributeValue.trim();
operator = "=";
} else if (attributeDefinition.getType().equals(Boolean.class.getName())) {
value = attributeValue.trim();
operator = "=";
} else if (attributeDefinition.getType().equals(ArrayList.class.getName())) {
value = "%" + attributeValue.trim() + "%";
operator = "like";
} else if (attributeDefinition.getType().equals(LinkedHashMap.class.getName())) {
value = "%" + attributeValue.trim() + "%";
operator = "like";
}
// FIXME - this doesn't work for map attributes, since they are not in attr_value column
// if fixed, we could add LargeString and LargeArrayList
String query = "select " + userMappingSelectQuery + " from users, user_attr_values where " + " user_attr_values.attr_value " + operator + " :value and users.id=user_attr_values.user_id and user_attr_values.attr_id=:attr_id";
MapSqlParameterSource namedParams = new MapSqlParameterSource();
namedParams.addValue("value", value);
namedParams.addValue("attr_id", attributeDefinition.getId());
try {
return namedParameterJdbcTemplate.query(query, namedParams, USER_MAPPER);
} catch (EmptyResultDataAccessException e) {
return new ArrayList<User>();
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project spring-framework by spring-projects.
the class SimpleJdbcCallTests method testAddInvoiceFuncWithMetaDataUsingMapParamSource.
@Test
public void testAddInvoiceFuncWithMetaDataUsingMapParamSource() throws Exception {
initializeAddInvoiceWithMetaData(true);
SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withFunctionName("add_invoice");
Number newId = adder.executeFunction(Number.class, new MapSqlParameterSource().addValue("amount", 1103).addValue("custid", 3));
assertEquals(4, newId.intValue());
verifyAddInvoiceWithMetaData(true);
verify(connection, atLeastOnce()).close();
}
use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project topjava10 by JavaWebinar.
the class JdbcMealRepositoryImpl method save.
@Override
@Transactional
public Meal save(Meal meal, int userId) {
MapSqlParameterSource map = new MapSqlParameterSource().addValue("id", meal.getId()).addValue("description", meal.getDescription()).addValue("calories", meal.getCalories()).addValue("date_time", meal.getDateTime()).addValue("user_id", userId);
if (meal.isNew()) {
Number newId = insertMeal.executeAndReturnKey(map);
meal.setId(newId.intValue());
} else {
if (namedParameterJdbcTemplate.update("" + "UPDATE meals " + " SET description=:description, calories=:calories, date_time=:date_time " + " WHERE id=:id AND user_id=:user_id", map) == 0) {
return null;
}
}
return meal;
}
use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project sakuli by ConSol.
the class DaoTestCaseImpl method saveTestCaseResult.
@Override
public void saveTestCaseResult(final TestCase testCase) {
LOGGER.info("Save results for test case \"" + testCase.getId() + "\"");
//create a map for the sql parameters
MapSqlParameterSource tcParameters = new MapSqlParameterSource();
tcParameters.addValue("sakuli_suites_id", testSuite.getDbPrimaryKey());
tcParameters.addValue("caseID", testCase.getId());
tcParameters.addValue("result", testCase.getState().getErrorCode());
tcParameters.addValue("result_desc", testCase.getState());
tcParameters.addValue("name", testCase.getName());
tcParameters.addValue("guid", testSuite.getGuid());
tcParameters.addValue("start", testCase.getStartDateAsUnixTimestamp());
tcParameters.addValue("stop", testCase.getStopDateAsUnixTimestamp());
int warningTime = testCase.getWarningTime();
tcParameters.addValue("warning", (warningTime != 0) ? warningTime : null);
int criticalTime = testCase.getCriticalTime();
tcParameters.addValue("critical", (criticalTime != 0) ? criticalTime : null);
tcParameters.addValue("browser", testSuite.getBrowserInfo());
tcParameters.addValue("lastpage", testCase.getLastURL());
//try to save the screenshot
tcParameters.addValue("screenshot", getScreenshotAsSqlLobValue(testCase), Types.BLOB);
tcParameters.addValue("duration", testCase.getDuration());
tcParameters.addValue("msg", testCase.getExceptionMessages(true));
//generate the sql-statement
SimpleJdbcInsert insertTCResults = new SimpleJdbcInsert(getDataSource()).withTableName("sakuli_cases").usingGeneratedKeyColumns("id");
LOGGER.debug("write the following values to 'sakuli_cases': " + tcParameters.getValues() + " => now execute ....");
int dbPrimaryKey = insertTCResults.executeAndReturnKey(tcParameters).intValue();
LOGGER.info("test case '" + testCase.getId() + "' has been written to 'sahi_cases' with primaryKey=" + dbPrimaryKey);
testCase.setDbPrimaryKey(dbPrimaryKey);
}
use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project sakuli by ConSol.
the class DaoTestCaseStepImpl method saveTestCaseSteps.
@Override
public void saveTestCaseSteps(SortedSet<TestCaseStep> steps, int primaryKeyOfTestCase) {
for (TestCaseStep step : steps) {
LOGGER.info("============== save STEP \"" + step.getName() + "\" ==============");
MapSqlParameterSource stepParameters = new MapSqlParameterSource();
stepParameters.addValue("sakuli_cases_id", primaryKeyOfTestCase);
stepParameters.addValue("result", step.getState().getErrorCode());
stepParameters.addValue("result_desc", step.getState());
stepParameters.addValue("name", step.getName());
stepParameters.addValue("start", step.getStartDateAsUnixTimestamp());
stepParameters.addValue("stop", step.getStopDateAsUnixTimestamp());
int warningTime = step.getWarningTime();
stepParameters.addValue("warning", (warningTime != 0) ? warningTime : null);
stepParameters.addValue("duration", step.getDuration());
LOGGER.debug("write the following values to 'sakuli_steps': " + stepParameters.getValues() + "\n now execute ....");
//generate the sql-statement
SimpleJdbcInsert insertStepResults = new SimpleJdbcInsert(getDataSource()).withTableName("sakuli_steps").usingGeneratedKeyColumns("id");
//execute the sql-statement and save the primary key
int dbPrimaryKey = insertStepResults.executeAndReturnKey(stepParameters).intValue();
LOGGER.info("test case step '" + step.getName() + "' has been written to 'sakuli_steps' with primaryKey=" + dbPrimaryKey);
step.setDbPrimaryKey(dbPrimaryKey);
}
}
Aggregations