use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class BaseExecutorTest method shouldSelectTwoSetsOfAuthorsViaProc.
@Test
public void shouldSelectTwoSetsOfAuthorsViaProc() throws Exception {
Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
try {
MappedStatement selectStatement = ExecutorTestHelper.prepareSelectTwoSetsOfAuthorsProc(config);
List<List<Author>> authorSets = executor.query(selectStatement, new HashMap<String, Object>() {
{
put("id1", 101);
put("id2", 102);
}
}, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
assertEquals(2, authorSets.size());
for (List<Author> authors : authorSets) {
assertEquals(2, authors.size());
for (Object author : authors) {
assertTrue(author instanceof Author);
}
}
} finally {
executor.rollback(true);
executor.close(false);
}
}
use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class ExecutorTestHelper method prepareSelectOneAuthorMappedStatementWithConstructorResults.
public static MappedStatement prepareSelectOneAuthorMappedStatementWithConstructorResults(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
MappedStatement ms = new MappedStatement.Builder(config, "selectAuthor", new StaticSqlSource(config, "SELECT * FROM author WHERE id = ?"), SqlCommandType.SELECT).parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {
{
add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
}
}).build()).resultMaps(new ArrayList<ResultMap>() {
{
add(new ResultMap.Builder(config, "defaultResultMap", Author.class, new ArrayList<ResultMapping>() {
{
add(new ResultMapping.Builder(config, null, "id", registry.getTypeHandler(Integer.class)).javaType(int.class).flags(new ArrayList<ResultFlag>() {
{
add(ResultFlag.CONSTRUCTOR);
}
}).build());
add(new ResultMapping.Builder(config, "username", "username", registry.getTypeHandler(String.class)).build());
add(new ResultMapping.Builder(config, "password", "password", registry.getTypeHandler(String.class)).build());
add(new ResultMapping.Builder(config, "email", "email", registry.getTypeHandler(String.class)).build());
add(new ResultMapping.Builder(config, "bio", "bio", registry.getTypeHandler(String.class)).build());
add(new ResultMapping.Builder(config, "favouriteSection", "favourite_section", registry.getTypeHandler(Section.class)).build());
}
}).build());
}
}).cache(authorCache).build();
return ms;
}
use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class BaseExecutorTest method shouldUpdateAuthor.
@Test
public void shouldUpdateAuthor() throws Exception {
Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
try {
Author author = new Author(101, "someone", "******", "someone@apache.org", null, Section.NEWS);
MappedStatement updateStatement = ExecutorTestHelper.prepareUpdateAuthorMappedStatement(config);
MappedStatement selectStatement = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
int rows = executor.update(updateStatement, author);
List<Author> authors = executor.query(selectStatement, 101, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
executor.flushStatements();
executor.rollback(true);
assertEquals(1, authors.size());
assertEquals(author.toString(), authors.get(0).toString());
assertTrue(1 == rows || BatchExecutor.BATCH_UPDATE_RETURN_VALUE == rows);
} finally {
executor.rollback(true);
executor.close(false);
}
}
use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class BaseExecutorTest method shouldInsertNewAuthorUsingSimpleNonPreparedStatements.
@Test
public void shouldInsertNewAuthorUsingSimpleNonPreparedStatements() throws Exception {
Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
try {
Author author = new Author(99, "someone", "******", "someone@apache.org", null, null);
MappedStatement insertStatement = ExecutorTestHelper.createInsertAuthorWithIDof99MappedStatement(config);
MappedStatement selectStatement = ExecutorTestHelper.createSelectAuthorWithIDof99MappedStatement(config);
int rows = executor.update(insertStatement, null);
List<Author> authors = executor.query(selectStatement, 99, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
executor.flushStatements();
executor.rollback(true);
assertEquals(1, authors.size());
assertEquals(author.toString(), authors.get(0).toString());
assertTrue(1 == rows || BatchExecutor.BATCH_UPDATE_RETURN_VALUE == rows);
} finally {
executor.rollback(true);
executor.close(false);
}
}
use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class ExpressionEvaluatorTest method shouldCompareStringsReturnFalse.
@Test
public void shouldCompareStringsReturnFalse() {
boolean value = evaluator.evaluateBoolean("username == 'norm'", new Author(1, "cbegin", "******", "cbegin@apache.org", "N/A", Section.NEWS));
assertEquals(false, value);
}
Aggregations