Search in sources :

Example 11 with SqlBind

use of org.eclipse.scout.rt.server.jdbc.SqlBind in project scout.rt by eclipse.

the class AbstractSqlStyle method buildBindFor.

@Override
public SqlBind buildBindFor(Object o, Class nullType) {
    if (o instanceof IHolder) {
        IHolder h = (IHolder) o;
        o = h.getValue();
        nullType = h.getHolderType();
    }
    // 
    Class c;
    if (o != null) {
        c = o.getClass();
    } else {
        if (nullType != null && IHolder.class.isAssignableFrom(nullType)) {
            try {
                nullType = TypeCastUtility.getGenericsParameterClass(nullType, IHolder.class);
            } catch (RuntimeException t) {
                LOG.debug("Could not determine type parameter class", t);
                nullType = null;
            }
        }
        c = nullType;
    }
    // 
    if (o == null && c == null) {
        return new SqlBind(Types.NULL, o);
    }
    return createBindFor(o, c);
}
Also used : SqlBind(org.eclipse.scout.rt.server.jdbc.SqlBind) IHolder(org.eclipse.scout.rt.platform.holders.IHolder)

Example 12 with SqlBind

use of org.eclipse.scout.rt.server.jdbc.SqlBind in project scout.rt by eclipse.

the class AbstractSqlStyleTest method testWriteBindForNullBlob.

/**
 * Test for {@link AbstractSqlStyle#writeBind} for null values with nulltype {@link Blob}
 *
 * @throws SQLException
 */
@Test
public void testWriteBindForNullBlob() throws SQLException {
    PreparedStatement ps = Mockito.mock(PreparedStatement.class);
    SqlBind bind = new SqlBind(Types.BLOB, null);
    sql.writeBind(ps, 1, bind);
    Mockito.verify(ps).setBlob(1, (Blob) null);
}
Also used : SqlBind(org.eclipse.scout.rt.server.jdbc.SqlBind) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test)

Example 13 with SqlBind

use of org.eclipse.scout.rt.server.jdbc.SqlBind in project scout.rt by eclipse.

the class AbstractSqlStyleTest method testBuildBindForNullCharacter.

/**
 * Test for {@link AbstractSqlStyle#buildBindFor} for null values with nulltype {@link Character}.
 */
@Test
public void testBuildBindForNullCharacter() {
    SqlBind bin = sql.buildBindFor(null, Character.class);
    assertEquals(Types.VARCHAR, bin.getSqlType());
    assertNull(bin.getValue());
}
Also used : SqlBind(org.eclipse.scout.rt.server.jdbc.SqlBind) Test(org.junit.Test)

Example 14 with SqlBind

use of org.eclipse.scout.rt.server.jdbc.SqlBind in project scout.rt by eclipse.

the class AbstractSqlStyleTest method testBuildBindForCharacter.

/**
 * Test for {@link AbstractSqlStyle#buildBindFor} for {@link Character} with nulltype {@link Character}.
 */
@Test
public void testBuildBindForCharacter() {
    Character c = Character.valueOf('x');
    SqlBind bin = sql.buildBindFor(c, Character.class);
    assertEquals(Types.VARCHAR, bin.getSqlType());
    assertTrue(bin.getValue() instanceof String);
}
Also used : SqlBind(org.eclipse.scout.rt.server.jdbc.SqlBind) Test(org.junit.Test)

Example 15 with SqlBind

use of org.eclipse.scout.rt.server.jdbc.SqlBind in project scout.rt by eclipse.

the class StatementProcessorCreateSqlDumpTest method runDump.

private void runDump(String expected, StatementType type, String statement) {
    ISqlStyle style = Mockito.mock(ISqlStyle.class);
    Mockito.when(style.buildBindFor(23, null)).thenReturn(new SqlBind(4, 23));
    Mockito.when(style.toPlainText(23)).thenReturn("23");
    Mockito.when(style.buildBindFor("lorem", null)).thenReturn(new SqlBind(1, "lorem"));
    Mockito.when(style.toPlainText("lorem")).thenReturn("'lorem'");
    ISqlService callerService = Mockito.mock(ISqlService.class);
    Mockito.when(callerService.getSqlStyle()).thenReturn(style);
    Object[] bindBases = new Object[] { new NVPair("myKey", 23), new NVPair("myText", "lorem") };
    P_StatementProcessor_UnderTest statementProcessor = new P_StatementProcessor_UnderTest(callerService, statement, bindBases);
    String dump = statementProcessor.getDump(type);
    assertEquals(type.name() + " dump", expected, dump);
}
Also used : SqlBind(org.eclipse.scout.rt.server.jdbc.SqlBind) ISqlStyle(org.eclipse.scout.rt.server.jdbc.style.ISqlStyle) ISqlService(org.eclipse.scout.rt.server.jdbc.ISqlService) NVPair(org.eclipse.scout.rt.platform.holders.NVPair)

Aggregations

SqlBind (org.eclipse.scout.rt.server.jdbc.SqlBind)15 Test (org.junit.Test)9 PreparedStatement (java.sql.PreparedStatement)7 BigDecimal (java.math.BigDecimal)3 ISqlStyle (org.eclipse.scout.rt.server.jdbc.style.ISqlStyle)3 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 PlatformExceptionTranslator (org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1 IHolder (org.eclipse.scout.rt.platform.holders.IHolder)1 NVPair (org.eclipse.scout.rt.platform.holders.NVPair)1 ISqlService (org.eclipse.scout.rt.server.jdbc.ISqlService)1