Class ReturningPolicy

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class ReturningPolicy
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable

    Purpose: Allows for INSERT or UPDATE operations to return values back into the object being written. This allows for table default values, trigger or stored procedures computed values to be set back into the object. This can be used with generated SQL on the Oracle platform using the RETURNING clause, or through stored procedures on other platforms.

    Since:
    TopLink 10.1.3
    See Also:
    Serialized Form
    • Field Detail

      • infos

        protected java.util.List<ReturningPolicy.Info> infos
        Stores an object of type Info for every call to any of addField.. methods. Should be filled out before initialize() is called: fields added after initialization are ignored.
      • main

        protected java.util.Collection<DatabaseField>[][] main
        The following attributes are initialized by initialize() method. Contains the actual DatabaseFields to be returned. Populated during descriptor initialization using infos. Here's the order:
         main[INSERT][RETURN_ONLY]  main[INSERT][WRITE_RETURN]  main[INSERT][MAPPED]    main[INSERT][UNMAPPED]    main[INSERT][ALL]
         main[UPDATE][RETURN_ONLY]  main[UPDATE][WRITE_RETURN]  main[UPDATE][MAPPED]    main[UPDATE][UNMAPPED]    main[UPDATE][ALL]
         
        After initialization main[UPDATE,WRITE_RETURN] will contain all DatabaseFields that should be returned on Update as read-write.
         main[i][RETURN_ONLY] + main[i][WRITE_RETURN] = main[i][MAPPED]
         main[i][MAPPED] + main[i][UNMAPPED] = main[i][ALL]
         
      • tableToFieldsForGenerationMap

        protected java.util.Map<DatabaseTable,​java.util.Vector<DatabaseField>>[] tableToFieldsForGenerationMap
        maps ClassDescriptor's tables into Vectors of fields to be used for call generation. Lazily initialized array [NUM_OPERATIONS]
      • isUsedToSetPrimaryKey

        protected boolean isUsedToSetPrimaryKey
        indicates whether ReturningPolicy is used for generation of the PK.
      • fieldsNotFromDescriptor_DefaultTable

        protected java.util.Map<DatabaseField,​DatabaseField> fieldsNotFromDescriptor_DefaultTable
        contains all default table the returning fields that are either unmapped or mapped supplied with types.
      • fieldsNotFromDescriptor_OtherTables

        protected java.util.Map<DatabaseField,​DatabaseField> fieldsNotFromDescriptor_OtherTables
        contains all the other tables returning fields that are either unmapped or mapped supplied with types.
    • Constructor Detail

      • ReturningPolicy

        public ReturningPolicy()
    • Method Detail

      • getDescriptor

        public ClassDescriptor getDescriptor()
        PUBLIC: Return the owner of the policy.
      • fieldIsNotFromDescriptor

        protected void fieldIsNotFromDescriptor​(DatabaseField field)
        INTERNAL:
      • getFieldsToGenerateInsert

        public java.util.Vector getFieldsToGenerateInsert​(DatabaseTable table)
        INTERNAL:
      • getFieldsToGenerateUpdate

        public java.util.Vector getFieldsToGenerateUpdate​(DatabaseTable table)
        INTERNAL:
      • setFieldInfos

        public void setFieldInfos​(java.util.List<ReturningPolicy.Info> infos)
        INTERNAL:
      • hasEqualFieldInfos

        public boolean hasEqualFieldInfos​(ReturningPolicy returningPolicyToCompare)
        INTERNAL: Used for testing only
      • hasEqualFieldInfos

        public boolean hasEqualFieldInfos​(java.util.List<ReturningPolicy.Info> infosToCompare)
        INTERNAL: Used for testing only
      • areCollectionsEqualAsSets

        public static boolean areCollectionsEqualAsSets​(java.util.Collection col1,
                                                        java.util.Collection col2)
        INTERNAL: Compares two Collections as sets (ignoring the order of the elements). Note that the passed Collections are cloned. Used for testing only.
      • getVectorOfFieldsToGenerate

        protected java.util.Vector<DatabaseField> getVectorOfFieldsToGenerate​(int operation,
                                                                              DatabaseTable table)
        INTERNAL:
      • getFieldsToMergeInsert

        public java.util.Collection<DatabaseField> getFieldsToMergeInsert()
        INTERNAL:
      • getFieldsToMergeUpdate

        public java.util.Collection<DatabaseField> getFieldsToMergeUpdate()
        INTERNAL:
      • clone

        public java.lang.Object clone()
        INTERNAL: Normally cloned when not yet initialized. If initialized ReturningPolicy cloned then the clone should be re-initialized.
        Overrides:
        clone in class java.lang.Object
      • setDescriptor

        public void setDescriptor​(ClassDescriptor descriptor)
        INTERNAL:
      • addFieldForInsert

        public void addFieldForInsert​(java.lang.String qualifiedName)
        PUBLIC: Define that the field will be returned from an insert operation.
      • addFieldForInsert

        public void addFieldForInsert​(java.lang.String qualifiedName,
                                      java.lang.Class type)
        PUBLIC: Define that the field will be returned from an insert operation. The type may be required to bind the output parameter if not known by the mapping.
      • addFieldForInsert

        public void addFieldForInsert​(DatabaseField field)
        PUBLIC: Define that the field will be returned from an insert operation.
      • addFieldForInsertReturnOnly

        public void addFieldForInsertReturnOnly​(java.lang.String qualifiedName)
        PUBLIC: Define that the field will be returned from an insert operation. A field added with addFieldForInsertReturnOnly method is excluded from INSERT clause during SQL generation.
      • addFieldForInsertReturnOnly

        public void addFieldForInsertReturnOnly​(java.lang.String qualifiedName,
                                                java.lang.Class type)
        PUBLIC: Define that the field will be returned from an insert operation. A field added with addFieldForInsertReturnOnly method is excluded from INSERT clause during SQL generation. The type may be required to bind the output parameter if not known by the mapping.
      • addFieldForInsertReturnOnly

        public void addFieldForInsertReturnOnly​(DatabaseField field)
        PUBLIC: Define that the field will be returned from an insert operation. A field added with addFieldForInsertReturnOnly method is excluded from INSERT clause during SQL generation.
      • addFieldForUpdate

        public void addFieldForUpdate​(java.lang.String qualifiedName)
        PUBLIC: Define that the field will be returned from an update operation.
      • addFieldForUpdate

        public void addFieldForUpdate​(java.lang.String qualifiedName,
                                      java.lang.Class type)
        PUBLIC: Define that the field will be returned from an update operation. The type may be required to bind the output parameter if not known by the mapping.
      • addFieldForUpdate

        public void addFieldForUpdate​(DatabaseField field)
        PUBLIC: Define that the field will be returned from an update operation.
      • addField

        protected void addField​(DatabaseField field,
                                boolean isInsert,
                                boolean isInsertModeReturnOnly,
                                boolean isUpdate)
        INTERNAL:
      • createField

        protected DatabaseField createField​(java.lang.String qualifiedName,
                                            java.lang.Class type)
        INTERNAL:
      • createCollection

        protected java.util.Collection createCollection()
        INTERNAL:
      • addFieldToMain

        protected void addFieldToMain​(int operation,
                                      int state,
                                      DatabaseField field)
      • addCollectionToMain

        protected void addCollectionToMain​(int operation,
                                           int state,
                                           java.util.Collection collection)
      • removeDuplicateAndValidateInfos

        protected java.util.Hashtable removeDuplicateAndValidateInfos​(AbstractSession session)
      • initialize

        public void initialize​(AbstractSession session)
        INTERNAL:
      • hasEqualMains

        public boolean hasEqualMains​(ReturningPolicy policy)
        INTERNAL: Both ReturningPolicies should be initialized
      • trimModifyRowForInsert

        public void trimModifyRowForInsert​(AbstractRecord modifyRow)
        INTERNAL:
      • trimModifyRow

        protected void trimModifyRow​(AbstractRecord modifyRow,
                                     int operation)
      • isUsedToSetPrimaryKey

        public boolean isUsedToSetPrimaryKey()
        PUBLIC:
      • clearInitialization

        protected void clearInitialization()
      • initializeIsUsedToSetPrimaryKey

        protected void initializeIsUsedToSetPrimaryKey()
      • validationAfterDescriptorInitialization

        public void validationAfterDescriptorInitialization​(AbstractSession session)
        INTERNAL:
      • getField

        public DatabaseField getField​(DatabaseField field)
        INTERNAL: Returns an equal field held by ReturningPolicy, or null.