![JAR search and dependency download from the Maven repository](/logo.png)
info.archinnov.achilles.annotations.Computed Maven / Gradle / Ivy
/*
* Copyright (C) 2012-2016 DuyHai DOAN
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package info.archinnov.achilles.annotations;
import java.lang.annotation.*;
/**
* Annotation for computed column. A computed column is a column obtained by
* applying a CQL function on other(s) column(s). A computed column can only be referenced
* in SELECT/read statements, not UPDATE/INSERT/DELETE
*
* Examples:
*
* //Normal column name
* {@literal @}Column(name = "first_name")
* private String firstName;
* //Write time of firstName
* {@literal @}Column
* {@literal @}Computed(function = "writetime", alias = "write_time", targetColumns = "first_name", cqlClass = Long.class)
* private Long firstNameWriteTime;
*
* In the above example, the field firstNameWriteTime is obtained by applying the function
* writime on the column first_name.
* The target CQL class is Long.
*
* Please note that the targerFields should reference CQL column names, not Java field name. In the example
* it should be "first_name" and not "firstName"
*
* This annotation will generate the following SELECT statement at runtime:
*
*
* SELECT first_name, writetime(first_name) AS write_time ....
*
*
*
* @see @Computed
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
public @interface Computed {
/**
* Mandatory. The name of the CQL function to be used.
*/
String function();
/**
* Mandatory. The alias of this computed column.
* Warning: if you have multiple computed columns in the same entity, please take
* care to choose different alias
*/
String alias();
/**
* Mandatory. The target CQL columns on which the function will be applied.
* You can passe in multiple columns. The ordering of columns does matter
*/
String[] targetColumns();
/**
* Mandatory. To help Achilles determine the CQL type at compile time, you have to specify
* the Cassandra Java data type produced by the function application. This type should be a CQL-compatible type.
*
* Example: the writetime function will produce a CQL bigint so it's corresponding
* Java type is Long
*/
Class> cqlClass();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy