Example usage for javax.persistence EnumType toString

List of usage examples for javax.persistence EnumType toString

Introduction

In this page you can find the example usage for javax.persistence EnumType toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.apache.openjpa.persistence.jdbc.XMLPersistenceMappingSerializer.java

@Override
protected void serializeFieldMappingContent(FieldMetaData fmd, PersistenceStrategy strategy)
        throws SAXException {
    if (fmd.getMappedBy() != null)
        return;/*from ww  w  .j a  v a  2  s .c  o  m*/

    // while I'd like to do auto detection based on join directions, etc.
    // the distinguished column / table / etc names forces our hand
    // esp for OpenJPA custom mappings.
    FieldMapping field = (FieldMapping) fmd;
    switch (strategy) {
    case ONE_ONE:
    case MANY_ONE:
        serializeColumns(field.getValueInfo(), ColType.JOIN, field.getMappingInfo().getTableName());
        return;
    case ONE_MANY:
        if (field.getMappingInfo().getJoinDirection() == MappingInfo.JOIN_NONE) {
            serializeColumns(field.getElementMapping().getValueInfo(), ColType.JOIN, null);
            return;
        }
        // else no break
    case MANY_MANY:
        if (field.getMappingInfo().hasSchemaComponents()
                || field.getElementMapping().getValueInfo().hasSchemaComponents()) {
            String table = field.getMappingInfo().getTableName();
            if (table != null) {
                int index = table.indexOf('.');
                if (index < 0)
                    addAttribute("name", table);
                else {
                    addAttribute("schema", table.substring(0, index));
                    addAttribute("name", table.substring(index + 1));
                }
            }
            startElement("join-table");
            serializeColumns(field.getMappingInfo(), ColType.JOIN, null);
            serializeColumns(field.getElementMapping().getValueInfo(), ColType.INVERSE, null);
            endElement("join-table");
        }
        return;
    case ELEM_COLL:
        if (field.getMappingInfo().hasSchemaComponents()
                || field.getElementMapping().getValueInfo().hasSchemaComponents()) {
            String table = field.getMappingInfo().getTableName();
            if (table != null) {
                int index = table.indexOf('.');
                if (index < 0)
                    addAttribute("name", table);
                else {
                    addAttribute("schema", table.substring(0, index));
                    addAttribute("name", table.substring(index + 1));
                }
            }
            startElement("collection-table");
            ValueMappingImpl elem = (ValueMappingImpl) field.getElement();
            serializeColumns(elem.getValueInfo(), ColType.COL, null);
            endElement("collection-table");
        }
        return;
    }

    serializeColumns(field.getValueInfo(), ColType.COL, field.getMappingInfo().getTableName());
    if (strategy == PersistenceStrategy.BASIC && isLob(field)) {
        startElement("lob");
        endElement("lob");
    }
    TemporalType temporal = getTemporal(field);
    if (temporal != null) {
        startElement("temporal");
        addText(temporal.toString());
        endElement("temporal");
    }

    EnumType enumType = getEnumType(field);
    if (enumType != null && enumType != EnumType.ORDINAL) {
        startElement("enumerated");
        addText(enumType.toString());
        endElement("enumerated");
    }
}