All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.empire.db.DBExpressionIndex Maven / Gradle / Ivy

There is a newer version: 3.3.0
Show newest version
/*
 * 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.
 */
package org.apache.empire.db;

import org.apache.empire.exceptions.InvalidArgumentException;

/**
 * This class handles the primary key for the tables.
 * The primary key contains one or more columns.
 * 

* * */ public class DBExpressionIndex extends DBIndex { private final static long serialVersionUID = 1L; private DBExpr[] columnExpressions; /** * Constructs a DBExpresionIndex * * @param name the index name * @param unique true if the index has only unique values or false otherwise * @param columnExpressions an array of one or more column expressions of the index */ public DBExpressionIndex(String name, boolean unique, DBExpr... columnExpressions) { super(name, (unique ? UNIQUE : STANDARD), null); // columnExpressions if (columnExpressions==null || columnExpressions.length==0) throw new InvalidArgumentException("columnExpressions", columnExpressions); // set expression this.columnExpressions = columnExpressions; } /** * Constructs a DBExpresionIndex * * @param name the index name * @param unique true if the index has only unique values or false otherwise * @param columnExpression an column expressions that defines the key values for the index */ public DBExpressionIndex(String name, boolean unique, DBColumnExpr expr) { this(name, unique, new DBColumnExpr[] { expr }); } @Override public DBDatabase getDatabase() { return columnExpressions[0].getDatabase(); } /** * Returns the columnExpressions belonging to this index. * * @return the columnExpressions belonging to this index */ @Override public DBExpr[] getExpressions() { return columnExpressions; } /** * Checks if this index contains the column col * * @param col the column * * @return true if this index contains this column */ @Override public boolean contains(DBColumn col) { for (int i = 0; i < columnExpressions.length; i++) { if (!(columnExpressions[i] instanceof DBColumnExpr)) continue; if (col.equals(((DBColumnExpr)columnExpressions[i]).getUpdateColumn())) return true; } return false; } /** * Gets the position of a specified DBColumn object. * * @param col the column * * @return the position or -1 if the column was not found */ @Override public int getColumnPos(DBColumn col) { return -1; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy