org.eclipse.persistence.tools.schemaframework.IndexDefinition Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eclipselink Show documentation
Show all versions of eclipselink Show documentation
EclipseLink build based upon Git transaction f2b9fc5
The newest version!
/*
* Copyright (c) 2011, 2023 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 org.eclipse.persistence.exceptions.ValidationException;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
/**
*
* 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;
}
}