001 /* 002 // $Id: Datatype.java 253 2009-06-30 03:06:10Z jhyde $ 003 // This software is subject to the terms of the Eclipse Public License v1.0 004 // Agreement, available at the following URL: 005 // http://www.eclipse.org/legal/epl-v10.html. 006 // Copyright (C) 2006-2008 Julian Hyde 007 // All Rights Reserved. 008 // You must accept the terms of that agreement to use this software. 009 */ 010 package org.olap4j.metadata; 011 012 import java.util.Map; 013 import java.util.HashMap; 014 015 /** 016 * Enumeration of the allowable data types of a Property or Measure. 017 * 018 * <p>The values derive from the OLE DB specification, specifically a 019 * subset of the OLE DB Types Indicators returned by SQL Server. 020 * 021 * @author jhyde 022 * @version $Id: Datatype.java 253 2009-06-30 03:06:10Z jhyde $ 023 * @since Aug 23, 2006 024 */ 025 public enum Datatype { 026 /* 027 * The following values exactly match VARENUM 028 * in Automation and may be used in VARIANT. 029 */ 030 INTEGER(3, "DBTYPE_I4", "A four-byte, signed integer: INTEGER"), 031 032 DOUBLE(5, "DBTYPE_R8", "A double-precision floating-point value: Double"), 033 034 CURRENCY( 035 6, 036 "DBTYPE_CY", 037 "A currency value: LARGE_INTEGER, Currency is a fixed-point number with " 038 + "four digits to the right of the decimal point. It is stored in an " 039 + "eight-byte signed integer, scaled by 10,000."), 040 041 BOOLEAN( 042 11, 043 "DBTYPE_BOOL", 044 "A Boolean value stored in the same way as in Automation: VARIANT_BOOL; " 045 + "0 means false and ~0 (bitwise, the value is not 0; that is, all bits " 046 + "are set to 1) means true."), 047 048 /** 049 * Used by SQL Server for value. 050 */ 051 VARIANT(12, "DBTYPE_VARIANT", "An Automation VARIANT"), 052 053 /** 054 * Used by SQL Server for font size. 055 */ 056 UNSIGNED_SHORT(18, "DBTYPE_UI2", "A two-byte, unsigned integer"), 057 058 /** 059 * Used by SQL Server for colors, font flags and cell ordinal. 060 */ 061 UNSIGNED_INTEGER(19, "DBTYPE_UI4", "A four-byte, unsigned integer"), 062 063 /* 064 * The following values exactly match VARENUM 065 * in Automation but cannot be used in VARIANT. 066 */ 067 LARGE_INTEGER( 068 20, 069 "DBTYPE_I8", 070 "An eight-byte, signed integer: LARGE_INTEGER"), 071 072 /* 073 * The following values are not in VARENUM in OLE. 074 */ 075 STRING( 076 130, 077 "DBTYPE_WSTR", 078 "A null-terminated Unicode character string: wchar_t[length]; If " 079 + "DBTYPE_WSTR is used by itself, the number of bytes allocated " 080 + "for the string, including the null-termination character, is " 081 + "specified by cbMaxLen in the DBBINDING structure. If " 082 + "DBTYPE_WSTR is combined with DBTYPE_BYREF, the number of bytes " 083 + "allocated for the string, including the null-termination character, " 084 + "is at least the length of the string plus two. In either case, the " 085 + "actual length of the string is determined from the bound length " 086 + "value. The maximum length of the string is the number of allocated " 087 + "bytes divided by sizeof(wchar_t) and truncated to the nearest " 088 + "integer."); 089 090 private final int xmlaOrdinal; 091 092 private static final Map<Integer, Datatype> xmlaMap = 093 new HashMap<Integer, Datatype>(); 094 095 static { 096 for (Datatype datatype : values()) { 097 xmlaMap.put(datatype.xmlaOrdinal, datatype); 098 } 099 } 100 101 Datatype( 102 int xmlaOrdinal, 103 String dbTypeIndicator, 104 String description) 105 { 106 this.xmlaOrdinal = xmlaOrdinal; 107 } 108 109 /** 110 * Looks up a Datatype by its XMLA ordinal. 111 * 112 * @param xmlaOrdinal Ordinal of a Datatype according to the XMLA 113 * specification. 114 * 115 * @return Datatype with the given ordinal, or null if there is no 116 * such Datatype 117 */ 118 public static Datatype forXmlaOrdinal(int xmlaOrdinal) { 119 return xmlaMap.get(xmlaOrdinal); 120 } 121 122 } 123 124 // End Datatype.java