001package com.nimbusds.infinispan.persistence.sql; 002 003 004import java.util.Collections; 005import java.util.List; 006import java.util.Map; 007 008import static org.jooq.impl.DSL.field; 009 010import net.jcip.annotations.Immutable; 011import org.jooq.Field; 012 013 014/** 015 * Immutable SQL record. 016 */ 017@Immutable 018public final class ImmutableSQLRecord implements SQLRecord { 019 020 021 /** 022 * The key column names. 023 */ 024 private final List<Field<?>> keyCols; 025 026 027 /** 028 * The fields. 029 */ 030 private final Map<Field<?>,?> fields; 031 032 033 /** 034 * Creates a new immutable SQL record. 035 * 036 * @param keyCols The key column names. Must not be empty. 037 * @param fields The fields. Must not be empty. 038 */ 039 public ImmutableSQLRecord(final List<Field<?>> keyCols, final Map<Field<?>, ?> fields) { 040 assert ! keyCols.isEmpty(); 041 this.keyCols = keyCols; 042 assert ! fields.isEmpty(); 043 this.fields = fields; 044 } 045 046 047 /** 048 * Creates a new immutable SQL record with a single key column. 049 * 050 * @param keyCol The key column name. Must not be {@code null}. 051 * @param fields The fields. Must not be empty. 052 */ 053 public ImmutableSQLRecord(final String keyCol, final Map<Field<?>, ?> fields) { 054 this(Collections.singletonList(field(keyCol)), fields); 055 } 056 057 058 @Override 059 public List<Field<?>> getKeyColumns() { 060 return keyCols; 061 } 062 063 064 @Override 065 public Map<Field<?>,?> getFields() { 066 return Collections.unmodifiableMap(fields); 067 } 068}