Example usage for javax.persistence TemporalType toString

List of usage examples for javax.persistence TemporalType toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.codehaus.grepo.query.jpa.generator.QueryGeneratorBase.java

protected void setPositionalParameter(int index, Object value, TemporalType temporalType, Query query) {
    if (temporalType != null && value == null) {
        // GREPO-58 handle null values AND temporalTypes correctly!
        logSetParameter(index, null, temporalType);
        query.setParameter(index, (Calendar) null, temporalType);
    } else if (temporalType != null && value instanceof Calendar) {
        logSetParameter(index, value, temporalType);
        query.setParameter(index, (Calendar) value, temporalType);
    } else if (temporalType != null && value instanceof Date) {
        logSetParameter(index, (Date) value, temporalType);
        query.setParameter(index, (Date) value, temporalType);
    } else {//from   ww w. ja v  a 2s  .  co m
        logSetParameter(index, value, null);
        query.setParameter(index, value);
        if (temporalType != null) {
            Object[] params = new Object[] { temporalType.toString(), value, Date.class.getName(),
                    Calendar.class.getName() };
            logger.warn(INVALID_TEMPORALTYPE_MSG, params);
        }
    }
}

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 2s . 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");
    }
}