Search in sources :

Example 1 with JDOMetadataImpl

use of org.datanucleus.api.jdo.metadata.JDOMetadataImpl 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 2 with JDOMetadataImpl

use of org.datanucleus.api.jdo.metadata.JDOMetadataImpl in project datanucleus-api-jdo by datanucleus.

the class JDOEnhancer method registerMetadata.

/* (non-Javadoc)
     * @see javax.jdo.JDOEnhancer#registerMetadata(javax.jdo.metadata.JDOMetadata)
     */
public void registerMetadata(javax.jdo.metadata.JDOMetadata metadata) {
    MetaDataManager mmgr = enhancer.getMetaDataManager();
    FileMetaData filemd = ((JDOMetadataImpl) metadata).getInternal();
    mmgr.loadUserMetaData(filemd, enhancer.getClassLoader());
}
Also used : JDOMetadataImpl(org.datanucleus.api.jdo.metadata.JDOMetadataImpl) MetaDataManager(org.datanucleus.metadata.MetaDataManager) FileMetaData(org.datanucleus.metadata.FileMetaData)

Example 3 with JDOMetadataImpl

use of org.datanucleus.api.jdo.metadata.JDOMetadataImpl in project tests by datanucleus.

the class JDOMetadataAPITest method testPackageClassInterface.

/**
 * Simple test that checks the numbers of packages, classes, interfaces contained.
 */
public void testPackageClassInterface() {
    JDOMetadata jdomd = pmf.newMetadata();
    PackageMetadata pmd1 = jdomd.newPackageMetadata("org.datanucleus.test");
    pmd1.newClassMetadata("MyClass1");
    pmd1.newClassMetadata("MyClass2");
    PackageMetadata pmd2 = jdomd.newPackageMetadata("org.datanucleus.test2");
    pmd2.newInterfaceMetadata("org.datanucleus.test3");
    // Check the JDO metadata
    assertEquals("Number of packages in JDO metadata is incorrect", 2, jdomd.getNumberOfPackages());
    assertEquals("Number of classes in JDO package metadata 1 is incorrect", 2, pmd1.getNumberOfClasses());
    assertEquals("Number of interfaces in JDO package metadata 1 is incorrect", 0, pmd1.getNumberOfInterfaces());
    assertEquals("Number of classes in JDO package metadata 2 is incorrect", 0, pmd2.getNumberOfClasses());
    assertEquals("Number of interfaces in JDO package metadata 2 is incorrect", 1, pmd2.getNumberOfInterfaces());
    // Check the internal metadata
    FileMetaData filemd = ((JDOMetadataImpl) jdomd).getInternal();
    assertEquals("Number of packages is incorrect", 2, filemd.getNoOfPackages());
}
Also used : JDOMetadataImpl(org.datanucleus.api.jdo.metadata.JDOMetadataImpl) JDOMetadata(javax.jdo.metadata.JDOMetadata) PackageMetadata(javax.jdo.metadata.PackageMetadata) FileMetaData(org.datanucleus.metadata.FileMetaData)

Aggregations

JDOMetadataImpl (org.datanucleus.api.jdo.metadata.JDOMetadataImpl)3 FileMetaData (org.datanucleus.metadata.FileMetaData)3 MetaDataManager (org.datanucleus.metadata.MetaDataManager)2 JDOUserException (javax.jdo.JDOUserException)1 JDOMetadata (javax.jdo.metadata.JDOMetadata)1 PackageMetadata (javax.jdo.metadata.PackageMetadata)1 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)1 ClassMetaData (org.datanucleus.metadata.ClassMetaData)1 InterfaceMetaData (org.datanucleus.metadata.InterfaceMetaData)1 PackageMetaData (org.datanucleus.metadata.PackageMetaData)1