Package lumis.portal.structure.sync
Class SyncUtil
- java.lang.Object
-
- lumis.portal.structure.sync.SyncUtil
-
public class SyncUtil extends java.lang.Object
Provides utility methods used by the structure synchronization implementation.- Since:
- 6.2.0
- Version:
- $Revision$ $Date$
-
-
Field Summary
Fields Modifier and Type Field Description static double
STRUCTURE_CURRENT_VERSION
The structure element version used currently.static java.lang.String
STRUCTURE_EMPTY_VERSION
The assumed structure version for structure with no version.static double
STRUCTURE_MINIMAL_COMPATIBLE_VERSION
The minimal structure element version compatible with current implementation.
-
Constructor Summary
Constructors Constructor Description SyncUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
arePropertiesEquivalent(java.lang.Object obj1, java.lang.Object obj2)
Returns whether the properties of two objects are equivalent.static void
eagerLoad(org.hibernate.Session session, java.util.Collection<?> objs)
Eager loads the given hibernate entity objects.static ChannelResume
getCurrentChannel()
Returns the channel that corresponds to the file currently being read or written.static boolean
isDefaultValue(java.lang.reflect.Field field, java.lang.Object value)
Indicates whether a value is the default value for a field.static boolean
isEquivalent(java.lang.Object obj1, java.lang.Object obj2)
Returns whether two objects are equivalent.static boolean
isEquivalentSortedCollection(java.util.Collection<?> col1, java.util.Collection<?> col2)
Returns whether two sorted collections are equivalent.static java.lang.String
normalizeFilename(java.lang.String filename)
Normalizes a filename by replacing special characters by underscore.static <T extends IFileElement>
Tread(java.lang.Class<T> clazz, IFile file, ChannelResume currentChannel)
Reads a structure file.static void
shallowUpdate(org.hibernate.Session session, java.lang.Object obj)
Performs a shallow update on a hibernate entity object.static void
writeIfModified(IFileElement obj, IFile file, ChannelResume currentChannel)
Writes a structure file, only if the semantics in the object is different.
-
-
-
Field Detail
-
STRUCTURE_CURRENT_VERSION
public static final double STRUCTURE_CURRENT_VERSION
The structure element version used currently.- Since:
- 15.0.0
- See Also:
- Constant Field Values
-
STRUCTURE_MINIMAL_COMPATIBLE_VERSION
public static final double STRUCTURE_MINIMAL_COMPATIBLE_VERSION
The minimal structure element version compatible with current implementation.- Since:
- 17.0.0
- See Also:
- Constant Field Values
-
STRUCTURE_EMPTY_VERSION
public static final java.lang.String STRUCTURE_EMPTY_VERSION
The assumed structure version for structure with no version.- Since:
- 15.0.0
- See Also:
- Constant Field Values
-
-
Method Detail
-
getCurrentChannel
public static ChannelResume getCurrentChannel()
Returns the channel that corresponds to the file currently being read or written.- Returns:
- the channel.
- Since:
- 6.2.0
- See Also:
#read(Class, File, ChannelResume)
,#write(Object, File, ChannelResume)
,#writeIfModified(Object, File, ChannelResume)
-
read
public static <T extends IFileElement> T read(java.lang.Class<T> clazz, IFile file, ChannelResume currentChannel) throws InvalidStructureFileException, InvalidStructureVersionException, java.io.IOException
Reads a structure file.- Type Parameters:
T
- the class mapped to the file root element.- Parameters:
clazz
- the class mapped to the file root element.file
- the file.currentChannel
- the channel the file belongs to.- Returns:
- the object that corresponds to the file root element, or
null
if the file does not exist. - Throws:
InvalidStructureFileException
- if the file format is invalid.InvalidStructureVersionException
- if the structure is out of date.java.io.IOException
- Since:
- 8.0.0
-
writeIfModified
public static void writeIfModified(IFileElement obj, IFile file, ChannelResume currentChannel)
Writes a structure file, only if the semantics in the object is different. If the file already exists it is overwritten.The write operation will occur locally or in the portal cluster depending on the
file
object type. If it is aIFile
the write will be cluster-wide, otherwise it will occur only locally.- Parameters:
obj
- the object to be written.file
- the file.currentChannel
- the channel the file belongs to.- Since:
- 8.0.0
-
isDefaultValue
public static boolean isDefaultValue(java.lang.reflect.Field field, java.lang.Object value)
Indicates whether a value is the default value for a field.- Parameters:
field
- the field.value
- the value.- Returns:
- true if the value is the default value, false otherwise.
- Since:
- 6.2.0
- See Also:
IDefaultAware
-
isEquivalentSortedCollection
public static boolean isEquivalentSortedCollection(java.util.Collection<?> col1, java.util.Collection<?> col2)
Returns whether two sorted collections are equivalent. They are considered equivalent if are of the same size and all values returned by their iterators areequivalent
, in the same order.- Parameters:
col1
- a collection.col2
- the other collection.- Returns:
- true if they are equivalent, false otherwise.
- Since:
- 6.2.0
-
isEquivalent
public static boolean isEquivalent(java.lang.Object obj1, java.lang.Object obj2)
Returns whether two objects are equivalent.By default only fields that would be output to the object's XML representation are compared. Relations to other entities are not compared (performs only a shallow comparison).
Custom equivalence rules are used if the object implements
ICustomEquivalence
.- Parameters:
obj1
- a object.obj2
- other object.- Returns:
- true if the objects are equivalent, false otherwise.
- Since:
- 6.2.0
-
arePropertiesEquivalent
public static boolean arePropertiesEquivalent(java.lang.Object obj1, java.lang.Object obj2)
Returns whether the properties of two objects are equivalent.By default only fields that would be output to the object's XML representation are compared. Relations to other entities are not compared (performs only a shallow comparison).
Custom equivalence rules are not used. To use them, use
isEquivalent(Object, Object)
instead of this method.- Parameters:
obj1
- a object.obj2
- other object.- Returns:
- true if the objects properties are equivalent, false otherwise.
- Since:
- 6.2.0
- See Also:
isEquivalent(Object, Object)
,isEquivalentSortedCollection(Collection, Collection)
-
shallowUpdate
public static void shallowUpdate(org.hibernate.Session session, java.lang.Object obj)
Performs a shallow update on a hibernate entity object.- Parameters:
session
- hibernate session for persistence access.obj
- object representing updated data.- Since:
- 6.2.0
-
eagerLoad
public static void eagerLoad(org.hibernate.Session session, java.util.Collection<?> objs)
Eager loads the given hibernate entity objects. Initializes all of the object's fields that are relations to other entities. Does not cascade the eager loading inside other entities.- Parameters:
session
- hibernate session for persistence access.objs
- the objects to load. All of them must be of the same class.- Since:
- 6.2.0
-
normalizeFilename
public static java.lang.String normalizeFilename(java.lang.String filename)
Normalizes a filename by replacing special characters by underscore.- Parameters:
filename
- the filename to be normalized.- Returns:
- the normalization result.
- Since:
- 6.2.0
-
-