Search in sources :

Example 1 with ISetter

use of org.apache.hop.pipeline.transforms.loadsave.setter.ISetter in project hop by apache.

the class LoadSaveBase method createValidatorMapAndInvokeSetters.

@SuppressWarnings({ "unchecked" })
protected Map<String, IFieldLoadSaveValidator<?>> createValidatorMapAndInvokeSetters(List<String> attributes, T metaToSave) {
    Map<String, IFieldLoadSaveValidator<?>> validatorMap = new HashMap<>();
    metadataProvider = new MemoryMetadataProvider();
    for (String attribute : attributes) {
        IGetter<?> getter = manipulator.getGetter(attribute);
        @SuppressWarnings("rawtypes") ISetter setter = manipulator.getSetter(attribute);
        IFieldLoadSaveValidator<?> validator = fieldLoadSaveValidatorFactory.createValidator(getter);
        try {
            Object testValue = validator.getTestObject();
            // no-inspection unchecked
            setter.set(metaToSave, testValue);
            if (testValue instanceof DatabaseMeta) {
                addDatabase((DatabaseMeta) testValue);
            } else if (testValue instanceof DatabaseMeta[]) {
                addDatabase((DatabaseMeta[]) testValue);
            }
        } catch (Exception e) {
            throw new RuntimeException("Unable to invoke setter for " + attribute, e);
        }
        validatorMap.put(attribute, validator);
    }
    return validatorMap;
}
Also used : ISetter(org.apache.hop.pipeline.transforms.loadsave.setter.ISetter) IFieldLoadSaveValidator(org.apache.hop.pipeline.transforms.loadsave.validator.IFieldLoadSaveValidator) DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) HopException(org.apache.hop.core.exception.HopException) MemoryMetadataProvider(org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider)

Example 2 with ISetter

use of org.apache.hop.pipeline.transforms.loadsave.setter.ISetter in project hop by apache.

the class ObjectValidator method getTestObject.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public T getTestObject() {
    try {
        T object = clazz.newInstance();
        for (String attribute : fieldNames) {
            ISetter setter = manipulator.getSetter(attribute);
            setter.set(object, fieldLoadSaveValidatorFactory.createValidator(manipulator.getGetter(attribute)).getTestObject());
        }
        return object;
    } catch (Exception e) {
        throw new RuntimeException("Unable to instantiate " + clazz, e);
    }
}
Also used : ISetter(org.apache.hop.pipeline.transforms.loadsave.setter.ISetter)

Example 3 with ISetter

use of org.apache.hop.pipeline.transforms.loadsave.setter.ISetter in project hop by apache.

the class LoadSaveTester method createValidatorMapAndInvokeSetters.

@Override
@SuppressWarnings("unchecked")
protected Map<String, IFieldLoadSaveValidator<?>> createValidatorMapAndInvokeSetters(List<String> attributes, T metaToSave) {
    Map<String, IFieldLoadSaveValidator<?>> validatorMap = new HashMap<>();
    for (String attribute : attributes) {
        IGetter<?> getter = manipulator.getGetter(attribute);
        @SuppressWarnings("rawtypes") ISetter setter = manipulator.getSetter(attribute);
        IFieldLoadSaveValidator<?> validator = fieldLoadSaveValidatorFactory.createValidator(getter);
        try {
            Object testValue = validator.getTestObject();
            setter.set(metaToSave, testValue);
            if (validator instanceof DatabaseMetaLoadSaveValidator) {
                addDatabase((DatabaseMeta) testValue);
            }
        } catch (Exception e) {
            throw new RuntimeException("Unable to invoke setter for " + attribute, e);
        }
        validatorMap.put(attribute, validator);
    }
    return validatorMap;
}
Also used : HashMap(java.util.HashMap) ISetter(org.apache.hop.pipeline.transforms.loadsave.setter.ISetter) IFieldLoadSaveValidator(org.apache.hop.pipeline.transforms.loadsave.validator.IFieldLoadSaveValidator) DatabaseMetaLoadSaveValidator(org.apache.hop.pipeline.transforms.loadsave.validator.DatabaseMetaLoadSaveValidator) HopException(org.apache.hop.core.exception.HopException)

Aggregations

ISetter (org.apache.hop.pipeline.transforms.loadsave.setter.ISetter)3 HopException (org.apache.hop.core.exception.HopException)2 IFieldLoadSaveValidator (org.apache.hop.pipeline.transforms.loadsave.validator.IFieldLoadSaveValidator)2 HashMap (java.util.HashMap)1 DatabaseMeta (org.apache.hop.core.database.DatabaseMeta)1 MemoryMetadataProvider (org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider)1 DatabaseMetaLoadSaveValidator (org.apache.hop.pipeline.transforms.loadsave.validator.DatabaseMetaLoadSaveValidator)1