In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use DataObject of Java". In daily operation, I believe many people have doubts about how to use DataObject of Java. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use DataObject of Java". Next, please follow the editor to study!
Data object
Data objects are used to describe business data, and data objects use attributes to store data.
The data object interface is designed to make programming easier because it provides access to all common types of business data and support for various access modes, such as name, index, and path-based access.
The data object interface contains the following methods:
Get and set the properties of the data object
Query whether a property is a collection
Create a new instance of the included child data object
Delete a data object from its container
Dispatch a data object from its container
Get the container of the data object and the properties it contains
Get the root data object
Get the data graph to which the data object belongs
Get the type of the data object
Get the order of the data objects (if any)
Get the additional properties of the data object (if any)
For many applications that do not use generated code, the data pair generation interface is the only SDO part used to write applications. For applications that use generated code, the generated interface will be used directly. Other parts of SDO are mainly used according to the needs of users.
Data object concept
Data objects can be divided into the following categories. During the classification process, open or sequenced concepts can be used alone or together.
Basic . A data object is similar to a JavaBean in which each property has an assigned range. All allowed property collections are available through the getType (). GetProperties () method. You can access the value of a property through the get (property) method. The order within attributes can be maintained, but the order that spans multiple attributes is not maintainable.
Open . A data object is similar to a JavaBean that allows extra properties. In XML, this is equivalent to open (wildcard) content. It is similar to a JavaBean that has an extra mapping with the new attribute. The extra property is not part of the property returned by the getType (). GetProperties () method. By using the getInstanceProperties () method, you can get the properties actually owned by a particular data object. Property values can be accessed using the get (property) method. The order within attributes can be maintained, but the order that spans multiple attributes is not maintainable.
Sequenced . Data objects are similar to a JavaBean that maintains the order within and between attributes at the same time. In XML, this is equivalent to a DOM. When using XML, Sequence represents the order of all XML elements within the data object. Property values can be obtained using the get (property) method, but maintaining an order that spans multiple attributes requires sequential interface. The getSequence () method returns the Sequence of all XML elements of the XML instance. The XML property has no concept of order and can be accessed through the get (property) method.
Values and properties of the data object
A data object has the data value assigned to its property. For example, the orderDate property of a purchase order data object has a value of: 2005-6-30. You can get or modify the value of the orderDate property of a data object by using the get ("orderDate") and set ("orderDate") methods of the data object. When using the generated code, you can also access the value of the property by using the getOrderDate () and setOrderDate () methods on the PurchaseOder interface.
On the data object interface, the attribute value can be accessed by using the get (String path) method based on the name of the attribute, or by using the index of the attribute or directly using the attribute object. The get (String path) method of the data object can use either an alias or a property name in the path. In this case, the path may be just the name of an attribute, or it may be a path representation based on a subset of XPath.
Type conversion
Sometimes the type of property is different from the type used in the application. For example, when a number of integers is displayed in the user interface, string types may be more efficient than integer expressions. The getString ("quantity") method, which has convenient access to the integer quantity property, will return a value of type string. In many applications, this simplifies a common task.
When calling the type accessor (accessor) get and set of a data object, type conversion must be performed if the value is not an instance of the type T required by the request. Type conversion is done automatically by the implementation of the data object. The SDO implementation is expected to implement the conversion between any data type and the type defined within the data object with as little information as possible during the conversion process. The supported data types are defined in the SDO DataTypes fragment. These types include:
Java basic types
Object wrapper for Java basic types
String
Date and time type
URI
Byte []
BigDecimal
BigInteger
Java and DataHelper describe type conversions. The supported type conversions are described in "DataType Conversions" on page 145 of this specification.
Multi-valued (Many-Valued) data object properties
Property may have one or more values. If a property is multivalued, the property.many returns true,get (property) method returns a list (List).
On a data interface or automatically generated code, a data object method that returns a value of List returns an empty list instead of a null when the property has no value. The returned list can describe any change in the value of the data object.
The getList (property) accessor is extremely convenient for accessing multi-valued properties. If property.many is true, then the set (property, value) and setList (property, value) methods need "value" to be java.util.Collection and List objects, respectively. These methods have the same effect as using the getList (property) .addAll (value) method immediately after using getList (property) .addAll ().
For multi-valued attributes, the get () and getList () methods return a list List containing the current values. The current value of the data object can be updated immediately through the List interface. Each time you access it using the get () or getList () method, the same List object is returned.
Determine whether an attribute is a collection
For a multi-valued attribute, the isSet (property) method returns:
True, if List is not empty
False, if List is empty
For a single-valued attribute, the isSet (property) method returns:
False, if Property has not been set () or has been unset ()
True, if the current value is not the default value of Property
For some instances, the implementation determines the value of isSet (property) based on the following policy:
After calling set () instead of calling unset (), isSet () returns True. After set (property, property.getDefault ()), isSet (property) returns True
When the current value is not equal to the default, isSet () returns true;. After set (property, property.getDefault ()), isSet (property) returns false.
The unset (property) accessor can be used to clear a simple property, so after unset (property), isSet (property) returns false,get (property), which returns the default. The delete () method cancels the value of all properties of the data object unless the property is read-only. After unset (), get (property) returns the default value, or an empty list for multi-valued attributes.
Note: attempting to modify a read-only property using set,unset or delete will throw an exception.
Include content (Containment)
The data objects in the data graph are organized into a tree structure. There is one data object as the root node of the tree, while other data objects make up the other leaf nodes of the tree.
You can create a tree structure by using an inclusive content reference (containment references) that starts with the root data object. The root data object refers to other data objects, and these data objects can further refer to deeper data objects. In addition to the root data object, each data object in the data graph must have a containing content reference from other nodes in the tree. Each data object in the diagram can track the location of its containing content reference.
For a data graph, it is possible to have a non-inclusive content reference (containment references). The data objects that these references point to are part of the same data graph (the referenced data objects must be part of the same tree), but these references have no effect on the tree structure of the data graph.
Both included and non-contained content are properties of the data object. The type of this property can be any data object type.
Whether a particular data object reference property is a content reference or a non-content reference is defined by the data model of the data graph, such as a XSD that defines an XML document data type. Once the data model is defined, it cannot be modified. You can query whether a particular reference is a containing reference by accessing property.containment.
Container data objects contain other data objects. The maximum number of data objects that can have a container data object. If a data object does not have a container, it is a root data object.
The getContainer () and getContainmentProperty () methods provide a simple top-down way to browse the contents of the data object. The getContainer () method returns a parent data object, and the getContainmentProperty () method returns the container property that contains the object. Using the detach () method, you can remove a data object from its container without making any changes.
Contains content that can be managed. When a data object is set or added as a value that contains content properties, it is removed from any of the previous content properties. There can be no loops in the contents. If setting or adding will generate a loop, an exception will be thrown.
Create and delete data objects
The creation method can create a data object of the type to which the property belongs, or a data object of the type described in the parameter, and can add a created data object to the specified property. If the type of the data object is a sequential type (the getType (). IsSequenced () method returns true), the newly created data object is added at the end of the order. If the property is single-valued, the value of the property is set to the newly created object. If the property is multi-valued, the newly created object is added as the last object. Only containing content properties can be used to create objects. All properties of a newly created object are canceled (no values assigned or only default values).
The delete () method cancels all non-read-only properties of the data object. If the containing content property is not read-only, the delete () method also removes the data object from the data object that contains it. Recursive sub-data objects that contain content properties are also deleted.
If other data objects have a single-step or non-containing property that points to the deleted data object, these references will not be modified. However, in order to meet the closed characteristics of the data graph, the values of the above attributes need to be changed. A deleted data object can be used again and can be added to the data graph again.
Sequential data object
Data objects may be sequential or non-sequential. The getType (). IsSequenced () method tells you whether the type of the data object is sequential.
If the type of the data object is sequential, the getSequence () method will return a Sequence, otherwise the getSequence () method will return null.
The order of the data objects is the same as the XML elements that express their attribute values. If you update a data object, the list or order returned from that data object performs the same data operation.
The order returned can effectively describe any change in the value of the data object.
Data object properties of open content
Data objects have two types of properties:
Attributes described by type (Type)
Properties that are not specified by a type (Type) are called open content (open content).
Properties related to the data object type can be obtained through the getType (). GetProperties () method, which returns a list.
In addition to having properties described by types, data objects can have other properties:
Deal with open or mixed XML content.
Encounter new attributes dynamically.
When Type.open is true, open content attributes are allowed. Some types set open to false because they cannot accept additional properties.
A property is derived from open content if it appears in the return value of the getInstanceProperties () method rather than in the return value of the getType () .getProperties () method. If a property comes from open content, then the isSet (property) method must return true.
If the equals () method is true, the properties specified by DataType Types can return different objects. For variable data values (for example, date types or string lists), modifications to these values are directly determined by the implementation.
When you use the getInstanceProperties () method, it returns a read-only list of all the properties currently used by a data object. This includes the properties of open content. The order of attributes begins with the return values of all getType (). GetProperties () methods; the order of other properties is determined by the implementation. Each call to the getInstanceProperties () method returns the same list object unless the data object has been updated, causing the contents of the list to change.
In an instance property, you can effectively find the corresponding property on the data object by calling the getProperty () method and based on the property name.
In order to set an open content value that has not been set (which does not appear in the return value of the getInstanceProperties () method), the setting of a data object or the creation of an accessor, or the addition to a list or order, the parameter of a property will be used, which can be found by visiting TypeHelper or XSDHelper. An example of creating an open content can be found on page 135 "Creating open content XML documents".
For all open content properties obtained through the getInstanceProperties () method, its isSet (property) method returns true.
Attribute index
When a data object has multiple attributes, each attribute can be referenced by a numeric index, where the numeric index of the first attribute starts at 0.
The property index used in the get (int property) method is the position of the property in the list returned by the getInstanceProperties () method.
It is not recommended to use an index parameter accessor on open content if the data is being modified; unless the index is used in the properties obtained by the getInstanceProperties () method, because in the getInstanceProperties () method, the property index of open content can be changed if the values of several open content properties can be set and unset repeatedly.
The following example is correct because the index is used with the getInstanceProperties () method. Note that because the data object is not synchronized, the user should not update it while reading. This example shows a normal pattern that loops through all instance properties and prints property names and values:
For (int item0; I
{
Property p = (Property) myDo.getInstanceProperties () .get (I)
System.out.println (p.getName () + "=" + myDo.getString (I))
}
The names and aliases of the properties obtained by the getInstanceProperties () method have a higher priority than those with a higher index, so open content properties can hide their real names by using the names defined in the type properties, because these attributes are at the beginning of the list. The order of priority is the order of the values returned by the getInstanceProperties () method.
In an event that copies a name, the open content property can be accessed through its alias, as long as the alias does not conflict with the names and aliases of other attributes that already exist.
Current state of the data object (current state)
The current state of the data object contains all the values used to distinguish it from the new object created by DataFactory, because the newly created object by DataFactory does not yet have a property collection and container. The current state of the data object is that all isSet () properties in the value returned by the getInstanceProperties () method are true. The container and containing content properties are part of the state of the data object that contains the data object. The following program prints out the current state of the data object myDO:
For (int item0; I
{
Property p = (Property) myDo.getInstanceProperties () .get (I)
If (myDo.isSet (p))
{
System.out.println (p.getName () + "=" + myDo.getString (I))
}
}
Data object interface
Public interface DataObject extends Serializable
{
Object get (String path)
Void set (String path, Object value)
Boolean isSet (String path)
Void unset (String path)
At this point, the study on "how to use the DataObject of Java" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.