Package org.datanucleus.exceptions

Examples of org.datanucleus.exceptions.NucleusException


                }
                else if (annName.equals(JPAAnnotationUtils.ORDER_BY))
                {
                    if (mmd.getOrderMetaData() != null)
                    {
                        throw new NucleusException("@OrderBy found yet field=" +
                            cmd.getFullClassName() + "." + member.getName() +
                            " already has ordering information!");
                    }

                    String orderBy = (String)annotationValues.get("value");
                    if (orderBy != null)
                    {
                        // "Ordered List"
                        OrderMetaData ordmd = new OrderMetaData();
                        ordmd.setOrdering(orderBy);
                        mmd.setOrderMetaData(ordmd);
                    }
                }
                else if (annName.equals(JPAAnnotationUtils.ORDER_COLUMN))
                {
                    if (mmd.getOrderMetaData() != null)
                    {
                        throw new NucleusException("@OrderColumn found yet field=" +
                            cmd.getFullClassName() + "." + member.getName() +
                        " already has ordering information!");
                    }

                    String columnName = (String)annotationValues.get("name");
View Full Code Here


                {
                }
            }
            if (ammd == null)
            {
                throw new NucleusException("Cannot obtain override field/property "+
                    overriddenName + " of class " + type + " for persistent class " + mmd.getClassName(true));
            }

            embmd.addMember(ammd);
            ammd.setParent(embmd);

            // Recurse to nested field type
            processEmbeddedAttributeOverride(ammd, nestedMemberName, type, column);
        }
        else
        {
            Member overriddenMember = null;
            java.lang.reflect.Member overrideMember = null;
            AbstractMemberMetaData ammd = null;

            // Try as field
            try
            {
                overrideMember = type.getDeclaredField(overriddenName);
                overriddenMember = new Member((Field)overrideMember);
                ammd = new FieldMetaData(embmd, overriddenName);
            }
            catch (Exception e)
            {
            }

            if (ammd == null)
            {
                // Try as property
                try
                {
                    overrideMember = type.getDeclaredMethod(ClassUtils.getJavaBeanGetterName(overriddenName, false));
                    overriddenMember = new Member((Method)overrideMember);
                    ammd = new PropertyMetaData(embmd, overriddenName);
                }
                catch (Exception e)
                {
                }
            }

            if (ammd == null)
            {
                throw new NucleusException("Cannot obtain override field/property "+
                    overriddenName + " of class " + type + " for persistent class " + mmd.getClassName(true));
            }

            embmd.addMember(ammd);
            ammd.addColumn(JPAAnnotationUtils.getColumnMetaDataForColumnAnnotation(ammd,
View Full Code Here

                if (isIdentity() != getStoreManager().getDatastoreAdapter().isIdentityFieldDataType(ci.getColumnDef()))
                {
                    //TODO localise
                    if (isIdentity())
                    {
                        throw new NucleusException("Expected an auto increment column ("+getIdentifier()+
                            ") in the database, but it is not").setFatal();
                    }
                    else
                    {
                        throw new NucleusException("According to the user metadata, the column ("+
                            getIdentifier()+") is not auto incremented, but the database says it is.").setFatal();
                    }
                }
            }
            catch (UnsupportedOperationException ex)
View Full Code Here

     * Accessor for a mapping for the ID (PersistenceCapable) for this table.
     * @return The (PersistenceCapable) ID mapping.
     **/
    public JavaTypeMapping getIdMapping()
    {
        throw new NucleusException("Attempt to get ID mapping of ProbeTable!").setFatal();
    }
View Full Code Here

            else if (versionMetaData.getVersionStrategy() == VersionStrategy.DATE_TIME)
            {
                if (!dba.supportsOption(RDBMSAdapter.DATETIME_STORES_MILLISECS))
                {
                    // TODO Localise this
                    throw new NucleusException("Class " + cmd.getFullClassName() + " is defined " +
                        "to use date-time versioning, yet this datastore doesnt support storing " +
                        "milliseconds in DATETIME/TIMESTAMP columns. Use version-number");
                }
                versionMapping = new VersionTimestampMapping(dba, this, mapMgr.getMapping(Timestamp.class));
            }
View Full Code Here

                                clr, FieldRole.ROLE_FIELD));
                        }
                    }
                    else if (mmd.getPersistenceModifier() != FieldPersistenceModifier.TRANSACTIONAL)
                    {
                        throw new NucleusException(LOCALISER.msg("057006",mmd.getName())).setFatal();
                    }

                    // Calculate if we need a FK adding due to a 1-N (FK) relationship
                    boolean needsFKToContainerOwner = false;
                    int relationType = mmd.getRelationType(clr);
                    if (relationType == Relation.ONE_TO_MANY_BI)
                    {
                        AbstractMemberMetaData[] relatedMmds = mmd.getRelatedMemberMetaData(clr);
                        if (mmd.getJoinMetaData() == null && relatedMmds[0].getJoinMetaData() == null)
                        {
                            needsFKToContainerOwner = true;
                        }
                    }
                    else if (relationType == Relation.ONE_TO_MANY_UNI)
                    {
                        if (mmd.getJoinMetaData() == null)
                        {
                            needsFKToContainerOwner = true;
                        }
                    }

                    if (needsFKToContainerOwner)
                    {
                        // 1-N uni/bidirectional using FK, so update the element side with a FK
                        if ((mmd.getCollection() != null && !SCOUtils.collectionHasSerialisedElements(mmd)) ||
                            (mmd.getArray() != null && !SCOUtils.arrayIsStoredInSingleColumn(mmd, storeMgr.getMetaDataManager())))
                        {
                            // 1-N ForeignKey collection/array, so add FK to element table
                            AbstractClassMetaData elementCmd = null;
                            if (mmd.hasCollection())
                            {
                                // Collection
                                elementCmd = storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(mmd.getCollection().getElementType(), clr);
                            }
                            else
                            {
                                // Array
                                elementCmd = storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(mmd.getType().getComponentType(), clr);
                            }
                            if (elementCmd == null)
                            {
                                // Elements that are reference types or non-PC will come through here
                                if (mmd.hasCollection())
                                {
                                    NucleusLogger.METADATA.warn(LOCALISER.msg("057016",
                                        theCmd.getFullClassName(), mmd.getCollection().getElementType()));
                                }
                                else
                                {
                                    NucleusLogger.METADATA.warn(LOCALISER.msg("057014",
                                        theCmd.getFullClassName(), mmd.getType().getComponentType().getName()));
                                }
                            }
                            else
                            {
                                AbstractClassMetaData[] elementCmds = null;
                                // TODO : Cater for interface elements, and get the metadata for the implementation classes here
                                if (elementCmd.getInheritanceMetaData().getStrategy() == InheritanceStrategy.SUBCLASS_TABLE)
                                {
                                    elementCmds = storeMgr.getClassesManagingTableForClass(elementCmd, clr);
                                }
                                else
                                {
                                    elementCmds = new ClassMetaData[1];
                                    elementCmds[0] = elementCmd;
                                }

                                // Run callbacks for each of the element classes.
                                for (int i=0;i<elementCmds.length;i++)
                                {
                                    storeMgr.addSchemaCallback(elementCmds[i].getFullClassName(), mmd);
                                    DatastoreClass dc = storeMgr.getDatastoreClass(elementCmds[i].getFullClassName(), clr);
                                    if (dc == null)
                                    {
                                        throw new NucleusException("Unable to add foreign-key to " +
                                            elementCmds[i].getFullClassName() + " to " + this + " since element has no table!");
                                    }
                                    ClassTable ct = (ClassTable) dc;
                                    if (ct.isInitialized())
                                    {
View Full Code Here

                            membersToAdd[pkFieldNum++] = mmd;
                            hasPrimaryKeyInThisClass = true;
                        }
                        else if (mmd.getPersistenceModifier() != FieldPersistenceModifier.TRANSACTIONAL)
                        {
                            throw new NucleusException(LOCALISER.msg("057006", mmd.getName())).setFatal();
                        }

                        // Check if auto-increment and that it is supported by this RDBMS
                        if ((mmd.getValueStrategy() == IdentityStrategy.IDENTITY) &&
                            !dba.supportsOption(DatastoreAdapter.IDENTITY_COLUMNS))
                        {
                            throw new NucleusException(LOCALISER.msg("057020",
                                cmd.getFullClassName(), mmd.getName())).setFatal();
                        }
                    }
                }
            }
            else
            {
                for (int relFieldNum=0; relFieldNum<fieldCount; ++relFieldNum)
                {
                    AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtPosition(relFieldNum);
                    if (fmd.isPrimaryKey())
                    {
                        if (fmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT)
                        {
                            membersToAdd[pkFieldNum++] = fmd;
                            hasPrimaryKeyInThisClass = true;
                        }
                        else if (fmd.getPersistenceModifier() != FieldPersistenceModifier.TRANSACTIONAL)
                        {
                            throw new NucleusException(LOCALISER.msg("057006",fmd.getName())).setFatal();
                        }

                        // Check if auto-increment and that it is supported by this RDBMS
                        if ((fmd.getValueStrategy() == IdentityStrategy.IDENTITY) &&
                            !dba.supportsOption(DatastoreAdapter.IDENTITY_COLUMNS))
                        {
                            throw new NucleusException(LOCALISER.msg("057020",
                                cmd.getFullClassName(), fmd.getName())).setFatal();
                        }
                    }
                }
            }
        }

        // No Primary Key defined, so search for superclass or handle datastore id
        if (!hasPrimaryKeyInThisClass)
        {
            if (cmd.getIdentityType() == IdentityType.APPLICATION)
            {
                // application-identity
                DatastoreClass elementCT = storeMgr.getDatastoreClass(cmd.getPersistenceCapableSuperclass(), clr);
                if (elementCT != null)
                {
                    // Superclass has a table so copy its PK mappings
                    ColumnMetaDataContainer colContainer = null;
                    if (cmd.getInheritanceMetaData() != null)
                    {
                        // Try via <inheritance><join>...</join></inheritance>
                        colContainer = cmd.getInheritanceMetaData().getJoinMetaData();
                    }
                    if (colContainer == null)
                    {
                        // Try via <primary-key>...</primary-key>
                        colContainer = cmd.getPrimaryKeyMetaData();
                    }

                    addApplicationIdUsingClassTableId(colContainer, elementCT, clr, cmd);
                }
                else
                {
                    // Superclass has no table so create new mappings and columns
                    AbstractClassMetaData pkCmd = storeMgr.getClassWithPrimaryKeyForClass(cmd.getSuperAbstractClassMetaData(), clr);
                    if (pkCmd != null)
                    {
                        pkMappings = new JavaTypeMapping[pkCmd.getNoOfPrimaryKeyMembers()];
                        pkFieldNum = 0;
                        fieldCount = pkCmd.getNoOfInheritedManagedMembers() + pkCmd.getNoOfManagedMembers();
                        for (int absFieldNum = 0; absFieldNum < fieldCount; ++absFieldNum)
                        {
                            AbstractMemberMetaData fmd = pkCmd.getMetaDataForManagedMemberAtAbsolutePosition(absFieldNum);
                            if (fmd.isPrimaryKey())
                            {
                                AbstractMemberMetaData overriddenFmd = cmd.getOverriddenMember(fmd.getName());
                                if (overriddenFmd != null)
                                {
                                    // PK field is overridden so use the overriding definition
                                    fmd = overriddenFmd;
                                }

                                if (fmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT)
                                {
                                    membersToAdd[pkFieldNum++] = fmd;
                                }
                                else if (fmd.getPersistenceModifier() != FieldPersistenceModifier.TRANSACTIONAL)
                                {
                                    throw new NucleusException(LOCALISER.msg("057006",fmd.getName())).setFatal();
                                }
                            }
                        }
                    }
                }
            }
            else if (cmd.getIdentityType() == IdentityType.DATASTORE)
            {
                // datastore-identity
                ColumnMetaDataContainer colContainer = null;
                if (cmd.getIdentityMetaData() != null && cmd.getIdentityMetaData().getColumnMetaData() != null &&
                    cmd.getIdentityMetaData().getColumnMetaData().length > 0)
                {
                    // Try via <datastore-identity>...</datastore-identity>
                    colContainer = cmd.getIdentityMetaData();
                }
                if (colContainer == null)
                {
                    // Try via <primary-key>...</primary-key>
                    colContainer = cmd.getPrimaryKeyMetaData();
                }
                addDatastoreId(colContainer, null, cmd);
            }
            else if (cmd.getIdentityType() == IdentityType.NONDURABLE)
            {
                // Do nothing since no identity!
            }
        }

        //add field mappings in the end, so we compute all columns after the post initialize
        for (int i=0; i<membersToAdd.length; i++)
        {
            if (membersToAdd[i] != null)
            {
                try
                {
                    DatastoreClass datastoreClass = getStoreManager().getDatastoreClass(membersToAdd[i].getType().getName(),clr);
                    if (datastoreClass.getIdMapping() == null)
                    {
                        throw new NucleusException("Unsupported relationship with field "+membersToAdd[i].getFullFieldName()).setFatal();
                    }
                }
                catch (NoTableManagedException ex)
                {
                    //do nothing
View Full Code Here

                    {
                        final String errMsg = "Table " + getIdentifier() +
                        " manages at least 2 subclasses that both define a field \"" + memberName + "\", " +
                        "and the fields' metadata is different or they have different type! That means you can get e.g. wrong fetch results.";
                        NucleusLogger.DATASTORE.error(errMsg);
                        throw new NucleusException(errMsg).setFatal();
                    }
                    mmd = foundMmd;
                }
            }
        }
View Full Code Here

    {
        Class c = sm.getObject().getClass();

        if (!sm.getExecutionContext().getClassLoaderResolver().isAssignableFrom(cmd.getFullClassName(),c))
        {
            throw new NucleusException(LOCALISER.msg("057013",cmd.getFullClassName(),c)).setFatal();
        }
    }
View Full Code Here

                    try
                    {
                        ResultObjectFactory rof = null;
                        if (elementsAreEmbedded || elementsAreSerialised)
                        {
                            throw new NucleusException("Cannot have FK array with non-persistent objects");
                        }
                        else
                        {
                            rof = storeMgr.newResultObjectFactory(emd, iteratorMappingDef, false, null,
                                clr.classForName(elementType));
View Full Code Here

TOP

Related Classes of org.datanucleus.exceptions.NucleusException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.