| 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 | */ |
| 16 | package com.datastax.driver.mapping.annotations; |
| 17 | |
| 18 | |
| 19 | import com.datastax.driver.mapping.Mapper; |
| 20 | |
| 21 | import java.lang.annotation.ElementType; |
| 22 | import java.lang.annotation.Retention; |
| 23 | import java.lang.annotation.RetentionPolicy; |
| 24 | import java.lang.annotation.Target; |
| 25 | |
| 26 | /** |
| 27 | * Annotates a "computed" field, which gets filled from a CQL expression in the SELECT query |
| 28 | * used to retrieve an entity. |
| 29 | * <p/> |
| 30 | * Note that such fields are only filled by default mapper operations ({@link Mapper#get(Object...)}), |
| 31 | * they will be ignored in accessor queries and save operations. |
| 32 | * <p/> |
| 33 | * As opposed to other mapper annotation, this one doesn't handle case sensitivity. If your expression |
| 34 | * contains case-sensitive names, you'll need to quote them explicitly: |
| 35 | * <pre> |
| 36 | * {@code @Computed("\"caseSensitiveFunction\"(v)")} |
| 37 | * </pre> |
| 38 | */ |
| 39 | @Target(ElementType.FIELD) |
| 40 | @Retention(RetentionPolicy.RUNTIME) |
| 41 | public @interface Computed { |
| 42 | /** |
| 43 | * The formula used to compute the field. |
| 44 | * <p/> |
| 45 | * This is a CQL expression like you would use directly in a query, for instance |
| 46 | * "writetime(v)". |
| 47 | * |
| 48 | * @return the formula. |
| 49 | */ |
| 50 | String value(); |
| 51 | } |