001/* 002 * Copyright 2015-2022 Transmogrify LLC, 2022-2026 Revetware LLC. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.pyranid; 018 019import org.jspecify.annotations.Nullable; 020 021import java.lang.annotation.ElementType; 022import java.lang.annotation.Retention; 023import java.lang.annotation.RetentionPolicy; 024import java.lang.annotation.Target; 025 026/** 027 * Allows specification of alternate column names for resultset mapping. 028 * <p> 029 * Useful in situations where column names are ugly, inconsistent, or do not map well to camel-case Java property names. 030 * Aliases are additive to the standard name candidates. 031 * <p> 032 * On a JavaBean, the annotated instance field must identify exactly one writable property exposed by a public 033 * instance setter. Matching includes JavaBeans capitalization and primitive-boolean fields such as 034 * {@code isActive} with {@code setActive(boolean)}. The mapper invokes the setter rather than writing the field. 035 * An unmatched, ambiguous or static annotated bean field is a mapping-metadata error, even if that field's 036 * aliases are absent from the selected columns. Record-component annotations do not require setters. 037 * <p> 038 * For example: 039 * 040 * <pre> 041 * public class Example { 042 * @DatabaseColumn({ "systok", "sys_tok" }) 043 * private UUID systemToken; 044 * 045 * public UUID getSystemToken() { 046 * return systemToken; 047 * } 048 * 049 * public void setSystemToken(UUID systemToken) { 050 * this.systemToken = systemToken; 051 * } 052 * } 053 * 054 * database.query("SELECT systok FROM example").fetchObject(Example.class); 055 * </pre> 056 * 057 * @author <a href="https://www.revetkn.com">Mark Allen</a> 058 * @since 1.0.0 059 */ 060@Target({ElementType.FIELD, ElementType.RECORD_COMPONENT}) 061@Retention(RetentionPolicy.RUNTIME) 062public @interface DatabaseColumn { 063 @Nullable 064 String[] value(); 065}