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();
}
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;
}
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;
}
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;
}
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);
}
Aggregations