org.xblackcat.sjpu.storage.impl.SqlAnnotatedBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sjpu-dbah Show documentation
Show all versions of sjpu-dbah Show documentation
Service for generating DB access logic in simple way via interfaces and annotations
package org.xblackcat.sjpu.storage.impl;
import org.xblackcat.sjpu.storage.ann.QueryType;
import org.xblackcat.sjpu.storage.ann.Sql;
import org.xblackcat.sjpu.storage.consumer.IRowSetConsumer;
import org.xblackcat.sjpu.storage.converter.builder.ConverterInfo;
import org.xblackcat.sjpu.storage.typemap.TypeMapper;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
/**
* 11.03.13 13:18
*
* @author xBlackCat
*/
class SqlAnnotatedBuilder extends ASelectAnnotatedBuilder {
public SqlAnnotatedBuilder(TypeMapper typeMapper, Map, Class extends IRowSetConsumer>> rowSetConsumers) {
super(Sql.class, typeMapper, rowSetConsumers);
}
@Override
protected QueryType getQueryType(Method m) {
final String sql = getAnnotation(m).value();
final QueryType type;
{
final Matcher matcher = AHBuilderUtils.FIRST_WORD_SQL.matcher(sql);
if (matcher.find()) {
final String word = matcher.group(1);
if ("select".equalsIgnoreCase(word)) {
type = QueryType.Select;
} else if ("insert".equalsIgnoreCase(word)) {
type = QueryType.Insert;
} else if ("update".equalsIgnoreCase(word)) {
type = QueryType.Update;
} else {
type = QueryType.Other;
}
} else {
type = QueryType.Other;
}
}
return type;
}
@Override
protected List appendDefineSql(StringBuilder body, ConverterInfo info, Method m) {
final String sql = getAnnotation(m).value();
return SqlStringUtils.appendSqlWithParts(body, sql, info.getSqlParts());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy