001// 002// Name 003// $RCSfile: KeyField.java,v $ 004// 005// Copyright 006// Copyright 2014 Cloud Software Group, Inc. ALL RIGHTS RESERVED. 007// Cloud Software Group, Inc. Confidential Information 008// 009// History 010// $Revision: 1.1.2.5 $ $Date: 2014/11/26 01:43:42 $ 011// 012package com.kabira.store; 013 014import com.kabira.platform.KeyComparisonOperator; 015 016/** 017 * Describes a field within the query performed by an application. 018 * <p> 019 * Passed as a list of KeyField to the query notification. For example, 020 * if the application query data is: 021 * <pre> 022 * KeyFieldValueList fieldValueList = new KeyFieldValueList(); 023 * fieldValueList.add("firstName", "fred"); 024 * </pre> 025 * The Query.query() queryData param is: 026 * <p> 027 * <pre> 028 * assert queryData.size() == 1; 029 * KeyField keyField = queryData.get(0); 030 * 031 * assert keyField.name == "firstName"; 032 * String firstNameValue = (String) keyField.value; 033 * assert firstNameValue.equals("fred"); 034 * assert keyField.comparisonOperator == KeyComparisonOperator.EQ; 035 * </pre> 036 * <p> 037* If the application KeyQuery data is: 038 * <pre> 039 * KeyFieldValueRangeList fieldValueRangeList = new KeyFieldValueRangeList(); 040 * fieldValueList.add("number", 12345, KeyComparisonOperator.GTE); 041 * fieldValueList.add("number", 22222, KeyComparisonOperator.GTE); 042 * </pre> 043 * The Query.query() queryData param is: 044 * <pre> 045 * assert queryData.size() == 2; 046 * KeyField keyField = queryData.get(0); 047 * 048 * assert keyField.name == "number"; 049 * int value = (Integer) keyField.value; 050 * assert value == 12345; 051 * assert keyField.comparisonOperator == KeyComparisonOperator.GTE; 052 * 053 * KeyField keyField = queryData.get(1); 054 * 055 * assert keyField.name == "number"; 056 * int value = (Integer) keyField.value; 057 * assert value == 22222; 058 * assert keyField.comparisonOperator == KeyComparisonOperator.GTE; 059 * 060 * </pre> 061 */ 062public class KeyField 063{ 064 /** 065 * The name of the field added to 066 * {@link com.kabira.platform.KeyFieldValueList} or 067 * {@link com.kabira.platform.KeyFieldValueRangeList}. 068 */ 069 public final String name; 070 071 /** 072 * The value for field <code>name</code> added to 073 * {@link com.kabira.platform.KeyFieldValueList} or 074 * {@link com.kabira.platform.KeyFieldValueRangeList}. 075 */ 076 public final Object value; 077 078 /** 079 * The comparison operator for field and data. 080 * For queries using 081 * {@link com.kabira.platform.KeyFieldValueList} 082 * the comparison operator will always be 083 * <code>KeyComparisonOperator.EQ</code>. 084 */ 085 public final KeyComparisonOperator comparisonOperator; 086 087 private KeyField() 088 { 089 this.name = null; 090 this.value = null; 091 this.comparisonOperator = KeyComparisonOperator.EQ; 092 } 093 094 KeyField( 095 final String fieldName, 096 final Object value, 097 final KeyComparisonOperator comparisonOperator) 098 { 099 this.name = fieldName; 100 this.value = value; 101 this.comparisonOperator = comparisonOperator; 102 } 103 104 @Override 105 public final String toString() 106 { 107 String description = name; 108 109 description += " "; 110 description += comparisonOperator; 111 description += " ["; 112 description += value; 113 description += "]"; 114 115 return description; 116 } 117}