############################################################################### ## ## ## ALEXANDRIA DIGITAL LIBRARY ## ## University of California at Santa Barbara ## ## ## ## ------------------------------------------------------------------------- ## ## ## ## Copyright (c) 2003 by the Regents of the University of California ## ## All rights reserved ## ## ## ## Redistribution and use in source and binary forms, with or without ## ## modification, are permitted provided that the following conditions are ## ## met: ## ## ## ## 1. Redistributions of source code must retain the above copyright ## ## notice, this list of conditions, and the following disclaimer. ## ## ## ## 2. Redistributions in binary form must reproduce the above copyright ## ## notice, this list of conditions, and the following disclaimer in ## ## the documentation and/or other materials provided with the ## ## distribution. ## ## ## ## 3. All advertising materials mentioning features or use of this ## ## software must display the following acknowledgement: This product ## ## includes software developed by the Alexandria Digital Library, ## ## University of California at Santa Barbara, and its contributors. ## ## ## ## 4. Neither the name of the University nor the names of its ## ## contributors may be used to endorse or promote products derived ## ## from this software without specific prior written permission. ## ## ## ## THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY ## ## EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ## ## WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE ## ## DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ## ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ## ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ## ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, ## ## STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ## ## ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ## ## POSSIBILITY OF SUCH DAMAGE. ## ## ## ############################################################################### # $Header: /export/home/gjanee/bucket99/paradigms/RCS/Identification_Integer.py,v 1.1 2003/02/05 06:17:38 gjanee Exp $ # SYNOPSIS # # Identification_Integer (table, idColumn, matchColumn, namespaces, # cardinality) # # table # A table to query, e.g., "holding". # # idColumn # The table's internal identifier column (i.e., the column # to be selected), e.g., "holding_id". # # matchColumn # The table's external identifier column (i.e., the column # against which the constraint is to be placed), e.g., # "fips_state_code". # # namespaces # A list of zero or more namespaces that the external # identifiers are members of, e.g., ["FIPS 5-2 numeric"]. # # cardinality # A Cardinality object representing the cardinality of # 'table' with respect to 'matchColumn'. # # DESCRIPTION # # Translates an identification constraint to an SQL integer # equality test, e.g., # # SELECT idColumn FROM table # WHERE matchColumn = id # # where 'id' is the identifier mentioned in the constraint. If # the constraint identifier is not an integer, or if the namespace # mentioned in the constraint is not one of the supported # namespaces, the query # # SELECT idColumn FROM table # WHERE 1 = 0 # # is returned. # # Exceptions thrown: # # none # # AUTHOR # # Greg Janee # gjanee@alexandria.ucsb.edu # # HISTORY # # $Log: Identification_Integer.py,v $ # Revision 1.1 2003/02/05 06:17:38 gjanee # Initial revision # import types import edu.ucsb.adl.middleware M = edu.ucsb.adl.middleware import UniversalTranslator UT = UniversalTranslator class Identification_Integer (UT.Paradigm): def __init__ (self, table, idColumn, matchColumn, namespaces, cardinality): UT.assertType(table, types.StringType) UT.assertType(idColumn, types.StringType) UT.assertType(matchColumn, types.StringType) UT.assertType(namespaces, types.ListType) UT.assertListElementType(namespaces, types.StringType) UT.assertType(cardinality, UT.Cardinality) self.table = table self.idColumn = idColumn self.matchColumn = matchColumn self.namespaces = namespaces self.cardinality = cardinality def translateBucketAtomic (self, constraint, vocabularies): UT.assertType(constraint, M.Query.IdentificationConstraint) assert constraint.getOperator() in UT.standardIdentificationOperators,\ "unsupported operator: " + constraint.getOperator() if constraint.getNamespace() != None and\ constraint.getNamespace() not in self.namespaces: return UT.constantFalseQuery(self.table, self.idColumn, self.cardinality) try: id = int(constraint.getIdentifier()) except ValueError: return UT.constantFalseQuery(self.table, self.idColumn, self.cardinality) table = UT.TableRef(self.table) return UT.Select( [UT.MainFrom(table, self.idColumn, self.cardinality)], UT.Expression([table, "." + self.matchColumn + " = " + str(id)]))