blob: 4316d8a9e2db22e3a0fb2a428d60b615bd9c1b17 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2008, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.core.context.orm;
import java.util.ListIterator;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.PersistentType;
import org.eclipse.jpt.core.context.XmlContextNode;
import org.eclipse.jpt.core.context.java.JavaPersistentType;
import org.eclipse.text.edits.DeleteEdit;
import org.eclipse.text.edits.ReplaceEdit;
/**
* Context <code>orm.xml</code> persistent type.
* <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*
* @version 3.0
* @since 2.0
*/
public interface OrmPersistentType
extends PersistentType, PersistentType.Owner, XmlContextNode
{
// ********** covariant overrides **********
EntityMappings getParent();
@SuppressWarnings("unchecked")
ListIterator<OrmPersistentAttribute> attributes();
OrmPersistentAttribute getAttributeNamed(String attributeName);
OrmTypeMapping getMapping();
//***************** specified attributes ***********************************
/**
* Return a read only iterator of the specified {@link OrmPersistentAttribute}s.
*/
ListIterator<OrmPersistentAttribute> specifiedAttributes();
/**
* Return the number of specified {@link OrmPersistentAttribute}s.
*/
int specifiedAttributesSize();
//TODO these are currently only used by tests, possibly remove them. OrmPersistenAttributes.setVirtual(boolean) is used by the UI
OrmPersistentAttribute addSpecifiedAttribute(String mappingKey, String attributeName);
void removeSpecifiedAttribute(OrmPersistentAttribute specifiedAttribute);
//***************** virtual attributes *************************************
String VIRTUAL_ATTRIBUTES_LIST = "virtualAttributes"; //$NON-NLS-1$
/**
* Return a read only iterator of the virtual orm persistent attributes. These
* are attributes that exist in the underyling java class, but are not specified
* in the orm.xml
*/
ListIterator<OrmPersistentAttribute> virtualAttributes();
/**
* Return the number of virtual orm persistent attributes. These are attributes that
* exist in the underyling java class, but are not specified in the orm.xml
*/
int virtualAttributesSize();
/**
* Return whether this persistent type contains the given virtual persistent attribute.
*/
boolean containsVirtualAttribute(OrmPersistentAttribute ormPersistentAttribute);
/**
* Remove the given specified orm persistent attribute from the orm.xml. The attribute
* will be removed from the orm.xml and moved from the list of specified attributes
* to the list of virtual attributes.
*/
void makeAttributeVirtual(OrmPersistentAttribute ormPersistentAttribute);
/**
* Add the given virtual orm persistent attribute to the orm.xml. The attribute will
* be added to the orm.xml and moved from the list of virtual attributes to the list
* of specified attributes
*/
void makeAttributeSpecified(OrmPersistentAttribute ormPersistentAttribute);
/**
* Add the given virtual orm persistent attribute to the orm.xml with a mapping of
* type mappingKey. The attribute will be added to the orm.xml and moved from
* the list of virtual attributes to the list of specified attributes
*/
void makeAttributeSpecified(OrmPersistentAttribute ormPersistentAttribute, String mappingKey);
//******************* mapping morphing *******************
void changeMapping(OrmPersistentAttribute ormPersistentAttribute, OrmAttributeMapping oldMapping, OrmAttributeMapping newMapping);
//******************* updating *******************
/**
* Update the OrmPersistentType context model object to match the
* resource model object. see {@link org.eclipse.jpt.core.JpaProject#update()}
*/
void update();
//******************* refactoring *******************
/**
* If this {@link OrmPersistentType#isFor(String)} the given IType, create a text
* DeleteEdit for deleting the type mapping element and any text that precedes it.
* Otherwise return an EmptyIterable.
* Though this will contain 1 or 0 DeleteEdits, using an Iterable
* for ease of use with other createDeleteEdit API.
*/
Iterable<DeleteEdit> createDeleteTypeEdits(IType type);
/**
* Create ReplaceEdits for renaming any references to the originalType to the newName.
* The originalType has not yet been renamed, the newName is the new short name.
*/
Iterable<ReplaceEdit> createRenameTypeEdits(IType originalType, String newName);
/**
* Create ReplaceEdits for moving any references to the originalType to the newPackage.
* The originalType has not yet been moved.
*/
Iterable<ReplaceEdit> createMoveTypeEdits(IType originalType, IPackageFragment newPackage);
/**
* Create ReplaceEdits for renaming any references to the originalPackage to the newName.
* The originalPackage has not yet been renamed.
*/
Iterable<ReplaceEdit> createRenamePackageEdits(IPackageFragment originalPackage, String newName);
//******************* misc *******************
boolean contains(int textOffset);
void classChanged(String oldClass, String newClass);
/**
* Return the Java persistent type that is referred to by this orm.xml persistent type.
* If there is no underlying java persistent type, then null is returned.
*/
JavaPersistentType getJavaPersistentType();
String JAVA_PERSISTENT_TYPE_PROPERTY = "javaPersistentType"; //$NON-NLS-1$
/**
* Return the persistent type's default package.
*/
String getDefaultPackage();
/**
* Return whether the persistent type is default metadata complete.
*/
boolean isDefaultMetadataComplete();
}