List of usage examples for org.apache.ibatis.reflection MetaObject hasSetter
public boolean hasSetter(String name)
From source file:com.dk3k.framework.redis.cache.mybatis.RedisConfigurationBuilder.java
License:Apache License
private void setConfigProperties(Properties properties, ConfigWithHost jedisConfig) { if (properties != null) { MetaObject metaCache = SystemMetaObject.forObject(jedisConfig); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String name = (String) entry.getKey(); String value = (String) entry.getValue(); if (metaCache.hasSetter(name)) { Class<?> type = metaCache.getSetterType(name); if (String.class == type) { metaCache.setValue(name, value); } else if (int.class == type || Integer.class == type) { metaCache.setValue(name, Integer.valueOf(value)); } else if (long.class == type || Long.class == type) { metaCache.setValue(name, Long.valueOf(value)); } else if (short.class == type || Short.class == type) { metaCache.setValue(name, Short.valueOf(value)); } else if (byte.class == type || Byte.class == type) { metaCache.setValue(name, Byte.valueOf(value)); } else if (float.class == type || Float.class == type) { metaCache.setValue(name, Float.valueOf(value)); } else if (boolean.class == type || Boolean.class == type) { metaCache.setValue(name, Boolean.valueOf(value)); } else if (double.class == type || Double.class == type) { metaCache.setValue(name, Double.valueOf(value)); } else { throw new CacheException("Unsupported property type: '" + name + "' of type " + type); }/*from ww w . j ava 2s .c o m*/ } } } }
From source file:com.hand.hap.mybatis.mapperhelper.MultipleJdbc3KeyGenerator.java
License:Open Source License
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;/*from w w w . j ava 2s . co m*/ } } return typeHandlers; }
From source file:com.ibatis.common.jdbc.DbcpConfiguration.java
License:Apache License
private BasicDataSource newDbcpConfiguration(Map map) { BasicDataSource basicDataSource = new BasicDataSource(); Iterator props = map.keySet().iterator(); MetaObject metaDataSource = SystemMetaObject.forObject(basicDataSource); while (props.hasNext()) { String propertyName = (String) props.next(); if (propertyName.startsWith(ADD_DRIVER_PROPS_PREFIX)) { String value = (String) map.get(propertyName); basicDataSource.addConnectionProperty(propertyName.substring(ADD_DRIVER_PROPS_PREFIX_LENGTH), value);/*from ww w.j av a 2 s. c o m*/ } else if (metaDataSource.hasSetter(propertyName)) { String value = (String) map.get(propertyName); Object convertedValue = convertValue(basicDataSource, propertyName, value); metaDataSource.setValue(propertyName, convertedValue); } } return basicDataSource; }
From source file:com.sinotopia.mybatis.mapper.mapperhelper.SelectKeyGenerator.java
License:Apache License
private void setValue(MetaObject metaParam, String property, Object value) { if (metaParam.hasSetter(property)) { if (metaParam.hasGetter(property)) { Object defaultValue = metaParam.getValue(property); if (defaultValue != null) { return; }//www. j av a 2 s .c o m } metaParam.setValue(property, value); } else { throw new ExecutorException("No setter found for the keyProperty '" + property + "' in " + metaParam.getOriginalObject().getClass().getName() + "."); } }
From source file:com.yimidida.shards.session.impl.ShardedSqlSessionImpl.java
License:Open Source License
@Override public int insert(String statement, Object parameter) { ShardId shardId = this.selectShardIdForNewObject(statement, parameter); if (shardId == null) { shardId = this.getShardIdForStatementOrParameter(statement, parameter); }//www. j av a2s .c o m Assert.notNull(shardId); // ?id setCurrentSubgraphShardId(shardId); log.debug(String.format("Inserting object of type %s to shard %s", parameter.getClass(), shardId)); SqlSession session = shardIdsToShards.get(shardId).establishSqlSession(); IdGenerator idGenerator = shardedSqlSessionFactory.getIdGenerator(); if (idGenerator != null) { //TODO(fengkuok) ? DB?session Serializable id = idGenerator.generate(session, parameter); log.debug(String.format( "Generating id for object %s ,the type of IdGenerator is %s and generated Id is %s.", parameter.getClass(), idGenerator.getClass(), id)); ParameterUtil.generatePrimaryKey(parameter, id); } final Object params = ParameterUtil.resolve(parameter, shardId); final int rows = session.insert(statement, params); //fixed set keys if (params instanceof Map) { Map map = (Map) params; Configuration configuration = session.getConfiguration(); MappedStatement ms = configuration.getMappedStatement(statement); if (parameter != null && ms != null && ms.getKeyProperties() != null) { String keyProperty = ms.getKeyProperties()[0]; // just one key property is supported final MetaObject metaParam = configuration.newMetaObject(parameter); if (keyProperty != null && metaParam.hasSetter(keyProperty)) { metaParam.setValue(keyProperty, map.get(keyProperty)); } } } return rows; }
From source file:com.zh.common.redis.RedisConfigurationBuilder.java
License:Apache License
private void setConfigProperties(Properties properties, RedisConfig jedisConfig) { if (properties != null) { MetaObject metaCache = SystemMetaObject.forObject(jedisConfig); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String name = (String) entry.getKey(); String value = (String) entry.getValue(); if (metaCache.hasSetter(name)) { Class<?> type = metaCache.getSetterType(name); if (String.class == type) { metaCache.setValue(name, value); } else if (int.class == type || Integer.class == type) { metaCache.setValue(name, Integer.valueOf(value)); } else if (long.class == type || Long.class == type) { metaCache.setValue(name, Long.valueOf(value)); } else if (short.class == type || Short.class == type) { metaCache.setValue(name, Short.valueOf(value)); } else if (byte.class == type || Byte.class == type) { metaCache.setValue(name, Byte.valueOf(value)); } else if (float.class == type || Float.class == type) { metaCache.setValue(name, Float.valueOf(value)); } else if (boolean.class == type || Boolean.class == type) { metaCache.setValue(name, Boolean.valueOf(value)); } else if (double.class == type || Double.class == type) { metaCache.setValue(name, Double.valueOf(value)); } else { throw new CacheException("Unsupported property type: '" + name + "' of type " + type); }// w w w .ja va 2 s . c om } } } }
From source file:org.mybatis.caches.redis.RedisConfigurationBuilder.java
License:Apache License
private void setConfigProperties(Properties properties, RedisConfig jedisConfig) { if (properties != null) { MetaObject metaCache = SystemMetaObject.forObject(jedisConfig); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String name = (String) entry.getKey(); String value = (String) entry.getValue(); if (metaCache.hasSetter(name)) { Class<?> type = metaCache.getSetterType(name); if (String.class == type) { metaCache.setValue(name, value); } else if (int.class == type || Integer.class == type) { metaCache.setValue(name, Integer.valueOf(value)); } else if (long.class == type || Long.class == type) { metaCache.setValue(name, Long.valueOf(value)); } else if (short.class == type || Short.class == type) { metaCache.setValue(name, Short.valueOf(value)); } else if (byte.class == type || Byte.class == type) { metaCache.setValue(name, Byte.valueOf(value)); } else if (float.class == type || Float.class == type) { metaCache.setValue(name, Float.valueOf(value)); } else if (boolean.class == type || Boolean.class == type) { metaCache.setValue(name, Boolean.valueOf(value)); } else if (double.class == type || Double.class == type) { metaCache.setValue(name, Double.valueOf(value)); } else { throw new CacheException("Unsupported property type: '" + name + "' of type " + type); }//from ww w .j ava 2 s .c o m } else if (isInteger(value)) { jedisConfig.getSettings().put(name, Integer.parseInt(value)); } } } }
From source file:org.nanoframework.orm.mybatis.plugin.AbstractDataSourceFactory.java
License:Apache License
@Override public void setProperties(Properties properties) { Properties driverProperties = new Properties(); MetaObject metaDataSource = SystemMetaObject.forObject(dataSource); for (Object key : properties.keySet()) { String propertyName = (String) key; if (metaDataSource.hasSetter(propertyName)) { String value = (String) properties.get(propertyName); /** */ if (StringUtils.isNotEmpty(value) && value.startsWith("${") && value.endsWith("}")) { continue; }// w w w . j a va2s.c o m Object convertedValue = convertValue(metaDataSource, propertyName, value); metaDataSource.setValue(propertyName, convertedValue); } else { throw new DataSourceException("Unknown DataSource property: " + propertyName); } } if (driverProperties.size() > 0) { metaDataSource.setValue("driverProperties", driverProperties); } }