Package info.archinnov.achilles.codec

Examples of info.archinnov.achilles.codec.Codec


    public ListCodec parseAndValidateListCodec(Field field) {
        final String fieldName = field.getName();
        final String className = field.getDeclaringClass().getCanonicalName();

        Codec codec = getValueCodecInstance(field);

        validateNotIdentityCodec(fieldName, className, codec);

        final Class<?> sourceType = codec.sourceType();
        final Class<?> targetType = codec.targetType();

        validateTypesNotNull(fieldName, className, sourceType, targetType);

        final Class<?> listValueType = TypeParser.inferValueClassForListOrSet(field.getGenericType(), field.getDeclaringClass());
View Full Code Here


    public SetCodec parseAndValidateSetCodec(Field field) {
        final String fieldName = field.getName();
        final String className = field.getDeclaringClass().getCanonicalName();

        Codec codec = getValueCodecInstance(field);

        validateNotIdentityCodec(fieldName, className, codec);

        final Class<?> sourceType = codec.sourceType();
        final Class<?> targetType = codec.targetType();

        validateTypesNotNull(fieldName, className, sourceType, targetType);

        final Class<?> listValueType = TypeParser.inferValueClassForListOrSet(field.getGenericType(), field.getDeclaringClass());
View Full Code Here

    public MapCodec parseAndValidateMapCodec(Field field) {
        final String fieldName = field.getName();
        final String className = field.getDeclaringClass().getCanonicalName();

        Codec keyCodec = getKeyCodecInstance(field);
        Codec valueCodec = getValueCodecInstance(field);

        Validator.validateBeanMappingFalse(keyCodec instanceof IdentityCodec && valueCodec instanceof IdentityCodec,
                "The @TypeTransformer on the field '%s' of class '%s' should declare a key/value codec other than IdentityCodec. Maybe you forgot to provided it ?",
                fieldName, className);
View Full Code Here

        final Field field = context.getCurrentField();
        log.debug("Parse list codec for field {}", field);
        if (filter.hasAnnotation(field, TypeTransformer.class)) {
            return typeTransformerParser.parseAndValidateListCodec(field);
        } else {
            final Codec simpleCodec = createSimpleCodecForCollection(context);
            return new ListCodecImpl(simpleCodec.sourceType(), simpleCodec.targetType(), simpleCodec);
        }
    }
View Full Code Here

        final Field field = context.getCurrentField();
        log.debug("Parse set codec for field {}", field);
        if (filter.hasAnnotation(field, TypeTransformer.class)) {
            return typeTransformerParser.parseAndValidateSetCodec(field);
        } else {
            final Codec simpleCodec = createSimpleCodecForCollection(context);
            return new SetCodecImpl(simpleCodec.sourceType(), simpleCodec.targetType(), simpleCodec);
        }
    }
View Full Code Here

            final Optional<Encoding> maybeEncodingKey = fromNullable(field.getAnnotation(Enumerated.class)).transform(keyEncoding);
            final Optional<Encoding> maybeEncodingValue = fromNullable(field.getAnnotation(Enumerated.class)).transform(valueEncoding);

            final Pair<Class<Object>, Class<Object>> sourceTargetTypes = TypeParser.determineMapGenericTypes(field);

            final Codec keyCodec = createSimpleCodec(context, sourceTargetTypes.left, maybeEncodingKey);
            final Codec valueCodec = createSimpleCodec(context, sourceTargetTypes.right, maybeEncodingValue);

            return MapCodecBuilder.fromKeyType(keyCodec.sourceType())
                    .toKeyType(keyCodec.targetType())
                    .withKeyCodec(keyCodec)
                    .fromValueType(valueCodec.sourceType())
                    .toValueType(valueCodec.targetType())
                    .withValueCodec(valueCodec);
        }

    }
View Full Code Here

            return input;
        }
    }
    private Codec createSimpleCodec(PropertyParsingContext context, Class type, Optional<Encoding> maybeEncoding) {
        log.debug("Create simple codec for java type {}", type);
        Codec codec;
        if (Byte.class.isAssignableFrom(type) || byte.class.isAssignableFrom(type)) {
            codec = new ByteCodec();
        } else if (byte[].class.isAssignableFrom(type)) {
            codec = new ByteArrayPrimitiveCodec();
        } else if (Byte[].class.isAssignableFrom(type)) {
View Full Code Here

        return codec;
    }

    private Codec createEnumCodec(Class type, Optional<Encoding> maybeEncoding) {
        log.debug("Create enum codec for java type {}", type);
        Codec codec;
        final List<Object> enumConstants = Arrays.asList(type.getEnumConstants());
        if (maybeEncoding.isPresent()) {
            if (maybeEncoding.get() == Encoding.NAME) {
                codec = new EnumNameCodec<>(enumConstants, type);
            } else {
View Full Code Here

        Field field = context.getCurrentField();
        final boolean staticColumn = isStaticColumn(field);
        boolean timeUUID = isTimeUUID(context, field);

        Method[] accessors = entityIntrospector.findAccessors(entityClass, field);
        final Codec simpleCodec = codecFactory.parseSimpleField(context);
        final Class<?> cql3ValueType = codecFactory.determineCQL3ValueType(simpleCodec, timeUUID);
        PropertyType type = SIMPLE;

        PropertyMeta propertyMeta = factory().objectMapper(context.getCurrentObjectMapper()).type(type)
                .propertyName(context.getCurrentPropertyName()).cqlColumnName(context.getCurrentCQL3ColumnName())
View Full Code Here

  }

  @Test
  public void should_build_simple() throws Exception {

        Codec simpleCodec = mock(Codec.class);

    PropertyMeta built = PropertyMetaBuilder.factory().type(SIMPLE).propertyName("prop").accessors(accessors)
                .field(field).objectMapper(objectMapper)
                .consistencyLevels(Pair.create(ONE, ALL))
                .simpleCodec(simpleCodec)
View Full Code Here

TOP

Related Classes of info.archinnov.achilles.codec.Codec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.