Issue Details (XML | Word | Printable)

Key: NUCCORE-1154
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Andy Jefferson
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.
DataNucleus Core

Add TypeConverter extension for converting object to multiple components, from java type to multiple datastore types

Created: 12/Mar/14 08:57 AM   Updated: 29/Mar/14 12:19 PM   Resolved: 22/Mar/14 10:20 AM
Component/s: Code Structure, Datastore Support, Java Types
Affects Version/s: None
Fix Version/s: 4.0.0.m2

 Description  « Hide
While we have TypeConverter providing for converting from a java member type to the java datastore type, if a java type is more conveniently persisted into multiple columns then we would have a converter like

public class ColorComponentsConverter implements TypeConverter<Color, int[]>, MultiColumnConverter
    public int[] toDatastoreType(Color memberValue)
        return new int[] {memberValue.getRed(), memberValue.getGreen(), memberValue.getBlue(), memberValue.getAlpha()};

    public Color toMemberType(int[] datastoreValue)
        if (datastoreValue == null)
            return null;

        return new Color(datastoreValue[0], datastoreValue[1], datastoreValue[2], datastoreValue[3]);

What this doesn't do though is generalise access to the types of the columns (and maybe additional info like default lengths for columns). So we could introduce a new interface something like

public interface MultiColumnConverter
     * Accessor for the number of columns the member is stored into.
     * @return Number of columns
    int getNumberOfColumns();

     * Accessor for the java type of the datastore column for the specified position.
     * @param position The position (0=first, 1=second, etc)
     * @return The java type of the column value
    Class getDatastoreColumnType(int position);

and then perhaps add on default column lengths too at some point. This could then be used by non-RDBMS stores in generating the necessary Column(s), and by RDBMS to avoid the need to have a XXXMapping

Sort Order: Ascending order - Click to sort in descending order
Andy Jefferson added a comment - 22/Mar/14 10:20 AM
GitHub master has this with an example. Will likely need extending when we try to push it further into the RDBMS plugin