if (c.getValue() instanceof String) String func = c.getValue().toString(); func = func.replaceAll(" ", ""); if (func.toUpperCase().matches(FUNCTION_KEYWORDS[i])) c.setValue(func); break outer; String columName = getColumnName(m, metaModel.entity(m.getEntityClazz()), c.getProperty()); boolean isSpecialFunction = false; for (int i = 0; i < FUNCTION_KEYWORDS.length; i++) if (c.getValue() instanceof String && c.getValue().toString().toUpperCase().matches(FUNCTION_KEYWORDS[i])) if (c.getValue().toString().toUpperCase().startsWith("INCREMENT(")) String val = c.getValue().toString().toUpperCase(); val = val.substring(10, val.indexOf(")")); update.put("$inc", new BasicDBObject(columName, Integer.valueOf(val))); else if (c.getValue().toString().toUpperCase().startsWith("DECREMENT(")) String val = c.getValue().toString().toUpperCase(); val = val.substring(10, val.indexOf(")")); update.put("$inc", new BasicDBObject(columName, -Integer.valueOf(val))); update.put(columName, c.getValue());
/** * Adds the update clause. * * @param property * the property * @param value * the value */ public void addUpdateClause(final String property, final String value) { UpdateClause updateClause = new UpdateClause(property.trim(), value.trim()); updateClauseQueue.add(updateClause); addTypedParameter( value.trim().startsWith("?") ? Type.INDEXED : value.trim().startsWith(":") ? Type.NAMED : null, property, updateClause); }
if (c.getValue() instanceof String) String func = c.getValue().toString(); func = func.replaceAll(" ", ""); if (func.toUpperCase().matches(FUNCTION_KEYWORDS[i])) c.setValue(func); break outer; String columName = getColumnName(m, metaModel.entity(m.getEntityClazz()), c.getProperty()); boolean isSpecialFunction = false; for (int i = 0; i < FUNCTION_KEYWORDS.length; i++) if (c.getValue() instanceof String && c.getValue().toString().toUpperCase().matches(FUNCTION_KEYWORDS[i])) if (c.getValue().toString().toUpperCase().startsWith("INCREMENT(")) String val = c.getValue().toString().toUpperCase(); val = val.substring(10, val.indexOf(")")); update.put("$inc", new BasicDBObject(columName, Integer.valueOf(val))); else if (c.getValue().toString().toUpperCase().startsWith("DECREMENT(")) String val = c.getValue().toString().toUpperCase(); val = val.substring(10, val.indexOf(")")); update.put("$inc", new BasicDBObject(columName, -Integer.valueOf(val))); update.put(columName, c.getValue());
String property = updateClause.getProperty(); Object value = updateClause.getValue();
String columnName = c.getProperty(); try if (c.getValue() instanceof String) PropertyAccessorHelper.set(result, (Field) attribute.getJavaMember(), c.getValue() .toString()); PropertyAccessorHelper.set(result, (Field) attribute.getJavaMember(), c.getValue());
Assert.assertNotNull(clause.getProperty()); Assert.assertNotNull(clause.getValue()); Assert.assertNotNull(clause.getClass()); Assert.assertNotNull(clause.toString());
String property = updateClause.getProperty(); Object value = updateClause.getValue();
for (UpdateClause q : kunderaQuery.getUpdateClauseQueue()) Assert.assertEquals("population", q.getProperty()); Assert.assertEquals("10", q.getValue()); Assert.assertEquals("population", result[0].getProperty()); Assert.assertEquals("10", result[0].getValue()); Assert.assertEquals("name", result[1].getProperty()); Assert.assertEquals("vivek", result[1].getValue());
if (updateClause != null) { List<Object> value = new ArrayList<Object>(); value.add(updateClause.getValue()); return value;
/** * Sets parameter value into filterClause, depending upon {@link Type}. * * @param name * parameter name. * @param value * parameter value. */ private void setParameterValue(String name, Object value) { if (typedParameter != null) { List<FilterClause> clauses = typedParameter.getParameters() != null ? typedParameter.getParameters().get(name) : null; if (clauses != null) { for (FilterClause clause : clauses) { clause.setValue(value); } } else { if (typedParameter.getUpdateParameters() != null) { UpdateClause updateClause = typedParameter.getUpdateParameters().get(name); updateClause.setValue(value); } else { logger.error("Error while setting parameter."); throw new QueryHandlerException("named parameter : " + name + " not found!"); } } } else { throw new QueryHandlerException("No named parameter present for query"); } }
/** * Inits the update clause. */ private void initUpdateClause() { for (UpdateClause updateClause : updateClauseQueue) { onTypedParameter(updateClause.getValue(), updateClause, updateClause.getProperty().trim()); } }