@Override public void customizeConverter(final DirectToFieldMapping databaseMapping, final Session session) { if (hasEnumTypeConverter(databaseMapping)) { final EnumTypeConverter eclipseConverter = (EnumTypeConverter) databaseMapping.getConverter(); final Class enumClazz = eclipseConverter.getEnumClass(); logFine(session, "Set enum-converter to field {0} with class {1}", databaseMapping.getField().getName(), enumClazz.getName()); databaseMapping.setConverter( new org.zalando.jpa.eclipselink.customizer.databasemapping.support.EnumTypeConverter(enumClazz, databaseMapping.getField().getColumnDefinition())); } }
/** * Reset field type to use BLOB/CLOB with type conversion mapping fix for 4k oracle thin driver bug. */ private void resetFieldTypeForLOB(DirectToFieldMapping mapping) { if (mapping.getFieldClassification().getName().equals("java.sql.Blob")) { //allow the platform to figure out what database field type gonna be used. //For example, Oracle9 will generate BLOB type, SQL Server generats IMAGE. getFieldDefFromDBField(mapping.getField(), false).setType(Byte[].class); } else if (mapping.getFieldClassification().getName().equals("java.sql.Clob")) { //allow the platform to figure out what database field type gonna be used. //For example, Oracle9 will generate CLOB type. SQL Server generats TEXT. getFieldDefFromDBField(mapping.getField(), false).setType(Character[].class); } }
/** * Allows {@link DirectToFieldMapping} (@Basic) mapping to be added to a * dynamic type through API. This method can be used on a new * {@link DynamicTypeImpl} that has yet to be added to a session and have * its descriptor initialized, or it can be called on an active * (initialized) descriptor. * <p> * There is no support currently for having the EclipseLink * {@link SchemaManager} generate ALTER TABLE calls so any new columns * expected must be added without the help of EclipseLink or use the * {@link SchemaManager#replaceObject(org.eclipse.persistence.tools.schemaframework.DatabaseObjectDefinition)} * to DROP and CREATE the table. WARNING: This will cause data loss. * * @param javaType * is the type of the attribute. If the type is a primitive it * will be converted to the comparable non-primitive type. */ public DirectToFieldMapping addDirectMapping(String name, Class<?> javaType, String fieldName) { DirectToFieldMapping mapping = new DirectToFieldMapping(); mapping.setAttributeName(name); mapping.setFieldName(fieldName); mapping.setAttributeClassification(javaType); return (DirectToFieldMapping) addMapping(mapping); }
/** * PUBLIC: * Add a direct to field mapping to the receiver. The new mapping specifies that * a variable accessed by the get and set methods of the class of objects which * the receiver describes maps in the default manner for its type to the indicated * database field. */ public DatabaseMapping addDirectMapping(String attributeName, String getMethodName, String setMethodName, String fieldName) { DirectToFieldMapping mapping = new DirectToFieldMapping(); mapping.setAttributeName(attributeName); mapping.setSetMethodName(setMethodName); mapping.setGetMethodName(getMethodName); mapping.setFieldName(fieldName); return addMapping(mapping); }
/** * PUBLIC: * Add a direct to field mapping to the receiver. The new mapping specifies that * an instance variable of the class of objects which the receiver describes maps in * the default manner for its type to the indicated database field. * * @param attributeName is the name of an instance variable of the * class which the receiver describes. * @param fieldName is the name of the database column which corresponds * with the designated instance variable. * @return The newly created DatabaseMapping is returned. */ public DatabaseMapping addDirectMapping(String attributeName, String fieldName) { DirectToFieldMapping mapping = new DirectToFieldMapping(); mapping.setAttributeName(attributeName); mapping.setFieldName(fieldName); return addMapping(mapping); }
@Override public void logDatabaseMapping(final DirectToFieldMapping databaseMapping, final Session session) { logFine(session, "\tmapping.attributeName : {0}", databaseMapping.getAttributeName()); logFine(session, "\tmapping.attributeClassification: {0}", databaseMapping.getAttributeClassification()); logFine(session, "\tmapping.field.name : {0}", databaseMapping.getField().getName()); logFine(session, "\tmapping.field.sqlType : {0}", databaseMapping.getField().getSqlType()); logFine(session, "\tmapping.field.typeName: {0}", databaseMapping.getField().getTypeName()); logFine(session, "\tmapping.field.columnDefinition : {0}", databaseMapping.getField().getColumnDefinition()); logFine(session, "\tmapping.fieldClassfication : {0}", databaseMapping.getFieldClassification()); }
protected boolean hasEnumTypeConverter(final DirectToFieldMapping databaseMapping) { return databaseMapping.getConverter() != null && EnumTypeConverter.class.equals(databaseMapping.getConverter().getClass()); }
m.setConverter(null); } else { m.setConverter(this); m.setFieldClassification(fieldClassification); m.setFieldClassificationClassName(fieldClassificationName);
/** * INTERNAL: * Return the DatabaseField that represents the key in a DirectMapMapping. If the * keyMapping is not a DirectMapping, this will return null * @return */ public DatabaseField getDirectKeyField(CollectionMapping baseMapping){ if (((DatabaseMapping)keyMapping).isDirectToFieldMapping()){ return ((DirectToFieldMapping)keyMapping).getField(); } return null; }
/** * INTERNAL: * Set a converter on the KeyField of a DirectCollectionMapping * @param keyConverter * @param mapping */ public void setKeyConverter(Converter keyConverter, DirectMapMapping mapping){ if (((DatabaseMapping)keyMapping).isDirectToFieldMapping()){ ((DirectToFieldMapping)keyMapping).setConverter(keyConverter); } else { throw DescriptorException.cannotSetConverterForNonDirectMapping(mapping.getDescriptor(), mapping, keyConverter.getClass().getName()); } }
/** * INTERNAL: * Set the DatabaseField that will represent the key in a DirectMapMapping * @param keyField * @param descriptor */ public void setKeyField(DatabaseField keyField, ClassDescriptor descriptor){ if (keyMapping == null){ DirectToFieldMapping newKeyMapping = new DirectToFieldMapping(); newKeyMapping.setField(keyField); newKeyMapping.setDescriptor(descriptor); setKeyMapping(newKeyMapping); } if (((DatabaseMapping)keyMapping).isDirectToFieldMapping()){ ((DirectToFieldMapping)keyMapping).setField(keyField);; } }
@Override public void customizeColumnName(final String tableName, final DirectToFieldMapping databaseMapping, final Session session) { logDatabaseMapping(databaseMapping, session); String newFieldName = null; EntityFieldInspector<?> entityFieldInspector = FieldInspector.getFieldInspector(databaseMapping); if (shouldCreateBooleanFieldName(entityFieldInspector)) { newFieldName = NameUtils.buildBooleanFieldName(tableName, databaseMapping.getAttributeName()); } else if (!entityFieldInspector.isNameValueSet()) { // default newFieldName = NameUtils.buildFieldName(tableName, databaseMapping.getAttributeName()); } else if (entityFieldInspector.isNameValueSet()) { // column-annotation name value is set newFieldName = NameUtils.buildFieldName(tableName, databaseMapping.getField().getName()); } databaseMapping.getField().setName(newFieldName); logFine(session, "set new field-name to {0}", newFieldName); }
/** * Return a new direct/basic mapping for this type of descriptor. */ public AbstractDirectMapping newDirectMapping() { return new DirectToFieldMapping(); }
/** * INTERNAL: * The mapping is initialized with the given session. This mapping is fully initialized * after this. */ @Override public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); setFieldClassification(XMLTypePlaceholder.class); }
/** * PUBLIC: * Set the field name in the mapping. */ public void setFieldName(String FieldName) { setField(new DatabaseField(FieldName)); }
/** * INTERNAL: * Default to mutable if mapped as a DOM. */ public void preInitialize(AbstractSession session) throws DescriptorException { if (this.attributeClassification == null) { this.attributeClassification = getAttributeAccessor().getAttributeClass(); } if ((this.isMutable == null) && (this.attributeClassification != ClassConstants.STRING)) { setIsMutable(true); } super.preInitialize(session); }
/** * INTERNAL: * Get the Converter for the key of this mapping if one exists * @return */ public Converter getKeyConverter(){ if (((DatabaseMapping)keyMapping).isDirectToFieldMapping()){ return ((DirectToFieldMapping)keyMapping).getConverter(); } return null; }
m.setConverter(null); } else { m.setConverter(this); m.setFieldClassification(fieldClassification); m.setFieldClassificationClassName(fieldClassificationName);
protected void writeValueIntoRow(AbstractRecord row, DatabaseField field, Object fieldValue) { row.add(getField(), fieldValue); } }
protected AbstractDirectMapping addDirectMappingForEnum(String fieldName, String className, String columnName) { DirectToFieldMapping dtfm = addDirectMapping(fieldName, null, columnName); dtfm.setConverter(new EnumTypeConverter(dtfm, className)); addMapping(dtfm); return dtfm; }