/** * Append list of columns from descriptor class to provided {@link StringBuilder}. * Use to create content of columns brackets in <code>INSERT INTO table (col1, col1) VALUES ...</code>. * @param target Target {@link StringBuilder}. * @param mappings Object attributes mappings. * @param separator String to separate values in list. */ public static void buildColsFromMappings(final StringBuilder target, final Collection<DatabaseMapping> mappings, final String separator) { for (Iterator<DatabaseMapping> i = mappings.iterator(); i.hasNext(); ) { target.append(i.next().getField().getName()); if (i.hasNext()) { target.append(separator); } } }
/** * Append list of columns from descriptor class to provided {@link StringBuilder}. * Use to create content of columns brackets in <code>INSERT INTO table (col1, col1) VALUES ...</code>. * @param target Target {@link StringBuilder}. * @param mappings Object attributes mappings. * @param separator String to separate values in list. */ public static void buildColsFromMappings(final StringBuilder target, final Collection<DatabaseMapping> mappings, final String separator) { for (Iterator<DatabaseMapping> i = mappings.iterator(); i.hasNext(); ) { target.append(i.next().getField().getName()); if (i.hasNext()) { target.append(separator); } } }
/** * INTERNAL: */ protected void addIdFieldFromAccessor(MappingAccessor accessor) { String attributeName = accessor.getAttributeName(); if (m_idFields.containsKey(attributeName)) { // It may be in our id fields map already if an attribute override // was specified on the embedded mapping. Make sure the existing id // field has its mapping accessor associated with it. m_idAccessors.put(m_idFields.get(attributeName), accessor); } else { DatabaseField field = accessor.getMapping().getField(); m_idFields.put(attributeName, field); m_idAccessors.put(field, accessor); } }
public static Map<String, Object> getPropertyInfo(SingularAttribute<?, ?> sa, EdmType type) { Map<String, Object> rt = new HashMap<String, Object>(); AttributeImpl<?, ?> ai = (AttributeImpl<?, ?>) sa; DatabaseMapping dm = CoreUtils.getFieldValue(ai, "mapping", DatabaseMapping.class); DatabaseField df = dm.getField(); if (df != null && EdmSimpleType.STRING.equals(type)) { rt.put("MaxLength", df.getLength()); } return rt; }
@Override public void initialize(DatabaseMapping mapping, Session session) { final DatabaseField field = mapping.getField(); field.setSqlType(java.sql.Types.OTHER); field.setTypeName("inet"); field.setColumnDefinition("INET"); } }
@Override public void initialize(DatabaseMapping mapping, Session session) { final DatabaseField field = mapping.getField(); field.setSqlType(java.sql.Types.OTHER); field.setTypeName("inet"); field.setColumnDefinition("INET"); } }
@SuppressWarnings("unchecked") @Override public void initialize(final DatabaseMapping mapping, final Session session) { enumClass = mapping.getAttributeClassification(); pgTypeName = mapping.getField().getColumnDefinition(); checkPgTypeName(); // if (Strings.isNullOrEmpty(pgTypeName)) { // pgTypeName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, enumClass.getSimpleName()); // } }
/** * Determines if a given descriptor contains a direct mapping to "text()" indicating a * simple mapping. In this case, a simple type or complex type with simple content * will be generated * * @param desc * @return */ protected boolean isSimple(XMLDescriptor desc) { boolean isSimple = false; for (DatabaseMapping mapping : desc.getMappings()) { if (mapping.isDirectToFieldMapping()) { XMLField xFld = (XMLField) mapping.getField(); if (xFld.getXPath().equals(TEXT)) { isSimple = true; break; } } else { break; } } return isSimple; }
private String getXPathForProperty(SDOProperty prop, boolean removeText, NamespaceResolver namespaceResolver) { if ((prop).getXmlMapping() != null) { String xpath = prop.getXmlMapping().getField().getName(); if (removeText && xpath.endsWith("/text()")) { xpath = xpath.substring(0, xpath.length() - 7); } return xpath; } else { String name = prop.getName(); if (prop.isOpenContent()) { String uri = prop.getUri(); if (uri != null) { String prefix = namespaceResolver.resolveNamespaceURI(uri); if ((prefix != null) && !prefix.equals(SDOConstants.EMPTY_STRING)) { return prefix + XMLConstants.COLON + name; } } } return name; } }
private String getXPathForProperty(SDOProperty prop, boolean removeText, NamespaceResolver namespaceResolver) { if ((prop).getXmlMapping() != null) { String xpath = prop.getXmlMapping().getField().getName(); if (removeText && xpath.endsWith("/text()")) { xpath = xpath.substring(0, xpath.length() - 7); } return xpath; } else { String name = prop.getName(); if (prop.isOpenContent()) { String uri = prop.getUri(); if (uri != null) { String prefix = namespaceResolver.resolveNamespaceURI(uri); if ((prefix != null) && !prefix.equals(SDOConstants.EMPTY_STRING)) { return prefix + XMLConstants.COLON + name; } } } return name; } }
@Override public void customize(Session session) throws SQLException { for (ClassDescriptor descriptor : session.getDescriptors().values()) { // Only change the table name for non-embedable entities with no // @Table already if (!descriptor.getTables().isEmpty() && descriptor.getAlias().equalsIgnoreCase(descriptor.getTableName())) { String tableName = addUnderscores(descriptor.getTableName()); descriptor.setTableName(tableName); for (IndexDefinition index : descriptor.getTables().get(0).getIndexes()) { index.setTargetTable(tableName); } } for (DatabaseMapping mapping : descriptor.getMappings()) { // Only change the column name for non-embedable entities with // no @Column already if (mapping.getField() != null && !mapping.getAttributeName().isEmpty() && mapping.getField().getName().equalsIgnoreCase(mapping.getAttributeName())) { mapping.getField().setName(addUnderscores(mapping.getAttributeName())); } } } }
/** * INTERNAL: * Update the primary key field on the owning descriptor the override field * given. */ protected void updatePrimaryKeyField(MappingAccessor idAccessor, DatabaseField overrideField) { getOwningDescriptor().removePrimaryKeyField(idAccessor.getMapping().getField()); getOwningDescriptor().addPrimaryKeyField(overrideField, idAccessor); }
private String getUriForProperty(SDODataObject currentObject) { SDOProperty prop = currentObject.getContainmentProperty(); if (prop.getXmlMapping() != null) { return ((XMLField)prop.getXmlMapping().getField()).getXPathFragment().getNamespaceURI(); } else { return prop.getUri(); } }
private String getUriForProperty(SDODataObject currentObject) { SDOProperty prop = currentObject.getContainmentProperty(); if (prop.getXmlMapping() != null) { return ((XMLField)prop.getXmlMapping().getField()).getXPathFragment().getNamespaceURI(); } else { return prop.getUri(); } }
/** * Is the attribute an id attribute. * @return boolean indicating whether or not attribute is an id */ public boolean isId() { if(this.getManagedTypeImpl().isMappedSuperclass()) { // The field on the mapping is the same field in the pkFields list on the descriptor // 288792: We can use the new isJPAId field here return (this.getDescriptor().getPrimaryKeyFields().contains(this.getMapping().getField())); } else { // 288792: Some id mappings will return false for isPrimaryKeyMapping but true for isJPAId return getMapping().isPrimaryKeyMapping() || getMapping().isJPAId(); } }
/** * Returns the namespace URI as declared in the XSD. * @param property to return namespace URI for. * @return the namespace URI as declared in the XSD. */ public String getNamespaceURI(Property property) { if (property == null) { return null; } String uri = null; if (property.isOpenContent()) { uri = ((SDOProperty)property).getUri(); } else { DatabaseMapping mapping = ((SDOProperty)property).getXmlMapping(); if (mapping != null) { XMLField xmlField = (XMLField) mapping.getField(); if (xmlField != null && xmlField.getXPathFragment() != null) { uri = xmlField.getXPathFragment().getNamespaceURI(); } } } return uri == null ? "" : uri; }
/** * Returns the namespace URI as declared in the XSD. * @param property to return namespace URI for. * @return the namespace URI as declared in the XSD. */ public String getNamespaceURI(Property property) { if (property == null) { return null; } String uri = null; if (property.isOpenContent()) { uri = ((SDOProperty)property).getUri(); } else { DatabaseMapping mapping = ((SDOProperty)property).getXmlMapping(); if (mapping != null) { XMLField xmlField = (XMLField) mapping.getField(); if (xmlField != null && xmlField.getXPathFragment() != null) { uri = xmlField.getXPathFragment().getNamespaceURI(); } } } return uri == null ? "" : uri; }
/** * INTERNAL: * Returns the corresponding attribute value for the specified field value. */ public Object convertDataValueToObjectValue(Object fieldValue, Session session) { Object attributeValue = null; if (fieldValue == null) { attributeValue = getFieldToAttributeValues().get(Helper.NULL_VALUE); } else { try { fieldValue = ((AbstractSession)session).getDatasourcePlatform().getConversionManager().convertObject(fieldValue, getFieldClassification()); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(mapping, mapping.getDescriptor(), e); } attributeValue = getFieldToAttributeValues().get(fieldValue); if (attributeValue == null) { if (getDefaultAttributeValue() != null) { attributeValue = getDefaultAttributeValue(); } else { // CR#3779 throw DescriptorException.noFieldValueConversionToAttributeValueProvided(fieldValue, getMapping().getField(), getMapping()); } } } return attributeValue; }
/** * INTERNAL: * Returns the corresponding attribute value for the specified field value. */ public Object convertDataValueToObjectValue(Object fieldValue, Session session) { Object attributeValue = null; if (fieldValue == null) { attributeValue = getFieldToAttributeValues().get(Helper.NULL_VALUE); } else { try { fieldValue = ((AbstractSession)session).getDatasourcePlatform().getConversionManager().convertObject(fieldValue, getFieldClassification()); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(mapping, mapping.getDescriptor(), e); } attributeValue = getFieldToAttributeValues().get(fieldValue); if (attributeValue == null) { if (getDefaultAttributeValue() != null) { attributeValue = getDefaultAttributeValue(); } else { // CR#3779 throw DescriptorException.noFieldValueConversionToAttributeValueProvided(fieldValue, getMapping().getField(), getMapping()); } } } return attributeValue; }
/** * INTERNAL: * Find the alias for a given table */ @Override public DatabaseTable aliasForTable(DatabaseTable table) { DatabaseMapping mapping = getMapping(); if (isAttribute() || ((mapping != null) && (mapping.isAggregateObjectMapping() || mapping.isTransformationMapping()))) { return ((DataExpression)this.baseExpression).aliasForTable(table); } //"ref" and "structure" mappings, no table printed in the FROM clause, need to get the table alias form the parent table if ((mapping != null) && (mapping.isReferenceMapping() || mapping.isStructureMapping())) { DatabaseTable alias = this.baseExpression.aliasForTable(mapping.getDescriptor().getTables().firstElement()); alias.setName(alias.getName() + "." + mapping.getField().getName()); return alias; } // For direct-collection mappings the alias is store on the table expression. if ((mapping != null) && (mapping.isDirectCollectionMapping())) { if (tableAliases != null){ DatabaseTable aliasedTable = tableAliases.keyAtValue(table); if (aliasedTable != null){ return aliasedTable; } } return getTable(table).aliasForTable(table); } return super.aliasForTable(table); }