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);
}
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);
}
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());
}
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);
}
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);
}
Aggregations