001:/*
002: * The contents of this file are subject to the Sapient Public License
003: * Version 1.0 (the "License"); you may not use this file except in compliance
004: * with the License. You may obtain a copy of the License at
005: * http://carbon.sf.net/License.html.
006: *
007: * Software distributed under the License is distributed on an "AS IS" basis,
008: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009: * the specific language governing rights and limitations under the License.
010: *
011: * The Original Code is The Carbon Component Framework.
012: *
013: * The Initial Developer of the Original Code is Sapient Corporation
014: *
015: * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
016: */
017:
018:package org.sape.carbon.services.sql;
019:
020:
021:import java.io.ObjectStreamException;
022:import java.io.Serializable;
023:import java.sql.ResultSet;
024:import java.util.Iterator;
025:
026:import org.sape.carbon.core.util.enum.BaseEnum;
027:import org.sape.carbon.core.util.enum.EnumNotFoundException;
028:
029:
030:/**
031: * <P>This is an enumeration of the supported Result Set types. These types
032: * are used in the creation of a connection for the purposes of configuring
033: * the type of Result Set that will be returned.</P>
034: *
035: * Copyright 2002 Sapient
036: * @since carbon 1.0
037: * @see java.sql.ResultSet
038: * @author Greg Hinkle, July 2002
039: * @version $Revision: 1.6 $($Author: dvoet $ / $Date: 2003/05/05 21:21:36 $)
040: */
041:public class ResultSetTypeEnum extends BaseEnum implements Serializable {
042:
043:
044: /**
045: * Represents the forward only type of result set
046: * @see java.sql.ResultSet#TYPE_FORWARD_ONLY
047: */
048: public static final ResultSetTypeEnum FORWARD_ONLY =
049: new ResultSetTypeEnum("TYPE_FORWARD_ONLY",
050: ResultSet.TYPE_FORWARD_ONLY);
051:
052: /**
053: * Represents the scroll insensitive type of result set
054: * @see java.sql.ResultSet#TYPE_SCROLL_INSENSITIVE
055: */
056: public static final ResultSetTypeEnum SCROLL_INSENSITIVE =
057: new ResultSetTypeEnum("TYPE_SCROLL_INSENSITIVE",
058: ResultSet.TYPE_SCROLL_INSENSITIVE);
059:
060: /**
061: * Represents the scroll sensitive type of result set
062: * @see java.sql.ResultSet#TYPE_SCROLL_SENSITIVE
063: */
064: public static final ResultSetTypeEnum SCROLL_SENSITIVE =
065: new ResultSetTypeEnum("TYPE_SCROLL_SENSITIVE",
066: ResultSet.TYPE_SCROLL_SENSITIVE);
067:
068: /**
069: * Constructs a enumeration of type <code>ResultSetTypeEnum</code>
070: *
071: * @param name the String name of a enumeration instance
072: * @param ordinal the integer ordinal value of a specific
073: * enumeration instance
074: */
075: private ResultSetTypeEnum(String name, int ordinal) {
076: super (ResultSetTypeEnum.class, name, ordinal);
077: }
078:
079:
080: /**
081: * Looks up a <code>ResultSetTypeEnum</code> by its string representation
082: *
083: * @param name the String name of a enumeration instance
084: * @return an specific <code>ResultSetTypeEnum</code>
085: * @throws ResultSetTypeEnumNotFoundException when there is no
086: * enumeration instance for the given name
087: */
088: public static final ResultSetTypeEnum getByName(String name)
089: throws ResultSetTypeEnumNotFoundException {
090:
091: ResultSetTypeEnum enum = (ResultSetTypeEnum)
092: BaseEnum.getByName(name, ResultSetTypeEnum.class);
093: if (enum != null) {
094: return enum;
095: } else {
096: throw new ResultSetTypeEnumNotFoundException(name);
097: }
098: }
099:
100: /**
101: * Looks up a <code>ResultSetTypeEnum</code> by its ordinal representation
102: *
103: * @param ordinal the integer ordinal value of a specific
104: * enumeration instance
105: * @return an specific <code>ResultSetTypeEnum</code>
106: * @throws ResultSetTypeEnumNotFoundException when there is no
107: * enumeration instance for the given ordinal
108: */
109: public static ResultSetTypeEnum getByOrdinal(int ordinal)
110: throws ResultSetTypeEnumNotFoundException {
111:
112: ResultSetTypeEnum enum =
113: (ResultSetTypeEnum)
114: BaseEnum.getByOrdinal(ordinal, ResultSetTypeEnum.class);
115:
116: if (enum != null) {
117: return enum;
118: } else {
119: throw new ResultSetTypeEnum.ResultSetTypeEnumNotFoundException(
120: (new Long(ordinal)).toString());
121: }
122: }
123:
124: /**
125: * Retrieves and iterator by ascending ordinal order for all enumerations
126: * of this type.
127: *
128: * @return an iterator over all <code>ResultSetTypeEnum</code>
129: */
130: public static Iterator iterator() {
131: return BaseEnum.iterator(ResultSetTypeEnum.class);
132: }
133:
134: /**
135: * Overrides part of serialization to return a reference to an
136: * enumeration instance that is managed by the Enumeration Subsystem.
137: * This will always return the SAME object instance for any single
138: * enum instance and is what allows the "==" operator to be used for
139: * comparisons.
140: *
141: * @throws ObjectStreamException indicates there is a failure to
142: * resolve the streamed object due to a format or read io
143: * exception
144: * @return the object instance that should be resolved by this class
145: */
146: final Object readResolve() throws ObjectStreamException {
147: return super .getByOrdinal(this .ordinal, ResultSetTypeEnum.class);
148: }
149:
150: /**
151: * This class is a typesafe retriever excepection for an enumeration
152: */
153: public static class ResultSetTypeEnumNotFoundException
154: extends EnumNotFoundException {
155:
156: /**
157: * @see EnumNotFoundException#EnumNotFoundException
158: */
159: public ResultSetTypeEnumNotFoundException(String name) {
160: super (ResultSetTypeEnum.class, name);
161: }
162: }
163:
164:
165:}
|