All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.paganini2008.devtools.db4j.mapper.BeanPropertyRowMapper Maven / Gradle / Ivy

There is a newer version: 2.0.5
Show newest version
/**
* Copyright 2021 Fred Feng ([email protected])

* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.paganini2008.devtools.db4j.mapper;

import com.github.paganini2008.devtools.beans.PropertyUtils;
import com.github.paganini2008.devtools.db4j.JdbcType;
import com.github.paganini2008.devtools.reflection.ConstructorUtils;

/**
 * 
 * BeanPropertyRowMapper
 *
 * @author Fred Feng
 * @version 1.0
 */
public class BeanPropertyRowMapper extends AbstractRowMapper {

	private final Class elementType;

	public BeanPropertyRowMapper(Class elementType) {
		this.elementType = elementType;
	}

	protected T createObject(int columnCount) {
		try {
			return ConstructorUtils.invokeConstructor(elementType, (Object[]) null);
		} catch (Exception e) {
			throw new RowMapperException(e);
		}
	}

	protected void setValue(T object, int columnIndex, String columnName, String columnDisplayName, JdbcType jdbcType, Object columnValue) {
		try {
			PropertyUtils.setProperty(object, columnDisplayName, columnValue);
		} catch (RuntimeException ignored) {
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy