Search in sources :

Example 11 with ClassMetaData

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());
}
Also used : ImplementsMetaData(org.datanucleus.metadata.ImplementsMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 12 with ClassMetaData

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();
}
Also used : InterfaceMetaData(org.datanucleus.metadata.InterfaceMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData) SequenceMetaData(org.datanucleus.metadata.SequenceMetaData)

Example 13 with ClassMetaData

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;
}
Also used : PackageMetaData(org.datanucleus.metadata.PackageMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 14 with ClassMetaData

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);
}
Also used : JDOMetadataImpl(org.datanucleus.api.jdo.metadata.JDOMetadataImpl) PackageMetaData(org.datanucleus.metadata.PackageMetaData) MetaDataManager(org.datanucleus.metadata.MetaDataManager) InterfaceMetaData(org.datanucleus.metadata.InterfaceMetaData) JDOUserException(javax.jdo.JDOUserException) FileMetaData(org.datanucleus.metadata.FileMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 15 with ClassMetaData

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));
}
Also used : MetaDataManager(org.datanucleus.metadata.MetaDataManager) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Aggregations

ClassMetaData (org.datanucleus.metadata.ClassMetaData)109 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)55 MetaDataManager (org.datanucleus.metadata.MetaDataManager)55 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)53 NucleusContext (org.datanucleus.NucleusContext)52 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)51 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)51 PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)38 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)18 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)14 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)14 ElementMetaData (org.datanucleus.metadata.ElementMetaData)14 JoinMetaData (org.datanucleus.metadata.JoinMetaData)14 PackageMetaData (org.datanucleus.metadata.PackageMetaData)14 Label (org.datanucleus.enhancer.asm.Label)6 FileMetaData (org.datanucleus.metadata.FileMetaData)6 InterfaceMetaData (org.datanucleus.metadata.InterfaceMetaData)6 PropertyMetaData (org.datanucleus.metadata.PropertyMetaData)6 KeyMetaData (org.datanucleus.metadata.KeyMetaData)5 MapMetaData (org.datanucleus.metadata.MapMetaData)5