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

org.eclipse.persistence.tools.schemaframework.IndexDefinition Maven / Gradle / Ivy

There is a newer version: 5.0.0-B03
Show newest version
/*
 * Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0,
 * or the Eclipse Distribution License v. 1.0 which is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 */

// Contributors:
//     Oracle - initial API and implementation
package org.eclipse.persistence.tools.schemaframework;

import java.util.*;
import java.io.*;
import org.eclipse.persistence.exceptions.*;
import org.eclipse.persistence.internal.sessions.AbstractSession;

/**
 * 

* Purpose: Allow for indexes to be created. *

* @author James Sutherland * @since EclipseLink 2.2 */ public class IndexDefinition extends DatabaseObjectDefinition { protected String targetTable; protected List fields; protected boolean isUnique; public IndexDefinition() { this.fields = new ArrayList<>(); } public boolean isUnique() { return isUnique; } public void setIsUnique(boolean isUnique) { this.isUnique = isUnique; } public String getTargetTable() { return targetTable; } /** * PUBLIC: * set qualified table name. */ public void setTargetTable(String targetTable) { this.targetTable = targetTable; } /** * PUBLIC: * Add the field to the index. */ public void addField(String fieldName) { this.fields.add(fieldName); } /** * INTERNAL: * Return the create type statement. */ @Override public Writer buildCreationWriter(AbstractSession session, Writer writer) throws ValidationException { try { writer.write(session.getPlatform().buildCreateIndex(getTargetTable(), getName(), getQualifier(), isUnique(), this.fields.toArray(new String[0]))); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; } /** * INTERNAL: * Return the drop type statement. */ @Override public Writer buildDeletionWriter(AbstractSession session, Writer writer) throws ValidationException { try { writer.write(session.getPlatform().buildDropIndex(getTargetTable(), getName(), getQualifier())); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } return writer; } public List getFields() { return fields; } public void setFields(List fields) { this.fields = fields; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy