package org.teiid.core.types.basic;

import java.math.BigDecimal;

import org.teiid.core.types.BinaryType;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.Transform;
import org.teiid.core.types.TransformationException;

/**
 * @author Dmitry Pogorelov
 * @date 2016.12.28
 */
public class BigDecimalToBinaryTransform extends Transform {
    public Object transformDirect(Object value) throws TransformationException {
        BigDecimal contents = (BigDecimal) value;
        return new BinaryType(contents.toBigInteger().toByteArray());
    }

    public Class<?> getSourceType() {
        return DataTypeManager.DefaultDataClasses.BIG_DECIMAL;
    }

    public Class<?> getTargetType() {
        return DataTypeManager.DefaultDataClasses.VARBINARY;
    }

    @Override
    public boolean isExplicit() {
        return true;
    }
}
