com.atlassian.confluence.importexport.xmlimport
Class ImportProcessorContext

java.lang.Object
  extended by com.atlassian.confluence.importexport.xmlimport.ImportProcessorContext
All Implemented Interfaces:
ImportProcessorSummary

public class ImportProcessorContext
extends java.lang.Object
implements ImportProcessorSummary

Context that records the current state of an import, and provides helper methods that are dependent on that state. The context is responsible for keeping track of which objects have been imported, any ID re-mappings that have occurred during the import, any operations that have been deferred because some dependent object is not present.


Constructor Summary
ImportProcessorContext(net.sf.hibernate.engine.SessionImplementor session, net.sf.hibernate.engine.SessionFactoryImplementor sessionFactory, com.atlassian.core.util.ProgressMeter meter, boolean preserveIds)
           
 
Method Summary
 void addExplicitIdMapping(TransientHibernateHandle transientHibernateHandle, java.io.Serializable mappedId)
           
 void addUnsatisfiedObjectDependencies(java.util.Set<TransientHibernateHandle> unsatisfiedObjectDependencies, ImportedObject importedObject)
          Defer the saving of an object because it has referential dependencies on some objects that have not yet been imported, but that can not be temporarily left null.
 void deferOperations(java.util.Map<TransientHibernateHandle,java.util.Set<Operation>> operations)
          Defer a set of operations until the objects they require have been imported.
<T> java.lang.Object
generateNewIdFor(java.lang.Class<T> clazz, T object)
           
 net.sf.hibernate.metadata.ClassMetadata getClassMetadata(java.lang.Class classToPersist)
          Gets the hibernate class metadata for a particular class
 java.lang.Object getContextVariable(java.lang.String key)
          Free-form storage so persisters can maintain state during an import (for example, the BucketPropertySet persister needs to maintain a counter to help it fix broken property IDs).
 java.lang.Object getIdMappingFor(TransientHibernateHandle handle)
           
 java.util.Collection<TransientHibernateHandle> getImportedObjectHandlesOfType(java.lang.Class clazz)
          Get handles for all objects of a particular class that were imported.
<T> java.util.Collection<T>
getImportedObjectsOfType(java.lang.Class<T> clazz)
          Retrieve all the objects of a particular class that were imported.
 java.util.Set<TransientHibernateHandle> getPersistedMappedHandles()
           
 net.sf.hibernate.persister.ClassPersister getPersister(java.lang.Class classToPersist)
          Get the Hibernate class persister for a particular class.
 net.sf.hibernate.engine.SessionImplementor getSession()
          Gets the current Hibernate session.
 java.lang.Object getUnfixedIdFor(java.lang.Class clazz, java.lang.Object originalId)
           
 boolean hasPendingDeferredObject()
          When an object that has previously been deferred due to missing dependencies is able to be persisted, it is pushed onto a stack.
 boolean isObjectAlreadyImported(TransientHibernateHandle key)
          Has an object with this type and ID already been imported? Checks against all the handles that have been recorded by objectImported(bucket.core.persistence.hibernate.schema.TransientHibernateHandle).
 java.lang.Object lookupObjectByUnfixedHandle(TransientHibernateHandle key)
          Find a previously imported object by the ID as it appeared in the backup file, even if it has since been assigned a new ID.
 ImportedObject nextPendingDeferredObject()
          Pops any pending deferred object off the stack (see hasPendingDeferredObject()
 void objectImported(TransientHibernateHandle handle)
          Record that a particular object has been successfully persisted.
 void reportIncompleteDefferredOperations()
          Log any deferred operations that are still pending.
 void saveObject(java.lang.Object object)
          Save a particular object to the Hibernate session.
 void saveObject(java.io.Serializable id, java.lang.Class classToPersist, java.lang.Object objectToPersist)
           
 void setContextVariable(java.lang.String key, java.lang.Object value)
          Free-form storage so persisters can maintain state during an import (for example, the BucketPropertySet persister needs to maintain a counter to help it fix broken property IDs).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImportProcessorContext

public ImportProcessorContext(net.sf.hibernate.engine.SessionImplementor session,
                              net.sf.hibernate.engine.SessionFactoryImplementor sessionFactory,
                              com.atlassian.core.util.ProgressMeter meter,
                              boolean preserveIds)
                       throws net.sf.hibernate.HibernateException
Throws:
net.sf.hibernate.HibernateException
Method Detail

objectImported

public void objectImported(TransientHibernateHandle handle)
                    throws java.lang.Exception
Record that a particular object has been successfully persisted. This will trigger any deferred operations that were waiting on that object to exist.

Parameters:
handle - the handle of the persisted object, before any ID mapping occurred
Throws:
java.lang.Exception - if some error occurred running the deferred operations

getPersister

public net.sf.hibernate.persister.ClassPersister getPersister(java.lang.Class classToPersist)
                                                       throws net.sf.hibernate.MappingException
Get the Hibernate class persister for a particular class.

Throws:
net.sf.hibernate.MappingException

isObjectAlreadyImported

public boolean isObjectAlreadyImported(TransientHibernateHandle key)
Has an object with this type and ID already been imported? Checks against all the handles that have been recorded by objectImported(bucket.core.persistence.hibernate.schema.TransientHibernateHandle).


saveObject

public void saveObject(java.lang.Object object)
                throws net.sf.hibernate.HibernateException
Save a particular object to the Hibernate session. IDs will be assigned to the object using Hibernate's standard ID generation. Should only be used if you are creating new objects during an import (i.e. migrating from an old data representation to some new one where IDs can not be preserved).

Throws:
net.sf.hibernate.HibernateException

getClassMetadata

public net.sf.hibernate.metadata.ClassMetadata getClassMetadata(java.lang.Class classToPersist)
                                                         throws net.sf.hibernate.HibernateException
Gets the hibernate class metadata for a particular class

Throws:
net.sf.hibernate.HibernateException

lookupObjectByUnfixedHandle

public java.lang.Object lookupObjectByUnfixedHandle(TransientHibernateHandle key)
                                             throws net.sf.hibernate.HibernateException
Find a previously imported object by the ID as it appeared in the backup file, even if it has since been assigned a new ID.

Throws:
net.sf.hibernate.HibernateException

getSession

public net.sf.hibernate.engine.SessionImplementor getSession()
Gets the current Hibernate session. Returns a SessionImplementor because our import code needs access to the Hibernate internals in order to work. This is a bug, not a feature.


deferOperations

public void deferOperations(java.util.Map<TransientHibernateHandle,java.util.Set<Operation>> operations)
Defer a set of operations until the objects they require have been imported.

Parameters:
operations - a map between the handle of the object that is being waited on, and the set of operations that should be executed once that object is imported.

hasPendingDeferredObject

public boolean hasPendingDeferredObject()
When an object that has previously been deferred due to missing dependencies is able to be persisted, it is pushed onto a stack. The backup processor should periodically pop objects off the stack and attempt to persist them again.

Returns:
whether there are any deferred objects that are ready to be saved
See Also:
nextPendingDeferredObject()

nextPendingDeferredObject

public ImportedObject nextPendingDeferredObject()
Pops any pending deferred object off the stack (see hasPendingDeferredObject()

Returns:
the next pending deferred object
Throws:
java.util.EmptyStackException - if there is no pending object
See Also:
hasPendingDeferredObject(), addUnsatisfiedObjectDependencies(java.util.Set, com.atlassian.confluence.importexport.xmlimport.model.ImportedObject)

addUnsatisfiedObjectDependencies

public void addUnsatisfiedObjectDependencies(java.util.Set<TransientHibernateHandle> unsatisfiedObjectDependencies,
                                             ImportedObject importedObject)
Defer the saving of an object because it has referential dependencies on some objects that have not yet been imported, but that can not be temporarily left null. Once the objects being depended on have been imported, the deferred object will be available from nextPendingDeferredObject()

Parameters:
unsatisfiedObjectDependencies -
importedObject -
See Also:
nextPendingDeferredObject(), hasPendingDeferredObject()

getContextVariable

public java.lang.Object getContextVariable(java.lang.String key)
Free-form storage so persisters can maintain state during an import (for example, the BucketPropertySet persister needs to maintain a counter to help it fix broken property IDs). Persisters are responsible for ensuring their context keys don't clash with any other persister.

Parameters:
key - the key of the context variable to retrieve
Returns:
the associated value, or null if there is no value associated with the key

setContextVariable

public void setContextVariable(java.lang.String key,
                               java.lang.Object value)
Free-form storage so persisters can maintain state during an import (for example, the BucketPropertySet persister needs to maintain a counter to help it fix broken property IDs). Persisters are responsible for ensuring their context keys don't clash with any other persister.

Parameters:
key - the key of the context variable to set
value - the value to associate with the key

getIdMappingFor

public java.lang.Object getIdMappingFor(TransientHibernateHandle handle)

saveObject

public void saveObject(java.io.Serializable id,
                       java.lang.Class classToPersist,
                       java.lang.Object objectToPersist)
                throws net.sf.hibernate.HibernateException,
                       java.sql.SQLException
Throws:
net.sf.hibernate.HibernateException
java.sql.SQLException

addExplicitIdMapping

public void addExplicitIdMapping(TransientHibernateHandle transientHibernateHandle,
                                 java.io.Serializable mappedId)

getPersistedMappedHandles

public java.util.Set<TransientHibernateHandle> getPersistedMappedHandles()
Specified by:
getPersistedMappedHandles in interface ImportProcessorSummary

getUnfixedIdFor

public java.lang.Object getUnfixedIdFor(java.lang.Class clazz,
                                        java.lang.Object originalId)
Specified by:
getUnfixedIdFor in interface ImportProcessorSummary

getImportedObjectHandlesOfType

public java.util.Collection<TransientHibernateHandle> getImportedObjectHandlesOfType(java.lang.Class clazz)
Get handles for all objects of a particular class that were imported. Useful for post-processing.

Specified by:
getImportedObjectHandlesOfType in interface ImportProcessorSummary
Parameters:
clazz - the class of objects being looked for
Returns:
a collection of handles to all imported objects of that type

getImportedObjectsOfType

public <T> java.util.Collection<T> getImportedObjectsOfType(java.lang.Class<T> clazz)
                                                 throws net.sf.hibernate.HibernateException
Retrieve all the objects of a particular class that were imported. This is a very inefficient method as it does a database lookup for each object. Only call it for things you know there will be a manageable number of (usually: spaces)

Specified by:
getImportedObjectsOfType in interface ImportProcessorSummary
Parameters:
clazz - the class being looked up
Returns:
a collection of all objects of the given type that were imported
Throws:
net.sf.hibernate.HibernateException - if the objects could not successfully be looked up

reportIncompleteDefferredOperations

public void reportIncompleteDefferredOperations()
                                         throws java.lang.Exception
Log any deferred operations that are still pending. Usually done at the end of an import in case something went wrong with the dependency mechanism (or the backup was corrupt)

Throws:
java.lang.Exception - there was some problem reporting the deferred operations (should not happen)

generateNewIdFor

public <T> java.lang.Object generateNewIdFor(java.lang.Class<T> clazz,
                                             T object)
                                  throws net.sf.hibernate.HibernateException,
                                         java.sql.SQLException
Throws:
net.sf.hibernate.HibernateException
java.sql.SQLException


Copyright © 2003-2011 Atlassian. All Rights Reserved.