本文整理汇总了Java中org.apache.ibatis.type.TypeHandlerRegistry类的典型用法代码示例。如果您正苦于以下问题:Java TypeHandlerRegistry类的具体用法?Java TypeHandlerRegistry怎么用?Java TypeHandlerRegistry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TypeHandlerRegistry类属于org.apache.ibatis.type包,在下文中一共展示了TypeHandlerRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareInsertAuthorMappedStatement
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
public static MappedStatement prepareInsertAuthorMappedStatement(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (id,username,password,email,bio,favourite_section) values(?,?,?,?,?,?)"), SqlCommandType.INSERT)
.parameterMap(
new ParameterMap.Builder(
config, "defaultParameterMap", Author.class,
new ArrayList<ParameterMapping>() {
{
add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build());
add(new ParameterMapping.Builder(config, "favouriteSection", registry.getTypeHandler(Section.class)).jdbcType(JdbcType.VARCHAR).build());
}
}).build())
.cache(authorCache).build();
return ms;
}
示例2: prepareSelectAuthorViaOutParams
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
public static MappedStatement prepareSelectAuthorViaOutParams(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
MappedStatement ms = new MappedStatement.Builder(config, "selectAuthorViaOutParams", new StaticSqlSource(config, "{call selectAuthorViaOutParams(?,?,?,?,?)}"), SqlCommandType.SELECT)
.statementType(StatementType.CALLABLE)
.parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
new ArrayList<ParameterMapping>() {
{
add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
}
}).build())
.resultMaps(new ArrayList<ResultMap>())
.cache(authorCache).build();
return ms;
}
示例3: registerJavaTypeInitializingTypeHandler
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
@Test
public void registerJavaTypeInitializingTypeHandler() {
final String MAPPER_CONFIG = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+ "<!DOCTYPE configuration PUBLIC \"-//mybatis.org//DTD Config 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-config.dtd\">\n"
+ "<configuration>\n"
+ " <typeHandlers>\n"
+ " <typeHandler javaType=\"org.apache.ibatis.builder.XmlConfigBuilderTest$MyEnum\"\n"
+ " handler=\"org.apache.ibatis.builder.XmlConfigBuilderTest$EnumOrderTypeHandler\"/>\n"
+ " </typeHandlers>\n"
+ "</configuration>\n";
XMLConfigBuilder builder = new XMLConfigBuilder(new StringReader(MAPPER_CONFIG));
builder.parse();
TypeHandlerRegistry typeHandlerRegistry = builder.getConfiguration().getTypeHandlerRegistry();
TypeHandler<MyEnum> typeHandler = typeHandlerRegistry.getTypeHandler(MyEnum.class);
assertTrue(typeHandler instanceof EnumOrderTypeHandler);
assertArrayEquals(MyEnum.values(), ((EnumOrderTypeHandler) typeHandler).constants);
}
示例4: prepareInsertAuthorMappedStatementWithAutoKey
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
public static MappedStatement prepareInsertAuthorMappedStatementWithAutoKey(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (username,password,email,bio,favourite_section) values(?,?,?,?,?)"), SqlCommandType.INSERT)
.parameterMap(
new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {
{
add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build());
add(new ParameterMapping.Builder(config, "favouriteSection", registry.getTypeHandler(Section.class)).jdbcType(JdbcType.VARCHAR).build());
}
}).build())
.cache(authorCache)
.keyGenerator(new Jdbc3KeyGenerator())
.keyProperty("id")
.build();
return ms;
}
示例5: prepareUpdateAuthorMappedStatement
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
public static MappedStatement prepareUpdateAuthorMappedStatement(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
MappedStatement ms = new MappedStatement.Builder(config, "updateAuthor", new StaticSqlSource(config,"UPDATE author SET username = ?, password = ?, email = ?, bio = ? WHERE id = ?"), SqlCommandType.UPDATE)
.parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
new ArrayList<ParameterMapping>() {
{
add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build());
add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
}
}).build())
.cache(authorCache).build();
return ms;
}
示例6: createSelectAuthorWithIDof99MappedStatement
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
public static MappedStatement createSelectAuthorWithIDof99MappedStatement(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
MappedStatement ms = new MappedStatement.Builder(config, "selectAuthor", new StaticSqlSource(config,"SELECT * FROM author WHERE id = 99"), SqlCommandType.SELECT)
.statementType(StatementType.STATEMENT)
.parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>()).build())
.resultMaps(new ArrayList<ResultMap>() {
{
add(new ResultMap.Builder(config, "defaultResultMap", Author.class, new ArrayList<ResultMapping>() {
{
add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(int.class)).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());
}
}).build());
}
}).build();
return ms;
}
示例7: getTypeHandlers
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
private TypeHandler<?>[] getTypeHandlers(TypeHandlerRegistry typeHandlerRegistry, MetaObject metaParam, String[] keyProperties, ResultSetMetaData rsmd) throws SQLException {
TypeHandler<?>[] typeHandlers = new TypeHandler<?>[keyProperties.length];
for (int i = 0; i < keyProperties.length; i++) {
if (metaParam.hasSetter(keyProperties[i])) {
TypeHandler<?> th;
try {
Class<?> keyPropertyType = metaParam.getSetterType(keyProperties[i]);
th = typeHandlerRegistry.getTypeHandler(keyPropertyType, JdbcType.forCode(rsmd.getColumnType(i + 1)));
} catch (BindingException e) {
th = null;
}
typeHandlers[i] = th;
}
}
return typeHandlers;
}
示例8: prepareInsertAuthorMappedStatementWithAutoKey
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
public static MappedStatement prepareInsertAuthorMappedStatementWithAutoKey(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (username,password,email,bio,favourite_section) values(?,?,?,?,?)"), SqlCommandType.INSERT)
.parameterMap(
new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {
{
add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build());
add(new ParameterMapping.Builder(config, "favouriteSection", registry.getTypeHandler(Section.class)).jdbcType(JdbcType.VARCHAR).build());
}
}).build())
.cache(authorCache)
.keyGenerator(Jdbc3KeyGenerator.INSTANCE)
.keyProperty("id")
.build();
return ms;
}
示例9: getTypeHandlers
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
private TypeHandler<?>[] getTypeHandlers(TypeHandlerRegistry typeHandlerRegistry, MetaObject metaParam, String[] keyProperties) {
TypeHandler<?>[] typeHandlers = new TypeHandler<?>[keyProperties.length];
for (int i = 0; i < keyProperties.length; i++) {
if (metaParam.hasSetter(keyProperties[i])) {
Class<?> keyPropertyType = metaParam.getSetterType(keyProperties[i]);
TypeHandler<?> th = typeHandlerRegistry.getTypeHandler(keyPropertyType);
typeHandlers[i] = th;
}
}
return typeHandlers;
}
示例10: getNamespaceSql
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
/**
* 通过命名空间方式获取sql
* @param session
* @param namespace
* @param params
* @return
*/
public static String getNamespaceSql(SqlSession session, String namespace, Object params) {
Configuration configuration = session.getConfiguration();
MappedStatement mappedStatement = configuration.getMappedStatement(namespace);
TypeHandlerRegistry typeHandlerRegistry = mappedStatement.getConfiguration().getTypeHandlerRegistry();
BoundSql boundSql = mappedStatement.getBoundSql(params);
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
String sql = boundSql.getSql();
if (parameterMappings != null) {
for (int i = 0; i < parameterMappings.size(); i++) {
ParameterMapping parameterMapping = parameterMappings.get(i);
if (parameterMapping.getMode() != ParameterMode.OUT) {
Object value;
String propertyName = parameterMapping.getProperty();
if (boundSql.hasAdditionalParameter(propertyName)) {
value = boundSql.getAdditionalParameter(propertyName);
} else if (params == null) {
value = null;
} else if (typeHandlerRegistry.hasTypeHandler(params.getClass())) {
value = params;
} else {
MetaObject metaObject = configuration.newMetaObject(params);
value = metaObject.getValue(propertyName);
}
JdbcType jdbcType = parameterMapping.getJdbcType();
if (value == null && jdbcType == null) jdbcType = configuration.getJdbcTypeForNull();
sql = replaceParameter(sql, value, jdbcType, parameterMapping.getJavaType());
}
}
}
return sql;
}
示例11: resolveTypeHandler
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
private void resolveTypeHandler() {
if (resultMapping.typeHandler == null && resultMapping.javaType != null) {
Configuration configuration = resultMapping.configuration;
TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
resultMapping.typeHandler = typeHandlerRegistry.getTypeHandler(resultMapping.javaType, resultMapping.jdbcType);
}
}
示例12: resolveTypeHandler
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
private void resolveTypeHandler() {
if (parameterMapping.typeHandler == null && parameterMapping.javaType != null) {
Configuration configuration = parameterMapping.configuration;
TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
parameterMapping.typeHandler = typeHandlerRegistry.getTypeHandler(parameterMapping.javaType, parameterMapping.jdbcType);
}
}
示例13: createCacheKey
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
@Override
public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {
if (closed) {
throw new ExecutorException("Executor was closed.");
}
CacheKey cacheKey = new CacheKey();
cacheKey.update(ms.getId());
cacheKey.update(rowBounds.getOffset());
cacheKey.update(rowBounds.getLimit());
cacheKey.update(boundSql.getSql());
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
TypeHandlerRegistry typeHandlerRegistry = ms.getConfiguration().getTypeHandlerRegistry();
// mimic DefaultParameterHandler logic
for (ParameterMapping parameterMapping : parameterMappings) {
if (parameterMapping.getMode() != ParameterMode.OUT) {
Object value;
String propertyName = parameterMapping.getProperty();
if (boundSql.hasAdditionalParameter(propertyName)) {
value = boundSql.getAdditionalParameter(propertyName);
} else if (parameterObject == null) {
value = null;
} else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
value = parameterObject;
} else {
MetaObject metaObject = configuration.newMetaObject(parameterObject);
value = metaObject.getValue(propertyName);
}
cacheKey.update(value);
}
}
if (configuration.getEnvironment() != null) {
// issue #176
cacheKey.update(configuration.getEnvironment().getId());
}
return cacheKey;
}
示例14: getTypeHandlers
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
private TypeHandler<?>[] getTypeHandlers(TypeHandlerRegistry typeHandlerRegistry, MetaObject metaParam, String[] keyProperties, ResultSetMetaData rsmd) throws SQLException {
TypeHandler<?>[] typeHandlers = new TypeHandler<?>[keyProperties.length];
for (int i = 0; i < keyProperties.length; i++) {
if (metaParam.hasSetter(keyProperties[i])) {
Class<?> keyPropertyType = metaParam.getSetterType(keyProperties[i]);
TypeHandler<?> th = typeHandlerRegistry.getTypeHandler(keyPropertyType, JdbcType.forCode(rsmd.getColumnType(i + 1)));
typeHandlers[i] = th;
}
}
return typeHandlers;
}
示例15: getMappedStatement
import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
MappedStatement getMappedStatement() {
final Configuration config = new Configuration();
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
return new MappedStatement.Builder(config, "testSelect", new StaticSqlSource(config, "some select statement"), SqlCommandType.SELECT).resultMaps(
new ArrayList<ResultMap>() {
{
add(new ResultMap.Builder(config, "testMap", HashMap.class, new ArrayList<ResultMapping>() {
{
add(new ResultMapping.Builder(config, "cOlUmN1", "CoLuMn1", registry.getTypeHandler(Integer.class)).build());
}
}).build());
}
}).build();
}