本文整理了Java中org.eclipse.persistence.oxm.mappings.XMLDirectMapping.getNullPolicy()
方法的一些代码示例,展示了XMLDirectMapping.getNullPolicy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLDirectMapping.getNullPolicy()
方法的具体详情如下:
包路径:org.eclipse.persistence.oxm.mappings.XMLDirectMapping
类名称:XMLDirectMapping
方法名:getNullPolicy
[英]INTERNAL: Get the AbstractNullPolicy from the Mapping.
The default policy is NullPolicy.
[中]内部:从映射中获取AbstractNullPolicy。
默认策略为NullPolicy。
代码示例来源:origin: stackoverflow.com
import org.eclipse.persistence.config.DescriptorCustomizer;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.mappings.DatabaseMapping;
import org.eclipse.persistence.oxm.mappings.XMLDirectMapping;
import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
public class AddressCustomizer implements DescriptorCustomizer {
@Override
public void customize(ClassDescriptor descriptor) throws Exception {
for(DatabaseMapping mapping : descriptor.getMappings()) {
if(mapping.isAbstractDirectMapping()) {
XMLDirectMapping xmlDirectMapping = (XMLDirectMapping) mapping;
xmlDirectMapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
xmlDirectMapping.getNullPolicy().setNullRepresentedByEmptyNode(true);
}
}
}
}
代码示例来源:origin: stackoverflow.com
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.mappings.DatabaseMapping;
import org.eclipse.persistence.oxm.mappings.XMLDirectMapping;
import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
import org.eclipse.persistence.sessions.*;
public class NullPolicySessionEventListener extends SessionEventAdapter {
@Override
public void preLogin(SessionEvent event) {
Project project = event.getSession().getProject();
for(ClassDescriptor descriptor : project.getOrderedDescriptors()) {
for(DatabaseMapping mapping : descriptor.getMappings()) {
if(mapping.isAbstractDirectMapping()) {
XMLDirectMapping xmlDirectMapping = (XMLDirectMapping) mapping;
xmlDirectMapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
xmlDirectMapping.getNullPolicy().setNullRepresentedByEmptyNode(true);
}
}
}
}
}
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
public boolean isWhitespaceAware() {
return !xmlDirectMapping.getNullPolicy().isNullRepresentedByEmptyNode();
}
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
public boolean isNullCapableValue() {
return xmlDirectMapping.getNullPolicy().getIsSetPerformedForAbsentNode();
}
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
public void setXPathNode(XPathNode xPathNode) {
super.setXPathNode(xPathNode);
xmlDirectMapping.getNullPolicy().xPathNode(xPathNode, this);
}
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core
public void writeSingleValue(Object value, Object parent, XMLRecord row, AbstractSession session) {
Object fieldValue = getFieldValue(value, session, row);
if(fieldValue == null && getNullPolicy() != null) {
getNullPolicy().directMarshal((Field) this.getField(), row, parent);
} else {
writeValueIntoRow(row, getField(), fieldValue);
}
}
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
public void writeSingleValue(Object value, Object parent, XMLRecord row, AbstractSession session) {
Object fieldValue = getFieldValue(value, session, row);
if(fieldValue == null && getNullPolicy() != null) {
getNullPolicy().directMarshal((Field) this.getField(), row, parent);
} else {
writeValueIntoRow(row, getField(), fieldValue);
}
}
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
/**
* INTERNAL:
* Return the mapping's attribute value from the row.
* The execution session is passed for the case of building a UnitOfWork clone
* directly from a row, the session set in the query will not know which platform to use
* for converting the value. Allows the correct session to be passed in.
*/
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery query, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) {
// PERF: Direct variable access.
boolean shouldCheckForXsiNil = getNullPolicy().isNullRepresentedByXsiNil();
return getAttributeValue(((DOMRecord)row).getIndicatingNoEntry(this.field, false, shouldCheckForXsiNil), executionSession, (XMLRecord)row);
}
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
/**
* INTERNAL:
* Return the mapping's attribute value from the row.
* The execution session is passed for the case of building a UnitOfWork clone
* directly from a row, the session set in the query will not know which platform to use
* for converting the value. Allows the correct session to be passed in.
*/
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery query, AbstractSession executionSession) {
// PERF: Direct variable access.
boolean shouldCheckForXsiNil = getNullPolicy().isNullRepresentedByXsiNil();
return getAttributeValue(((DOMRecord)row).getIndicatingNoEntry(this.field, false, shouldCheckForXsiNil), executionSession, (XMLRecord)row);
}
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core
/**
* INTERNAL:
* Return the mapping's attribute value from the row.
* The execution session is passed for the case of building a UnitOfWork clone
* directly from a row, the session set in the query will not know which platform to use
* for converting the value. Allows the correct session to be passed in.
*/
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery query, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) {
// PERF: Direct variable access.
boolean shouldCheckForXsiNil = getNullPolicy().isNullRepresentedByXsiNil();
return getAttributeValue(((DOMRecord)row).getIndicatingNoEntry(this.field, false, shouldCheckForXsiNil), executionSession, (XMLRecord)row);
}
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
containerAttributeMapping.setSetMethodName("setContainerAttributeName");
containerAttributeMapping.setXPath("container-attribute/text()");
((NullPolicy)containerAttributeMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
descriptor.addMapping(containerAttributeMapping);
containerGetMethodMapping.setSetMethodName("setContainerGetMethodName");
containerGetMethodMapping.setXPath("container-get-method/text()");
((NullPolicy)containerGetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
descriptor.addMapping(containerGetMethodMapping);
containerSetMethodMapping.setSetMethodName("setContainerSetMethodName");
containerSetMethodMapping.setXPath("container-set-method/text()");
((NullPolicy)containerSetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
descriptor.addMapping(containerSetMethodMapping);
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
containerAttributeMapping.setSetMethodName("setContainerAttributeName");
containerAttributeMapping.setXPath("container-attribute/text()");
((NullPolicy)containerAttributeMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
descriptor.addMapping(containerAttributeMapping);
containerGetMethodMapping.setSetMethodName("setContainerGetMethodName");
containerGetMethodMapping.setXPath("container-get-method/text()");
((NullPolicy)containerGetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
descriptor.addMapping(containerGetMethodMapping);
containerSetMethodMapping.setSetMethodName("setContainerSetMethodName");
containerSetMethodMapping.setXPath("container-set-method/text()");
((NullPolicy)containerSetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
descriptor.addMapping(containerSetMethodMapping);
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core
containerAttributeMapping.setSetMethodName("setContainerAttributeName");
containerAttributeMapping.setXPath("container-attribute/text()");
((NullPolicy)containerAttributeMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
descriptor.addMapping(containerAttributeMapping);
containerGetMethodMapping.setSetMethodName("setContainerGetMethodName");
containerGetMethodMapping.setXPath("container-get-method/text()");
((NullPolicy)containerGetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
descriptor.addMapping(containerGetMethodMapping);
containerSetMethodMapping.setSetMethodName("setContainerSetMethodName");
containerSetMethodMapping.setXPath("container-set-method/text()");
((NullPolicy)containerSetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
descriptor.addMapping(containerSetMethodMapping);
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.sdo
mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
mapping.getNullPolicy().setNullRepresentedByEmptyNode(true);
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
mapping.getNullPolicy().setNullRepresentedByEmptyNode(true);
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core
containerAttributeMapping.setSetMethodName("setContainerAttributeName");
containerAttributeMapping.setXPath("container-attribute/text()");
((NullPolicy)containerAttributeMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
descriptor.addMapping(containerAttributeMapping);
containerGetMethodMapping.setSetMethodName("setContainerGetMethodName");
containerGetMethodMapping.setXPath("container-get-method/text()");
((NullPolicy)containerGetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
descriptor.addMapping(containerGetMethodMapping);
containerSetMethodMapping.setSetMethodName("setContainerSetMethodName");
containerSetMethodMapping.setXPath("container-set-method/text()");
((NullPolicy)containerSetMethodMapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
descriptor.addMapping(containerSetMethodMapping);
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object objectValue, AbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) {
Object fieldValue = xmlDirectMapping.getFieldValue(objectValue, session, marshalRecord);
// Check for a null value
if (null == fieldValue) {
// Perform marshal operations based on the null policy
return xmlDirectMapping.getNullPolicy().directMarshal(xPathFragment, marshalRecord, object, session, namespaceResolver);
} else {
QName schemaType = getSchemaType((XMLField) xmlDirectMapping.getField(), fieldValue, session);
String stringValue = getValueToWrite(schemaType, fieldValue, (XMLConversionManager) session.getDatasourcePlatform().getConversionManager(), namespaceResolver);
XPathFragment groupingFragment = marshalRecord.openStartGroupingElements(namespaceResolver);
if (xPathFragment.isAttribute()) {
marshalRecord.attribute(xPathFragment, namespaceResolver, stringValue);
marshalRecord.closeStartGroupingElements(groupingFragment);
} else {
marshalRecord.closeStartGroupingElements(groupingFragment);
if (xmlDirectMapping.isCDATA()) {
marshalRecord.cdata(stringValue);
} else {
marshalRecord.characters(stringValue);
}
}
return true;
}
}
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
protected ClassDescriptor buildDatabaseFieldDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(DatabaseField.class);
descriptor.setDefaultRootElement("field");
descriptor.getInheritancePolicy().setClassIndicatorField(new XMLField("@xsi:type"));
descriptor.getInheritancePolicy().addClassIndicator(DatabaseField.class, getSecondaryNamespaceXPath() + "column");
descriptor.getInheritancePolicy().addClassIndicator(XMLField.class, getPrimaryNamespaceXPath() + "node");
descriptor.getInheritancePolicy().addClassIndicator(XMLUnionField.class, getPrimaryNamespaceXPath() + "union-node");
XMLDirectMapping tableMapping = new XMLDirectMapping();
tableMapping.setAttributeName("table");
tableMapping.setGetMethodName("getTableName");
tableMapping.setSetMethodName("setTableName");
tableMapping.setXPath("@table");
tableMapping.setNullValue("");
descriptor.addMapping(tableMapping);
XMLDirectMapping nameMapping = new XMLDirectMapping();
nameMapping.setAttributeName("name");
nameMapping.setGetMethodName("getName");
nameMapping.setSetMethodName("setName");
nameMapping.setXPath("@name");
nameMapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
descriptor.addMapping(nameMapping);
return descriptor;
}
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core
protected ClassDescriptor buildDatabaseFieldDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(DatabaseField.class);
descriptor.setDefaultRootElement("field");
descriptor.getInheritancePolicy().setClassIndicatorField(new XMLField("@xsi:type"));
descriptor.getInheritancePolicy().addClassIndicator(DatabaseField.class, getSecondaryNamespaceXPath() + "column");
descriptor.getInheritancePolicy().addClassIndicator(XMLField.class, getPrimaryNamespaceXPath() + "node");
descriptor.getInheritancePolicy().addClassIndicator(XMLUnionField.class, getPrimaryNamespaceXPath() + "union-node");
XMLSchemaReference reference = new XMLSchemaClassPathReference();
reference.setSchemaContext("/"+ getSecondaryNamespaceXPath() + "column");
descriptor.setSchemaReference(reference);
XMLDirectMapping tableMapping = new XMLDirectMapping();
tableMapping.setAttributeName("table");
tableMapping.setGetMethodName("getTableName");
tableMapping.setSetMethodName("setTableName");
tableMapping.setXPath("@table");
tableMapping.setNullValue("");
descriptor.addMapping(tableMapping);
XMLDirectMapping nameMapping = new XMLDirectMapping();
nameMapping.setAttributeName("name");
nameMapping.setGetMethodName("getName");
nameMapping.setSetMethodName("setName");
nameMapping.setXPath("@name");
nameMapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
descriptor.addMapping(nameMapping);
return descriptor;
}
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
protected ClassDescriptor buildDatabaseFieldDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(DatabaseField.class);
descriptor.setDefaultRootElement("field");
descriptor.getInheritancePolicy().setClassIndicatorField(new XMLField("@xsi:type"));
descriptor.getInheritancePolicy().addClassIndicator(DatabaseField.class, getSecondaryNamespaceXPath() + "column");
descriptor.getInheritancePolicy().addClassIndicator(XMLField.class, getPrimaryNamespaceXPath() + "node");
descriptor.getInheritancePolicy().addClassIndicator(XMLUnionField.class, getPrimaryNamespaceXPath() + "union-node");
XMLSchemaReference reference = new XMLSchemaClassPathReference();
reference.setSchemaContext("/"+ getSecondaryNamespaceXPath() + "column");
descriptor.setSchemaReference(reference);
XMLDirectMapping tableMapping = new XMLDirectMapping();
tableMapping.setAttributeName("table");
tableMapping.setGetMethodName("getTableName");
tableMapping.setSetMethodName("setTableName");
tableMapping.setXPath("@table");
tableMapping.setNullValue("");
descriptor.addMapping(tableMapping);
XMLDirectMapping nameMapping = new XMLDirectMapping();
nameMapping.setAttributeName("name");
nameMapping.setGetMethodName("getName");
nameMapping.setSetMethodName("setName");
nameMapping.setXPath("@name");
nameMapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
descriptor.addMapping(nameMapping);
return descriptor;
}
内容来源于网络,如有侵权,请联系作者删除!