Search in sources :

Example 26 with ClassNotResolvedException

use of org.datanucleus.exceptions.ClassNotResolvedException in project datanucleus-core by datanucleus.

the class MetaDataManagerImpl method loadClasses.

/* (non-Javadoc)
     * @see org.datanucleus.metadata.MetaDataManager#loadClasses(java.lang.String[], java.lang.ClassLoader)
     */
@Override
public FileMetaData[] loadClasses(String[] classNames, ClassLoader loader) {
    if (!allowMetaDataLoad) {
        return null;
    }
    boolean originatingLoadCall = false;
    if (listenersLoadedMetaData == null && listeners != null) {
        originatingLoadCall = true;
        listenersLoadedMetaData = new ArrayList<AbstractClassMetaData>();
    }
    try {
        if (originatingLoadCall) {
            updateLock.lock();
        }
        if (NucleusLogger.METADATA.isDebugEnabled()) {
            NucleusLogger.METADATA.debug(Localiser.msg("044006", StringUtils.objectArrayToString(classNames)));
        }
        // Load classes
        ClassLoaderResolver clr = nucleusContext.getClassLoaderResolver(loader);
        Collection<FileMetaData> fileMetaData = new ArrayList<>();
        Set<Exception> exceptions = new HashSet<>();
        for (String className : classNames) {
            try {
                Class cls = clr.classForName(className);
                // Check for MetaData for this class (take precedence over annotations if they exist)
                AbstractClassMetaData cmd = classMetaDataByClass.get(className);
                if (cmd == null) {
                    // No MetaData so try annotations
                    FileMetaData filemd = loadAnnotationsForClass(cls, clr, true, false);
                    if (filemd != null) {
                        // Store file against an annotations specific "URL"
                        registerFile("annotations:" + className, filemd, clr);
                        fileMetaData.add(filemd);
                    } else {
                        cmd = getMetaDataForClass(cls, clr);
                        if (cmd == null) {
                            // Class has no metadata or annotations so warn the user
                            NucleusLogger.METADATA.debug(Localiser.msg("044017", className));
                        } else {
                            fileMetaData.add(cmd.getPackageMetaData().getFileMetaData());
                        }
                    }
                } else {
                    fileMetaData.add(cmd.getPackageMetaData().getFileMetaData());
                // We have MetaData, and any annotations will be merged in during the populate process
                }
            } catch (ClassNotResolvedException e) {
                // log and ignore this exception
                NucleusLogger.METADATA.error(StringUtils.getStringFromStackTrace(e));
            } catch (Exception e) {
                exceptions.add(e);
            }
        }
        if (!exceptions.isEmpty()) {
            // Exceptions while loading annotations
            throw new NucleusUserException(Localiser.msg("044016"), exceptions.toArray(new Throwable[exceptions.size()]), null);
        }
        if (!fileMetaData.isEmpty()) {
            // Populate/Initialise all loaded FileMetaData
            initialiseFileMetaDataForUse(fileMetaData, clr);
        }
        if (NucleusLogger.METADATA.isDebugEnabled()) {
            NucleusLogger.METADATA.debug(Localiser.msg("044010"));
        }
        if (originatingLoadCall) {
            processListenerLoadingCall();
        }
        return fileMetaData.toArray(new FileMetaData[fileMetaData.size()]);
    } finally {
        if (originatingLoadCall) {
            updateLock.unlock();
        }
    }
}
Also used : NucleusUserException(org.datanucleus.exceptions.NucleusUserException) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) ArrayList(java.util.ArrayList) ClassNotResolvedException(org.datanucleus.exceptions.ClassNotResolvedException) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) NucleusException(org.datanucleus.exceptions.NucleusException) IOException(java.io.IOException) ClassNotResolvedException(org.datanucleus.exceptions.ClassNotResolvedException) NoPersistenceInformationException(org.datanucleus.exceptions.NoPersistenceInformationException) HashSet(java.util.HashSet)

Example 27 with ClassNotResolvedException

use of org.datanucleus.exceptions.ClassNotResolvedException in project datanucleus-core by datanucleus.

the class MetaDataManagerImpl method getClassesImplementingInterface.

/* (non-Javadoc)
     * @see org.datanucleus.metadata.MetaDataManager#getClassesImplementingInterface(java.lang.String, org.datanucleus.ClassLoaderResolver)
     */
@Override
public String[] getClassesImplementingInterface(String interfaceName, ClassLoaderResolver clr) {
    Collection<Class> classes = new HashSet<>();
    Class intfClass = clr.classForName(interfaceName);
    Collection<String> generatedClassNames = new HashSet<>();
    // Loop through all known classes and find the implementations
    Collection<AbstractClassMetaData> cmds = classMetaDataByClass.values();
    boolean isPersistentInterface = false;
    for (AbstractClassMetaData acmd : cmds) {
        Class implClass = null;
        try {
            implClass = clr.classForName(acmd.getFullClassName());
        } catch (ClassNotResolvedException cnre) {
        // Implementation class not yet generated
        }
        if (implClass != null) {
            if (acmd instanceof ClassMetaData) {
                // Make sure that we are initialised since implementsMetaData wont be set
                initialiseAbstractClassMetaData(acmd, clr);
                if (intfClass.isAssignableFrom(implClass)) {
                    if (!((ClassMetaData) acmd).isAbstract()) {
                        classes.add(implClass);
                    }
                }
            } else if (acmd instanceof InterfaceMetaData) {
                if (intfClass.isAssignableFrom(implClass)) {
                    isPersistentInterface = true;
                }
            }
        } else {
            if (isPersistentInterfaceImplementation(interfaceName, acmd.getFullClassName())) {
                isPersistentInterface = true;
                generatedClassNames.add(acmd.getFullClassName());
            }
        }
    }
    if (isPersistentInterface && nucleusContext instanceof PersistenceNucleusContext && ((PersistenceNucleusContext) nucleusContext).getImplementationCreator() != null) {
        // JDO "persistent interfaces" - deliberately kept separate from normal persistence since it is largely undocumented and best left alone
        // TODO this is very time consuming. got to do some cache
        classes.add(((PersistenceNucleusContext) nucleusContext).getImplementationCreator().newInstance(intfClass, clr).getClass());
        int numClasses = classes.size() + generatedClassNames.size();
        String[] classNames = new String[numClasses];
        int i = 0;
        Iterator<Class> classIter = classes.iterator();
        while (classIter.hasNext()) {
            classNames[i++] = classIter.next().getName();
        }
        Iterator<String> classNameIter = generatedClassNames.iterator();
        while (classNameIter.hasNext()) {
            classNames[i++] = classNameIter.next();
        }
        return classNames;
    } else if (!classes.isEmpty()) {
        // Normal persistence
        // Put the classes into a sorter so we make sure we get the initial implementations first followed by any subclasses of these implementations.
        // This is needed because when generating the schema we require the subclass implementations to already have their datastore column created
        Collection<Class> classesSorted = new TreeSet(new InterfaceClassComparator());
        Iterator<Class> classesIter = classes.iterator();
        while (classesIter.hasNext()) {
            classesSorted.add(classesIter.next());
        }
        // Return the class names (in the same order)
        String[] classNames = new String[classesSorted.size()];
        Iterator<Class> iter = classesSorted.iterator();
        int i = 0;
        while (iter.hasNext()) {
            classNames[i++] = iter.next().getName();
        }
        return classNames;
    }
    return null;
}
Also used : ClassNotResolvedException(org.datanucleus.exceptions.ClassNotResolvedException) TreeSet(java.util.TreeSet) PersistenceNucleusContext(org.datanucleus.PersistenceNucleusContext) Iterator(java.util.Iterator) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 28 with ClassNotResolvedException

use of org.datanucleus.exceptions.ClassNotResolvedException in project datanucleus-core by datanucleus.

the class AbstractClassMetaData method validateObjectIdClass.

/**
 * Validate the objectid-class of this class.
 * @param clr ClassLoader resolver
 */
protected void validateObjectIdClass(ClassLoaderResolver clr) {
    if (getPersistableSuperclass() == null) {
        // Only check root persistable class PK
        if (objectidClass != null) {
            ApiAdapter api = mmgr.getApiAdapter();
            Class obj_cls = null;
            try {
                // Load the class, using the same class loader resolver as this class
                obj_cls = clr.classForName(objectidClass);
            } catch (ClassNotResolvedException cnre) {
                // ObjectIdClass not found
                throw new InvalidClassMetaDataException("044079", fullName, objectidClass);
            }
            boolean validated = false;
            Set<Throwable> errors = new HashSet<>();
            try {
                // Check against the API Adapter in use for this MetaData
                if (api.isValidPrimaryKeyClass(obj_cls, this, clr, getNoOfPopulatedPKMembers(), mmgr)) {
                    validated = true;
                }
            } catch (NucleusException ex) {
                errors.add(ex);
            }
            if (!validated) {
                // This needs coordinating with the test expectations in the enhancer unit tests.
                throw new NucleusUserException(Localiser.msg("019016", getFullClassName(), obj_cls.getName()), errors.toArray(new Throwable[errors.size()]));
            }
        }
    }
}
Also used : ApiAdapter(org.datanucleus.api.ApiAdapter) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) NucleusException(org.datanucleus.exceptions.NucleusException) ClassNotResolvedException(org.datanucleus.exceptions.ClassNotResolvedException) HashSet(java.util.HashSet)

Example 29 with ClassNotResolvedException

use of org.datanucleus.exceptions.ClassNotResolvedException in project datanucleus-core by datanucleus.

the class AbstractMemberMetaData method populate.

/**
 * Method to provide the details of the field being represented by this MetaData hence populating
 * certain parts of the MetaData. This is used to firstly provide defaults for attributes that aren't
 * specified in the MetaData, and secondly to report any errors with attributes that have been specifed
 * that are inconsistent with the field being represented.
 * Either a field or a method should be passed in (one or the other) depending on what is being represented
 * by this "member".
 * @param clr ClassLoaderResolver to use for any class loading
 * @param field Field that we are representing (if it's a field)
 * @param method Method(property) that we are representing (if it's a method).
 * @param primary the primary ClassLoader to use (or null)
 * @param mmgr MetaData manager
 */
public synchronized void populate(ClassLoaderResolver clr, Field field, Method method, ClassLoader primary, MetaDataManager mmgr) {
    if (isPopulated() || isInitialised()) {
        return;
    }
    // Set defaults for cascading when not yet set
    ApiAdapter apiAdapter = mmgr.getNucleusContext().getApiAdapter();
    if (cascadePersist == null) {
        cascadePersist = apiAdapter.getDefaultCascadePersistForField();
    }
    if (cascadeUpdate == null) {
        cascadeUpdate = apiAdapter.getDefaultCascadeUpdateForField();
    }
    if (cascadeDelete == null) {
        cascadeDelete = apiAdapter.getDefaultCascadeDeleteForField();
    }
    if (cascadeDetach == null) {
        cascadeDetach = apiAdapter.getDefaultCascadeDetachForField();
    }
    if (cascadeRefresh == null) {
        cascadeRefresh = apiAdapter.getDefaultCascadeRefreshForField();
    }
    if (field == null && method == null) {
        NucleusLogger.METADATA.error(Localiser.msg("044106", getClassName(), getName()));
        throw new InvalidMemberMetaDataException("044106", getClassName(), getName());
    }
    // No class loader, so use System
    if (clr == null) {
        NucleusLogger.METADATA.warn(Localiser.msg("044067", name, getClassName(true)));
        clr = mmgr.getNucleusContext().getClassLoaderResolver(null);
    }
    memberRepresented = field != null ? field : method;
    if (type == null) {
        // Type not yet set so set from field/method (will only be set if we are imposing the type due to Java generics TypeVariable usage)
        if (field != null) {
            this.type = field.getType();
        } else if (method != null) {
            this.type = method.getReturnType();
        }
    }
    if (className != null) {
        // Property is overriding a superclass property, so check that it is valid
        Class thisClass = null;
        if (parent instanceof EmbeddedMetaData) {
            // <embedded> is contained in a <field>, <element>, <key>, <value>
            // but could be multiple levels deep so adopt a generic strategy for finding the parent class
            MetaData superMd = parent.getParent();
            thisClass = ((AbstractMemberMetaData) superMd).getType();
        } else {
            // Overriding field in a superclass of this class
            try {
                thisClass = clr.classForName(getAbstractClassMetaData().getPackageName() + "." + getAbstractClassMetaData().getName());
            } catch (ClassNotResolvedException cnre) {
            // Do nothing
            }
        }
        Class fieldClass = null;
        try {
            fieldClass = clr.classForName(className);
        } catch (ClassNotResolvedException cnre) {
            try {
                fieldClass = clr.classForName(getAbstractClassMetaData().getPackageName() + "." + className);
                className = getAbstractClassMetaData().getPackageName() + "." + className;
            } catch (ClassNotResolvedException cnre2) {
                NucleusLogger.METADATA.error(Localiser.msg("044113", getClassName(), getName(), className));
                NucleusException ne = new InvalidMemberMetaDataException("044113", getClassName(), getName(), className);
                ne.setNestedException(cnre);
                throw ne;
            }
        }
        if (fieldClass != null && !fieldClass.isAssignableFrom(thisClass)) {
            // TODO We could also check if persistable, but won't work when enhancing
            NucleusLogger.METADATA.error(Localiser.msg("044114", getClassName(), getName(), className));
            throw new InvalidMemberMetaDataException("044114", getClassName(), getName(), className);
        }
    }
    if (primaryKey == null) {
        // Primary key not set by user so initialise it to false
        primaryKey = Boolean.FALSE;
    }
    // Update "embedded" based on type
    if (primaryKey == Boolean.FALSE && embedded == null) {
        Class element_type = getType();
        if (element_type.isArray()) {
            element_type = element_type.getComponentType();
            if (mmgr.getNucleusContext().getTypeManager().isDefaultEmbeddedType(element_type)) {
                embedded = Boolean.TRUE;
            }
        } else if (mmgr.getNucleusContext().getTypeManager().isDefaultEmbeddedType(element_type)) {
            embedded = Boolean.TRUE;
        }
    }
    if (embedded == null) {
        embedded = Boolean.FALSE;
    }
    // Update "persistence-modifier" according to type etc
    if (FieldPersistenceModifier.DEFAULT.equals(persistenceModifier)) {
        if (getTypeConverterName() != null) {
            // Explicitly set a converter, so assume it is persistent
            persistenceModifier = FieldPersistenceModifier.PERSISTENT;
        } else {
            boolean isPcClass = getType().isArray() ? isFieldArrayTypePersistable(mmgr) : mmgr.isFieldTypePersistable(type);
            if (!isPcClass) {
                if (getType().isArray() && getType().getComponentType().isInterface()) {
                    isPcClass = mmgr.getMetaDataForClassInternal(getType().getComponentType(), clr) != null;
                } else if (getType().isInterface()) {
                    isPcClass = mmgr.getMetaDataForClassInternal(getType(), clr) != null;
                }
            }
            persistenceModifier = getDefaultFieldPersistenceModifier(getType(), memberRepresented.getModifiers(), isPcClass, mmgr);
        }
    }
    // TODO If this field is NONE in superclass, make it NONE here too
    // If type is a container, load create the metadata. The field will be handled as a container if it
    // has a ContainerHandler registered against it.
    TypeManager typeMgr = mmgr.getNucleusContext().getTypeManager();
    ContainerHandler containerHandler = typeMgr.getContainerHandler(type);
    if (containerHandler == null) {
        // No container handler registered for this type
        if (hasContainer()) {
            // Container metadata specified on a type that is not a valid or supported container
            NucleusLogger.METADATA.error(Localiser.msg("044212", getClassName(), getName(), type));
            NucleusException ne = new InvalidMemberMetaDataException("044212", getClassName(), getName(), type);
            throw ne;
        }
    } else {
        // Field is a container type
        if (!hasContainer()) {
            // No container metadata has not been specified yet, create a default empty one
            setContainer(containerHandler.newMetaData());
        }
        containerHandler.populateMetaData(clr, primary, this);
    }
    // Update "default-fetch-group" according to type
    if (defaultFetchGroup == null && persistenceModifier.equals(FieldPersistenceModifier.NONE)) {
        defaultFetchGroup = Boolean.FALSE;
    } else if (defaultFetchGroup == null && persistenceModifier.equals(FieldPersistenceModifier.TRANSACTIONAL)) {
        defaultFetchGroup = Boolean.FALSE;
    } else if (defaultFetchGroup == null) {
        defaultFetchGroup = Boolean.FALSE;
        if (!primaryKey.equals(Boolean.TRUE)) {
            if (hasContainer() && containerHandler != null) {
                defaultFetchGroup = containerHandler.isDefaultFetchGroup(clr, typeMgr, this);
            } else if (typeMgr.isDefaultFetchGroup(getType())) {
                // If still not determined rely on the type
                defaultFetchGroup = Boolean.TRUE;
            }
        }
    }
    // Field is not specified as "persistent" yet has DFG or primary-key !
    if (persistenceModifier.equals(FieldPersistenceModifier.TRANSACTIONAL) || persistenceModifier.equals(FieldPersistenceModifier.NONE)) {
        if (defaultFetchGroup == Boolean.TRUE || primaryKey == Boolean.TRUE) {
            throw new InvalidMemberMetaDataException("044109", getClassName(), name, this.getType().getName(), persistenceModifier.toString());
        }
    }
    if (storeInLob) {
        // Set up the jdbcType/serialized settings according to the field type in line with JPA
        boolean useClob = false;
        if (type == String.class || (type.isArray() && type.getComponentType() == Character.class) || (type.isArray() && type.getComponentType() == char.class)) {
            useClob = true;
            if (columns == null || columns.isEmpty()) {
                // Create a CLOB column. What if the RDBMS doesn't support CLOB ?
                ColumnMetaData colmd = new ColumnMetaData();
                colmd.setName(column);
                colmd.setJdbcType("CLOB");
                addColumn(colmd);
            } else {
                ColumnMetaData colmd = columns.get(0);
                colmd.setJdbcType("CLOB");
            }
        }
        if (!useClob) {
            serialized = Boolean.TRUE;
        }
    }
    if (!mmgr.isDefaultNullable() && !hasContainer()) {
        // Find column metadata definition, creating one if not specified
        ColumnMetaData colMmd;
        if (columns == null || columns.isEmpty()) {
            newColumnMetaData();
        }
        colMmd = getColumnMetaData()[0];
        // Set column not-null by default
        if (colMmd.getAllowsNull() == null) {
            colMmd.setAllowsNull(Boolean.FALSE);
        }
    }
    if (this.containerMetaData != null && this.dependent != null) {
        // Check for invalid dependent field specifications
        NucleusLogger.METADATA.error(Localiser.msg("044110", getClassName(), getName(), ((ClassMetaData) this.parent).getName()));
        throw new InvalidMemberMetaDataException("044110", getClassName(), getName(), ((ClassMetaData) this.parent).getName());
    }
    if (embedded == Boolean.TRUE && embeddedMetaData == null) {
        // User specified "embedded" on the member, yet no embedded definition so add one TODO Omit this, since we should only use when provided
        AbstractClassMetaData memberCmd = mmgr.getMetaDataForClassInternal(getType(), clr);
        if (memberCmd != null) {
            embeddedMetaData = new EmbeddedMetaData();
            embeddedMetaData.setParent(this);
        }
    }
    if (embeddedMetaData != null) {
        // Update with any extensions (for lack of features in JPA)
        if (hasExtension("null-indicator-column")) {
            embeddedMetaData.setNullIndicatorColumn(getValueForExtension("null-indicator-column"));
            if (hasExtension("null-indicator-value")) {
                embeddedMetaData.setNullIndicatorValue(getValueForExtension("null-indicator-value"));
            }
        }
        // Populate any embedded object
        embeddedMetaData.populate(clr, primary);
        embedded = Boolean.TRUE;
    }
    if (containerMetaData != null && persistenceModifier == FieldPersistenceModifier.PERSISTENT) {
        // Populate any container
        if (containerMetaData instanceof CollectionMetaData) {
        // if (cascadeDelete)
        // {
        // // User has set cascade-delete (JPA) so set the element as dependent
        // getCollection().element.dependent = Boolean.TRUE;
        // }
        // getCollection().populate(clr, primary, mmgr);
        } else if (containerMetaData instanceof MapMetaData) {
        // String keyCascadeVal = getValueForExtension("cascade-delete-key");
        // if (cascadeDelete)
        // {
        // // User has set cascade-delete (JPA) so set the value as dependent
        // getMap().key.dependent = Boolean.FALSE; // JPA spec doesn't define what this should be
        // getMap().value.dependent = Boolean.TRUE;
        // }
        // if (keyCascadeVal != null)
        // {
        // if (keyCascadeVal.equalsIgnoreCase("true"))
        // {
        // getMap().key.dependent = Boolean.TRUE;
        // }
        // else
        // {
        // getMap().key.dependent = Boolean.FALSE;
        // }
        // }
        // getMap().populate(clr, primary, mmgr);
        } else if (containerMetaData instanceof ArrayMetaData) {
        // if (cascadeDelete)
        // {
        // // User has set cascade-delete (JPA) so set the element as dependent
        // getArray().element.dependent = Boolean.TRUE;
        // }
        // getArray().populate(clr, primary, mmgr);
        }
    }
    if (mmgr.isFieldTypePersistable(type) && cascadeDelete) {
        setDependent(true);
    }
    if (hasExtension(MetaData.EXTENSION_MEMBER_IMPLEMENTATION_CLASSES)) {
        // Check the validity of the implementation-classes and qualify them where required.
        StringBuilder str = new StringBuilder();
        String[] implTypes = getValuesForExtension(MetaData.EXTENSION_MEMBER_IMPLEMENTATION_CLASSES);
        for (int i = 0; i < implTypes.length; i++) {
            String implTypeName = ClassUtils.createFullClassName(getAbstractClassMetaData().getPackageName(), implTypes[i]);
            if (i > 0) {
                str.append(",");
            }
            try {
                clr.classForName(implTypeName);
                str.append(implTypeName);
            } catch (ClassNotResolvedException cnre) {
                try {
                    // Maybe the user specified a java.lang class without fully-qualifying it
                    // This is beyond the scope of the JDO spec which expects java.lang cases to be fully-qualified
                    String langClassName = ClassUtils.getJavaLangClassForType(implTypeName);
                    clr.classForName(langClassName);
                    str.append(langClassName);
                } catch (ClassNotResolvedException cnre2) {
                    // Implementation type not found
                    throw new InvalidMemberMetaDataException("044116", getClassName(), getName(), implTypes[i]);
                }
            }
        }
        // Replace with this new value
        addExtension(MetaData.EXTENSION_MEMBER_IMPLEMENTATION_CLASSES, str.toString());
    }
    // Set up persistence flags for enhancement process
    byte serializable = 0;
    if (Serializable.class.isAssignableFrom(getType()) || getType().isPrimitive()) {
        serializable = Persistable.SERIALIZABLE;
    }
    if (FieldPersistenceModifier.NONE.equals(persistenceModifier)) {
        persistenceFlags = 0;
    } else if (FieldPersistenceModifier.TRANSACTIONAL.equals(persistenceModifier) && Modifier.isTransient(memberRepresented.getModifiers())) {
        persistenceFlags = (byte) (Persistable.CHECK_WRITE | serializable);
    } else if (primaryKey.booleanValue()) {
        persistenceFlags = (byte) (Persistable.MEDIATE_WRITE | serializable);
    } else if (defaultFetchGroup.booleanValue()) {
        persistenceFlags = (byte) (Persistable.CHECK_READ | Persistable.CHECK_WRITE | serializable);
    } else if (!defaultFetchGroup.booleanValue()) {
        persistenceFlags = (byte) (Persistable.MEDIATE_READ | Persistable.MEDIATE_WRITE | serializable);
    } else {
        persistenceFlags = 0;
    }
    // Set fields that are not relations
    if (persistenceModifier != FieldPersistenceModifier.PERSISTENT) {
        // Not a relation field so set relation information
        relationType = RelationType.NONE;
    } else if (containerMetaData == null && !mmgr.isFieldTypePersistable(type)) {
        if (!type.getName().equals(ClassNameConstants.Object) && !type.isInterface()) {
            // Not a container field, not a persistable type, nor a reference type so not a relation field
            relationType = RelationType.NONE;
        }
    }
    if (serialized == Boolean.TRUE && hasExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME)) {
        NucleusLogger.METADATA.warn(Localiser.msg("044127", getClassName(), getName(), getValueForExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME)));
        serialized = Boolean.FALSE;
    }
    setPopulated();
}
Also used : Serializable(java.io.Serializable) ApiAdapter(org.datanucleus.api.ApiAdapter) ClassNotResolvedException(org.datanucleus.exceptions.ClassNotResolvedException) ContainerHandler(org.datanucleus.store.types.ContainerHandler) TypeManager(org.datanucleus.store.types.TypeManager) NucleusException(org.datanucleus.exceptions.NucleusException)

Example 30 with ClassNotResolvedException

use of org.datanucleus.exceptions.ClassNotResolvedException in project datanucleus-core by datanucleus.

the class XcaliaIdentityStringTranslator method getIdentity.

/* (non-Javadoc)
     * @see org.datanucleus.identity.IdentityStringTranslator#getIdentity(org.datanucleus.ExecutionContext, java.lang.String)
     */
public Object getIdentity(ExecutionContext ec, String stringId) {
    ClassLoaderResolver clr = ec.getClassLoaderResolver();
    // a). find the first part before any colon, and try as class name
    // b). try the first part as discriminator
    Object id = null;
    int idStringPos = stringId.indexOf(':');
    if (idStringPos > 0) {
        String definer = stringId.substring(0, idStringPos);
        String idKey = stringId.substring(idStringPos + 1);
        AbstractClassMetaData acmd = null;
        try {
            // See if this is the className
            clr.classForName(definer);
            acmd = ec.getMetaDataManager().getMetaDataForClass(definer, clr);
        } catch (ClassNotResolvedException cnre) {
            // Not a class so maybe a discriminator
            acmd = ec.getMetaDataManager().getMetaDataForDiscriminator(definer);
        }
        if (acmd != null) {
            if (acmd.getIdentityType() == IdentityType.DATASTORE) {
                // "idKey" assumed to be the key of the datastore-identity
                try {
                    Long keyLong = Long.valueOf(idKey);
                    id = ec.getNucleusContext().getIdentityManager().getDatastoreId(acmd.getFullClassName(), keyLong);
                } catch (NumberFormatException nfe) {
                    // Maybe is String based
                    id = ec.getNucleusContext().getIdentityManager().getDatastoreId(acmd.getFullClassName(), idKey);
                }
            } else if (acmd.getIdentityType() == IdentityType.APPLICATION) {
                // "idKey" assumed to be the toString() output of the application-identity
                id = ec.getNucleusContext().getIdentityManager().getApplicationId(clr, acmd, idKey);
            }
        }
    } else {
    // Maybe is an OID.toString() ?
    // TODO Support this
    }
    return id;
}
Also used : ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) ClassNotResolvedException(org.datanucleus.exceptions.ClassNotResolvedException) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Aggregations

ClassNotResolvedException (org.datanucleus.exceptions.ClassNotResolvedException)34 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)18 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)13 NucleusException (org.datanucleus.exceptions.NucleusException)10 HashSet (java.util.HashSet)8 ArrayList (java.util.ArrayList)6 Iterator (java.util.Iterator)6 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)6 IOException (java.io.IOException)5 Collection (java.util.Collection)5 Method (java.lang.reflect.Method)4 List (java.util.List)4 ApiAdapter (org.datanucleus.api.ApiAdapter)4 Field (java.lang.reflect.Field)3 NucleusObjectNotFoundException (org.datanucleus.exceptions.NucleusObjectNotFoundException)3 SCOID (org.datanucleus.identity.SCOID)3 ObjectProvider (org.datanucleus.state.ObjectProvider)3 Constructor (java.lang.reflect.Constructor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2