Search in sources :

Example 1 with PackageMetaData

use of org.datanucleus.metadata.PackageMetaData in project datanucleus-core by datanucleus.

the class DataNucleusEnhancer method validate.

/**
 * Method to validate all classes defined by addClass, addClasses, addJar, addPersistenceUnit, addFiles.
 * @return Number of classes validated
 */
public int validate() {
    if (componentsToEnhance.isEmpty()) {
        // Nothing to validate
        return 0;
    }
    // Load the meta-data for the registered components to enhance.
    long startTime = System.currentTimeMillis();
    Collection<FileMetaData> fileMetaData = getFileMetadataForInput();
    // Validate the classes implied by the FileMetaData
    long inputTime = System.currentTimeMillis();
    Set<String> classNames = new HashSet<String>();
    Iterator<FileMetaData> filemdIter = fileMetaData.iterator();
    while (filemdIter.hasNext()) {
        FileMetaData filemd = filemdIter.next();
        for (int packagenum = 0; packagenum < filemd.getNoOfPackages(); packagenum++) {
            PackageMetaData pmd = filemd.getPackage(packagenum);
            for (int classnum = 0; classnum < pmd.getNoOfClasses(); classnum++) {
                ClassMetaData cmd = pmd.getClass(classnum);
                if (classNames.contains(cmd.getFullClassName())) {
                    // Already processed, maybe via annotations and this is MetaData
                    continue;
                }
                classNames.add(cmd.getFullClassName());
                byte[] bytes = bytesForClassesToEnhanceByClassName != null ? bytesForClassesToEnhanceByClassName.get(cmd.getFullClassName()) : null;
                ClassEnhancer classEnhancer = getClassEnhancer(cmd, bytes);
                validateClass(cmd, classEnhancer);
            }
        }
    }
    // Log info about timings
    long enhanceTime = System.currentTimeMillis();
    String msg = null;
    if (verbose) {
        msg = Localiser.msg("005004", classNames.size(), "" + (inputTime - startTime), "" + (enhanceTime - inputTime), "" + (enhanceTime - startTime));
    } else {
        msg = Localiser.msg("005005", classNames.size());
    }
    addMessage(msg, false);
    // Remove the input specification
    if (bytesForClassesToEnhanceByClassName != null) {
        bytesForClassesToEnhanceByClassName.clear();
        bytesForClassesToEnhanceByClassName = null;
    }
    componentsToEnhance.clear();
    return classNames.size();
}
Also used : PackageMetaData(org.datanucleus.metadata.PackageMetaData) FileMetaData(org.datanucleus.metadata.FileMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData) HashSet(java.util.HashSet)

Example 2 with PackageMetaData

use of org.datanucleus.metadata.PackageMetaData in project datanucleus-core by datanucleus.

the class MetaDataAutoStarter method getAllClassData.

/**
 * Accessor for all auto start data for this starter.
 * @return The class auto start data. Collection of StoreData elements
 * @throws org.datanucleus.exceptions.DatastoreInitialisationException If an error occurs in datastore init
 */
public Collection<StoreData> getAllClassData() throws DatastoreInitialisationException {
    if (metaDataFiles == null) {
        return Collections.EMPTY_SET;
    }
    Collection<FileMetaData> fileMetaData = storeMgr.getNucleusContext().getMetaDataManager().loadFiles(metaDataFiles.split(","), clr);
    Iterator<FileMetaData> iter = fileMetaData.iterator();
    while (iter.hasNext()) {
        FileMetaData filemd = iter.next();
        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);
                classes.add(new StoreData(cmd.getFullClassName().trim(), null, StoreData.Type.FCO, null));
            }
        }
    }
    return classes;
}
Also used : PackageMetaData(org.datanucleus.metadata.PackageMetaData) FileMetaData(org.datanucleus.metadata.FileMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData) StoreData(org.datanucleus.store.StoreData)

Example 3 with PackageMetaData

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

the class JDOMetadataImpl method newInterfaceMetadata.

/* (non-Javadoc)
     * @see javax.jdo.metadata.JDOMetadata#newInterfaceMetadata(java.lang.Class)
     */
public InterfaceMetadata newInterfaceMetadata(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);
    InterfaceMetaData internalImd = internalPmd.newInterfaceMetadata(className);
    InterfaceMetadataImpl imd = new InterfaceMetadataImpl(internalImd);
    imd.parent = pmd;
    return imd;
}
Also used : PackageMetaData(org.datanucleus.metadata.PackageMetaData) InterfaceMetaData(org.datanucleus.metadata.InterfaceMetaData)

Example 4 with PackageMetaData

use of org.datanucleus.metadata.PackageMetaData 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 5 with PackageMetaData

use of org.datanucleus.metadata.PackageMetaData 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)

Aggregations

PackageMetaData (org.datanucleus.metadata.PackageMetaData)18 ClassMetaData (org.datanucleus.metadata.ClassMetaData)14 MetaDataManager (org.datanucleus.metadata.MetaDataManager)8 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)7 NucleusContext (org.datanucleus.NucleusContext)7 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)6 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)6 FileMetaData (org.datanucleus.metadata.FileMetaData)6 PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)6 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)5 InterfaceMetaData (org.datanucleus.metadata.InterfaceMetaData)4 SequenceMetaData (org.datanucleus.metadata.SequenceMetaData)4 TableGeneratorMetaData (org.datanucleus.metadata.TableGeneratorMetaData)3 HashSet (java.util.HashSet)2 DiscriminatorMetaData (org.datanucleus.metadata.DiscriminatorMetaData)2 FetchPlanMetaData (org.datanucleus.metadata.FetchPlanMetaData)2 QueryMetaData (org.datanucleus.metadata.QueryMetaData)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1