use of org.datanucleus.metadata.ColumnMetaData 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.ColumnMetaData 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.ColumnMetaData in project datanucleus-api-jdo by datanucleus.
the class JDOMetaDataHelper method getXMLForMetaData.
public String getXMLForMetaData(IdentityMetaData idmd, String prefix, String indent) {
StringBuilder str = new StringBuilder();
if (idmd.getValueStrategy() != null) {
str.append(prefix).append("<datastore-identity strategy=\"" + idmd.getValueStrategy() + "\"");
} else {
str.append(prefix).append("<datastore-identity");
}
if (idmd.getColumnName() != null) {
str.append("\n").append(prefix).append(" column=\"" + idmd.getColumnName() + "\"");
}
if (idmd.getSequence() != null) {
str.append("\n").append(prefix).append(" sequence=\"" + idmd.getSequence() + "\"");
}
if ((idmd.getColumnMetaData() != null) || idmd.getNoOfExtensions() > 0) {
str.append(">\n");
// Column MetaData
ColumnMetaData columnMetaData = idmd.getColumnMetaData();
if (columnMetaData != null) {
str.append(getXMLForMetaData(columnMetaData, prefix + indent, indent));
}
// Add extensions
processExtensions(idmd.getExtensions(), str, prefix, indent);
str.append(prefix).append("</datastore-identity>\n");
} else {
str.append("/>\n");
}
return str.toString();
}
use of org.datanucleus.metadata.ColumnMetaData in project datanucleus-api-jdo by datanucleus.
the class JDOMetaDataHelper method getXMLForMetaData.
public String getXMLForMetaData(KeyMetaData keymd, String prefix, String indent) {
StringBuilder str = new StringBuilder();
str.append(prefix).append("<key");
if (keymd.getMappedBy() != null) {
str.append(" mapped-by=\"" + keymd.getMappedBy() + "\"");
}
if (!StringUtils.isWhitespace(keymd.getTable())) {
str.append(" table=\"" + keymd.getTable() + "\"");
}
if (!StringUtils.isWhitespace(keymd.getColumnName())) {
str.append(" column=\"" + keymd.getColumnName() + "\"");
}
str.append(">\n");
// Add columns
ColumnMetaData[] columns = keymd.getColumnMetaData();
if (columns != null) {
for (ColumnMetaData colmd : columns) {
str.append(getXMLForMetaData(colmd, prefix + indent, indent));
}
}
// Add index metadata
if (keymd.getIndexMetaData() != null) {
str.append(getXMLForMetaData(keymd.getIndexMetaData(), prefix + indent, indent));
}
// Add unique metadata
if (keymd.getUniqueMetaData() != null) {
str.append(getXMLForMetaData(keymd.getUniqueMetaData(), prefix + indent, indent));
}
// Add embedded metadata
if (keymd.getEmbeddedMetaData() != null) {
str.append(getXMLForMetaData(keymd.getEmbeddedMetaData(), prefix + indent, indent));
}
// Add foreign-key metadata
if (keymd.getForeignKeyMetaData() != null) {
str.append(getXMLForMetaData(keymd.getForeignKeyMetaData(), prefix + indent, indent));
}
// Add extensions
processExtensions(keymd.getExtensions(), str, prefix, indent);
str.append(prefix).append("</key>\n");
return str.toString();
}
use of org.datanucleus.metadata.ColumnMetaData in project datanucleus-api-jdo by datanucleus.
the class MemberMetadataImpl method newColumnMetadata.
/* (non-Javadoc)
* @see javax.jdo.metadata.MemberMetadata#newColumnMetadata()
*/
public ColumnMetadata newColumnMetadata() {
ColumnMetaData internalColmd = getInternal().newColumnMetaData();
ColumnMetadataImpl colmd = new ColumnMetadataImpl(internalColmd);
colmd.parent = this;
return colmd;
}
Aggregations