Elffuss BraidHub

kikocis/java-driver public

845bfcad3488 · 1.7 KiBRawPermalink
1/*
2 * Copyright (C) 2012-2015 DataStax Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.datastax.driver.mapping;
17
18import com.datastax.driver.core.TypeCodec;
19import com.google.common.reflect.TypeToken;
20
21import java.util.concurrent.atomic.AtomicInteger;
22
23abstract class ColumnMapper<T> {
24
25 final MappedProperty<T> property;
26 final String alias;
27 final int position;
28
29 @SuppressWarnings("unchecked")
30 protected ColumnMapper(MappedProperty<T> property, int position, AtomicInteger columnCounter) {
31 this.property = property;
32 this.position = position;
33 this.alias = (columnCounter != null)
34 ? AnnotationParser.newAlias(columnCounter.incrementAndGet())
35 : null;
36 }
37
38 abstract Object getValue(T entity);
39
40 abstract void setValue(T entity, Object value);
41
42 String getColumnName() {
43 return property.columnName();
44 }
45
46 String getAlias() {
47 return alias;
48 }
49
50 public TypeCodec<Object> getCustomCodec() {
51 return property.customCodec();
52 }
53
54 /**
55 * The Java type of this column.
56 */
57 @SuppressWarnings("unchecked")
58 public TypeToken<Object> getJavaType() {
59 return (TypeToken<Object>) property.type();
60 }
61
62}