use of org.datanucleus.metadata.ForeignKeyMetaData in project datanucleus-api-jdo by datanucleus.
the class JoinMetadataImpl method getForeignKeyMetadata.
/* (non-Javadoc)
* @see javax.jdo.metadata.JoinMetadata#getForeignKeyMetadata()
*/
public ForeignKeyMetadata getForeignKeyMetadata() {
ForeignKeyMetaData internalFkmd = getInternal().getForeignKeyMetaData();
if (internalFkmd == null) {
return null;
}
ForeignKeyMetadataImpl fkmd = new ForeignKeyMetadataImpl(internalFkmd);
fkmd.parent = this;
return fkmd;
}
use of org.datanucleus.metadata.ForeignKeyMetaData in project datanucleus-api-jdo by datanucleus.
the class JDOAnnotationUtils method getFKMetaData.
/**
* Convenience method to create a ForeignKeyMetaData from the annotations data.
* @param name Name of the constraint
* @param table Name of the table (optional)
* @param unique Whether the constraint is unique
* @param deferred Whether the constraint is deferred
* @param deleteAction Any delete action
* @param updateAction Any update action
* @param fields Fields to apply the constraint across (optional)
* @param columns Columns to apply the constraint across (optional)
* @return The ForeignKeyMetaData
*/
public static ForeignKeyMetaData getFKMetaData(String name, String table, String unique, String deferred, String deleteAction, String updateAction, String[] fields, Column[] columns) {
ForeignKeyMetaData fkmd = new ForeignKeyMetaData();
fkmd.setName(name);
fkmd.setTable(table);
fkmd.setUnique(unique);
fkmd.setDeferred(deferred);
fkmd.setDeleteAction(org.datanucleus.metadata.ForeignKeyAction.getForeignKeyAction(deleteAction));
fkmd.setUpdateAction(org.datanucleus.metadata.ForeignKeyAction.getForeignKeyAction(updateAction));
if (fields != null && fields.length > 0) {
for (int j = 0; j < fields.length; j++) {
fkmd.addMember(fields[j]);
}
}
if (fkmd.getNumberOfMembers() == 0 && columns != null && columns.length > 0) {
for (int j = 0; j < columns.length; j++) {
ColumnMetaData colmd = JDOAnnotationUtils.getColumnMetaDataForColumnAnnotation(columns[j]);
fkmd.addColumn(colmd);
}
}
return fkmd;
}
use of org.datanucleus.metadata.ForeignKeyMetaData in project datanucleus-api-jdo by datanucleus.
the class JDOMetaDataHelper method getXMLForMetaData.
/**
* Method to convert an internal class/interface metadata into the associated JDO XML metadata.
* @param cmd Metadata for the class/interface
* @param prefix Prefix for the XML (e.g " ")
* @param indent Indent for each block of XML (e.g " ")
* @return The XML
*/
public String getXMLForMetaData(AbstractClassMetaData cmd, String prefix, String indent) {
StringBuilder str = new StringBuilder();
boolean intf = (cmd instanceof InterfaceMetaData);
if (intf) {
str.append(prefix).append("<interface name=\"" + cmd.getName() + "\"");
} else {
str.append(prefix).append("<class name=\"" + cmd.getName() + "\"");
}
if (cmd.getIdentityType() != null) {
str.append("\n").append(prefix).append(" identity-type=\"" + cmd.getIdentityType() + "\"");
}
if (cmd.getObjectidClass() != null) {
str.append("\n").append(prefix).append(" objectid-class=\"" + cmd.getObjectidClass() + "\"");
}
if (!cmd.isRequiresExtent()) {
str.append("\n").append(prefix).append(" requires-extent=\"" + cmd.isRequiresExtent() + "\"");
}
if (cmd.isEmbeddedOnly()) {
str.append("\n").append(prefix).append(" embedded-only=\"" + cmd.isEmbeddedOnly() + "\"");
}
if (cmd.getPersistenceModifier() != null) {
str.append("\n").append(prefix).append(" persistence-modifier=\"" + cmd.getPersistenceModifier() + "\"");
}
if (cmd.getCatalog() != null) {
str.append("\n").append(prefix).append(" catalog=\"" + cmd.getCatalog() + "\"");
}
if (cmd.getSchema() != null) {
str.append("\n").append(prefix).append(" schema=\"" + cmd.getSchema() + "\"");
}
if (cmd.getTable() != null) {
str.append("\n").append(prefix).append(" table=\"" + cmd.getTable() + "\"");
}
if (cmd.isDetachable()) {
str.append("\n").append(prefix).append(" detachable=\"" + cmd.isDetachable() + "\"");
}
str.append(">\n");
// Identity
if (cmd.getIdentityMetaData() != null) {
str.append(getXMLForMetaData(cmd.getIdentityMetaData(), prefix + indent, indent));
}
// PrimaryKey
if (cmd.getPrimaryKeyMetaData() != null) {
str.append(getXMLForMetaData(cmd.getPrimaryKeyMetaData(), prefix + indent, indent));
}
// Inheritance
if (cmd.getInheritanceMetaData() != null) {
str.append(getXMLForMetaData(cmd.getInheritanceMetaData(), prefix + indent, indent));
}
// Add Version
if (cmd.getVersionMetaData() != null) {
str.append(getXMLForMetaData(cmd.getVersionMetaData(), prefix + indent, indent));
}
// Add joins
List<JoinMetaData> joins = cmd.getJoinMetaData();
if (joins != null) {
for (JoinMetaData joinmd : joins) {
str.append(getXMLForMetaData(joinmd, prefix + indent, indent));
}
}
// Add foreign-keys
List<ForeignKeyMetaData> foreignKeys = cmd.getForeignKeyMetaData();
if (foreignKeys != null) {
for (ForeignKeyMetaData fkmd : foreignKeys) {
str.append(getXMLForMetaData(fkmd, prefix + indent, indent));
}
}
// Add indexes
List<IndexMetaData> indexes = cmd.getIndexMetaData();
if (indexes != null) {
for (IndexMetaData idxmd : indexes) {
str.append(getXMLForMetaData(idxmd, prefix + indent, indent));
}
}
// Add unique constraints
List<UniqueMetaData> uniqueConstraints = cmd.getUniqueMetaData();
if (uniqueConstraints != null) {
for (UniqueMetaData unimd : uniqueConstraints) {
str.append(getXMLForMetaData(unimd, prefix + indent, indent));
}
}
// Add members
int numMembers = cmd.getNoOfMembers();
for (int i = 0; i < numMembers; i++) {
AbstractMemberMetaData mmd = cmd.getMetaDataForMemberAtRelativePosition(i);
str.append(getXMLForMetaData(mmd, prefix + indent, indent));
}
// Add unmapped columns
List<ColumnMetaData> unmappedColumns = cmd.getUnmappedColumns();
if (unmappedColumns != null) {
for (int i = 0; i < unmappedColumns.size(); i++) {
ColumnMetaData col = unmappedColumns.get(i);
str.append(getXMLForMetaData(col, prefix + indent, indent));
}
}
// Add queries
QueryMetaData[] queries = cmd.getQueries();
if (queries != null) {
for (int i = 0; i < queries.length; i++) {
QueryMetaData q = queries[i];
str.append(getXMLForMetaData(q, prefix + indent, indent));
}
}
// Add fetch-groups
Set<FetchGroupMetaData> fetchGroups = cmd.getFetchGroupMetaData();
if (fetchGroups != null) {
for (FetchGroupMetaData fgmd : fetchGroups) {
str.append(getXMLForMetaData(fgmd, prefix + indent, indent));
}
}
// Add extensions
processExtensions(cmd.getExtensions(), str, prefix, indent);
if (intf) {
str.append(prefix + "</interface>\n");
} else {
str.append(prefix + "</class>\n");
}
return str.toString();
}
use of org.datanucleus.metadata.ForeignKeyMetaData in project datanucleus-api-jdo by datanucleus.
the class KeyMetadataImpl method newForeignKeyMetadata.
/* (non-Javadoc)
* @see javax.jdo.metadata.KeyMetadata#newForeignKeyMetadata()
*/
public ForeignKeyMetadata newForeignKeyMetadata() {
ForeignKeyMetaData internalFkmd = getInternal().newForeignKeyMetaData();
ForeignKeyMetadataImpl fkmd = new ForeignKeyMetadataImpl(internalFkmd);
fkmd.parent = this;
return fkmd;
}
use of org.datanucleus.metadata.ForeignKeyMetaData in project datanucleus-api-jdo by datanucleus.
the class MemberMetadataImpl method newForeignKeyMetadata.
public ForeignKeyMetadata newForeignKeyMetadata() {
ForeignKeyMetaData internalFkmd = getInternal().newForeignKeyMetaData();
ForeignKeyMetadataImpl fkmd = new ForeignKeyMetadataImpl(internalFkmd);
fkmd.parent = this;
return fkmd;
}
Aggregations