use of org.datanucleus.metadata.PropertyMetaData in project datanucleus-rdbms by datanucleus.
the class ClassTable method getMemberMapping.
/**
* Accessor for the field mapping for the specified field.
* The field can be managed by a supertable of this table.
* @param mmd MetaData for this field/property
* @return the Mapping for the field/property
*/
public JavaTypeMapping getMemberMapping(AbstractMemberMetaData mmd) {
if (mmd == null) {
return null;
}
if (mmd instanceof PropertyMetaData && mmd.getAbstractClassMetaData() instanceof InterfaceMetaData) {
// TODO Fix Persistent Interfaces lookup
return getMemberMapping(mmd.getName());
}
if (mmd.isPrimaryKey()) {
assertIsPKInitialized();
} else {
assertIsInitialized();
}
// Check if we manage this field
JavaTypeMapping m = memberMappingsMap.get(mmd);
if (m != null) {
return m;
}
if (mmd.isPrimaryKey() && pkMappings != null) {
// pkMappings aren't in memberMappingsMap when in subclasses
for (int i = 0; i < pkMappings.length; i++) {
if (pkMappings[i].getMemberMetaData().equals(mmd)) {
return pkMappings[i];
}
}
}
Iterator<Map.Entry<AbstractMemberMetaData, JavaTypeMapping>> memberMapIter = memberMappingsMap.entrySet().iterator();
while (memberMapIter.hasNext()) {
// If we have overridden this member then it may have a different AbstractMemberMetaData passed in (i.e the override)
Map.Entry<AbstractMemberMetaData, JavaTypeMapping> entry = memberMapIter.next();
if (entry.getKey().getFullFieldName().equals(mmd.getFullFieldName())) {
return entry.getValue();
}
}
// Check supertable
int ifc = cmd.getNoOfInheritedManagedMembers();
if (mmd.getAbsoluteFieldNumber() < ifc) {
if (supertable != null) {
m = supertable.getMemberMapping(mmd);
if (m != null) {
return m;
}
}
}
// Check secondary tables
if (secondaryTables != null) {
Collection secTables = secondaryTables.values();
Iterator iter = secTables.iterator();
while (iter.hasNext()) {
SecondaryTable secTable = (SecondaryTable) iter.next();
m = secTable.getMemberMapping(mmd);
if (m != null) {
return m;
}
}
}
return null;
}
use of org.datanucleus.metadata.PropertyMetaData in project datanucleus-api-jdo by datanucleus.
the class JDOMetaDataHelper method getXMLForMetaData.
public String getXMLForMetaData(AbstractMemberMetaData mmd, String prefix, String indent) {
if (mmd.isStatic() || mmd.isFinal()) {
// If this field is static or final, don't bother with MetaData since we will ignore it anyway.
return "";
}
boolean field = (mmd instanceof FieldMetaData);
// Field needs outputting so generate metadata
StringBuilder str = new StringBuilder();
if (field) {
str.append(prefix).append("<field name=\"" + mmd.getName() + "\"");
} else {
str.append(prefix).append("<property name=\"" + mmd.getName() + "\"");
}
if (mmd.getPersistenceModifier() != null && !StringUtils.isWhitespace(mmd.getPersistenceModifier().toString())) {
str.append("\n").append(prefix).append(" persistence-modifier=\"" + mmd.getPersistenceModifier() + "\"");
}
if (!StringUtils.isWhitespace(mmd.getTable())) {
str.append("\n").append(prefix).append(" table=\"" + mmd.getTable() + "\"");
}
if (mmd.isPrimaryKey()) {
str.append("\n").append(prefix).append(" primary-key=\"" + mmd.isPrimaryKey() + "\"");
}
str.append("\n").append(prefix).append(" null-value=\"" + mmd.getNullValue() + "\"");
if (mmd.isDefaultFetchGroup()) {
str.append("\n").append(prefix).append(" default-fetch-group=\"" + mmd.isDefaultFetchGroup() + "\"");
}
if (mmd.isEmbedded()) {
str.append("\n").append(prefix).append(" embedded=\"" + mmd.isEmbedded() + "\"");
}
if (mmd.isSerialized()) {
str.append("\n").append(prefix).append(" serialized=\"" + mmd.isSerialized() + "\"");
}
if (mmd.isDependent()) {
str.append("\n").append(prefix).append(" dependent=\"" + mmd.isDependent() + "\"");
}
if (mmd.getMappedBy() != null) {
str.append("\n").append(prefix).append(" mapped-by=\"" + mmd.getMappedBy() + "\"");
}
String[] fieldTypes = mmd.getFieldTypes();
if (fieldTypes != null) {
str.append("\n").append(prefix).append(" field-type=\"");
for (int i = 0; i < fieldTypes.length; i++) {
str.append(fieldTypes[i]);
}
str.append("\"");
}
if (!StringUtils.isWhitespace(mmd.getLoadFetchGroup())) {
str.append("\n").append(prefix).append(" load-fetch-group=\"" + mmd.getLoadFetchGroup() + "\"");
}
if (mmd.getRecursionDepth() != AbstractMemberMetaData.DEFAULT_RECURSION_DEPTH && mmd.getRecursionDepth() != AbstractMemberMetaData.UNDEFINED_RECURSION_DEPTH) {
str.append("\n").append(prefix).append(" recursion-depth=\"" + mmd.getRecursionDepth() + "\"");
}
if (mmd.getValueStrategy() != null) {
str.append("\n").append(prefix).append(" value-strategy=\"" + mmd.getValueStrategy() + "\"");
}
if (mmd.getSequence() != null) {
str.append("\n").append(prefix).append(" sequence=\"" + mmd.getSequence() + "\"");
}
if (!field) {
PropertyMetaData propmd = (PropertyMetaData) mmd;
if (propmd.getFieldName() != null) {
str.append("\n").append(prefix).append(" field-name=\"" + propmd.getFieldName() + "\"");
}
}
if (mmd.getIndexMetaData() == null && mmd.getIndexed() != null) {
str.append("\n").append(prefix).append(" indexed=\"" + mmd.getIndexed() + "\"");
}
if (mmd.getUniqueMetaData() == null) {
str.append("\n").append(prefix).append(" unique=\"" + mmd.isUnique() + "\"");
}
str.append(">\n");
// Add field containers
ContainerMetaData contmd = mmd.getContainer();
if (contmd != null) {
if (contmd instanceof CollectionMetaData) {
CollectionMetaData c = (CollectionMetaData) contmd;
str.append(getXMLForMetaData(c, prefix + indent, indent));
} else if (contmd instanceof ArrayMetaData) {
ArrayMetaData c = (ArrayMetaData) contmd;
str.append(getXMLForMetaData(c, prefix + indent, indent));
} else if (contmd instanceof MapMetaData) {
MapMetaData c = (MapMetaData) contmd;
str.append(getXMLForMetaData(c, prefix + indent, indent));
}
}
// Add columns
ColumnMetaData[] columnMetaData = mmd.getColumnMetaData();
if (columnMetaData != null) {
for (int i = 0; i < columnMetaData.length; i++) {
str.append(getXMLForMetaData(columnMetaData[i], prefix + indent, indent));
}
}
// Add join
if (mmd.getJoinMetaData() != null) {
str.append(getXMLForMetaData(mmd.getJoinMetaData(), prefix + indent, indent));
}
// Add element
if (mmd.getElementMetaData() != null) {
str.append(getXMLForMetaData(mmd.getElementMetaData(), prefix + indent, indent));
}
// Add key
if (mmd.getKeyMetaData() != null) {
str.append(getXMLForMetaData(mmd.getKeyMetaData(), prefix + indent, indent));
}
// Add value
if (mmd.getValueMetaData() != null) {
str.append(getXMLForMetaData(mmd.getValueMetaData(), prefix + indent, indent));
}
// Add order
if (mmd.getOrderMetaData() != null) {
str.append(getXMLForMetaData(mmd.getOrderMetaData(), prefix + indent, indent));
}
// Add embedded
if (mmd.getEmbeddedMetaData() != null) {
str.append(getXMLForMetaData(mmd.getEmbeddedMetaData(), prefix + indent, indent));
}
// Add index
if (mmd.getIndexMetaData() != null) {
str.append(getXMLForMetaData(mmd.getIndexMetaData(), prefix + indent, indent));
}
// Add unique
if (mmd.getUniqueMetaData() != null) {
str.append(getXMLForMetaData(mmd.getUniqueMetaData(), prefix + indent, indent));
}
// Add foreign-key
if (mmd.getForeignKeyMetaData() != null) {
str.append(getXMLForMetaData(mmd.getForeignKeyMetaData(), prefix + indent, indent));
}
// Add extensions
processExtensions(mmd.getExtensions(), str, prefix, indent);
if (field) {
str.append(prefix).append("</field>\n");
} else {
str.append(prefix).append("</property>\n");
}
return str.toString();
}
use of org.datanucleus.metadata.PropertyMetaData in project datanucleus-api-jdo by datanucleus.
the class TypeMetadataImpl method newPropertyMetadata.
/* (non-Javadoc)
* @see javax.jdo.metadata.ComponentMetadata#newPropertyMetadata(java.lang.reflect.Method)
*/
public PropertyMetadata newPropertyMetadata(Method method) {
String methodName = method.getName();
String name = null;
if (methodName.startsWith("set")) {
name = methodName.substring(3);
} else if (methodName.startsWith("get")) {
name = methodName.substring(3);
} else if (methodName.startsWith("is")) {
name = methodName.substring(2);
} else {
throw new JDOUserException("Method " + methodName + " is not a Java-bean method");
}
String propertyName = name.substring(0, 1).toLowerCase() + name.substring(1);
PropertyMetaData internalPmd = getInternal().newPropertyMetadata(propertyName);
PropertyMetadataImpl pmd = new PropertyMetadataImpl(internalPmd);
pmd.parent = this;
return pmd;
}
use of org.datanucleus.metadata.PropertyMetaData in project datanucleus-api-jdo by datanucleus.
the class TypeMetadataImpl method newPropertyMetadata.
/* (non-Javadoc)
* @see javax.jdo.metadata.ComponentMetadata#newPropertyMetadata(java.lang.String)
*/
public PropertyMetadata newPropertyMetadata(String name) {
PropertyMetaData internalPmd = getInternal().newPropertyMetadata(name);
PropertyMetadataImpl pmd = new PropertyMetadataImpl(internalPmd);
pmd.parent = this;
return pmd;
}
use of org.datanucleus.metadata.PropertyMetaData in project datanucleus-api-jdo by datanucleus.
the class IndexMetadataImpl method newPropertyMetadata.
/* (non-Javadoc)
* @see javax.jdo.metadata.IndexMetadata#newPropertyMetadata(java.lang.String)
*/
public PropertyMetadata newPropertyMetadata(String name) {
PropertyMetaData internalPmd = new PropertyMetaData(getInternal(), name);
PropertyMetadataImpl pmd = new PropertyMetadataImpl(internalPmd);
pmd.parent = this;
return pmd;
}
Aggregations