Search in sources :

Example 6 with Converter

use of com.hazelcast.sql.impl.type.converter.Converter in project hazelcast by hazelcast.

the class QueryDataTypeUtils method resolveTypeForClass.

@SuppressWarnings({ "checkstyle:CyclomaticComplexity", "checkstyle:ReturnCount", "checkstyle:MethodLength" })
public static QueryDataType resolveTypeForClass(Class<?> clazz) {
    Converter converter = Converters.getConverter(clazz);
    QueryDataTypeFamily typeFamily = converter.getTypeFamily();
    switch(typeFamily) {
        case VARCHAR:
            if (converter == StringConverter.INSTANCE) {
                return VARCHAR;
            } else {
                assert converter == CharacterConverter.INSTANCE;
                return VARCHAR_CHARACTER;
            }
        case BOOLEAN:
            return BOOLEAN;
        case TINYINT:
            return TINYINT;
        case SMALLINT:
            return SMALLINT;
        case INTEGER:
            return INT;
        case BIGINT:
            return BIGINT;
        case DECIMAL:
            if (converter == BigDecimalConverter.INSTANCE) {
                return DECIMAL;
            } else {
                assert converter == BigIntegerConverter.INSTANCE;
                return DECIMAL_BIG_INTEGER;
            }
        case REAL:
            return REAL;
        case DOUBLE:
            return DOUBLE;
        case DATE:
            return DATE;
        case TIME:
            return TIME;
        case TIMESTAMP:
            return TIMESTAMP;
        case TIMESTAMP_WITH_TIME_ZONE:
            if (converter == DateConverter.INSTANCE) {
                return TIMESTAMP_WITH_TZ_DATE;
            } else if (converter == CalendarConverter.INSTANCE) {
                return TIMESTAMP_WITH_TZ_CALENDAR;
            } else if (converter == InstantConverter.INSTANCE) {
                return TIMESTAMP_WITH_TZ_INSTANT;
            } else if (converter == OffsetDateTimeConverter.INSTANCE) {
                return TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME;
            } else {
                assert converter == ZonedDateTimeConverter.INSTANCE;
                return TIMESTAMP_WITH_TZ_ZONED_DATE_TIME;
            }
        case OBJECT:
        case MAP:
            return OBJECT;
        case NULL:
            return NULL;
        case JSON:
            return JSON;
        default:
            throw new IllegalArgumentException("Unexpected class: " + clazz);
    }
}
Also used : ZonedDateTimeConverter(com.hazelcast.sql.impl.type.converter.ZonedDateTimeConverter) DateConverter(com.hazelcast.sql.impl.type.converter.DateConverter) CharacterConverter(com.hazelcast.sql.impl.type.converter.CharacterConverter) InstantConverter(com.hazelcast.sql.impl.type.converter.InstantConverter) Converter(com.hazelcast.sql.impl.type.converter.Converter) BigDecimalConverter(com.hazelcast.sql.impl.type.converter.BigDecimalConverter) OffsetDateTimeConverter(com.hazelcast.sql.impl.type.converter.OffsetDateTimeConverter) BigIntegerConverter(com.hazelcast.sql.impl.type.converter.BigIntegerConverter) StringConverter(com.hazelcast.sql.impl.type.converter.StringConverter) CalendarConverter(com.hazelcast.sql.impl.type.converter.CalendarConverter)

Example 7 with Converter

use of com.hazelcast.sql.impl.type.converter.Converter in project hazelcast by hazelcast.

the class QueryDataTypeTest method testSerialization.

@Test
public void testSerialization() {
    for (Converter converter : Converters.getConverters()) {
        QueryDataType original = new QueryDataType(converter);
        QueryDataType restored = serializeAndCheck(original, SqlDataSerializerHook.QUERY_DATA_TYPE);
        checkEquals(original, restored, true);
    }
}
Also used : ZonedDateTimeConverter(com.hazelcast.sql.impl.type.converter.ZonedDateTimeConverter) LocalDateConverter(com.hazelcast.sql.impl.type.converter.LocalDateConverter) ByteConverter(com.hazelcast.sql.impl.type.converter.ByteConverter) IntegerConverter(com.hazelcast.sql.impl.type.converter.IntegerConverter) LocalTimeConverter(com.hazelcast.sql.impl.type.converter.LocalTimeConverter) DateConverter(com.hazelcast.sql.impl.type.converter.DateConverter) CharacterConverter(com.hazelcast.sql.impl.type.converter.CharacterConverter) DoubleConverter(com.hazelcast.sql.impl.type.converter.DoubleConverter) InstantConverter(com.hazelcast.sql.impl.type.converter.InstantConverter) ObjectConverter(com.hazelcast.sql.impl.type.converter.ObjectConverter) Converter(com.hazelcast.sql.impl.type.converter.Converter) LongConverter(com.hazelcast.sql.impl.type.converter.LongConverter) BigDecimalConverter(com.hazelcast.sql.impl.type.converter.BigDecimalConverter) OffsetDateTimeConverter(com.hazelcast.sql.impl.type.converter.OffsetDateTimeConverter) NullConverter(com.hazelcast.sql.impl.type.converter.NullConverter) ShortConverter(com.hazelcast.sql.impl.type.converter.ShortConverter) LocalDateTimeConverter(com.hazelcast.sql.impl.type.converter.LocalDateTimeConverter) BigIntegerConverter(com.hazelcast.sql.impl.type.converter.BigIntegerConverter) StringConverter(com.hazelcast.sql.impl.type.converter.StringConverter) BooleanConverter(com.hazelcast.sql.impl.type.converter.BooleanConverter) CalendarConverter(com.hazelcast.sql.impl.type.converter.CalendarConverter) FloatConverter(com.hazelcast.sql.impl.type.converter.FloatConverter) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Converter (com.hazelcast.sql.impl.type.converter.Converter)7 BigDecimalConverter (com.hazelcast.sql.impl.type.converter.BigDecimalConverter)2 BigIntegerConverter (com.hazelcast.sql.impl.type.converter.BigIntegerConverter)2 CalendarConverter (com.hazelcast.sql.impl.type.converter.CalendarConverter)2 CharacterConverter (com.hazelcast.sql.impl.type.converter.CharacterConverter)2 DateConverter (com.hazelcast.sql.impl.type.converter.DateConverter)2 InstantConverter (com.hazelcast.sql.impl.type.converter.InstantConverter)2 OffsetDateTimeConverter (com.hazelcast.sql.impl.type.converter.OffsetDateTimeConverter)2 StringConverter (com.hazelcast.sql.impl.type.converter.StringConverter)2 ZonedDateTimeConverter (com.hazelcast.sql.impl.type.converter.ZonedDateTimeConverter)2 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)1 Literal (com.hazelcast.jet.sql.impl.validate.literal.Literal)1 QueryException (com.hazelcast.sql.impl.QueryException)1 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)1 QueryDataTypeFamily (com.hazelcast.sql.impl.type.QueryDataTypeFamily)1 BooleanConverter (com.hazelcast.sql.impl.type.converter.BooleanConverter)1 ByteConverter (com.hazelcast.sql.impl.type.converter.ByteConverter)1 DoubleConverter (com.hazelcast.sql.impl.type.converter.DoubleConverter)1 FloatConverter (com.hazelcast.sql.impl.type.converter.FloatConverter)1 IntegerConverter (com.hazelcast.sql.impl.type.converter.IntegerConverter)1