List of usage examples for org.springframework.jdbc.core.namedparam SqlParameterSource getValue
@Nullable
Object getValue(String paramName) throws IllegalArgumentException;
From source file:com.opengamma.elsql.LikeSqlFragment.java
@Override protected void toSQL(StringBuilder buf, ElSqlBundle bundle, SqlParameterSource paramSource) { String value = ObjectUtils.toString(paramSource.getValue(_variable)); if (bundle.getConfig().isLikeWildcard(value)) { buf.append("LIKE "); super.toSQL(buf, bundle, paramSource); buf.append(bundle.getConfig().getLikeSuffix()); } else {// w w w . ja va2 s . c o m buf.append("= "); super.toSQL(buf, bundle, paramSource); } }
From source file:fr.acxio.tools.agia.item.database.FieldSetSqlParameterSourceProviderTest.java
@Test public void testNoName() { FieldSetSqlParameterSourceProvider aProvider = new FieldSetSqlParameterSourceProvider(); FieldSet aFieldSet = new DefaultFieldSet(new String[] { "Facture", "2222.22", "2014-08-01T12:00:00.000" }); SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSet); assertNotNull(aResult);//from ww w . j a v a2 s . co m assertEquals("Facture", aResult.getValue("rec0_ucol0")); assertEquals("2222.22", aResult.getValue("rec0_ucol1")); assertEquals("2014-08-01T12:00:00.000", aResult.getValue("rec0_ucol2")); assertFalse(aResult.hasValue("rec1_ucol0")); }
From source file:fr.acxio.tools.agia.item.database.FieldSetSqlParameterSourceProviderTest.java
@Test public void test() { FieldSetSqlParameterSourceProvider aProvider = new FieldSetSqlParameterSourceProvider(); FieldSet aFieldSet = new DefaultFieldSet(new String[] { "Facture", "2222.22", "2014-08-01T12:00:00.000" }, new String[] { "TypeDoc", "Montant", "Date" }); SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSet); assertNotNull(aResult);/*from w w w. ja v a 2 s . co m*/ assertEquals("Facture", aResult.getValue("rec0_TypeDoc")); assertEquals("2222.22", aResult.getValue("rec0_Montant")); assertEquals("2014-08-01T12:00:00.000", aResult.getValue("rec0_Date")); assertFalse(aResult.hasValue("rec1_TypeDoc")); }
From source file:fr.acxio.tools.agia.item.database.FieldSetSqlParameterSourceProviderTest.java
@Test public void testEmptyNames() { FieldSetSqlParameterSourceProvider aProvider = new FieldSetSqlParameterSourceProvider(); FieldSet aFieldSet = new DefaultFieldSet(new String[] { "Facture", "2222.22", "2014-08-01T12:00:00.000" }, new String[] { "", "", "" }); SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSet); assertNotNull(aResult);//from ww w. ja va 2s. c o m assertEquals("Facture", aResult.getValue("rec0_ucol0")); assertEquals("2222.22", aResult.getValue("rec0_ucol1")); assertEquals("2014-08-01T12:00:00.000", aResult.getValue("rec0_ucol2")); assertFalse(aResult.hasValue("rec1_ucol0")); }
From source file:fr.acxio.tools.agia.item.database.FieldSetSqlParameterSourceProviderTest.java
@Test public void testNullNames() { FieldSetSqlParameterSourceProvider aProvider = new FieldSetSqlParameterSourceProvider(); FieldSet aFieldSet = new DefaultFieldSet(new String[] { "Facture", "2222.22", "2014-08-01T12:00:00.000" }, new String[] { null, null, null }); SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSet); assertNotNull(aResult);/* w ww . j a v a 2 s .c om*/ assertEquals("Facture", aResult.getValue("rec0_ucol0")); assertEquals("2222.22", aResult.getValue("rec0_ucol1")); assertEquals("2014-08-01T12:00:00.000", aResult.getValue("rec0_ucol2")); assertFalse(aResult.hasValue("rec1_ucol0")); }
From source file:fr.acxio.tools.agia.item.database.FieldSetSqlParameterSourceProviderTest.java
@Test public void testNoNameNewPrefix() { FieldSetSqlParameterSourceProvider aProvider = new FieldSetSqlParameterSourceProvider(); aProvider.setFieldsetNamePrefix("field"); aProvider.setUnnamedColumnPrefix("column"); FieldSet aFieldSet = new DefaultFieldSet(new String[] { "Facture", "2222.22", "2014-08-01T12:00:00.000" }); SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSet); assertNotNull(aResult);//from w w w.j a va 2 s. c o m assertEquals("Facture", aResult.getValue("field0_column0")); assertEquals("2222.22", aResult.getValue("field0_column1")); assertEquals("2014-08-01T12:00:00.000", aResult.getValue("field0_column2")); assertFalse(aResult.hasValue("field1_column0")); }
From source file:fr.acxio.tools.agia.item.database.ListFieldSetSqlParameterSourceProviderTest.java
@Test public void testNoName() { ListFieldSetSqlParameterSourceProvider aProvider = new ListFieldSetSqlParameterSourceProvider(); List<FieldSet> aFieldSetList = new ArrayList<FieldSet>(1); aFieldSetList.add(new DefaultFieldSet(new String[] { "Facture", "2222.22", "2014-08-01T12:00:00.000" })); aFieldSetList.add(new DefaultFieldSet(new String[] { "Avoir", "-333.00", "" })); SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSetList); assertNotNull(aResult);//from w ww .j a v a2 s . co m assertEquals("Facture", aResult.getValue("rec0_ucol0")); assertEquals("2222.22", aResult.getValue("rec0_ucol1")); assertEquals("2014-08-01T12:00:00.000", aResult.getValue("rec0_ucol2")); assertEquals("Avoir", aResult.getValue("rec1_ucol0")); assertEquals("-333.00", aResult.getValue("rec1_ucol1")); assertEquals("", aResult.getValue("rec1_ucol2")); assertFalse(aResult.hasValue("rec2_ucol0")); }
From source file:fr.acxio.tools.agia.item.database.ListFieldSetSqlParameterSourceProviderTest.java
@Test public void test() { ListFieldSetSqlParameterSourceProvider aProvider = new ListFieldSetSqlParameterSourceProvider(); List<FieldSet> aFieldSetList = new ArrayList<FieldSet>(2); aFieldSetList.add(new DefaultFieldSet(new String[] { "Facture", "2222.22", "2014-08-01T12:00:00.000" }, new String[] { "TypeDoc", "Montant", "Date" })); aFieldSetList.add(new DefaultFieldSet(new String[] { "Avoir", "-333.00", "" }, new String[] { "TypeDoc", "Montant", "Date" })); SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSetList); assertNotNull(aResult);/*from w w w . j a v a2 s . c om*/ assertEquals("Facture", aResult.getValue("rec0_TypeDoc")); assertEquals("2222.22", aResult.getValue("rec0_Montant")); assertEquals("2014-08-01T12:00:00.000", aResult.getValue("rec0_Date")); assertEquals("Avoir", aResult.getValue("rec1_TypeDoc")); assertEquals("-333.00", aResult.getValue("rec1_Montant")); assertEquals("", aResult.getValue("rec1_Date")); assertFalse(aResult.hasValue("rec2_TypeDoc")); }
From source file:com.opengamma.elsql.OffsetFetchSqlFragment.java
@Override protected void toSQL(StringBuilder buf, ElSqlBundle bundle, SqlParameterSource paramSource) { int offset = 0; int fetchLimit = 0; if (_offsetVariable != null && paramSource.hasValue(_offsetVariable)) { offset = ((Number) paramSource.getValue(_offsetVariable)).intValue(); }//from w w w . j a v a2 s . c om if (paramSource.hasValue(_fetchVariable)) { fetchLimit = ((Number) paramSource.getValue(_fetchVariable)).intValue(); } else if (StringUtils.containsOnly(_fetchVariable, "0123456789")) { fetchLimit = Integer.parseInt(_fetchVariable); } buf.append(bundle.getConfig().getPaging(offset, fetchLimit == Integer.MAX_VALUE ? 0 : fetchLimit)); }
From source file:com.opengamma.elsql.PagingSqlFragment.java
/** * Applies the paging.//from w w w.java 2s .co m * * @param selectToPage the contents of the enclosed block, not null * @param bundle the elsql bundle for context, not null * @param paramSource the SQL parameters, not null */ protected String applyPaging(String selectToPage, ElSqlBundle bundle, SqlParameterSource paramSource) { int offset = 0; int fetchLimit = 0; if (_offsetVariable != null && paramSource.hasValue(_offsetVariable)) { offset = ((Number) paramSource.getValue(_offsetVariable)).intValue(); } if (paramSource.hasValue(_fetchVariable)) { fetchLimit = ((Number) paramSource.getValue(_fetchVariable)).intValue(); } else if (StringUtils.containsOnly(_fetchVariable, "0123456789")) { fetchLimit = Integer.parseInt(_fetchVariable); } return bundle.getConfig().addPaging(selectToPage, offset, fetchLimit == Integer.MAX_VALUE ? 0 : fetchLimit); }