use of org.datanucleus.metadata.ClassMetaData in project datanucleus-api-jdo by datanucleus.
the class JDOMetaDataManager method registerPersistentInterface.
/**
* Method to register a persistent interface and its implementation with the MetaData system.
* @param imd MetaData for the interface
* @param implClass The implementation class
* @param clr ClassLoader Resolver to use
*/
public void registerPersistentInterface(InterfaceMetaData imd, Class implClass, ClassLoaderResolver clr) {
// Create ClassMetaData for the implementation
ClassMetaData cmd = new ClassMetaData(imd, ClassUtils.getClassNameForClass(implClass), true);
cmd.addImplements(new ImplementsMetaData(imd.getFullClassName()));
// Register the ClassMetaData for the implementation
registerMetaDataForClass(cmd.getFullClassName(), cmd);
// Register the metadata for the implementation against this persistent interface
classMetaDataByInterface.put(imd.getFullClassName(), cmd);
initialiseClassMetaData(cmd, implClass, clr);
// Deregister the metadata for the implementation from those "not found"
if (NucleusLogger.METADATA.isDebugEnabled()) {
NucleusLogger.METADATA.debug(Localiser.msg("044044", implClass.getName()));
}
classesWithoutPersistenceInfo.remove(implClass.getName());
}
use of org.datanucleus.metadata.ClassMetaData in project datanucleus-api-jdo by datanucleus.
the class JDOMetaDataHelper method getXMLForMetaData.
public String getXMLForMetaData(PackageMetaData pmd, String prefix, String indent) {
StringBuilder str = new StringBuilder();
str.append(prefix).append("<package name=\"" + pmd.getName() + "\"");
if (pmd.getCatalog() != null) {
str.append(" catalog=\"" + pmd.getCatalog() + "\"");
}
if (pmd.getSchema() != null) {
str.append(" schema=\"" + pmd.getSchema() + "\"");
}
str.append(">\n");
// Add interfaces
if (pmd.getNoOfInterfaces() > 0) {
for (int i = 0; i < pmd.getNoOfInterfaces(); i++) {
InterfaceMetaData imd = pmd.getInterface(i);
str.append(getXMLForMetaData(imd, prefix + indent, indent));
}
}
// Add classes
if (pmd.getNoOfClasses() > 0) {
for (int i = 0; i < pmd.getNoOfClasses(); i++) {
ClassMetaData cmd = pmd.getClass(i);
str.append(getXMLForMetaData(cmd, prefix + indent, indent));
}
}
// Add sequences
SequenceMetaData[] seqmds = pmd.getSequences();
if (seqmds != null) {
for (SequenceMetaData seqmd : seqmds) {
str.append(getXMLForMetaData(seqmd, prefix + indent, indent));
}
}
// Add extensions
processExtensions(pmd.getExtensions(), str, prefix, indent);
str.append(prefix).append("</package>\n");
return str.toString();
}
use of org.datanucleus.metadata.ClassMetaData in project datanucleus-api-jdo by datanucleus.
the class JDOMetadataImpl method newClassMetadata.
/* (non-Javadoc)
* @see javax.jdo.metadata.JDOMetadata#newClassMetadata(java.lang.Class)
*/
public ClassMetadata newClassMetadata(Class cls) {
String packageName = ClassUtils.getPackageNameForClass(cls);
// Adds if necessary
PackageMetaData internalPmd = getInternal().newPackageMetadata(packageName);
PackageMetadataImpl pmd = new PackageMetadataImpl(internalPmd);
pmd.parent = this;
String className = ClassUtils.getClassNameForClass(cls);
ClassMetaData internalCmd = internalPmd.newClassMetadata(className);
ClassMetadataImpl cmd = new ClassMetadataImpl(internalCmd);
cmd.parent = pmd;
return cmd;
}
use of org.datanucleus.metadata.ClassMetaData in project datanucleus-api-jdo by datanucleus.
the class JDOPersistenceManagerFactory method registerMetadata.
/**
* Method to register the supplied metadata with the persistence process managed by this
* <code>PersistenceManagerFactory</code>.
* Metadata can be created using the method {@link #newMetadata}.
* @param metadata The Metadata to register.
*/
public void registerMetadata(javax.jdo.metadata.JDOMetadata metadata) {
checkJDOPermission(JDOPermission.GET_METADATA);
MetaDataManager mmgr = nucleusContext.getMetaDataManager();
FileMetaData filemd = ((JDOMetadataImpl) metadata).getInternal();
// Check if already defined
for (int i = 0; i < filemd.getNoOfPackages(); i++) {
PackageMetaData pmd = filemd.getPackage(i);
for (int j = 0; j < pmd.getNoOfClasses(); j++) {
ClassMetaData cmd = pmd.getClass(j);
if (mmgr.hasMetaDataForClass(cmd.getFullClassName())) {
throw new JDOUserException("Cannot redefine metadata for " + cmd.getFullClassName());
}
}
for (int j = 0; j < pmd.getNoOfInterfaces(); j++) {
InterfaceMetaData imd = pmd.getInterface(j);
if (mmgr.hasMetaDataForClass(imd.getFullClassName())) {
throw new JDOUserException("Cannot redefine metadata for " + imd.getFullClassName());
}
}
}
mmgr.loadUserMetaData(filemd, null);
}
use of org.datanucleus.metadata.ClassMetaData in project datanucleus-api-jdo by datanucleus.
the class NucleusJDOHelper method getMetaDataForClass.
// ------------------------------------ MetaData --------------------------------
/**
* Accessor for the MetaData for the specified class
* @param pmf PersistenceManager factory
* @param cls The class
* @return The MetaData for the class
*/
public static ClassMetaData getMetaDataForClass(PersistenceManagerFactory pmf, Class cls) {
if (pmf == null || cls == null) {
return null;
}
if (!(pmf instanceof JDOPersistenceManagerFactory)) {
return null;
}
JDOPersistenceManagerFactory myPMF = (JDOPersistenceManagerFactory) pmf;
MetaDataManager mdmgr = myPMF.getNucleusContext().getMetaDataManager();
return (ClassMetaData) mdmgr.getMetaDataForClass(cls, myPMF.getNucleusContext().getClassLoaderResolver(null));
}
Aggregations