Author: tfischer
Date: Fri Oct 8 19:27:16 2010
New Revision: 1005979
URL: http://svn.apache.org/viewvc?rev=1005979&view=rev
Log:
TORQUE-151: support BIT as key
Added:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/BooleanKey.java
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/SimpleKey.java
Added:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/BooleanKey.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/BooleanKey.java?rev=1005979&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/BooleanKey.java
(added)
+++
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/BooleanKey.java
Fri Oct 8 19:27:16 2010
@@ -0,0 +1,168 @@
+package org.apache.torque.om;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * This class can be used as an ObjectKey to uniquely identify an
+ * object within an application where the id consists
+ * of a Boolean.
+ *
+ * @author <a href="mailto:[email protected]">John McNally</a>
+ * @version $Id: StringKey.java 473821 2006-11-11 22:37:25Z tv $
+ */
+public class BooleanKey extends SimpleKey
+{
+ /**
+ * Serial version
+ */
+ private static final long serialVersionUID = 5109588772086713341L;
+
+ /**
+ * Creates an SimpleKey whose internal representation will be
+ * set later, through a set method
+ */
+ public BooleanKey()
+ {
+ }
+
+ /**
+ * Creates a BooleanKey whose internal representation is a Boolean
+ *
+ * @param key the key value
+ */
+ public BooleanKey(Boolean key)
+ {
+ this.key = key;
+ }
+
+ /**
+ * Creates a BooleanKey that is equivalent to key.
+ *
+ * @param key the key value
+ */
+ public BooleanKey(BooleanKey key)
+ {
+ if (key != null)
+ {
+ this.key = key.getValue();
+ }
+ else
+ {
+ this.key = null;
+ }
+ }
+
+ /**
+ * Sets the internal representation to a String.
+ *
+ * @param key the key value
+ */
+ public void setValue(String key)
+ {
+ if (key == null)
+ {
+ this.key = null;
+ }
+ else
+ {
+ this.key = Boolean.parseBoolean(key);
+ }
+ }
+
+ /**
+ * Sets the internal representation to a Boolean.
+ *
+ * @param key the key value
+ */
+ public void setValue(Boolean key)
+ {
+ this.key = key;
+ }
+
+ /**
+ * Sets the internal representation to the same object used by key.
+ *
+ * @param key the key value
+ */
+ public void setValue(BooleanKey key)
+ {
+ if (key != null)
+ {
+ this.key = key.getValue();
+ }
+ else
+ {
+ this.key = null;
+ }
+ }
+
+ /**
+ * Access the underlying Boolean object.
+ *
+ * @return a <code>Boolean</code> value
+ */
+ public Boolean getBoolean()
+ {
+ return (Boolean) key;
+ }
+
+ /**
+ * keyObj is equal to this StringKey if keyObj is a StringKey or String
+ * that contains the same information this key contains. Two ObjectKeys
+ * that both contain null values are not considered equal.
+ *
+ * @param keyObj the comparison value
+ * @return whether the two objects are equal
+ */
+ public boolean equals(Object keyObj)
+ {
+ boolean isEqual = false;
+
+ if (key != null)
+ {
+ if (keyObj instanceof Boolean)
+ {
+ isEqual = keyObj.equals(key);
+ }
+ // check against a BooleanKey. Two keys are equal, if their
+ // internal keys equivalent.
+ else if (keyObj instanceof BooleanKey)
+ {
+ Object obj = ((BooleanKey) keyObj).getValue();
+ isEqual = key.equals(obj);
+ }
+ }
+ return isEqual;
+ }
+
+ /**
+ * get a String representation
+ *
+ * @return a String representation of an empty String if the value is null
+ */
+ public String toString()
+ {
+ if (key != null)
+ {
+ return key.toString();
+ }
+ return "";
+ }
+}
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/SimpleKey.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/SimpleKey.java?rev=1005979&r1=1005978&r2=1005979&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/SimpleKey.java
(original)
+++
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/SimpleKey.java
Fri Oct 8 19:27:16 2010
@@ -128,4 +128,14 @@ public abstract class SimpleKey extends
{
return new DateKey(key);
}
+
+ /**
+ * Creates a SimpleKey equivalent to key
+ * @param key the key value
+ * @return a SimpleKey
+ */
+ public static SimpleKey keyFor(Boolean key)
+ {
+ return new BooleanKey(key);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]