org.eclipse.persistence.oxm.mappings.XMLDirectMapping.getNullPolicy()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(15.7k)|赞(0)|评价(0)|浏览(141)

本文整理了Java中org.eclipse.persistence.oxm.mappings.XMLDirectMapping.getNullPolicy()方法的一些代码示例,展示了XMLDirectMapping.getNullPolicy()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLDirectMapping.getNullPolicy()方法的具体详情如下:
包路径:org.eclipse.persistence.oxm.mappings.XMLDirectMapping
类名称:XMLDirectMapping
方法名:getNullPolicy

XMLDirectMapping.getNullPolicy介绍

[英]INTERNAL: Get the AbstractNullPolicy from the Mapping.
The default policy is NullPolicy.
[中]内部:从映射中获取AbstractNullPolicy。
默认策略为NullPolicy。

代码示例

代码示例来源:origin: stackoverflow.com

  1. import org.eclipse.persistence.config.DescriptorCustomizer;
  2. import org.eclipse.persistence.descriptors.ClassDescriptor;
  3. import org.eclipse.persistence.mappings.DatabaseMapping;
  4. import org.eclipse.persistence.oxm.mappings.XMLDirectMapping;
  5. import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
  6. public class AddressCustomizer implements DescriptorCustomizer {
  7. @Override
  8. public void customize(ClassDescriptor descriptor) throws Exception {
  9. for(DatabaseMapping mapping : descriptor.getMappings()) {
  10. if(mapping.isAbstractDirectMapping()) {
  11. XMLDirectMapping xmlDirectMapping = (XMLDirectMapping) mapping;
  12. xmlDirectMapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
  13. xmlDirectMapping.getNullPolicy().setNullRepresentedByEmptyNode(true);
  14. }
  15. }
  16. }
  17. }

代码示例来源:origin: stackoverflow.com

  1. import org.eclipse.persistence.descriptors.ClassDescriptor;
  2. import org.eclipse.persistence.mappings.DatabaseMapping;
  3. import org.eclipse.persistence.oxm.mappings.XMLDirectMapping;
  4. import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
  5. import org.eclipse.persistence.sessions.*;
  6. public class NullPolicySessionEventListener extends SessionEventAdapter {
  7. @Override
  8. public void preLogin(SessionEvent event) {
  9. Project project = event.getSession().getProject();
  10. for(ClassDescriptor descriptor : project.getOrderedDescriptors()) {
  11. for(DatabaseMapping mapping : descriptor.getMappings()) {
  12. if(mapping.isAbstractDirectMapping()) {
  13. XMLDirectMapping xmlDirectMapping = (XMLDirectMapping) mapping;
  14. xmlDirectMapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
  15. xmlDirectMapping.getNullPolicy().setNullRepresentedByEmptyNode(true);
  16. }
  17. }
  18. }
  19. }
  20. }

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

  1. public boolean isWhitespaceAware() {
  2. return !xmlDirectMapping.getNullPolicy().isNullRepresentedByEmptyNode();
  3. }

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

  1. public boolean isNullCapableValue() {
  2. return xmlDirectMapping.getNullPolicy().getIsSetPerformedForAbsentNode();
  3. }

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

  1. public void setXPathNode(XPathNode xPathNode) {
  2. super.setXPathNode(xPathNode);
  3. xmlDirectMapping.getNullPolicy().xPathNode(xPathNode, this);
  4. }

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

  1. public void writeSingleValue(Object value, Object parent, XMLRecord row, AbstractSession session) {
  2. Object fieldValue = getFieldValue(value, session, row);
  3. if(fieldValue == null && getNullPolicy() != null) {
  4. getNullPolicy().directMarshal((Field) this.getField(), row, parent);
  5. } else {
  6. writeValueIntoRow(row, getField(), fieldValue);
  7. }
  8. }

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

  1. public void writeSingleValue(Object value, Object parent, XMLRecord row, AbstractSession session) {
  2. Object fieldValue = getFieldValue(value, session, row);
  3. if(fieldValue == null && getNullPolicy() != null) {
  4. getNullPolicy().directMarshal((Field) this.getField(), row, parent);
  5. } else {
  6. writeValueIntoRow(row, getField(), fieldValue);
  7. }
  8. }

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

  1. /**
  2. * INTERNAL:
  3. * Return the mapping's attribute value from the row.
  4. * The execution session is passed for the case of building a UnitOfWork clone
  5. * directly from a row, the session set in the query will not know which platform to use
  6. * for converting the value. Allows the correct session to be passed in.
  7. */
  8. public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery query, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) {
  9. // PERF: Direct variable access.
  10. boolean shouldCheckForXsiNil = getNullPolicy().isNullRepresentedByXsiNil();
  11. return getAttributeValue(((DOMRecord)row).getIndicatingNoEntry(this.field, false, shouldCheckForXsiNil), executionSession, (XMLRecord)row);
  12. }

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

  1. /**
  2. * INTERNAL:
  3. * Return the mapping's attribute value from the row.
  4. * The execution session is passed for the case of building a UnitOfWork clone
  5. * directly from a row, the session set in the query will not know which platform to use
  6. * for converting the value. Allows the correct session to be passed in.
  7. */
  8. public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery query, AbstractSession executionSession) {
  9. // PERF: Direct variable access.
  10. boolean shouldCheckForXsiNil = getNullPolicy().isNullRepresentedByXsiNil();
  11. return getAttributeValue(((DOMRecord)row).getIndicatingNoEntry(this.field, false, shouldCheckForXsiNil), executionSession, (XMLRecord)row);
  12. }

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

  1. /**
  2. * INTERNAL:
  3. * Return the mapping's attribute value from the row.
  4. * The execution session is passed for the case of building a UnitOfWork clone
  5. * directly from a row, the session set in the query will not know which platform to use
  6. * for converting the value. Allows the correct session to be passed in.
  7. */
  8. public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery query, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) {
  9. // PERF: Direct variable access.
  10. boolean shouldCheckForXsiNil = getNullPolicy().isNullRepresentedByXsiNil();
  11. return getAttributeValue(((DOMRecord)row).getIndicatingNoEntry(this.field, false, shouldCheckForXsiNil), executionSession, (XMLRecord)row);
  12. }

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

  1. containerAttributeMapping.setSetMethodName("setContainerAttributeName");
  2. containerAttributeMapping.setXPath("container-attribute/text()");
  3. ((NullPolicy)containerAttributeMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
  4. descriptor.addMapping(containerAttributeMapping);
  5. containerGetMethodMapping.setSetMethodName("setContainerGetMethodName");
  6. containerGetMethodMapping.setXPath("container-get-method/text()");
  7. ((NullPolicy)containerGetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
  8. descriptor.addMapping(containerGetMethodMapping);
  9. containerSetMethodMapping.setSetMethodName("setContainerSetMethodName");
  10. containerSetMethodMapping.setXPath("container-set-method/text()");
  11. ((NullPolicy)containerSetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
  12. descriptor.addMapping(containerSetMethodMapping);

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

  1. containerAttributeMapping.setSetMethodName("setContainerAttributeName");
  2. containerAttributeMapping.setXPath("container-attribute/text()");
  3. ((NullPolicy)containerAttributeMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
  4. descriptor.addMapping(containerAttributeMapping);
  5. containerGetMethodMapping.setSetMethodName("setContainerGetMethodName");
  6. containerGetMethodMapping.setXPath("container-get-method/text()");
  7. ((NullPolicy)containerGetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
  8. descriptor.addMapping(containerGetMethodMapping);
  9. containerSetMethodMapping.setSetMethodName("setContainerSetMethodName");
  10. containerSetMethodMapping.setXPath("container-set-method/text()");
  11. ((NullPolicy)containerSetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
  12. descriptor.addMapping(containerSetMethodMapping);

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

  1. containerAttributeMapping.setSetMethodName("setContainerAttributeName");
  2. containerAttributeMapping.setXPath("container-attribute/text()");
  3. ((NullPolicy)containerAttributeMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
  4. descriptor.addMapping(containerAttributeMapping);
  5. containerGetMethodMapping.setSetMethodName("setContainerGetMethodName");
  6. containerGetMethodMapping.setXPath("container-get-method/text()");
  7. ((NullPolicy)containerGetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
  8. descriptor.addMapping(containerGetMethodMapping);
  9. containerSetMethodMapping.setSetMethodName("setContainerSetMethodName");
  10. containerSetMethodMapping.setXPath("container-set-method/text()");
  11. ((NullPolicy)containerSetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
  12. descriptor.addMapping(containerSetMethodMapping);

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.sdo

  1. mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
  2. mapping.getNullPolicy().setNullRepresentedByEmptyNode(true);

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

  1. mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
  2. mapping.getNullPolicy().setNullRepresentedByEmptyNode(true);

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

  1. containerAttributeMapping.setSetMethodName("setContainerAttributeName");
  2. containerAttributeMapping.setXPath("container-attribute/text()");
  3. ((NullPolicy)containerAttributeMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
  4. descriptor.addMapping(containerAttributeMapping);
  5. containerGetMethodMapping.setSetMethodName("setContainerGetMethodName");
  6. containerGetMethodMapping.setXPath("container-get-method/text()");
  7. ((NullPolicy)containerGetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
  8. descriptor.addMapping(containerGetMethodMapping);
  9. containerSetMethodMapping.setSetMethodName("setContainerSetMethodName");
  10. containerSetMethodMapping.setXPath("container-set-method/text()");
  11. ((NullPolicy)containerSetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
  12. descriptor.addMapping(containerSetMethodMapping);

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

  1. public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object objectValue, AbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) {
  2. Object fieldValue = xmlDirectMapping.getFieldValue(objectValue, session, marshalRecord);
  3. // Check for a null value
  4. if (null == fieldValue) {
  5. // Perform marshal operations based on the null policy
  6. return xmlDirectMapping.getNullPolicy().directMarshal(xPathFragment, marshalRecord, object, session, namespaceResolver);
  7. } else {
  8. QName schemaType = getSchemaType((XMLField) xmlDirectMapping.getField(), fieldValue, session);
  9. String stringValue = getValueToWrite(schemaType, fieldValue, (XMLConversionManager) session.getDatasourcePlatform().getConversionManager(), namespaceResolver);
  10. XPathFragment groupingFragment = marshalRecord.openStartGroupingElements(namespaceResolver);
  11. if (xPathFragment.isAttribute()) {
  12. marshalRecord.attribute(xPathFragment, namespaceResolver, stringValue);
  13. marshalRecord.closeStartGroupingElements(groupingFragment);
  14. } else {
  15. marshalRecord.closeStartGroupingElements(groupingFragment);
  16. if (xmlDirectMapping.isCDATA()) {
  17. marshalRecord.cdata(stringValue);
  18. } else {
  19. marshalRecord.characters(stringValue);
  20. }
  21. }
  22. return true;
  23. }
  24. }

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

  1. protected ClassDescriptor buildDatabaseFieldDescriptor() {
  2. XMLDescriptor descriptor = new XMLDescriptor();
  3. descriptor.setJavaClass(DatabaseField.class);
  4. descriptor.setDefaultRootElement("field");
  5. descriptor.getInheritancePolicy().setClassIndicatorField(new XMLField("@xsi:type"));
  6. descriptor.getInheritancePolicy().addClassIndicator(DatabaseField.class, getSecondaryNamespaceXPath() + "column");
  7. descriptor.getInheritancePolicy().addClassIndicator(XMLField.class, getPrimaryNamespaceXPath() + "node");
  8. descriptor.getInheritancePolicy().addClassIndicator(XMLUnionField.class, getPrimaryNamespaceXPath() + "union-node");
  9. XMLDirectMapping tableMapping = new XMLDirectMapping();
  10. tableMapping.setAttributeName("table");
  11. tableMapping.setGetMethodName("getTableName");
  12. tableMapping.setSetMethodName("setTableName");
  13. tableMapping.setXPath("@table");
  14. tableMapping.setNullValue("");
  15. descriptor.addMapping(tableMapping);
  16. XMLDirectMapping nameMapping = new XMLDirectMapping();
  17. nameMapping.setAttributeName("name");
  18. nameMapping.setGetMethodName("getName");
  19. nameMapping.setSetMethodName("setName");
  20. nameMapping.setXPath("@name");
  21. nameMapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
  22. descriptor.addMapping(nameMapping);
  23. return descriptor;
  24. }

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

  1. protected ClassDescriptor buildDatabaseFieldDescriptor() {
  2. XMLDescriptor descriptor = new XMLDescriptor();
  3. descriptor.setJavaClass(DatabaseField.class);
  4. descriptor.setDefaultRootElement("field");
  5. descriptor.getInheritancePolicy().setClassIndicatorField(new XMLField("@xsi:type"));
  6. descriptor.getInheritancePolicy().addClassIndicator(DatabaseField.class, getSecondaryNamespaceXPath() + "column");
  7. descriptor.getInheritancePolicy().addClassIndicator(XMLField.class, getPrimaryNamespaceXPath() + "node");
  8. descriptor.getInheritancePolicy().addClassIndicator(XMLUnionField.class, getPrimaryNamespaceXPath() + "union-node");
  9. XMLSchemaReference reference = new XMLSchemaClassPathReference();
  10. reference.setSchemaContext("/"+ getSecondaryNamespaceXPath() + "column");
  11. descriptor.setSchemaReference(reference);
  12. XMLDirectMapping tableMapping = new XMLDirectMapping();
  13. tableMapping.setAttributeName("table");
  14. tableMapping.setGetMethodName("getTableName");
  15. tableMapping.setSetMethodName("setTableName");
  16. tableMapping.setXPath("@table");
  17. tableMapping.setNullValue("");
  18. descriptor.addMapping(tableMapping);
  19. XMLDirectMapping nameMapping = new XMLDirectMapping();
  20. nameMapping.setAttributeName("name");
  21. nameMapping.setGetMethodName("getName");
  22. nameMapping.setSetMethodName("setName");
  23. nameMapping.setXPath("@name");
  24. nameMapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
  25. descriptor.addMapping(nameMapping);
  26. return descriptor;
  27. }

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

  1. protected ClassDescriptor buildDatabaseFieldDescriptor() {
  2. XMLDescriptor descriptor = new XMLDescriptor();
  3. descriptor.setJavaClass(DatabaseField.class);
  4. descriptor.setDefaultRootElement("field");
  5. descriptor.getInheritancePolicy().setClassIndicatorField(new XMLField("@xsi:type"));
  6. descriptor.getInheritancePolicy().addClassIndicator(DatabaseField.class, getSecondaryNamespaceXPath() + "column");
  7. descriptor.getInheritancePolicy().addClassIndicator(XMLField.class, getPrimaryNamespaceXPath() + "node");
  8. descriptor.getInheritancePolicy().addClassIndicator(XMLUnionField.class, getPrimaryNamespaceXPath() + "union-node");
  9. XMLSchemaReference reference = new XMLSchemaClassPathReference();
  10. reference.setSchemaContext("/"+ getSecondaryNamespaceXPath() + "column");
  11. descriptor.setSchemaReference(reference);
  12. XMLDirectMapping tableMapping = new XMLDirectMapping();
  13. tableMapping.setAttributeName("table");
  14. tableMapping.setGetMethodName("getTableName");
  15. tableMapping.setSetMethodName("setTableName");
  16. tableMapping.setXPath("@table");
  17. tableMapping.setNullValue("");
  18. descriptor.addMapping(tableMapping);
  19. XMLDirectMapping nameMapping = new XMLDirectMapping();
  20. nameMapping.setAttributeName("name");
  21. nameMapping.setGetMethodName("getName");
  22. nameMapping.setSetMethodName("setName");
  23. nameMapping.setXPath("@name");
  24. nameMapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
  25. descriptor.addMapping(nameMapping);
  26. return descriptor;
  27. }

相关文章