Example usage for org.springframework.jdbc.core.namedparam SqlParameterSource hasValue

List of usage examples for org.springframework.jdbc.core.namedparam SqlParameterSource hasValue

Introduction

In this page you can find the example usage for org.springframework.jdbc.core.namedparam SqlParameterSource hasValue.

Prototype

boolean hasValue(String paramName);

Source Link

Document

Determine whether there is a value for the specified named parameter.

Usage

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();
    }/*w  w  w.j  a  v a  2s  . co  m*/
    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./*w  w w  . j  ava 2s  .c om*/
 * 
 * @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);
}

From source file:fr.acxio.tools.agia.item.database.ListFieldSetSqlParameterSourceProviderTest.java

@Test
public void testNull() {
    ListFieldSetSqlParameterSourceProvider aProvider = new ListFieldSetSqlParameterSourceProvider();
    SqlParameterSource aResult = aProvider.createSqlParameterSource(null);
    assertNotNull(aResult);//  w ww  .j a  va2 s  .  c  o  m
    assertFalse(aResult.hasValue("rec0_TypeDoc"));
}

From source file:fr.acxio.tools.agia.item.database.FieldSetSqlParameterSourceProviderTest.java

@Test
public void testNull() {
    FieldSetSqlParameterSourceProvider aProvider = new FieldSetSqlParameterSourceProvider();
    SqlParameterSource aResult = aProvider.createSqlParameterSource(null);
    assertNotNull(aResult);//from   w  ww. ja v  a2 s.c  om
    assertFalse(aResult.hasValue("rec0_TypeDoc"));
}

From source file:fr.acxio.tools.agia.item.database.ListFieldSetSqlParameterSourceProviderTest.java

@Test
public void testEmpty() {
    ListFieldSetSqlParameterSourceProvider aProvider = new ListFieldSetSqlParameterSourceProvider();
    List<FieldSet> aFieldSetList = new ArrayList<FieldSet>(1);
    SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSetList);
    assertNotNull(aResult);//from  w  ww .j  a va 2 s  . c  om
    assertFalse(aResult.hasValue("rec0_TypeDoc"));
}

From source file:fr.acxio.tools.agia.item.database.FieldSetSqlParameterSourceProviderTest.java

@Test
public void testEmpty() {
    FieldSetSqlParameterSourceProvider aProvider = new FieldSetSqlParameterSourceProvider();
    FieldSet aFieldSet = new DefaultFieldSet(new String[] {}, new String[] {});
    SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSet);
    assertNotNull(aResult);//from  w  w  w .ja  va2  s.c  o  m
    assertFalse(aResult.hasValue("rec0_TypeDoc"));
}

From source file:fr.acxio.tools.agia.item.database.ListFieldSetSqlParameterSourceProviderTest.java

@Test
public void testEmptyFieldSet() {
    ListFieldSetSqlParameterSourceProvider aProvider = new ListFieldSetSqlParameterSourceProvider();
    List<FieldSet> aFieldSetList = new ArrayList<FieldSet>(1);
    aFieldSetList.add(new DefaultFieldSet(new String[] {}, new String[] {}));
    SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSetList);
    assertNotNull(aResult);/*  www. j av  a 2  s .  c o  m*/
    assertFalse(aResult.hasValue("rec0_TypeDoc"));
}

From source file:fr.acxio.tools.agia.item.database.ListFieldSetSqlParameterSourceProviderTest.java

@Test
public void testNullFieldSet() {
    ListFieldSetSqlParameterSourceProvider aProvider = new ListFieldSetSqlParameterSourceProvider();
    List<FieldSet> aFieldSetList = new ArrayList<FieldSet>(1);
    aFieldSetList.add(null);/*from w w  w .  j a va 2 s .c o m*/
    SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSetList);
    assertNotNull(aResult);
    assertFalse(aResult.hasValue("rec0_TypeDoc"));
}

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  w  w  w  . j a v  a  2  s .com
    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 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  w ww .j av a 2  s .com
    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"));
}