Java Code Examples for net.sf.cglib.beans.BeanMap#getPropertyType()

The following examples show how to use net.sf.cglib.beans.BeanMap#getPropertyType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultCellProcessor.java    From bdf3 with Apache License 2.0 6 votes vote down vote up
protected void cellParse(Context context) {
	MappingRule mappingRule = context.getCurrentMappingRule();
	BeanMap beanMap = BeanMap.create(context.getCurrentEntity());
	String propertyName = mappingRule.getPropertyName();
	Class<?> type = beanMap.getPropertyType(propertyName);
	Object value = context.getValue();
	value = value == null ? null : value.toString();
	for (TypeConverter typeConverter : typeConverters) {
		if (typeConverter.support(type)) {
			try {
				value = typeConverter.fromText(type, mappingRule.getMappingValueIfNeed((String) value));
			} catch (Exception e) {
				if (mappingRule.isIgnoreErrorFormatData()) {
					log.debug(e.getMessage());
					value = Constants.IGNORE_ERROR_FORMAT_DATA;
				} else {
					throw new DataFormatException(context.getCurrentCell().getRow(), context.getCurrentCell().getCol(), (String) value);
				}
			}
			break;
		}
	}
	context.setValue(value);
}
 
Example 2
Source File: ParseRecordPolicyImpl.java    From bdf3 with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Context context) throws ClassNotFoundException {
	List<Record> records = context.getRecords();
	
	for (int i = context.getStartRow(); i < records.size(); i++) {
		Record record = records.get(i);
		Object entity = BeanUtils.newInstance(context.getEntityClass());
		context.setCurrentEntity(entity);
		context.setCurrentRecord(record);
		String idProperty = JpaUtil.getIdName(context.getEntityClass());
		BeanMap beanMap = BeanMap.create(context.getCurrentEntity());
		if (beanMap.getPropertyType(idProperty) == String.class) {
			beanMap.put(idProperty, UUID.randomUUID().toString());
		}
		for (MappingRule mappingRule : context.getMappingRules()) {
			Cell cell = record.getCell(mappingRule.getExcelColumn());

			context.setCurrentMappingRule(mappingRule);
			context.setCurrentCell(cell);
			cellPreprocess(context);
			cellProcess(context);
			cellPostprocess(context);
			
		}
		JpaUtil.persist(entity);
		if (i % 100 == 0) {
			JpaUtil.persistAndFlush(entity);
			JpaUtil.getEntityManager(entity).clear();
		} else {
			JpaUtil.persist(entity);
		}
	}

}