com.atlassian.bamboo.migration
Class BambooStAXMappingHelperAbstractImpl<T>

java.lang.Object
  extended by com.atlassian.bamboo.migration.BambooStAXMappingHelperAbstractImpl<T>
Type Parameters:
T -
All Implemented Interfaces:
BambooStAXMappingHelper<T>
Direct Known Subclasses:
BambooStAXMappingListHelperAbstractImpl, BuildDefinitionMapper, BuildNotificationMapper, BuildNumberMapper, ServerIDMapper, SharedCapabilityMapper

public abstract class BambooStAXMappingHelperAbstractImpl<T>
extends java.lang.Object
implements BambooStAXMappingHelper<T>

Skeleton implementation of StAX based export-import helper class The XML representation of such an object is: valueOfPropertyA valueOfPropertyB ...


Constructor Summary
protected BambooStAXMappingHelperAbstractImpl(net.sf.hibernate.SessionFactory sessionFactory)
           
 
Method Summary
protected  void commitClearSession(net.sf.hibernate.Session session)
          Utility method for clearing the Hibernate session
protected  void commitSession(net.sf.hibernate.Session session)
          Utility method for committing the Hibernate session
protected abstract  T createItemInstance(org.codehaus.staxmate.in.SMInputCursor inputCursor)
          Creates empty instance of the imported object
protected  org.codehaus.staxmate.out.SMOutputElement createRootElement(org.codehaus.staxmate.out.SMOutputElement outputElement)
          Create root node for the exported object.
protected  void exportProperties(org.codehaus.staxmate.out.SMOutputElement outputElement, T object, net.sf.hibernate.Session session)
          Export object properties.
 void exportXml(net.sf.hibernate.Session session, org.codehaus.staxmate.out.SMOutputElement outputElement, T object)
          Implementation of object export.
protected  void exportXml(org.codehaus.staxmate.out.SMOutputElement outputElement, T object)
          Implementation of object export.
protected  net.sf.hibernate.Session getSession()
          Get the Hibernate session
 net.sf.hibernate.SessionFactory getSessionFactory()
           
protected  void importProperties(T object, org.codehaus.staxmate.in.SMInputCursor inputCursor, net.sf.hibernate.Session session)
          Import properties to the object.
 T importXml(net.sf.hibernate.Session session, org.codehaus.staxmate.in.SMInputCursor inputCursor)
          Implementation of object import.
protected  T importXml(org.codehaus.staxmate.in.SMInputCursor inputCursor)
          Object import.
protected  void saveBambooObject(net.sf.hibernate.Session session, BambooObject object)
          Save object without regenerating the id if already assigned.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.atlassian.bamboo.migration.BambooStAXMappingHelper
getXmlRootNodeName
 

Constructor Detail

BambooStAXMappingHelperAbstractImpl

protected BambooStAXMappingHelperAbstractImpl(net.sf.hibernate.SessionFactory sessionFactory)
Method Detail

exportProperties

protected void exportProperties(@NotNull
                                org.codehaus.staxmate.out.SMOutputElement outputElement,
                                @NotNull
                                T object,
                                @NotNull
                                net.sf.hibernate.Session session)
                         throws java.lang.Exception
Export object properties. Implementing classed should override this method to export custom properties.

Parameters:
outputElement - the parent node
object - object being exported
session - Hibernate session object
Throws:
java.lang.Exception - when something went wrong

exportXml

protected final void exportXml(@NotNull
                               org.codehaus.staxmate.out.SMOutputElement outputElement,
                               @NotNull
                               T object)
                        throws java.lang.Exception
Implementation of object export. This base implementation is usually sufficient: it creates the root node and calls exportProperties.

Parameters:
outputElement - an element at which exported should create a node to export data
object - object being exported
Throws:
java.lang.Exception - when something went wrong

exportXml

public void exportXml(@NotNull
                      net.sf.hibernate.Session session,
                      @NotNull
                      org.codehaus.staxmate.out.SMOutputElement outputElement,
                      @NotNull
                      T object)
               throws java.lang.Exception
Implementation of object export. This base implementation is usually sufficient: it creates the root node and calls exportProperties.

Specified by:
exportXml in interface BambooStAXMappingHelper<T>
Parameters:
session - Hibernate session object
outputElement - an element at which exported should create a node to export data
object - object being exported
Throws:
java.lang.Exception - when something went wrong

createItemInstance

@NotNull
protected abstract T createItemInstance(org.codehaus.staxmate.in.SMInputCursor inputCursor)
                                 throws java.lang.Exception
Creates empty instance of the imported object

Parameters:
inputCursor - input cursor that points to the parent node containing object properties
Returns:
empty instance of the imported object
Throws:
javax.xml.stream.XMLStreamException - when something went wrong
java.lang.Exception

importProperties

protected void importProperties(@NotNull
                                T object,
                                @NotNull
                                org.codehaus.staxmate.in.SMInputCursor inputCursor,
                                @NotNull
                                net.sf.hibernate.Session session)
                         throws java.lang.Exception
Import properties to the object. Due to nature of XML parsing this method is called for each child node in the node that was passed to importXml method

Parameters:
object - object being imported
inputCursor - input cursor pointing to the child node of node that was passed to importXml method
session - Hibernate session object
Throws:
java.lang.Exception - when something went wrong

importXml

@NotNull
protected final T importXml(@NotNull
                                    org.codehaus.staxmate.in.SMInputCursor inputCursor)
                     throws java.lang.Exception
Object import.

Parameters:
inputCursor - input cursor that points to the parent node containing object properties
Returns:
an imported object
Throws:
java.lang.Exception - when something went wrong

importXml

@NotNull
public T importXml(@NotNull
                           net.sf.hibernate.Session session,
                           @NotNull
                           org.codehaus.staxmate.in.SMInputCursor inputCursor)
            throws java.lang.Exception
Implementation of object import. This base implementation is usually sufficient: - create the imported object instance - iterate over child nodes on input node and for each of them call importProperties method

Specified by:
importXml in interface BambooStAXMappingHelper<T>
Parameters:
session - Hibernate session object
inputCursor - a cursor that points to the parent node containing object properties
Returns:
an imported object
Throws:
java.lang.Exception - when something went wrong

createRootElement

@NotNull
protected org.codehaus.staxmate.out.SMOutputElement createRootElement(@NotNull
                                                                              org.codehaus.staxmate.out.SMOutputElement outputElement)
                                                               throws javax.xml.stream.XMLStreamException
Create root node for the exported object.

Parameters:
outputElement - parent node for the object's root node
Returns:
SMOutputElement representing newly created object's root node
Throws:
javax.xml.stream.XMLStreamException - when something went wrong

commitClearSession

protected void commitClearSession(@NotNull
                                  net.sf.hibernate.Session session)
                           throws net.sf.hibernate.HibernateException,
                                  java.sql.SQLException
Utility method for clearing the Hibernate session

Parameters:
session - db session
Throws:
net.sf.hibernate.HibernateException - when session.flush() operation fails
java.sql.SQLException - when session.connection().commit() operation fails

commitSession

protected void commitSession(@NotNull
                             net.sf.hibernate.Session session)
                      throws net.sf.hibernate.HibernateException,
                             java.sql.SQLException
Utility method for committing the Hibernate session

Parameters:
session - db session
Throws:
net.sf.hibernate.HibernateException - when session.flush() operation fails
java.sql.SQLException - when session.connection().commit() operation fails

saveBambooObject

protected void saveBambooObject(@NotNull
                                net.sf.hibernate.Session session,
                                @NotNull
                                BambooObject object)
                         throws net.sf.hibernate.HibernateException
Save object without regenerating the id if already assigned.

Parameters:
session - Hibernate session object
object - object to be saved
Throws:
net.sf.hibernate.HibernateException - when save operation failed

getSession

protected net.sf.hibernate.Session getSession()
Get the Hibernate session

Returns:
Hibernate session object

getSessionFactory

public net.sf.hibernate.SessionFactory getSessionFactory()


Copyright © 2011 Atlassian. All Rights Reserved.