Package org.jpox.metadata

Examples of org.jpox.metadata.InvalidPrimaryKeyException


    {
        // When using inner class, must be static
        if (ClassUtils.isInnerClass(pkClass.getName()) &&
            !Modifier.isStatic(pkClass.getModifiers()))
        {
            throw new InvalidPrimaryKeyException(LOCALISER, "019000",
                    cmd.getFullClassName(), pkClass.getName());
        }

        // Must be public
        if (!Modifier.isPublic(pkClass.getModifiers()))
        {
            throw new InvalidPrimaryKeyException(LOCALISER, "019001",
                    cmd.getFullClassName(), pkClass.getName());
        }

        // Must implement Serializable
        if (!Serializable.class.isAssignableFrom(pkClass))
        {
            throw new InvalidPrimaryKeyException(LOCALISER, "019002",
                    cmd.getFullClassName(), pkClass.getName());
        }

        // a). JDO's SingleFieldIdentity class
        if (isSingleFieldIdentityClass(pkClass.getName()))
        {
            if (noOfPkFields != 1)
            {
                throw new InvalidPrimaryKeyException(LOCALISER, "019003",
                    cmd.getFullClassName());
            }
        }
        // b). Users own primary key class
        else
        {
            // Must have public default constructor
            try
            {
                Constructor constructor = pkClass.getConstructor(new Class[0]);
                if (constructor == null ||
                    !Modifier.isPublic(constructor.getModifiers()))
                {
                    throw new InvalidPrimaryKeyException(LOCALISER, "019004",
                        cmd.getFullClassName(), pkClass.getName());
                }
            }
            catch (NoSuchMethodException ex)
            {
                throw new InvalidPrimaryKeyException(LOCALISER, "019004",
                    cmd.getFullClassName(), pkClass.getName());
            }

            // Must have public String arg constructor
            try
            {
                Constructor constructor=
                    pkClass.getConstructor(new Class[] {String.class});
                if (constructor == null ||
                    !Modifier.isPublic(constructor.getModifiers()))
                {
                    throw new InvalidPrimaryKeyException(LOCALISER, "019005",
                        cmd.getFullClassName(), pkClass.getName());
                }
            }
            catch (NoSuchMethodException nsme)
            {
            }

            // Must override toString() method
            try
            {
                java.lang.reflect.Method method=pkClass.getMethod("toString",new Class[0]);
                if (method == null ||
                    !Modifier.isPublic(method.getModifiers()) ||
                    method.getDeclaringClass().equals(Object.class))
                {
                    throw new InvalidPrimaryKeyException(LOCALISER, "019006",
                        cmd.getFullClassName(), pkClass.getName());
                }
            }
            catch (NoSuchMethodException nsme)
            {
            }

            // Must override hashCode() method
            try
            {
                java.lang.reflect.Method method=pkClass.getMethod("hashCode",new Class[0]);
                if (method == null ||
                    method.getDeclaringClass().equals(Object.class))
                {
                    throw new InvalidPrimaryKeyException(LOCALISER, "019007",
                        cmd.getFullClassName(), pkClass.getName());
                }
            }
            catch (NoSuchMethodException nsme)
            {
            }

            // Must override equals(Object) method
            try
            {
                java.lang.reflect.Method method=pkClass.getMethod("equals",new Class[] {Object.class});
                if (method == null ||
                    method.getDeclaringClass().equals(Object.class))
                {
                    throw new InvalidPrimaryKeyException(LOCALISER, "019008",
                        cmd.getFullClassName(), pkClass.getName());
                }
            }
            catch (NoSuchMethodException nsme)
            {
            }

            // Check the field types of the objectid-class
            int noPkFields = processPrimaryKeyClass(pkClass, cmd, clr);
            Collection superclasses = ClassUtils.getSuperclasses(pkClass);
            if (superclasses != null && superclasses.size() > 0)
            {
                Iterator superclassIter = superclasses.iterator();
                while (superclassIter.hasNext())
                {
                    Class supercls = (Class)superclassIter.next();
                    noPkFields += processPrimaryKeyClass(supercls, cmd, clr);
                }
            }

            // No of Primary Key fields and no of fields in
            // objectid-class must concur
            if (noOfPkFields != noPkFields &&
                cmd.getIdentityType() == IdentityType.APPLICATION)
            {
                throw new InvalidPrimaryKeyException(LOCALISER, "019015",
                    cmd.getFullClassName(), pkClass.getName(),
                    "" + noOfPkFields, "" + noPkFields);
            }
        }
View Full Code Here


            {
                // All non-static fields must be serializable
                if (!fieldsInPkClass[i].getType().isPrimitive() &&
                    !(Serializable.class).isAssignableFrom(fieldsInPkClass[i].getType()))
                {
                    throw new InvalidPrimaryKeyException(LOCALISER, "019009",
                        cmd.getFullClassName(), pkClass.getName(),
                        fieldsInPkClass[i].getName());
                }

                // All non-static fields must be public
                if (!Modifier.isPublic(fieldsInPkClass[i].getModifiers()))
                {
                    throw new InvalidPrimaryKeyException(LOCALISER, "019010",
                        cmd.getFullClassName(), pkClass.getName(),
                        fieldsInPkClass[i].getName());
                }

                // non-static fields of objectid-class include
                // persistence-capable object field
                AbstractMemberMetaData fieldInPcClass = cmd.getMetaDataForMember(fieldsInPkClass[i].getName());
                boolean found_field = false;
                if (fieldInPcClass == null)
                {
                    throw new InvalidPrimaryKeyException(LOCALISER, "019011",
                        cmd.getFullClassName(), pkClass.getName(),
                        fieldsInPkClass[i].getName());
                }

                // check if the field in objectid-class has the same type as the
                // Type declared in the PersistenceCapable class
                if (fieldInPcClass.getTypeName().equals(fieldsInPkClass[i].getType().getName()))
                {
                    found_field = true;
                }

                // Check for primary key field that is PC (Compound Identity - aka Identifying Relations)
                if (!found_field)
                {
                    String fieldTypePkClass = fieldsInPkClass[i].getType().getName();
                    AbstractClassMetaData ref_cmd = cmd.getMetaDataManager().getMetaDataForClassInternal(fieldInPcClass.getType(), clr);
                    if (ref_cmd == null)
                    {
                        throw new InvalidPrimaryKeyException(LOCALISER, "019012",
                            cmd.getFullClassName(), pkClass.getName(),
                            fieldsInPkClass[i].getName(), fieldInPcClass.getType().getName());
                    }
                    if (ref_cmd.getObjectidClass() == null)
                    {
                        //Single Field Identity
                        if (isSingleFieldIdentityClass(fieldTypePkClass))
                        {
                            throw new InvalidPrimaryKeyException(LOCALISER, "019014",
                                cmd.getFullClassName(), pkClass.getName(),
                                fieldsInPkClass[i].getName(), fieldTypePkClass, ref_cmd.getFullClassName());
                        }
                    }
                    if (!fieldTypePkClass.equals(ref_cmd.getObjectidClass()))
                    {
                        throw new InvalidPrimaryKeyException(LOCALISER, "019013",
                            cmd.getFullClassName(), pkClass.getName(),
                            fieldsInPkClass[i].getName(), fieldTypePkClass, ref_cmd.getObjectidClass());
                    }
                    found_field=true;
                }
                if (!found_field)
                {
                    throw new InvalidPrimaryKeyException(LOCALISER, "019012",
                        cmd.getFullClassName(), pkClass.getName(),
                        fieldsInPkClass[i].getName(), fieldInPcClass.getType().getName());
                }

                noOfPkFields++;
View Full Code Here

        catch (JPOXUserException ue)
        {
            Throwable[] nested = ue.getNestedExceptions();
            assertEquals(nested.length, 1);
            assertEquals(nested[0].getClass(), InvalidPrimaryKeyException.class);
            InvalidPrimaryKeyException ipke = (InvalidPrimaryKeyException)nested[0];
            assertEquals("019012", ipke.getMessageKey());
        }
        catch (Throwable e)
        {
      e.printStackTrace();
      fail(e.getClass().getName() + ": " + e.getMessage());
View Full Code Here

        catch (JPOXUserException ue)
        {
            Throwable[] nested = ue.getNestedExceptions();
            assertEquals(nested.length, 1);
            assertEquals(nested[0].getClass(), InvalidPrimaryKeyException.class);
            InvalidPrimaryKeyException ipke = (InvalidPrimaryKeyException)nested[0];
            assertEquals("019004", ipke.getMessageKey());
        }
        catch (Throwable e)
        {
      e.printStackTrace();
      fail(e.getClass().getName() + ": " + e.getMessage());
View Full Code Here

        catch (JPOXUserException ue)
        {
            Throwable[] nested = ue.getNestedExceptions();
            assertEquals(nested.length, 1);
            assertEquals(nested[0].getClass(), InvalidPrimaryKeyException.class);
            InvalidPrimaryKeyException ipke = (InvalidPrimaryKeyException)nested[0];
            assertEquals("019002", ipke.getMessageKey());
        }
        catch (Throwable e)
        {
      e.printStackTrace();
      fail(e.getClass().getName() + ": " + e.getMessage());
View Full Code Here

        catch (JPOXUserException ue)
        {
            Throwable[] nested = ue.getNestedExceptions();
            assertEquals(nested.length, 1);
            assertEquals(nested[0].getClass(), InvalidPrimaryKeyException.class);
            InvalidPrimaryKeyException ipke = (InvalidPrimaryKeyException)nested[0];
            assertEquals("019004", ipke.getMessageKey());
        }
        catch (Throwable e)
        {
      e.printStackTrace();
      fail(e.getClass().getName() + ": " + e.getMessage());
View Full Code Here

        catch (JPOXUserException ue)
        {
            Throwable[] nested = ue.getNestedExceptions();
            assertEquals(nested.length, 1);
            assertEquals(nested[0].getClass(), InvalidPrimaryKeyException.class);
            InvalidPrimaryKeyException ipke = (InvalidPrimaryKeyException)nested[0];
            assertEquals("019002", ipke.getMessageKey());
        }
        catch (Throwable e)
        {
      e.printStackTrace();
      fail(e.getClass().getName() + ": " + e.getMessage());
View Full Code Here

        catch (JPOXUserException ue)
        {
            Throwable[] nested = ue.getNestedExceptions();
            assertEquals(nested.length, 1);
            assertEquals(nested[0].getClass(), InvalidPrimaryKeyException.class);
            InvalidPrimaryKeyException ipke = (InvalidPrimaryKeyException)nested[0];
            assertEquals("019006", ipke.getMessageKey());
        }
        catch (Throwable e)
        {
      e.printStackTrace();
      fail(e.getClass().getName() + ": " + e.getMessage());
View Full Code Here

        catch (JPOXUserException ue)
        {
            Throwable[] nested = ue.getNestedExceptions();
            assertEquals(nested.length, 1);
            assertEquals(nested[0].getClass(), InvalidPrimaryKeyException.class);
            InvalidPrimaryKeyException ipke = (InvalidPrimaryKeyException)nested[0];
            assertEquals("019006", ipke.getMessageKey());
        }
        catch (Throwable e)
        {
      e.printStackTrace();
      fail(e.getClass().getName() + ": " + e.getMessage());
View Full Code Here

        catch (JPOXUserException ue)
        {
            Throwable[] nested = ue.getNestedExceptions();
            assertEquals(nested.length, 1);
            assertEquals(nested[0].getClass(), InvalidPrimaryKeyException.class);
            InvalidPrimaryKeyException ipke = (InvalidPrimaryKeyException)nested[0];
            assertEquals("019010", ipke.getMessageKey());
        }
        catch (Throwable e)
        {
      e.printStackTrace();
      fail(e.getClass().getName() + ": " + e.getMessage());
View Full Code Here

TOP

Related Classes of org.jpox.metadata.InvalidPrimaryKeyException

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.