org.eobjects.metamodel.convert
Class Converters

java.lang.Object
  extended by org.eobjects.metamodel.convert.Converters

public final class Converters
extends Object

This class consists of static methods for decorating DataContexts with TypeConverters, which allows for automatic conversion of values on data read and write operations.


Method Summary
static DataContext addTypeConverter(DataContext dataContext, Column column, TypeConverter<?,?> converter)
          Adds a type converter to a specific column in the DataContext.
static UpdateableDataContext addTypeConverter(UpdateableDataContext dataContext, Column column, TypeConverter<?,?> converter)
          Adds a type converter to a specific column in the DataContext.
static DataContext addTypeConverters(DataContext dataContext, Map<Column,TypeConverter<?,?>> converters)
          Adds a collection of type converters to specific columns in the DataContext
static UpdateableDataContext addTypeConverters(UpdateableDataContext dataContext, Map<Column,TypeConverter<?,?>> converters)
          Adds a collection of type converters to specific columns in the DataContext
static Map<Column,TypeConverter<?,?>> autoDetectConverters(DataContext dataContext, Column[] columns, int sampleSize)
          Auto-detects / guesses the type converters to be applied on set of columns.
static Map<Column,TypeConverter<?,?>> autoDetectConverters(DataContext dataContext, Table table, int sampleSize)
          Auto-detects / guesses the type converters to be applied on a table.
protected static
<RB extends RowBuilder<?>>
RB
convertRow(RB rowBuilder, Map<Column,TypeConverter<?,?>> converters)
          Converts values in a RowBuilder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addTypeConverter

public static UpdateableDataContext addTypeConverter(UpdateableDataContext dataContext,
                                                     Column column,
                                                     TypeConverter<?,?> converter)
Adds a type converter to a specific column in the DataContext.

Parameters:
dataContext - the DataContext to decorate
column - the column which holds values to convert
converter - the converter to use on the specified column
Returns:
a decorated DataContext, which should be used for successive operations on the data.

addTypeConverter

public static DataContext addTypeConverter(DataContext dataContext,
                                           Column column,
                                           TypeConverter<?,?> converter)
Adds a type converter to a specific column in the DataContext.

Parameters:
dataContext - the DataContext to decorate
column - the column which holds values to convert
converter - the converter to use on the specified column
Returns:
a decorated DataContext, which should be used for successive operations on the data.

addTypeConverters

public static UpdateableDataContext addTypeConverters(UpdateableDataContext dataContext,
                                                      Map<Column,TypeConverter<?,?>> converters)
Adds a collection of type converters to specific columns in the DataContext

Parameters:
dataContext - the DataContext to decorate
converters - a map containing columns and mapped type converters.
Returns:
a decorated DataContext, which should be used for successive operations on the data.

addTypeConverters

public static DataContext addTypeConverters(DataContext dataContext,
                                            Map<Column,TypeConverter<?,?>> converters)
Adds a collection of type converters to specific columns in the DataContext

Parameters:
dataContext - the DataContext to decorate
converters - a map containing columns and mapped type converters.
Returns:
a decorated DataContext, which should be used for successive operations on the data.

autoDetectConverters

public static Map<Column,TypeConverter<?,?>> autoDetectConverters(DataContext dataContext,
                                                                  Column[] columns,
                                                                  int sampleSize)
Auto-detects / guesses the type converters to be applied on set of columns. This method will query the String columns in order to assert which columns are likely candidates for conversion. As such this method is not guaranteed to pick the correct converters, since data can change over time or other conversions can be requested.

Parameters:
dataContext - the DataContext that holds the data.
columns - the columns to inspect to find type conversion candidates.
sampleSize - the max amount of rows to query for doing auto-detection. Use Integer.MAX_VALUE if no constraint should be put on the number of records to sample.
Returns:
a map of Columns and TypeConverters which can be used (eg. with the addTypeConverters(DataContext, Map) method) to decorate the DataContext with type converters.

autoDetectConverters

public static Map<Column,TypeConverter<?,?>> autoDetectConverters(DataContext dataContext,
                                                                  Table table,
                                                                  int sampleSize)
Auto-detects / guesses the type converters to be applied on a table. This method will query the String columns of a table in order to assert which columns are likely candidates for conversion. As such this method is not guaranteed to pick the correct converters, since data can change over time or other conversions can be requested.

Parameters:
dataContext - the DataContext that holds the data.
table - the table to inspect to find type conversion candidates. This table will hold all columns of the result.
sampleSize - the max amount of rows to query for doing auto-detection. Use Integer.MAX_VALUE if no constraint should be put on the number of records to sample.
Returns:
a map of Columns and TypeConverters which can be used (eg. with the addTypeConverters(DataContext, Map) method) to decorate the DataContext with type converters.

convertRow

protected static <RB extends RowBuilder<?>> RB convertRow(RB rowBuilder,
                                                          Map<Column,TypeConverter<?,?>> converters)
Converts values in a RowBuilder.

Parameters:
rowBuilder -
converters -
Returns:


Copyright © 2007-2013. All Rights Reserved.