001: /**********************************************************************
002: Copyright (c) 2004 Andy Jefferson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015: Contributors:
016: ...
017: **********************************************************************/package org.jpox.metadata;
018:
019: import java.io.Serializable;
020:
021: /**
022: * Representation of the query languages.
023: *
024: * @since 1.1
025: * @version $Revision: 1.5 $
026: */
027: public class QueryLanguage implements Serializable {
028: /**
029: * language="javax.jdo.query.JDOQL"
030: */
031: public static final QueryLanguage JDOQL = new QueryLanguage(1);
032:
033: /**
034: * language="javax.jdo.query.SQL"
035: */
036: public static final QueryLanguage SQL = new QueryLanguage(2);
037:
038: /**
039: * language="javax.jdo.query.JPOXSQL"
040: */
041: public static final QueryLanguage JPOXSQL = new QueryLanguage(3);
042:
043: /**
044: * language="javax.jdo.query.JPQL"
045: */
046: public static final QueryLanguage JPQL = new QueryLanguage(4);
047:
048: private final int typeId;
049:
050: private QueryLanguage(int i) {
051: this .typeId = i;
052: }
053:
054: /**
055: * Indicates whether some other object is "equal to" this one.
056: * @param o the reference object with which to compare.
057: * @return true if this object is the same as the obj argument; false otherwise.
058: */
059: public boolean equals(Object o) {
060: if (o instanceof QueryLanguage) {
061: return ((QueryLanguage) o).typeId == typeId;
062: }
063: return false;
064: }
065:
066: /**
067: * Returns a string representation of the object.
068: * @return a string representation of the object.
069: */
070: public String toString() {
071: switch (typeId) {
072: case 1:
073: return "javax.jdo.query.JDOQL";
074: case 2:
075: return "javax.jdo.query.SQL";
076: case 3:
077: return "javax.jdo.query.JPOXSQL";
078: case 4:
079: return "javax.jdo.query.JPQL";
080: }
081: return "";
082: }
083:
084: /**
085: * Accessor to the query language type
086: * @return the type
087: */
088: public int getType() {
089: return typeId;
090: }
091:
092: /**
093: * Return QueryLanguage from String.
094: * @param value identity-type attribute value
095: * @return Instance of QueryLanguage. If parse failed, return null.
096: */
097: public static QueryLanguage getQueryLanguage(final String value) {
098: if (value == null) {
099: // Default to JDOQL if nothing passed in
100: return QueryLanguage.JDOQL;
101: } else if (QueryLanguage.JDOQL.toString().equalsIgnoreCase(
102: value)) {
103: return QueryLanguage.JDOQL;
104: } else if (QueryLanguage.SQL.toString().equalsIgnoreCase(value)) {
105: return QueryLanguage.SQL;
106: } else if (QueryLanguage.JPOXSQL.toString().equalsIgnoreCase(
107: value)) {
108: return QueryLanguage.JPOXSQL;
109: } else if (QueryLanguage.JPQL.toString()
110: .equalsIgnoreCase(value)) {
111: return QueryLanguage.JPQL;
112: }
113: return null;
114: }
115: }
|