Search in sources :

Example 11 with MappingManager

use of org.datanucleus.store.rdbms.mapping.MappingManager in project datanucleus-rdbms by datanucleus.

the class DiscriminatorMapping method createDiscriminatorMapping.

/**
 * Convenience method to create a discriminator mapping in the specified table, using the provided
 * discriminator metadata.
 * @param table The table
 * @param dismd The discriminator metadata
 * @return Discriminator mapping
 */
public static DiscriminatorMapping createDiscriminatorMapping(Table table, DiscriminatorMetaData dismd) {
    RDBMSStoreManager storeMgr = table.getStoreManager();
    MappingManager mapMgr = storeMgr.getMappingManager();
    if (dismd.getStrategy() == DiscriminatorStrategy.CLASS_NAME) {
        return new DiscriminatorStringMapping(table, mapMgr.getMapping(String.class), dismd);
    } else if (dismd.getStrategy() == DiscriminatorStrategy.VALUE_MAP) {
        ColumnMetaData disColmd = dismd.getColumnMetaData();
        if (disColmd != null && disColmd.getJdbcType() != null) {
            if (MetaDataUtils.isJdbcTypeNumeric(disColmd.getJdbcType())) {
                return new DiscriminatorLongMapping(table, mapMgr.getMapping(Long.class), dismd);
            }
            return new DiscriminatorStringMapping(table, mapMgr.getMapping(String.class), dismd);
        }
        return new DiscriminatorStringMapping(table, mapMgr.getMapping(String.class), dismd);
    } else if (dismd.getStrategy() == DiscriminatorStrategy.VALUE_MAP_ENTITY_NAME) {
        ColumnMetaData disColmd = dismd.getColumnMetaData();
        if (disColmd != null && disColmd.getJdbcType() != null) {
            if (MetaDataUtils.isJdbcTypeNumeric(disColmd.getJdbcType())) {
                return new DiscriminatorLongMapping(table, mapMgr.getMapping(Long.class), dismd);
            }
            return new DiscriminatorStringMapping(table, mapMgr.getMapping(String.class), dismd);
        }
        return new DiscriminatorStringMapping(table, mapMgr.getMapping(String.class), dismd);
    }
    return null;
}
Also used : MappingManager(org.datanucleus.store.rdbms.mapping.MappingManager) ColumnMetaData(org.datanucleus.metadata.ColumnMetaData) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager)

Example 12 with MappingManager

use of org.datanucleus.store.rdbms.mapping.MappingManager in project datanucleus-rdbms by datanucleus.

the class SingleFieldMapping method prepareDatastoreMapping.

/**
 * Method to prepare a field mapping for use in the datastore.
 * This creates the column in the table.
 */
protected void prepareDatastoreMapping() {
    MappingManager mmgr = storeMgr.getMappingManager();
    Column col = mmgr.createColumn(this, getJavaTypeForDatastoreMapping(0), 0);
    mmgr.createDatastoreMapping(this, mmd, 0, col);
}
Also used : Column(org.datanucleus.store.rdbms.table.Column) MappingManager(org.datanucleus.store.rdbms.mapping.MappingManager)

Aggregations

MappingManager (org.datanucleus.store.rdbms.mapping.MappingManager)12 Column (org.datanucleus.store.rdbms.table.Column)10 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)8 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)2 DatastoreMapping (org.datanucleus.store.rdbms.mapping.datastore.DatastoreMapping)2 Timestamp (java.sql.Timestamp)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NucleusException (org.datanucleus.exceptions.NucleusException)1 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)1 ClassMetaData (org.datanucleus.metadata.ClassMetaData)1 DiscriminatorMetaData (org.datanucleus.metadata.DiscriminatorMetaData)1 ElementMetaData (org.datanucleus.metadata.ElementMetaData)1 KeyMetaData (org.datanucleus.metadata.KeyMetaData)1 RelationType (org.datanucleus.metadata.RelationType)1 ValueMetaData (org.datanucleus.metadata.ValueMetaData)1 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)1 IdentifierFactory (org.datanucleus.store.rdbms.identifier.IdentifierFactory)1 CorrespondentColumnsMapper (org.datanucleus.store.rdbms.mapping.CorrespondentColumnsMapper)1