use of org.datanucleus.metadata.PropertyMetaData in project datanucleus-api-jdo by datanucleus.
the class JDOMetaDataHandler method startElement.
/**
* Handler method called at the start of an element.
* @param uri URI of the tag
* @param localName Local name
* @param qName Element name
* @param attrs Attributes for this element
* @throws SAXException in parsing errors
*/
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
if (charactersBuffer.length() > 0) {
// Cater for subelements that appear before the end of the body text (save the body text with the
// parent)
String currentString = getString().trim();
if (getStack() instanceof QueryMetaData) {
((QueryMetaData) getStack()).setQuery(currentString.trim());
}
}
if (localName.length() < 1) {
localName = qName;
}
try {
if (localName.equals("jdo")) {
FileMetaData filemd = (FileMetaData) getStack();
filemd.setType(MetadataFileType.JDO_FILE);
filemd.setCatalog(getAttr(attrs, "catalog"));
filemd.setSchema(getAttr(attrs, "schema"));
} else if (localName.equals("orm")) {
FileMetaData filemd = (FileMetaData) getStack();
filemd.setType(MetadataFileType.JDO_ORM_FILE);
filemd.setCatalog(getAttr(attrs, "catalog"));
filemd.setSchema(getAttr(attrs, "schema"));
} else if (localName.equals("jdoquery")) {
FileMetaData filemd = (FileMetaData) getStack();
filemd.setType(MetadataFileType.JDO_QUERY_FILE);
} else if (localName.equals("fetch-plan")) {
FileMetaData filemd = (FileMetaData) metadata;
FetchPlanMetaData fpmd = filemd.newFetchPlanMetadata(getAttr(attrs, "name"));
fpmd.setMaxFetchDepth(getAttr(attrs, "max-fetch-depth"));
fpmd.setFetchSize(getAttr(attrs, "fetch-size"));
pushStack(fpmd);
} else if (localName.equals("package")) {
FileMetaData filemd = (FileMetaData) getStack();
PackageMetaData pmd = filemd.newPackageMetadata(getAttr(attrs, "name"));
pmd.setCatalog(getAttr(attrs, "catalog"));
pmd.setSchema(getAttr(attrs, "schema"));
pushStack(pmd);
} else if (localName.equals("class")) {
PackageMetaData pmd = (PackageMetaData) getStack();
ClassMetaData cmd = newClassObject(pmd, attrs);
pmd.addClass(cmd);
pushStack(cmd);
} else if (localName.equals("interface")) {
PackageMetaData pmd = (PackageMetaData) getStack();
InterfaceMetaData imd = newInterfaceObject(pmd, attrs);
pmd.addInterface(imd);
pushStack(imd);
} else if (localName.equals("primary-key")) {
MetaData md = getStack();
PrimaryKeyMetaData pkmd = new PrimaryKeyMetaData();
pkmd.setName(getAttr(attrs, "name"));
pkmd.setColumnName(getAttr(attrs, "column"));
if (md instanceof AbstractClassMetaData) {
((AbstractClassMetaData) md).setPrimaryKeyMetaData(pkmd);
} else if (md instanceof JoinMetaData) {
((JoinMetaData) md).setPrimaryKeyMetaData(pkmd);
}
pushStack(pkmd);
} else if (localName.equals("implements")) {
ClassMetaData cmd = (ClassMetaData) getStack();
ImplementsMetaData imd = new ImplementsMetaData(getAttr(attrs, "name"));
cmd.addImplements(imd);
pushStack(imd);
} else if (localName.equals("property")) {
MetaData parent = getStack();
if (parent instanceof AbstractClassMetaData) {
AbstractClassMetaData acmd = (AbstractClassMetaData) parent;
PropertyMetaData propmd = newPropertyObject(acmd, attrs);
acmd.addMember(propmd);
pushStack(propmd);
} else if (parent instanceof EmbeddedMetaData) {
EmbeddedMetaData emd = (EmbeddedMetaData) parent;
PropertyMetaData propmd = newPropertyObject(emd, attrs);
emd.addMember(propmd);
pushStack(propmd);
} else if (parent instanceof ImplementsMetaData) {
ImplementsMetaData implmd = (ImplementsMetaData) parent;
PropertyMetaData propmd = newPropertyObject(implmd, attrs);
implmd.addProperty(propmd);
pushStack(propmd);
} else if (parent instanceof FetchGroupMetaData) {
FetchGroupMetaData fgmd = (FetchGroupMetaData) parent;
FetchGroupMemberMetaData fgmmd = new FetchGroupMemberMetaData(fgmd, getAttr(attrs, "name"));
fgmmd.setRecursionDepth(getAttr(attrs, "recursion-depth"));
fgmmd.setProperty();
fgmd.addMember(fgmmd);
pushStack(fgmmd);
}
} else if (localName.equals("datastore-identity")) {
AbstractClassMetaData acmd = (AbstractClassMetaData) getStack();
IdentityMetaData idmd = new IdentityMetaData();
idmd.setColumnName(getAttr(attrs, "column"));
idmd.setValueStrategy(ValueGenerationStrategy.getIdentityStrategy(getAttr(attrs, "strategy")));
idmd.setSequence(getAttr(attrs, "sequence"));
acmd.setIdentityMetaData(idmd);
pushStack(idmd);
} else if (localName.equals("inheritance")) {
MetaData parent = getStack();
AbstractClassMetaData acmd = (AbstractClassMetaData) parent;
InheritanceMetaData inhmd = new InheritanceMetaData();
inhmd.setStrategy(getAttr(attrs, "strategy"));
acmd.setInheritanceMetaData(inhmd);
pushStack(inhmd);
} else if (localName.equals("discriminator")) {
MetaData md = getStack();
if (md instanceof InheritanceMetaData) {
InheritanceMetaData inhmd = (InheritanceMetaData) md;
DiscriminatorMetaData dismd = inhmd.newDiscriminatorMetadata();
dismd.setColumnName(getAttr(attrs, "column"));
dismd.setValue(getAttr(attrs, "value"));
dismd.setStrategy(getAttr(attrs, "strategy"));
dismd.setIndexed(getAttr(attrs, "indexed"));
pushStack(dismd);
} else if (md instanceof EmbeddedMetaData) {
EmbeddedMetaData embmd = (EmbeddedMetaData) md;
DiscriminatorMetaData dismd = embmd.newDiscriminatorMetadata();
dismd.setColumnName(getAttr(attrs, "column"));
dismd.setValue(getAttr(attrs, "value"));
dismd.setStrategy(getAttr(attrs, "strategy"));
dismd.setIndexed(getAttr(attrs, "indexed"));
pushStack(dismd);
}
} else if (localName.equals("query")) {
MetaData emd = getStack();
String name = getAttr(attrs, "name");
String lang = getAttr(attrs, "language");
if (!StringUtils.isWhitespace(lang)) {
if (// Convert to JDOQL
lang.equals(JDOQuery.JDOQL_QUERY_LANGUAGE)) {
lang = QueryLanguage.JDOQL.toString();
} else if (// Convert to SQL
lang.equals(JDOQuery.SQL_QUERY_LANGUAGE)) {
lang = QueryLanguage.SQL.toString();
} else if (// Convert to JPQL
lang.equals(JDOQuery.JPQL_QUERY_LANGUAGE)) {
lang = QueryLanguage.JPQL.toString();
}
}
if (emd instanceof ClassMetaData) {
ClassMetaData cmd = (ClassMetaData) emd;
if (StringUtils.isWhitespace(name)) {
throw new InvalidClassMetaDataException("044154", cmd.getFullClassName());
}
QueryMetaData qmd = new QueryMetaData(name);
qmd.setScope(cmd.getFullClassName());
qmd.setLanguage(lang);
qmd.setUnmodifiable(getAttr(attrs, "unmodifiable"));
qmd.setResultClass(getAttr(attrs, "result-class"));
qmd.setUnique(getAttr(attrs, "unique"));
qmd.setFetchPlanName(getAttr(attrs, "fetch-plan"));
cmd.addQuery(qmd);
pushStack(qmd);
} else if (emd instanceof InterfaceMetaData) {
InterfaceMetaData imd = (InterfaceMetaData) emd;
if (StringUtils.isWhitespace(name)) {
throw new InvalidClassMetaDataException("044154", imd.getFullClassName());
}
QueryMetaData qmd = new QueryMetaData(name);
qmd.setScope(imd.getFullClassName());
qmd.setLanguage(lang);
qmd.setUnmodifiable(getAttr(attrs, "unmodifiable"));
qmd.setResultClass(getAttr(attrs, "result-class"));
qmd.setUnique(getAttr(attrs, "unique"));
qmd.setFetchPlanName(getAttr(attrs, "fetch-plan"));
imd.addQuery(qmd);
pushStack(qmd);
} else if (emd instanceof FileMetaData) {
FileMetaData filemd = (FileMetaData) emd;
QueryMetaData qmd = filemd.newQueryMetadata(name);
qmd.setLanguage(lang);
qmd.setUnmodifiable(getAttr(attrs, "unmodifiable"));
qmd.setResultClass(getAttr(attrs, "result-class"));
qmd.setUnique(getAttr(attrs, "unique"));
qmd.setFetchPlanName(getAttr(attrs, "fetch-plan"));
pushStack(qmd);
}
} else if (localName.equals("sequence")) {
PackageMetaData pmd = (PackageMetaData) getStack();
SequenceMetaData seqmd = pmd.newSequenceMetadata(getAttr(attrs, "name"), getAttr(attrs, "strategy"));
seqmd.setFactoryClass(getAttr(attrs, "factory-class"));
seqmd.setDatastoreSequence(getAttr(attrs, "datastore-sequence"));
String seqSize = getAttr(attrs, "allocation-size");
if (seqSize != null) {
seqmd.setAllocationSize(seqSize);
}
String seqStart = getAttr(attrs, "initial-value");
if (seqStart != null) {
seqmd.setInitialValue(seqStart);
}
pushStack(seqmd);
} else if (localName.equals("field")) {
MetaData md = getStack();
if (md instanceof FetchGroupMetaData) {
FetchGroupMetaData fgmd = (FetchGroupMetaData) md;
FetchGroupMemberMetaData fgmmd = new FetchGroupMemberMetaData(md, getAttr(attrs, "name"));
fgmmd.setRecursionDepth(getAttr(attrs, "recursion-depth"));
fgmd.addMember(fgmmd);
pushStack(fgmmd);
return;
}
FieldMetaData fmd = newFieldObject(md, attrs);
if (md instanceof ClassMetaData) {
ClassMetaData cmd = (ClassMetaData) md;
cmd.addMember(fmd);
} else if (md instanceof EmbeddedMetaData) {
EmbeddedMetaData emd = (EmbeddedMetaData) md;
emd.addMember(fmd);
} else if (md instanceof ForeignKeyMetaData) {
ForeignKeyMetaData fkmd = (ForeignKeyMetaData) md;
fkmd.addMember(fmd.getName());
} else if (md instanceof IndexMetaData) {
IndexMetaData imd = (IndexMetaData) md;
imd.addMember(fmd.getName());
} else if (md instanceof UniqueMetaData) {
UniqueMetaData umd = (UniqueMetaData) md;
umd.addMember(fmd.getName());
}
pushStack(fmd);
} else if (localName.equals("join")) {
MetaData parent = getStack();
String tableName = getAttr(attrs, "table");
String columnName = getAttr(attrs, "column");
String outer = getAttr(attrs, "outer");
IndexedValue indexed = IndexedValue.getIndexedValue(getAttr(attrs, "indexed"));
String unique = getAttr(attrs, "unique");
String deleteAction = getAttr(attrs, "delete-action");
JoinMetaData joinmd = null;
if (parent instanceof AbstractMemberMetaData) {
AbstractMemberMetaData fmd = (AbstractMemberMetaData) parent;
joinmd = fmd.newJoinMetaData();
} else if (parent instanceof AbstractClassMetaData) {
AbstractClassMetaData cmd = (AbstractClassMetaData) parent;
joinmd = new JoinMetaData();
cmd.addJoin(joinmd);
} else if (parent instanceof InheritanceMetaData) {
InheritanceMetaData inhmd = (InheritanceMetaData) parent;
joinmd = inhmd.newJoinMetadata();
} else {
throw new NucleusUserException("Error processing JDO XML metadata. Found \"join\" with parent " + StringUtils.toJVMIDString(parent) + " - not supported");
}
joinmd.setTable(tableName);
joinmd.setColumnName(columnName);
joinmd.setOuter(MetaDataUtils.getBooleanForString(outer, false));
joinmd.setIndexed(indexed);
joinmd.setUnique(unique);
joinmd.setDeleteAction(deleteAction);
pushStack(joinmd);
} else if (localName.equals("map")) {
AbstractMemberMetaData fmd = (AbstractMemberMetaData) getStack();
MapMetaData mapmd = fmd.newMapMetaData();
mapmd.setKeyType(getAttr(attrs, "key-type"));
String embKeyStr = getAttr(attrs, "embedded-key");
if (!StringUtils.isWhitespace(embKeyStr)) {
mapmd.setEmbeddedKey(Boolean.valueOf(embKeyStr));
}
String serKeyStr = getAttr(attrs, "serialized-key");
if (!StringUtils.isWhitespace(serKeyStr)) {
mapmd.setSerializedKey(Boolean.valueOf(serKeyStr));
}
String depKeyStr = getAttr(attrs, "dependent-key");
if (!StringUtils.isWhitespace(depKeyStr)) {
mapmd.setDependentKey(Boolean.valueOf(depKeyStr));
}
mapmd.setValueType(getAttr(attrs, "value-type"));
String embValStr = getAttr(attrs, "embedded-value");
if (!StringUtils.isWhitespace(embValStr)) {
mapmd.setEmbeddedValue(Boolean.valueOf(embValStr));
}
String serValStr = getAttr(attrs, "serialized-value");
if (!StringUtils.isWhitespace(serValStr)) {
mapmd.setSerializedValue(Boolean.valueOf(serValStr));
}
String depValStr = getAttr(attrs, "dependent-value");
if (!StringUtils.isWhitespace(depValStr)) {
mapmd.setDependentValue(Boolean.valueOf(depValStr));
}
pushStack(mapmd);
} else if (localName.equals("array")) {
AbstractMemberMetaData fmd = (AbstractMemberMetaData) getStack();
ArrayMetaData arrmd = fmd.newArrayMetaData();
arrmd.setElementType(getAttr(attrs, "element-type"));
String embElemStr = getAttr(attrs, "embedded-element");
if (!StringUtils.isWhitespace(embElemStr)) {
arrmd.setEmbeddedElement(Boolean.valueOf(embElemStr));
}
String serElemStr = getAttr(attrs, "serialized-element");
if (!StringUtils.isWhitespace(serElemStr)) {
arrmd.setSerializedElement(Boolean.valueOf(serElemStr));
}
String depElemStr = getAttr(attrs, "dependent-element");
if (!StringUtils.isWhitespace(depElemStr)) {
arrmd.setDependentElement(Boolean.valueOf(depElemStr));
}
pushStack(arrmd);
} else if (localName.equals("collection")) {
AbstractMemberMetaData fmd = (AbstractMemberMetaData) getStack();
CollectionMetaData collmd = fmd.newCollectionMetaData();
collmd.setElementType(getAttr(attrs, "element-type"));
String embElemStr = getAttr(attrs, "embedded-element");
if (!StringUtils.isWhitespace(embElemStr)) {
collmd.setEmbeddedElement(Boolean.valueOf(embElemStr));
}
String serElemStr = getAttr(attrs, "serialized-element");
if (!StringUtils.isWhitespace(serElemStr)) {
collmd.setSerializedElement(Boolean.valueOf(serElemStr));
}
String depElemStr = getAttr(attrs, "dependent-element");
if (!StringUtils.isWhitespace(depElemStr)) {
collmd.setDependentElement(Boolean.valueOf(depElemStr));
}
pushStack(collmd);
} else if (localName.equals("column")) {
MetaData md = getStack();
ColumnMetaData colmd = new ColumnMetaData();
colmd.setName(getAttr(attrs, "name"));
colmd.setTarget(getAttr(attrs, "target"));
colmd.setTargetMember(getAttr(attrs, "target-field"));
colmd.setJdbcType(getAttr(attrs, "jdbc-type"));
colmd.setSqlType(getAttr(attrs, "sql-type"));
colmd.setLength(getAttr(attrs, "length"));
colmd.setScale(getAttr(attrs, "scale"));
colmd.setAllowsNull(getAttr(attrs, "allows-null"));
colmd.setDefaultValue(getAttr(attrs, "default-value"));
colmd.setInsertValue(getAttr(attrs, "insert-value"));
// JDO 3.1+
String pos = getAttr(attrs, "position");
if (pos != null) {
colmd.setPosition(pos);
}
if (md instanceof AbstractMemberMetaData) {
AbstractMemberMetaData fmd = (AbstractMemberMetaData) md;
fmd.addColumn(colmd);
} else if (md instanceof AbstractElementMetaData) {
AbstractElementMetaData elemd = (AbstractElementMetaData) md;
elemd.addColumn(colmd);
} else if (md instanceof JoinMetaData) {
JoinMetaData jnmd = (JoinMetaData) md;
jnmd.addColumn(colmd);
} else if (md instanceof IdentityMetaData) {
IdentityMetaData idmd = (IdentityMetaData) md;
idmd.setColumnMetaData(colmd);
} else if (md instanceof ForeignKeyMetaData) {
ForeignKeyMetaData fkmd = (ForeignKeyMetaData) md;
fkmd.addColumn(colmd);
} else if (md instanceof IndexMetaData) {
IndexMetaData idxmd = (IndexMetaData) md;
idxmd.addColumn(colmd.getName());
} else if (md instanceof UniqueMetaData) {
UniqueMetaData unimd = (UniqueMetaData) md;
unimd.addColumn(colmd.getName());
} else if (md instanceof OrderMetaData) {
OrderMetaData ormd = (OrderMetaData) md;
ormd.addColumn(colmd);
} else if (md instanceof DiscriminatorMetaData) {
DiscriminatorMetaData dismd = (DiscriminatorMetaData) md;
dismd.setColumnMetaData(colmd);
} else if (md instanceof VersionMetaData) {
VersionMetaData vermd = (VersionMetaData) md;
vermd.setColumnMetaData(colmd);
} else if (md instanceof AbstractClassMetaData) {
AbstractClassMetaData cmd = (AbstractClassMetaData) md;
cmd.addUnmappedColumn(colmd);
} else if (md instanceof PrimaryKeyMetaData) {
PrimaryKeyMetaData pkmd = (PrimaryKeyMetaData) md;
pkmd.addColumn(colmd);
}
pushStack(colmd);
} else if (localName.equals("element")) {
AbstractMemberMetaData fmd = (AbstractMemberMetaData) getStack();
ElementMetaData elemmd = new ElementMetaData();
elemmd.setTable(getAttr(attrs, "table"));
elemmd.setColumnName(getAttr(attrs, "column"));
elemmd.setDeleteAction(getAttr(attrs, "delete-action"));
elemmd.setUpdateAction(getAttr(attrs, "update-action"));
elemmd.setIndexed(IndexedValue.getIndexedValue(getAttr(attrs, "indexed")));
elemmd.setUnique(MetaDataUtils.getBooleanForString(getAttr(attrs, "unique"), false));
String mappedBy = getAttr(attrs, "mapped-by");
elemmd.setMappedBy(mappedBy);
if (!StringUtils.isWhitespace(mappedBy) && fmd.getMappedBy() == null) {
// With collection/array this is the same as mapped-by on the field
fmd.setMappedBy(mappedBy);
}
String converterAttr = getAttr(attrs, "converter");
String disableConverterAttr = getAttr(attrs, "use-default-conversion");
if (disableConverterAttr != null && Boolean.getBoolean(disableConverterAttr)) {
// TODO Disable on the element?
} else if (!StringUtils.isWhitespace(converterAttr)) {
TypeManager typeMgr = mmgr.getNucleusContext().getTypeManager();
ClassLoaderResolver clr = mmgr.getNucleusContext().getClassLoaderResolver(null);
Class converterCls = clr.classForName(converterAttr);
if (typeMgr.getTypeConverterForName(converterCls.getName()) == null) {
// Not yet cached an instance of this converter so create one
AttributeConverter conv = JDOTypeConverterUtils.createAttributeConverter((PersistenceNucleusContext) mmgr.getNucleusContext(), converterCls);
// TODO element type
Class attrType = JDOTypeConverterUtils.getAttributeTypeForAttributeConverter(converterCls, null);
Class dbType = JDOTypeConverterUtils.getDatastoreTypeForAttributeConverter(converterCls, attrType, null);
// Register the TypeConverter under the name of the AttributeConverter class
JDOTypeConverter typeConv = new JDOTypeConverter(conv);
typeMgr.registerConverter(converterAttr, typeConv, attrType, dbType, false, null);
}
elemmd.addExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME, converterAttr);
}
fmd.setElementMetaData(elemmd);
pushStack(elemmd);
} else if (localName.equals("key")) {
AbstractMemberMetaData fmd = (AbstractMemberMetaData) getStack();
KeyMetaData keymd = new KeyMetaData();
keymd.setTable(getAttr(attrs, "table"));
keymd.setColumnName(getAttr(attrs, "column"));
keymd.setDeleteAction(getAttr(attrs, "delete-action"));
keymd.setUpdateAction(getAttr(attrs, "update-action"));
keymd.setIndexed(IndexedValue.getIndexedValue(getAttr(attrs, "indexed")));
keymd.setUnique(MetaDataUtils.getBooleanForString(getAttr(attrs, "unique"), false));
keymd.setMappedBy(getAttr(attrs, "mapped-by"));
String converterAttr = getAttr(attrs, "converter");
String disableConverterAttr = getAttr(attrs, "use-default-conversion");
if (disableConverterAttr != null && Boolean.getBoolean(disableConverterAttr)) {
// TODO Disable on the key?
} else if (!StringUtils.isWhitespace(converterAttr)) {
TypeManager typeMgr = mmgr.getNucleusContext().getTypeManager();
ClassLoaderResolver clr = mmgr.getNucleusContext().getClassLoaderResolver(null);
Class converterCls = clr.classForName(converterAttr);
if (typeMgr.getTypeConverterForName(converterCls.getName()) == null) {
// Not yet cached an instance of this converter so create one
AttributeConverter conv = JDOTypeConverterUtils.createAttributeConverter((PersistenceNucleusContext) mmgr.getNucleusContext(), converterCls);
// TODO key type
Class attrType = JDOTypeConverterUtils.getAttributeTypeForAttributeConverter(converterCls, null);
Class dbType = JDOTypeConverterUtils.getDatastoreTypeForAttributeConverter(converterCls, attrType, null);
// Register the TypeConverter under the name of the AttributeConverter class
JDOTypeConverter typeConv = new JDOTypeConverter(conv);
typeMgr.registerConverter(converterAttr, typeConv, attrType, dbType, false, null);
}
keymd.addExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME, converterAttr);
}
fmd.setKeyMetaData(keymd);
pushStack(keymd);
} else // New value
if (localName.equals("value")) {
AbstractMemberMetaData fmd = (AbstractMemberMetaData) getStack();
ValueMetaData valuemd = new ValueMetaData();
valuemd.setTable(getAttr(attrs, "table"));
valuemd.setColumnName(getAttr(attrs, "column"));
valuemd.setDeleteAction(getAttr(attrs, "delete-action"));
valuemd.setUpdateAction(getAttr(attrs, "update-action"));
valuemd.setIndexed(IndexedValue.getIndexedValue(getAttr(attrs, "indexed")));
valuemd.setUnique(MetaDataUtils.getBooleanForString(getAttr(attrs, "unique"), false));
valuemd.setMappedBy(getAttr(attrs, "mapped-by"));
String converterAttr = getAttr(attrs, "converter");
String disableConverterAttr = getAttr(attrs, "use-default-conversion");
if (disableConverterAttr != null && Boolean.getBoolean(disableConverterAttr)) {
// TODO Disable on the value?
} else if (!StringUtils.isWhitespace(converterAttr)) {
TypeManager typeMgr = mmgr.getNucleusContext().getTypeManager();
ClassLoaderResolver clr = mmgr.getNucleusContext().getClassLoaderResolver(null);
Class converterCls = clr.classForName(converterAttr);
if (typeMgr.getTypeConverterForName(converterCls.getName()) == null) {
// Not yet cached an instance of this converter so create one
AttributeConverter conv = JDOTypeConverterUtils.createAttributeConverter((PersistenceNucleusContext) mmgr.getNucleusContext(), converterCls);
// TODO value type
Class attrType = JDOTypeConverterUtils.getAttributeTypeForAttributeConverter(converterCls, null);
Class dbType = JDOTypeConverterUtils.getDatastoreTypeForAttributeConverter(converterCls, attrType, null);
// Register the TypeConverter under the name of the AttributeConverter class
JDOTypeConverter typeConv = new JDOTypeConverter(conv);
typeMgr.registerConverter(converterAttr, typeConv, attrType, dbType, false, null);
}
valuemd.addExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME, converterAttr);
}
fmd.setValueMetaData(valuemd);
pushStack(valuemd);
} else // New fetch-group
if (localName.equals("fetch-group")) {
MetaData md = getStack();
FetchGroupMetaData fgmd = new FetchGroupMetaData(getAttr(attrs, "name"));
String postLoadStr = getAttr(attrs, "post-load");
if (!StringUtils.isWhitespace(postLoadStr)) {
fgmd.setPostLoad(Boolean.valueOf(postLoadStr));
}
if (md instanceof FetchGroupMetaData) {
FetchGroupMetaData fgmdParent = (FetchGroupMetaData) md;
fgmdParent.addFetchGroup(fgmd);
} else if (md instanceof AbstractClassMetaData) {
AbstractClassMetaData cmd = (AbstractClassMetaData) md;
cmd.addFetchGroup(fgmd);
} else if (md instanceof FetchPlanMetaData) {
FetchPlanMetaData fpmd = (FetchPlanMetaData) md;
fpmd.addFetchGroup(fgmd);
}
pushStack(fgmd);
} else if (localName.equals("extension")) {
MetaData md = getStack();
String vendorName = getAttr(attrs, "vendor-name");
if (StringUtils.isWhitespace(vendorName)) {
throw new InvalidMetaDataException("044160", vendorName, getAttr(attrs, "key"), getAttr(attrs, "value"));
}
if (vendorName != null && vendorName.equalsIgnoreCase(MetaData.VENDOR_NAME)) {
md.addExtension(getAttr(attrs, "key"), getAttr(attrs, "value"));
}
} else if (localName.equals("version")) {
AbstractClassMetaData cmd = (AbstractClassMetaData) getStack();
VersionMetaData vermd = cmd.newVersionMetadata();
String strategy = getAttr(attrs, "strategy");
if (!StringUtils.isWhitespace(strategy)) {
vermd.setStrategy(strategy);
}
vermd.setColumnName(getAttr(attrs, "column"));
vermd.setIndexed(IndexedValue.getIndexedValue(getAttr(attrs, "indexed")));
pushStack(vermd);
} else if (localName.equals("index")) {
MetaData md = getStack();
IndexMetaData idxmd = new IndexMetaData();
idxmd.setName(getAttr(attrs, "name"));
idxmd.setTable(getAttr(attrs, "table"));
String uniStr = getAttr(attrs, "unique");
if (!StringUtils.isWhitespace(uniStr)) {
idxmd.setUnique(Boolean.valueOf(uniStr));
}
if (md instanceof AbstractClassMetaData) {
AbstractClassMetaData cmd = (AbstractClassMetaData) md;
cmd.addIndex(idxmd);
} else if (md instanceof AbstractMemberMetaData) {
AbstractMemberMetaData fmd = (AbstractMemberMetaData) md;
fmd.setIndexMetaData(idxmd);
} else if (md instanceof JoinMetaData) {
JoinMetaData jmd = (JoinMetaData) md;
jmd.setIndexMetaData(idxmd);
} else if (md instanceof AbstractElementMetaData) {
AbstractElementMetaData elmd = (AbstractElementMetaData) md;
elmd.setIndexMetaData(idxmd);
} else if (md instanceof OrderMetaData) {
OrderMetaData omd = (OrderMetaData) md;
omd.setIndexMetaData(idxmd);
} else if (md instanceof VersionMetaData) {
VersionMetaData vermd = (VersionMetaData) md;
vermd.setIndexMetaData(idxmd);
} else if (md instanceof DiscriminatorMetaData) {
DiscriminatorMetaData dismd = (DiscriminatorMetaData) md;
dismd.setIndexMetaData(idxmd);
}
pushStack(idxmd);
} else if (localName.equals("unique")) {
MetaData md = getStack();
UniqueMetaData unimd = new UniqueMetaData();
unimd.setName(getAttr(attrs, "name"));
unimd.setTable(getAttr(attrs, "table"));
String defStr = getAttr(attrs, "deferred");
if (!StringUtils.isWhitespace(defStr)) {
unimd.setDeferred(Boolean.valueOf(defStr));
}
if (md instanceof AbstractClassMetaData) {
AbstractClassMetaData cmd = (AbstractClassMetaData) md;
cmd.addUniqueConstraint(unimd);
} else if (md instanceof AbstractMemberMetaData) {
AbstractMemberMetaData fmd = (AbstractMemberMetaData) md;
fmd.setUniqueMetaData(unimd);
} else if (md instanceof JoinMetaData) {
JoinMetaData jmd = (JoinMetaData) md;
jmd.setUniqueMetaData(unimd);
} else if (md instanceof AbstractElementMetaData) {
AbstractElementMetaData elmd = (AbstractElementMetaData) md;
elmd.setUniqueMetaData(unimd);
}
pushStack(unimd);
} else if (localName.equals("foreign-key")) {
MetaData md = getStack();
ForeignKeyMetaData fkmd = new ForeignKeyMetaData();
fkmd.setName(getAttr(attrs, "name"));
fkmd.setTable(getAttr(attrs, "table"));
fkmd.setUnique(getAttr(attrs, "unique"));
fkmd.setDeferred(getAttr(attrs, "deferred"));
fkmd.setDeleteAction(ForeignKeyAction.getForeignKeyAction(getAttr(attrs, "delete-action")));
fkmd.setUpdateAction(ForeignKeyAction.getForeignKeyAction(getAttr(attrs, "update-action")));
if (md instanceof AbstractClassMetaData) {
AbstractClassMetaData cmd = (AbstractClassMetaData) md;
cmd.addForeignKey(fkmd);
} else if (md instanceof AbstractMemberMetaData) {
AbstractMemberMetaData fmd = (AbstractMemberMetaData) md;
fmd.setForeignKeyMetaData(fkmd);
} else if (md instanceof JoinMetaData) {
JoinMetaData jmd = (JoinMetaData) md;
jmd.setForeignKeyMetaData(fkmd);
} else if (md instanceof AbstractElementMetaData) {
AbstractElementMetaData elmd = (AbstractElementMetaData) md;
elmd.setForeignKeyMetaData(fkmd);
}
pushStack(fkmd);
} else if (localName.equals("order")) {
OrderMetaData ordmd = new OrderMetaData();
ordmd.setIndexed(IndexedValue.getIndexedValue(getAttr(attrs, "indexed")));
ordmd.setColumnName(getAttr(attrs, "column"));
ordmd.setMappedBy(getAttr(attrs, "mapped-by"));
AbstractMemberMetaData fmd = (AbstractMemberMetaData) getStack();
fmd.setOrderMetaData(ordmd);
pushStack(ordmd);
} else if (localName.equals("embedded")) {
MetaData md = getStack();
EmbeddedMetaData embmd = new EmbeddedMetaData();
embmd.setOwnerMember(getAttr(attrs, "owner-field"));
embmd.setNullIndicatorColumn(getAttr(attrs, "null-indicator-column"));
embmd.setNullIndicatorValue(getAttr(attrs, "null-indicator-value"));
if (md instanceof AbstractMemberMetaData) {
AbstractMemberMetaData fmd = (AbstractMemberMetaData) md;
fmd.setEmbeddedMetaData(embmd);
} else if (md instanceof KeyMetaData) {
KeyMetaData kmd = (KeyMetaData) md;
kmd.setEmbeddedMetaData(embmd);
} else if (md instanceof ValueMetaData) {
ValueMetaData vmd = (ValueMetaData) md;
vmd.setEmbeddedMetaData(embmd);
} else if (md instanceof ElementMetaData) {
ElementMetaData elmd = (ElementMetaData) md;
elmd.setEmbeddedMetaData(embmd);
}
pushStack(embmd);
} else {
String message = Localiser.msg("044037", qName);
NucleusLogger.METADATA.error(message);
throw new RuntimeException(message);
}
} catch (RuntimeException ex) {
NucleusLogger.METADATA.error(Localiser.msg("044042", qName, getStack(), uri), ex);
throw ex;
}
}
use of org.datanucleus.metadata.PropertyMetaData in project datanucleus-core by datanucleus.
the class AbstractAnnotationReader method getMetaDataForClass.
/**
* Accessor for the ClassMetaData for the specified class from its annotations.
* The returned ClassMetaData will be unpopulated and uninitialised.
* @param cls The class
* @param pmd MetaData for the owning package
* @param clr ClassLoader resolver
* @return The ClassMetaData
*/
public AbstractClassMetaData getMetaDataForClass(Class cls, PackageMetaData pmd, ClassLoaderResolver clr) {
AnnotationObject[] classAnnotations = getClassAnnotationsForClass(cls);
if (classAnnotations == null || classAnnotations.length == 0) {
return null;
}
AbstractClassMetaData cmd = processClassAnnotations(pmd, cls, classAnnotations, clr);
if (cmd != null) {
// Process using any user-provided class annotation handlers
AnnotationManager annMgr = mmgr.getAnnotationManager();
for (AnnotationObject classAnnotation : classAnnotations) {
String annName = classAnnotation.getName();
ClassAnnotationHandler handler = annMgr.getHandlerForClassAnnotation(annName);
if (handler != null) {
handler.processClassAnnotation(classAnnotation, cmd, clr);
}
}
if (cmd.getPersistenceModifier() == ClassPersistenceModifier.PERSISTENCE_CAPABLE) {
Collection<AnnotatedMember> annotatedFields = getFieldAnnotationsForClass(cls);
Collection<AnnotatedMember> annotatedGetterMethods = getJavaBeanAccessorAnnotationsForClass(cls);
// Check for duplicate field/method and put on to field
for (AnnotatedMember field : annotatedFields) {
Iterator<AnnotatedMember> methodIter = annotatedGetterMethods.iterator();
while (methodIter.hasNext()) {
AnnotatedMember method = methodIter.next();
if (field.getName().equals(method.getName())) {
NucleusLogger.METADATA.info("Processable annotations specified on both field and getter for " + cls.getName() + "." + field.getName() + " so using as FIELD");
field.addAnnotations(method.getAnnotations());
methodIter.remove();
break;
}
}
}
// Check if we are using property or field access
boolean propertyAccessor = false;
if (cmd.getAccessViaField() != null) {
// Respect @Access setting if provided
if (cmd.getAccessViaField() == Boolean.FALSE) {
propertyAccessor = true;
}
} else {
// Extract the annotations for the getters
for (AnnotatedMember method : annotatedGetterMethods) {
if (method.getAnnotations().length > 0) {
// We have a getter with at least one annotation so must be using properties
propertyAccessor = true;
}
}
}
// Process the getters
for (AnnotatedMember method : annotatedGetterMethods) {
AnnotationObject[] annotations = method.getAnnotations();
if ((annotations == null || annotations.length == 0) && method.getMember().isProperty() && !propertyAccessor) {
// Getter with no annotations, and not using property access so ignore
continue;
}
// Process member annotations. We allow each annotation reader to create members if default persistent and no annotations
AbstractMemberMetaData mmd = processMemberAnnotations(cmd, method.getMember(), annotations);
if (annotations != null && annotations.length > 0) {
// Process using any user-provided member annotation handlers
for (AnnotationObject annotation : annotations) {
String annName = annotation.getName();
MemberAnnotationHandler handler = annMgr.getHandlerForMemberAnnotation(annName);
if (handler != null) {
if (mmd == null) {
mmd = new PropertyMetaData(cmd, method.getMember().getName());
cmd.addMember(mmd);
}
handler.processMemberAnnotation(annotation, mmd, clr);
}
}
}
}
// Process the fields
for (AnnotatedMember field : annotatedFields) {
AnnotationObject[] annotations = field.getAnnotations();
if ((annotations == null || annotations.length == 0) && !field.getMember().isProperty() && propertyAccessor) {
// Field with no annotations, and using property access so ignore
continue;
}
// Process fields. We allow each annotation reader to create members if default persistent and no annotations
AbstractMemberMetaData mmd = processMemberAnnotations(cmd, field.getMember(), annotations);
if (annotations != null && annotations.length > 0) {
// Process using any user-provided member annotation handlers
for (AnnotationObject annotation : annotations) {
String annName = annotation.getName();
MemberAnnotationHandler handler = annMgr.getHandlerForMemberAnnotation(annName);
if (handler != null) {
if (mmd == null) {
mmd = new FieldMetaData(cmd, field.getMember().getName());
cmd.addMember(mmd);
}
handler.processMemberAnnotation(annotation, mmd, clr);
}
}
}
}
// Process other methods (for listeners etc)
Method[] methods = cls.getDeclaredMethods();
for (Method method : methods) {
processMethodAnnotations(cmd, method);
}
}
}
return cmd;
}
use of org.datanucleus.metadata.PropertyMetaData in project datanucleus-core by datanucleus.
the class NewObjectIdInstance1 method execute.
/**
* Method to add the contents of the class method.
*/
public void execute() {
visitor.visitCode();
Label startLabel = new Label();
visitor.visitLabel(startLabel);
ClassMetaData cmd = enhancer.getClassMetaData();
if (cmd.getIdentityType() == IdentityType.APPLICATION) {
// application identity
if (!cmd.isInstantiable()) {
// Application identity but mapped-superclass with no PK defined, so throw exception
visitor.visitTypeInsn(Opcodes.NEW, getClassEnhancer().getNamer().getFatalInternalExceptionAsmClassName());
visitor.visitInsn(Opcodes.DUP);
visitor.visitLdcInsn("This class has no identity");
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, getClassEnhancer().getNamer().getFatalInternalExceptionAsmClassName(), "<init>", "(Ljava/lang/String;)V");
visitor.visitInsn(Opcodes.ATHROW);
Label endLabel = new Label();
visitor.visitLabel(endLabel);
visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
visitor.visitMaxs(3, 1);
} else {
String objectIdClass = cmd.getObjectidClass();
int[] pkFieldNums = cmd.getPKMemberPositions();
if (IdentityUtils.isSingleFieldIdentityClass(objectIdClass)) {
// SingleFieldIdentity
String ACN_objectIdClass = objectIdClass.replace('.', '/');
AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(pkFieldNums[0]);
visitor.visitTypeInsn(Opcodes.NEW, ACN_objectIdClass);
visitor.visitInsn(Opcodes.DUP);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;");
visitor.visitVarInsn(Opcodes.ALOAD, 0);
if (fmd instanceof PropertyMetaData) {
// Persistent property so use dnGetXXX()
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getGetMethodPrefixMethodName() + fmd.getName(), "()" + Type.getDescriptor(fmd.getType()));
} else {
// Persistent field so use xxx
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), Type.getDescriptor(fmd.getType()));
}
Class primitiveType = ClassUtils.getPrimitiveTypeForType(fmd.getType());
if (primitiveType != null) {
// Using object wrapper of primitive so use wrapper constructor
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, ACN_objectIdClass, "<init>", "(Ljava/lang/Class;" + Type.getDescriptor(fmd.getType()) + ")V");
} else {
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, ACN_objectIdClass, "<init>", "(Ljava/lang/Class;" + getNamer().getTypeDescriptorForSingleFieldIdentityGetKey(objectIdClass) + ")V");
}
visitor.visitInsn(Opcodes.ARETURN);
Label endLabel = new Label();
visitor.visitLabel(endLabel);
visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
visitor.visitMaxs(4, 1);
} else {
// User-provided app identity, and compound identity
String ACN_objectIdClass = objectIdClass.replace('.', '/');
visitor.visitTypeInsn(Opcodes.NEW, ACN_objectIdClass);
visitor.visitInsn(Opcodes.DUP);
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, ACN_objectIdClass, "<init>", "()V");
visitor.visitInsn(Opcodes.ARETURN);
Label endLabel = new Label();
visitor.visitLabel(endLabel);
visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
visitor.visitMaxs(2, 1);
}
}
} else {
// datastore/nondurable identity
visitor.visitInsn(Opcodes.ACONST_NULL);
visitor.visitInsn(Opcodes.ARETURN);
Label endLabel = new Label();
visitor.visitLabel(endLabel);
visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
visitor.visitMaxs(1, 1);
}
visitor.visitEnd();
}
use of org.datanucleus.metadata.PropertyMetaData in project datanucleus-core by datanucleus.
the class ProvideField method execute.
/**
* Method to add the contents of the class method.
*/
public void execute() {
AbstractMemberMetaData[] fields = enhancer.getClassMetaData().getManagedMembers();
String pcSuperclassName = enhancer.getClassMetaData().getPersistableSuperclass();
visitor.visitCode();
Label startLabel = new Label();
visitor.visitLabel(startLabel);
if (pcSuperclassName != null) {
if (fields.length > 0) {
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), getNamer().getStateManagerDescriptor());
Label l1 = new Label();
visitor.visitJumpInsn(Opcodes.IFNONNULL, l1);
visitor.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalStateException");
visitor.visitInsn(Opcodes.DUP);
visitor.visitLdcInsn("state manager is null");
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalStateException", "<init>", "(Ljava/lang/String;)V");
visitor.visitInsn(Opcodes.ATHROW);
visitor.visitLabel(l1);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitVarInsn(Opcodes.ILOAD, 1);
visitor.visitFieldInsn(Opcodes.GETSTATIC, getClassEnhancer().getASMClassName(), getNamer().getInheritedFieldCountFieldName(), "I");
visitor.visitInsn(Opcodes.ISUB);
Label[] fieldOptions = new Label[fields.length];
for (int i = 0; i < fields.length; i++) {
fieldOptions[i] = new Label();
}
Label defaultLabel = new Label();
Label endSwitchLabel = new Label();
// switch:
visitor.visitTableSwitchInsn(0, fields.length - 1, defaultLabel, fieldOptions);
for (int i = 0; i < fields.length; i++) {
visitor.visitLabel(fieldOptions[i]);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), getNamer().getStateManagerDescriptor());
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitVarInsn(Opcodes.ILOAD, 1);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
if (fields[i] instanceof PropertyMetaData) {
// Persistent property so use dnGetXXX()
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getGetMethodPrefixMethodName() + fields[i].getName(), "()" + Type.getDescriptor(fields[i].getType()));
} else {
// Persistent field so use xxx
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), fields[i].getName(), Type.getDescriptor(fields[i].getType()));
}
visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getStateManagerAsmClassName(), "provided" + EnhanceUtils.getTypeNameForPersistableMethod(fields[i].getType()) + "Field", "(" + getNamer().getPersistableDescriptor() + "I" + EnhanceUtils.getTypeDescriptorForEnhanceMethod(fields[i].getType()) + ")V");
visitor.visitJumpInsn(Opcodes.GOTO, endSwitchLabel);
}
// default:
visitor.visitLabel(defaultLabel);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitVarInsn(Opcodes.ILOAD, 1);
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, pcSuperclassName.replace('.', '/'), getNamer().getProvideFieldMethodName(), "(I)V");
// End of switch
visitor.visitLabel(endSwitchLabel);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitInsn(Opcodes.RETURN);
Label endLabel = new Label();
visitor.visitLabel(endLabel);
visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
visitor.visitLocalVariable(argNames[0], "I", null, startLabel, endLabel, 1);
visitor.visitMaxs(4, 2);
} else {
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitVarInsn(Opcodes.ILOAD, 1);
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, pcSuperclassName.replace('.', '/'), getNamer().getProvideFieldMethodName(), "(I)V");
visitor.visitInsn(Opcodes.RETURN);
Label endLabel = new Label();
visitor.visitLabel(endLabel);
visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
visitor.visitLocalVariable(argNames[0], "I", null, startLabel, endLabel, 1);
visitor.visitMaxs(2, 2);
}
} else {
if (fields.length > 0) {
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), getNamer().getStateManagerDescriptor());
Label l1 = new Label();
visitor.visitJumpInsn(Opcodes.IFNONNULL, l1);
visitor.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalStateException");
visitor.visitInsn(Opcodes.DUP);
visitor.visitLdcInsn("state manager is null");
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalStateException", "<init>", "(" + EnhanceUtils.CD_String + ")V");
visitor.visitInsn(Opcodes.ATHROW);
visitor.visitLabel(l1);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitVarInsn(Opcodes.ILOAD, 1);
Label[] fieldOptions = new Label[fields.length];
for (int i = 0; i < fields.length; i++) {
fieldOptions[i] = new Label();
}
Label defaultLabel = new Label();
Label endSwitchLabel = new Label();
// switch:
visitor.visitTableSwitchInsn(0, fields.length - 1, defaultLabel, fieldOptions);
for (int i = 0; i < fields.length; i++) {
visitor.visitLabel(fieldOptions[i]);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), getNamer().getStateManagerDescriptor());
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitVarInsn(Opcodes.ILOAD, 1);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
if (fields[i] instanceof PropertyMetaData) {
// Persistent property so use dnGetXXX()
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getGetMethodPrefixMethodName() + fields[i].getName(), "()" + Type.getDescriptor(fields[i].getType()));
} else {
// Persistent field so use xxx
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), fields[i].getName(), Type.getDescriptor(fields[i].getType()));
}
visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getStateManagerAsmClassName(), "provided" + EnhanceUtils.getTypeNameForPersistableMethod(fields[i].getType()) + "Field", "(" + getNamer().getPersistableDescriptor() + "I" + EnhanceUtils.getTypeDescriptorForEnhanceMethod(fields[i].getType()) + ")V");
visitor.visitJumpInsn(Opcodes.GOTO, endSwitchLabel);
}
// default:
visitor.visitLabel(defaultLabel);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalArgumentException");
visitor.visitInsn(Opcodes.DUP);
visitor.visitTypeInsn(Opcodes.NEW, "java/lang/StringBuffer");
visitor.visitInsn(Opcodes.DUP);
visitor.visitLdcInsn("out of field index :");
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/StringBuffer", "<init>", "(Ljava/lang/String;)V");
visitor.visitVarInsn(Opcodes.ILOAD, 1);
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuffer", "append", "(I)Ljava/lang/StringBuffer;");
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuffer", "toString", "()Ljava/lang/String;");
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalArgumentException", "<init>", "(Ljava/lang/String;)V");
visitor.visitInsn(Opcodes.ATHROW);
// End of switch
visitor.visitLabel(endSwitchLabel);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitInsn(Opcodes.RETURN);
Label l7 = new Label();
visitor.visitLabel(l7);
visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, l7, 0);
visitor.visitLocalVariable(argNames[0], "I", null, startLabel, l7, 1);
visitor.visitMaxs(5, 2);
} else {
visitor.visitInsn(Opcodes.RETURN);
Label endLabel = new Label();
visitor.visitLabel(endLabel);
visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
visitor.visitLocalVariable(argNames[0], "I", null, startLabel, endLabel, 1);
visitor.visitMaxs(0, 2);
}
}
visitor.visitEnd();
}
use of org.datanucleus.metadata.PropertyMetaData in project datanucleus-core by datanucleus.
the class EnhancerPropertySetterAdapter method visitMethodInsn.
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (mmd instanceof PropertyMetaData) {
// Check for any calls to getters/setters of properties that are from superclass(es)
String ownerClassName = owner.replace('/', '.');
AbstractClassMetaData cmd = enhancer.getClassMetaData();
if (!enhancer.getASMClassName().equals(owner)) {
String propName = ClassUtils.getFieldNameForJavaBeanSetter(name);
if (propName != null) {
boolean callingOverriddenSuperclassMethod = false;
while (cmd.getSuperAbstractClassMetaData() != null) {
cmd = cmd.getSuperAbstractClassMetaData();
if (cmd.getFullClassName().equals(ownerClassName)) {
AbstractMemberMetaData theMmd = cmd.getMetaDataForMember(mmd.getName());
if (theMmd != null) {
callingOverriddenSuperclassMethod = true;
break;
}
}
}
if (callingOverriddenSuperclassMethod) {
// Call dnGet{propName} in owner instead of "get{propName}"
String redirectMethodName = enhancer.getNamer().getSetMethodPrefixMethodName() + propName;
visitor.visitMethodInsn(opcode, owner, redirectMethodName, desc, itf);
return;
}
}
}
}
visitor.visitMethodInsn(opcode, owner, name, desc, itf);
}
Aggregations