use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class SettableDataSetterFactoryTest method testUDT.
@Test
public void testUDT() throws Exception {
UserType ut = newDBObjectUserType();
Setter<SettableByIndexData, DbObject> setter = factory.getSetter(newPM(DbObject.class, ut));
DbObject object = DbObject.newInstance();
setter.set(statement, object);
ArgumentCaptor<UDTValue> argumentCaptor = ArgumentCaptor.forClass(UDTValue.class);
verify(statement).setUDTValue(eq(0), argumentCaptor.capture());
UDTValue value = argumentCaptor.getValue();
assertUdtEqualsDbObject(value, object);
setter.set(statement, null);
verify(statement).setToNull(0);
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class ObjectClassMetaTest method testAliasProvider.
@Test
public void testAliasProvider() {
ReflectionService reflectionService = ReflectionService.newInstance().withAliasProvider(new AliasProvider() {
@Override
public String getAliasForMethod(Method method) {
if ("getName".equals(method.getName())) {
return "myname";
}
return null;
}
@Override
public String getAliasForField(Field field) {
if ("id".equals(field.getName())) {
return "myid";
}
return null;
}
@Override
public Table getTable(Class<?> target) {
return null;
}
});
ClassMeta<DbObject> classMeta = reflectionService.getClassMeta(DbObject.class);
PropertyFinder<DbObject> propertyFinder1 = classMeta.newPropertyFinder(propertyFilter);
// force non direct mode
propertyFinder1.findProperty(DefaultPropertyNameMatcher.of("email"), new Object[0]);
assertNotNull(propertyFinder1.findProperty(DefaultPropertyNameMatcher.of("myid"), new Object[0]));
assertNotNull(propertyFinder1.findProperty(DefaultPropertyNameMatcher.of("myname"), new Object[0]));
classMeta = ReflectionService.newInstance().getClassMeta(DbObject.class);
PropertyFinder<DbObject> propertyFinder2 = classMeta.newPropertyFinder(propertyFilter);
// force non direct mode
propertyFinder2.findProperty(DefaultPropertyNameMatcher.of("email"), new Object[0]);
assertNull(propertyFinder2.findProperty(DefaultPropertyNameMatcher.of("myid"), new Object[0]));
assertNull(propertyFinder2.findProperty(DefaultPropertyNameMatcher.of("myname"), new Object[0]));
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class ConvertDelegateSetterTest method testSet.
@Test
public void testSet() throws Exception {
ConvertDelegateSetter<DbObject, UUID, String> setter = new ConvertDelegateSetter<DbObject, UUID, String>(new Setter<DbObject, String>() {
@Override
public void set(DbObject target, String value) throws Exception {
target.setName(value);
}
}, new Converter<UUID, String>() {
@Override
public String convert(UUID in) throws Exception {
return in.toString();
}
});
DbObject o = new DbObject();
UUID uuid = UUID.randomUUID();
setter.set(o, uuid);
assertEquals(uuid.toString(), o.getName());
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class JdbcTemplateCrudTest method testCrudBatch.
@Test
public void testCrudBatch() throws SQLException {
JdbcTemplateCrud<DbObject, Long> objectCrud = JdbcTemplateMapperFactory.newInstance().<DbObject, Long>crud(DbObject.class, Long.class).to(template, "TEST_DB_OBJECT");
DbObject object = DbObject.newInstance();
assertNull(objectCrud.read(object.getId()));
// create
final List<DbObject> objects = Arrays.asList(object);
Long key = objectCrud.create(objects, new CheckedConsumer<Long>() {
Long key;
@Override
public void accept(Long aLong) throws Exception {
key = aLong;
}
}).key;
assertNull(key);
List<Long> keys = Arrays.asList(object.getId());
// read
assertEquals(objects, objectCrud.read(keys, new ListCollector<DbObject>()).getList());
object.setName("Udpdated");
// update
objectCrud.update(objects);
assertEquals(object, objectCrud.read(object.getId()));
// delete
objectCrud.delete(keys);
assertNull(objectCrud.read(key));
objectCrud.create(objects);
assertEquals(objects, objectCrud.read(keys, new ListCollector<DbObject>()).getList());
objectCrud.delete(keys);
try {
objectCrud.createOrUpdate(objects);
assertEquals(objects, objectCrud.read(keys, new ListCollector<DbObject>()).getList());
} catch (UnsupportedOperationException e) {
}
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class JdbcTemplateCrudTest method testLazyCrud.
@Test
public void testLazyCrud() throws SQLException {
// drop table if exist
try {
template.execute("DROP TABLE TEST_DB_OBJECT_LAZY");
} catch (Exception e) {
}
JdbcTemplateCrud<DbObject, Long> objectCrud = JdbcTemplateMapperFactory.newInstance().<DbObject, Long>crud(DbObject.class, Long.class).lazilyTo(template, "TEST_DB_OBJECT_LAZY");
template.execute("create table TEST_DB_OBJECT_LAZY(" + " id bigint primary key," + " name varchar(100), " + " email varchar(100)," + " creation_Time timestamp, type_ordinal int, type_name varchar(10) )");
DbObject object = DbObject.newInstance();
assertNull(objectCrud.read(object.getId()));
// create
Long key = objectCrud.create(object, new CheckedConsumer<Long>() {
Long key;
@Override
public void accept(Long aLong) throws Exception {
key = aLong;
}
}).key;
assertNull(key);
key = object.getId();
// read
assertEquals(object, objectCrud.read(key));
}
Aggregations