CN107766039B - Method, server and storage medium for accessing attribute value from Java object - Google Patents

Method, server and storage medium for accessing attribute value from Java object Download PDF

Info

Publication number
CN107766039B
CN107766039B CN201711037346.9A CN201711037346A CN107766039B CN 107766039 B CN107766039 B CN 107766039B CN 201711037346 A CN201711037346 A CN 201711037346A CN 107766039 B CN107766039 B CN 107766039B
Authority
CN
China
Prior art keywords
attribute
data transmission
transmission object
attribute value
value
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201711037346.9A
Other languages
Chinese (zh)
Other versions
CN107766039A (en
Inventor
张小松
毛才斐
李小培
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Property and Casualty Insurance Company of China Ltd
Original Assignee
Ping An Property and Casualty Insurance Company of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Property and Casualty Insurance Company of China Ltd filed Critical Ping An Property and Casualty Insurance Company of China Ltd
Priority to CN201711037346.9A priority Critical patent/CN107766039B/en
Publication of CN107766039A publication Critical patent/CN107766039A/en
Application granted granted Critical
Publication of CN107766039B publication Critical patent/CN107766039B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Stored Programmes (AREA)
  • Devices For Executing Special Programs (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method for accessing attribute values from Java objects, a server and a storage medium, wherein the method for accessing the attribute values from the Java objects configures attribute corresponding relations of all fields in a first data transmission object and a second data transmission object in a configuration file; for each pair of attribute corresponding relations, acquiring an attribute value of the first data transmission object through a reflection toolkit; calling a value taking method of the open source tool to obtain a reference attribute value, comparing the reference attribute value with an attribute value of the first data transmission object and outputting a comparison result; and when the comparison result is the same, converting the attribute value of the first data transmission object into the data type of the second data transmission object, and setting the attribute value into the attribute of the second data transmission object. The invention improves the efficiency of storing/fetching the attribute value from the data transmission object and avoids the performance bottleneck under high concurrency.

Description

Method, server and storage medium for accessing attribute value from Java object
Technical Field
The invention relates to the technical field of application programs, in particular to a method, a server and a storage medium for accessing attribute values from Java objects.
Background
In Java (an object oriented programming language) programs, it is often necessary to use expressions to store/retrieve attribute values from a DTO (data transfer object). For example, there is a usertdo, which has a name attribute field (other fields are omitted), and each field has a corresponding get/set method for storing/taking values (this is the prior art).
Scene 1: configuring a verification rule 'UserDTO.name = length: 20' in a configuration file, identifying an expression 'UserDTO.name' before verification, and acquiring a name attribute value from a UserDTO object. If the object has a multi-level structure, the expression also has multiple levels, such as "UserDTO.
Scene 2: the DTOs of different systems are different, but data interaction is required, DTO conversion is required, a corresponding relation 'UserDTO.name = UserInfoDTO.UserName' can be configured through a configuration file, and the value of the UserDTO.name is required to be acquired and then stored in the UserInfoDTO.UserName during DTO conversion.
Using expressions to store/retrieve attribute values from DTO, there are two common schemes in the industry:
first, open source tool ognl (objectgraphics navigation language): the early-stage use is wide, and the fault tolerance is good. But due to the use of a synchronized lock and java ordinary reflection method invoke in the open source tool OGNL to invoke the get and set methods of the field, poor performance at high concurrency results.
Second, the open source tool Mvel (a powerful expression language based on Java application): performance is better than that of the open source tool OGNL, but because the bottom layer still uses java ordinary reflection method to invoke the get/set method of the field, it is about 10 times less efficient than directly invoking get/set.
Accordingly, the prior art is yet to be improved and developed.
Disclosure of Invention
In view of the above-mentioned shortcomings in the prior art, the present invention aims to provide a method, a server and a storage medium for accessing attribute values from Java objects, which improves the efficiency of accessing attribute values from data transmission objects and avoids performance bottlenecks under high concurrency; through actual measurement, the performance of the system is 200 times faster than that of an open source tool OGNL and more than 2 times faster than that of an open source tool Mvel; meanwhile, the consumption of a server CPU (Central Processing Unit) is obviously reduced.
In order to achieve the purpose, the invention adopts the following technical scheme:
a method of accessing attribute values from a Java object, comprising the steps of:
configuring attribute corresponding relations of all fields in the first data transmission object and the second data transmission object in a configuration file;
for each pair of attribute corresponding relations, acquiring an attribute value of the first data transmission object through a reflection toolkit;
calling a value taking method of the open source tool to obtain a reference attribute value, comparing the reference attribute value with an attribute value of the first data transmission object and outputting a comparison result;
and when the comparison result is the same, converting the attribute value of the first data transmission object into the data type of the second data transmission object, and setting the attribute value into the attribute of the second data transmission object.
In the method for accessing attribute values from a Java object, the step of obtaining the attribute value of the first data transmission object through the reflection toolkit for each pair of attribute correspondences includes:
initializing a method accessor object of a class corresponding to the first data transmission object by using a reflection toolkit;
dividing all expressions of a first data transmission object by using separators to obtain a first attribute item of the expression;
obtaining the name of the method for taking out the attribute item through splicing, numbering the method for taking out and obtaining the attribute value of the corresponding item;
judging whether attribute items exist in the expression of the second data transmission object: if yes, obtaining the next attribute item of the expression and returning to the previous step; and if not, ending the value taking.
In the method for accessing an attribute value from a Java object, the step of calling a value-taking method of an open source tool to obtain a reference attribute value, comparing the reference attribute value with an attribute value of a first data transmission object, and outputting a comparison result includes:
comparing whether the corresponding data are the same according to the types of the attribute value and the reference attribute value of the first data transmission object, and adding different field names and corresponding values thereof into a returned result hash table;
and if the hash table of the returned result is not empty, outputting the hash table of the returned result to the error log.
In the method for accessing an attribute value from a Java object, the step of comparing whether corresponding data are identical according to the type of the attribute value of the first data transmission object and the reference attribute value includes:
if the attribute value and the reference attribute value of the first data transmission object are of the data type, comparing whether the data of the attribute value and the reference attribute value of the first data transmission object are equal;
if the attribute value and the reference attribute value of the first data transmission object are of the list type, traversing each element in the two lists, and respectively comparing values at the same position in the lists;
and if the attribute value and the reference attribute value of the first data transmission object are of the hash table type, traversing each element in the two hash tables, and comparing the attribute values corresponding to the same field code.
In the method for accessing attribute values from a Java object, when the comparison result is the same, the step of converting the attribute value of the first data transmission object into the data type of the second data transmission object and setting the attribute value into the attribute of the second data transmission object includes:
when the comparison result is the same, acquiring the domain and the data type corresponding to the corresponding field from the class corresponding to the second data transmission object; converting the data type of the attribute value into the data type of the field;
initializing a method accessor object of a class corresponding to the second data transmission object using a reflection toolkit;
dividing the expression of the second data transmission object by using the separators to obtain the attribute items of the expression;
obtaining the name of a setting method of the changed field through splicing, numbering the setting method and setting a field value;
judging whether attribute items exist in the expression of the second data transmission object: if so, acquiring the next attribute item of the expression according to the previous segmentation and returning to the previous step; and setting the attribute value into the corresponding attribute item until the attribute item between the last two separators is obtained and the previous step is returned.
In the method for accessing attribute values from a Java object, after the step of converting the attribute values of the first data transmission object into the data type of the second data transmission object and setting the attribute values into the attributes of the second data transmission object when the comparison result is the same, the method further comprises:
and calling a setting value method of the open source tool to obtain a setting value attribute value, comparing the setting value attribute value with the attribute value of the second data transmission object, and outputting a comparison result.
In the method for accessing attribute values from Java objects, before the step of initializing using reflection toolkit, the method further comprises:
initializing a class method accessor object, initializing the attribute corresponding relation between a fetching method and a number, and between a setting method and the number, and storing the initialized fetching method accessor object and the number in a cache.
In the method for accessing attribute values from a Java object, before the step of obtaining a domain corresponding to a corresponding field from a class corresponding to a second data transmission object, the method further includes:
all domain lists in the class are initialized and put into the cache for storage.
An application server for accessing attribute values from Java objects, comprising: the system comprises a processor, a memory and a communication bus, wherein the memory is stored with a computer readable program which can be executed by the processor;
the communication bus realizes connection communication between the processor and the memory;
the processor, when executing the computer readable program, performs the steps in a method for accessing property values from a Java object as described in any of the above.
A computer readable storage medium, storing one or more programs, which are executable by one or more processors, to perform the steps in a method of accessing property values from Java objects as described in any above.
Compared with the prior art, in the method for accessing the attribute values from the Java object, the server and the storage medium, the method for accessing the attribute values from the Java object configures the attribute corresponding relation of all fields in the first data transmission object and the second data transmission object in the configuration file; for each pair of attribute corresponding relations, acquiring an attribute value of the first data transmission object through a reflection toolkit; calling a value taking method of the open source tool to obtain a reference attribute value, comparing the reference attribute value with an attribute value of the first data transmission object and outputting a comparison result; and when the comparison result is the same, converting the attribute value of the first data transmission object into the data type of the second data transmission object, and setting the attribute value into the attribute of the second data transmission object. The efficiency of storing/fetching the attribute value from the data transmission object is improved, and the performance bottleneck under high concurrency is avoided.
Drawings
FIG. 1 is a flow chart of a method for accessing attribute values from Java objects according to the present invention;
FIG. 2 is a flowchart illustrating step S20 of the method for accessing attribute values from Java objects according to the present invention;
FIG. 3 is a flowchart illustrating step S30 of the method for accessing attribute values from Java objects according to the present invention;
FIG. 4 is a flowchart illustrating step S40 of the method for accessing attribute values from Java objects according to the present invention;
FIG. 5 is a diagram illustrating an operating environment of an application server for accessing attribute values from Java objects according to an embodiment of the present invention;
FIG. 6 is a functional block diagram of the preferred embodiment of the present invention for installing an application server that accesses attribute values from Java objects.
Detailed Description
In view of the disadvantage that the efficiency of storing/retrieving attribute values from a DTO (data transfer object) by using the existing expression is low, the present invention aims to provide a method, a server and a storage medium for accessing attribute values from a Java object, wherein the attribute correspondence relationship of all fields of two DTOs is configured in a configuration file, for each pair of fields, the attribute value of one DTO is first obtained, then converted into the data type of the other DTO, and then set into the attribute of the other DTO, so that the efficiency of storing/retrieving attribute values from the DTO is improved, and the performance bottleneck under high concurrency is avoided.
In order to make the objects, technical solutions and effects of the present invention clearer and clearer, the present invention is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
An efficient reflection toolkit ReflectSM under Java is an open source tool or a Java class library, provides high-performance reflection processing through code generation, and automatically provides an access class for a get/set field; the principle is as follows: assuming a data model UserDTO, the program newly generates a Class UserDTOMethodAcess which is isomorphic with UserDTO. The Class can realize the calling of the total entry invoke method of all get/set methods of UserDTO, and numbers all get/set methods. When calling, firstly finding the number of the required method, then finding the actual get/set method through the number, and then calling. Thus, the attribute value can be quickly stored/fetched as if it were directly get/set once the number of the method is unambiguous. Specific contents of reflactasm high performance reflection can be referred to as:
http://blog.csdn.net/z69183787/article/details/51657771。
however, the reflection toolkit refleptsm is slow to initialize and does not support the expression "userdto. The call can only be made if the get/set method name is unambiguous, and there is currently no open source tool in the industry that implements "deposit/retrieve attribute values from DTO using expressions" based on the reflection toolkit refleptsm. The embodiment uses the high-performance reflection characteristic of the reflection toolkit reflactasm to create a high-performance conversion tool to implement the method for accessing the attribute values from the Java objects.
Please refer to fig. 1, which is a flowchart illustrating a method for accessing attribute values from Java objects according to the present invention. As shown in fig. 1, the method for accessing attribute values from Java objects includes the following steps:
s10, configuring the attribute corresponding relation of all fields in the first data transmission object and the second data transmission object in the configuration file.
In this embodiment, taking the first data transmission object as dto (a) and the second data transmission object as dto (B) as an example, the corresponding relationship of the attributes of all the fields of dto (a) and dto (B) is configured in the configuration file (configured according to the actual service scenario, which is not limited herein), for example, attribute "dto (a),. attributeA = dto (B),. attributeB", that is, the attribute of a in dto (a) corresponds to the attribute of B in dto (B).
And S20, acquiring the attribute value of the first data transmission object through the reflection toolkit for each pair of attribute corresponding relations.
The embodiment provides a high-performance method for acquiring attribute values from data transmission objects by using expressions, which is realized based on a reflection toolkit reflactasm. Take the value of usertdo. Please refer to fig. 2, which is a flowchart illustrating step S20 of the method for accessing attribute values from a Java object according to the present invention.
As shown in fig. 2, the step S20 is mainly to use an expression to take an attribute value from a data transmission object, that is, to obtain a value (a) of dto (a).
S21, initializing the method accessor object of the class corresponding to the first data transmission object by using the reflection toolkit.
In this embodiment, a reflection toolkit reflactasm is used to initialize a method accessor object (dto (a)) of a Class (Class used in this embodiment) corresponding to dto (a), that is, dto (a) method accessor, and preferentially check a cache.
S22, dividing all expressions of the first data transmission object by using separators, and obtaining the first attribute item of the expression.
Where the separator is ". and the expression may be single-layered or multi-layered, such as usertdo. The first attribute item is taken out for processing, and then one attribute item is taken out for processing in sequence. The items represent the contents of the fields such as name, date, amount, etc. (all in english). Taking the item as the name as an example, the expression user dto.name is segmented using a separator to obtain a first attribute name.
And S23, obtaining the name of the extraction method of the attribute item through splicing, numbering the extraction method and obtaining the attribute value of the corresponding item.
The name of the method of fetching the attribute name (i.e. the name of the get method, such as the getName) is obtained by splicing. Get the number index1 of the fetch method through UserDTOMethodAccess. And obtaining the attribute value name1 of the name through UserDTOMethodAccess (UserDTO, index 1).
S24, judging whether the expression of the second data transmission object has attribute items: if yes, acquiring the next attribute item of the expression and returning to the step S23; and if not, ending the value taking.
If the expression is a multilayer structure, such as user dto.name.xx.xx, the attribute name behind the next separator is obtained according to the previous segmentation, the steps S23 to S24 are repeated to obtain the value corresponding to the attribute name, and the step S25 is continued until no next attribute name exists.
And S30, calling a value taking method of the open source tool to obtain a reference attribute value, comparing the reference attribute value with the attribute value of the first data transmission object, and outputting a comparison result. After the operation is finished, the high-performance method for taking the attribute value from the data transmission object by using the expression obtains the attribute value name1 of the name item of the first data transmission object, and the attribute values of all the items are collectively called value (a). In the embodiment, the reference attribute value name2 is obtained by calling the existing value taking method of the open source tool OGNL, and the difference between the name1 and the name2 is compared to ensure the correctness of the operation result of the high-performance conversion tool. Please refer to fig. 3, which is a flowchart illustrating step S30 of the method for accessing attribute values from Java objects according to the present invention.
As shown in fig. 3, the step S30 includes:
and S31, comparing whether the corresponding data are the same according to the types of the attribute values and the reference attribute values of the first data transmission object, and adding different field names and corresponding values to a returned result hash table.
If the names 1 and the names 2 are of the basic data type (e.g., string, integer, floating point, date, etc.), then the data of the attribute value name1 and the reference attribute value name2 of the first data transfer object are compared for equality. If name1 and name2 are types of lists (here, a List, a class in a Java class library, which may be considered a two-way concatenated serial, object collection managed in a linear column), then traversing each element in both lists, and comparing the values at the same position in the lists separately. If names 1 and names 2 are of the type hash table (HashMap, a subset of Map, also called hash table, with key-value pair mapping as storage structure), then each element in the two hash tables is traversed and names corresponding to the same key (field code) are compared. If the name1 and the name2 are DTO types, the data transmission object is converted into a hash table by an open source tool, and then the data transmission object is compared by adopting the comparison mode of the hash table types.
In the comparison process, if a certain field is inconsistent, the field name and the values of both fields (the value obtained by the high-performance conversion tool and the value obtained by the open source tool OGNL provided in this embodiment) are added to the hash table of the returned result. And comparing the child elements in the List type, the HashMap type and the DTO type in sequence according to the steps in a recursive mode.
And S32, if the hash table of the returned result is not empty, outputting the hash table of the returned result to the error log. Monitoring such error logs can discover problems in a timely manner. If the returned result hash table is empty, it indicates that the value obtained by the high-performance conversion tool provided in this embodiment is equal to the value obtained by the open source tool OGNL, and the obtained attribute value of the first data transfer object is correct.
In particular implementations, a switch can be provided to control whether a comparison with the results of the open source tool OGNL is required. The switch can be turned on at the initial stage of on-line and can be turned off after stabilization so as to avoid influencing the system performance.
And S40, when the comparison result is the same, converting the attribute value of the first data transmission object into the data type of the second data transmission object, and setting the attribute value into the attribute of the second data transmission object. Please refer to fig. 4, which is a flowchart illustrating step S40 of the method for accessing attribute values from Java objects according to the present invention.
As shown in fig. 4, the step S40 is mainly to set the attribute value of the first data transmission object to the attribute of the second data transmission object by using an expression to set the attribute value of the data transmission object, for example, setting the attribute value name1 to userinfodto.
S41, when the comparison result is the same, obtaining the domain and the data type corresponding to the corresponding field from the class corresponding to the second data transmission object; the data type of the attribute value is converted into the data type of the field.
And when the comparison result is the same, acquiring a Field (a Field for representing the encapsulation of the Field attribute and preferentially checking the cache) corresponding to the Field userName from the Class corresponding to the UserInfoDTO, and acquiring the data type of the Field through the Field. The data type for attribute value name1 is converted to the data type for field userName.
Furthermore, in this step, it is slow to obtain the Field "corresponding to the Field userName from the Class. All Field lists in a Class may be initialized in advance and placed in the cache at once. When the Field needs to be fetched, the Field is directly fetched from the buffer, so that the influence of the step on the performance speed can be avoided.
The Field list cache initialization method of Class comprises the following steps: firstly, acquiring all Field lists of a Class corresponding to the DTO through getDecleardfields, and then storing Field. If the Class has a parent Class, polling the parent Class; a Field list for a Class is stored using one HashMap and hashmaps for different classes are wrapped with another large HashMap.
And S42, initializing the method accessor object of the class corresponding to the second data transmission object by using the reflection tool kit.
Namely, initializing the method (UserInfoDTOMethodAccess) of Class corresponding to the UserInfoDTO, and preferentially checking the cache.
S43, dividing the expression of the second data transmission object by using the separator to obtain the attribute item of the expression;
use name to carry on the segmentation to expression UserInfoDTO. userName, get the first attribute name.
And S44, obtaining the name of the setting method of the changed field through splicing, numbering the setting method and setting the field value.
In this embodiment, the set method name (i.e., the set method name, such as setUserName) of the field userName is obtained by splicing. The number index2 (look ahead cache) of this setup method is obtained by userinfodtome. Invoke (UserInfoDTO, index2, name1) sets a field value.
S45, judging whether the expression of the second data transmission object has attribute items: if so, acquiring the next attribute item of the expression according to the previous segmentation and returning to the previous step; and setting the attribute value into the corresponding attribute item until the attribute item between the last two separators is obtained and the previous step is returned.
If the expression has a multilayer structure, such as UserInfoDTO.userName.x.xx, the method for taking the attribute value is used in a recursive mode until the object value DTO (x) of the attribute x between the last two separators is obtained, and then name1 is set to the attribute xx of the DTO (x) according to the steps S44-S45.
After the attribute value of the first data transmission object is set into the attribute of the second data transmission object through the above steps, the setting value method of the open source tool OGNL may be called again to obtain the setting value attribute value (which is the prior art, specifically, the open source tool OGNL. getvalue ("attribute name", data transmission object) is called to obtain the setting value attribute value), the setting value attribute value is compared with the attribute value of the second data transmission object, and the comparison result is output (whether the attribute value of the second data transmission object obtained by the high-performance conversion tool is correct is determined through comparison). After the operation is finished, the high-performance mode for setting the attribute value of the data transmission object by using the expression can obtain an updated object UserInfoDTO, a setting value method of the existing open source tool OGNL can be called to obtain different results UserInfoDTO2, and then the difference between the UserInfoDTO and the UserInfoDTO2 is compared to ensure the accuracy of the operation result of the high-performance conversion tool. Similar to step S30, the specific comparison method only needs to replace the comparison object with the set value attribute value generated by the open source tool OGNL and the attribute value of the second data transmission object. And will not be described in detail herein.
Further, steps S21, S23, S42, and S44, which involve initializing MethodAccess and numbering the method, respectively, may slow system operation. And (4) placing the obtained product into a cache by initializing the methodAccess of the Class at one time and the attribute corresponding relation between the taking-out method and the serial number, and between the setting method and the serial number. When the number of the method is required to be taken, the number of the method is directly taken from the cache, and the influence of the number on the performance speed can be almost eliminated.
The method of the Class, the method of get/set and the initialization method of the attribute corresponding relation cache of the number are as follows: initializing Methodaccess of Class; then, a Field list is obtained from a Class-Field cache, the list is traversed (the step specifically comprises the steps of obtaining an attribute name through the field.getName, obtaining a get/set method name through a splicing mode, obtaining the number of the method through the method access.getIndex and putting the number into the cache), and finally, an object lock is used for synchronization when the cache is initialized: synchronized (inputclass), i.e., blocking of initialization caches of different Class objects can be prevented.
Taking the first data transmission object as dto (a) and the second data transmission object as dto (b) as an example, the method for accessing attribute values from Java objects includes the following steps:
101. configuring attribute corresponding relations of all fields in DTO (A) and DTO (B) in a configuration file;
102. initializing DTO (A) corresponding MethodAccess (DTO (A)) of Class by using a reflection toolkit ReflectaSM;
103. segmenting an expression DTO (A) attribute A by using a separator to obtain a first attribute name;
104. obtaining a get method name getAttribute A of an attribute name by splicing, obtaining a number index (A) of the get method by DTO (A) method index. getIndex ("getAttribute A"), and obtaining an attribute value (A) of attribute A by DTO (A) method index. invoke (DTO (A), index (A));
105. judging whether attribute items exist in the expression or not: if yes, obtaining the next attribute item of the expression and returning to the step 104; if not, ending the value taking;
106. calling a value taking method of an open source tool OGNL to obtain a reference attribute value, comparing the reference attribute value with an attribute value of a first data transmission object and outputting a comparison result;
107. when the comparison result is the same, acquiring a Field (cache priority) corresponding to the Field attributeB from the Class corresponding to the DTO (B), and then obtaining the data type of the Field through the field.getType (); converting the data type of value (A) into the data type of the field attribute B to obtain value (A1);
108. initializing DTO (B) corresponding Methodaccess (DTO (B) Methodaccess) of Class by using a reflection toolkit ReflectSM;
109. dividing an expression DTO (B) of a second data transmission object by using a separator to obtain a first attribute name;
110. obtaining a set method name setAttribute B of attribute B in a splicing mode; get the method number index2 by dto (b) methodaccess. getindex ("setattebusteb"); field values are set by dto (b) method invoke (dto (b), index2, value (a 1)).
111. Judging whether attribute items exist in the expression of the second data transmission object: if yes, according to the previous division, obtaining an object value DTO (x) of the attribute x between the last two separators, returning to the step 110, and setting the value (A1) to the attribute xx of the DTO (x);
120. and calling a setting value method of the open source tool OGNL to obtain a setting value attribute value, comparing the setting value attribute value with the attribute value of the second data transmission object, and outputting a comparison result.
Referring to fig. 5, fig. 5 is a schematic diagram illustrating an internal structure of a computer device according to an embodiment. The computer equipment can be a terminal or a server, wherein the terminal can be an electronic equipment with a communication function, such as a smart phone, a tablet computer, a notebook computer, a desktop computer, a personal digital assistant and a wearable equipment. The server may be an independent server or a server cluster composed of a plurality of servers. Referring to fig. 5, the computer apparatus includes a processor, a non-volatile storage medium, an internal memory, and a network interface connected through a system bus. Wherein the non-volatile storage medium of the computer device may store an operating system and a computer readable program that, when executed, may cause the processor to perform a method of accessing property values from Java objects. The processor of the computer device is used for providing calculation and control capability and supporting the operation of the whole computer device. The internal memory may have stored therein a computer readable program that, when executed by the processor, causes the processor to perform a method for accessing attribute values from Java objects. The network interface of the computer device is used for network communication, such as grabbing tasks and the like. Those skilled in the art will appreciate that the architecture shown in fig. 5 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
The present invention also provides an application server for accessing attribute values from Java objects, comprising a processor 10, a memory 20 and a display 30. Fig. 5 shows only some of the components of the application server accessing property values from Java objects, but it should be understood that not all of the shown components are required to be implemented, and that more or fewer components may be implemented instead.
The storage 20 may in some embodiments be an internal storage unit of the components of the application server accessing the attribute values from the Java object, for example a hard disk or a memory of the application server. The memory 20 may also be an external storage device for each component of the application server accessing the attribute values from the Java objects in other embodiments, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, provided on each component of the application server accessing the attribute values from the Java objects. Further, the memory 20 may include both an internal storage unit and an external storage device of the application server accessing the attribute values from the Java object. The memory 20 is used for storing application software installed in the application server accessing the attribute values from the Java object and various types of data, such as program codes of the application server accessing the attribute values from the Java object. The memory 20 may also be used to temporarily store data that has been output or is to be output. In one embodiment, the storage 20 stores a program 40 for accessing attribute values from Java objects, and the program 40 for accessing attribute values from Java objects is executable by the processor 10, so as to implement the method for accessing attribute values from Java objects according to embodiments of the present application.
The processor 10 may be a Central Processing Unit (CPU), a microprocessor or other data Processing chip in some embodiments, and is used for running program codes stored in the memory 20 or Processing data, such as executing the authority authentication method.
The display 30 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch panel, or the like in some embodiments. The display 30 is used for displaying the result information of accessing the attribute values in the slave Java object. The components 10-30 of the application server accessing property values from Java objects communicate with each other via a system bus.
In one embodiment, when the processor 10 executes the program 40 for accessing property values from Java objects in the memory 20, the following steps are implemented:
configuring attribute corresponding relations of all fields in the first data transmission object and the second data transmission object in a configuration file;
for each pair of attribute corresponding relations, acquiring an attribute value of the first data transmission object through a reflection toolkit;
calling a value taking method of the open source tool to obtain a reference attribute value, comparing the reference attribute value with an attribute value of the first data transmission object and outputting a comparison result;
and when the comparison result is the same, converting the attribute value of the first data transmission object into the data type of the second data transmission object, and setting the attribute value into the attribute of the second data transmission object.
Further, in the application server for accessing attribute values from Java objects, the step of obtaining the attribute value of the first data transmission object through the reflection toolkit for each pair of attribute correspondences includes:
initializing a method accessor object of a class corresponding to the first data transmission object by using a reflection toolkit;
dividing all expressions of a first data transmission object by using separators to obtain a first attribute item of the expression;
obtaining the name of the method for taking out the attribute item through splicing, numbering the method for taking out and obtaining the attribute value of the corresponding item;
judging whether attribute items exist in the expression of the second data transmission object: if yes, obtaining the next attribute item of the expression and returning to the previous step; and if not, ending the value taking.
The step of calling the value taking method of the open source tool to obtain the reference attribute value, comparing the reference attribute value with the attribute value of the first data transmission object and outputting the comparison result comprises the following steps:
comparing whether the corresponding data are the same according to the types of the attribute value and the reference attribute value of the first data transmission object, and adding different field names and corresponding values thereof into a returned result hash table;
and if the hash table of the returned result is not empty, outputting the hash table of the returned result to the error log.
The step of comparing whether the corresponding data are identical according to the types of the attribute value and the reference attribute value of the first data transmission object includes:
if the attribute value and the reference attribute value of the first data transmission object are of the data type, comparing whether the data of the attribute value and the reference attribute value of the first data transmission object are equal;
if the attribute value and the reference attribute value of the first data transmission object are of the list type, traversing each element in the two lists, and respectively comparing values at the same position in the lists;
and if the attribute value and the reference attribute value of the first data transmission object are of the hash table type, traversing each element in the two hash tables, and comparing the attribute values corresponding to the same field code.
When the comparison result is the same, the step of converting the attribute value of the first data transmission object into the data type of the second data transmission object and setting the attribute value into the attribute of the second data transmission object comprises the following steps:
when the comparison result is the same, acquiring the domain and the data type corresponding to the corresponding field from the class corresponding to the second data transmission object; converting the data type of the attribute value into the data type of the field;
initializing a method accessor object of a class corresponding to the second data transmission object using a reflection toolkit;
dividing the expression of the second data transmission object by using the separators to obtain the attribute items of the expression;
obtaining the name of a setting method of the changed field through splicing, numbering the setting method and setting a field value;
judging whether attribute items exist in the expression of the second data transmission object: if so, acquiring the next attribute item of the expression according to the previous segmentation and returning to the previous step; and setting the attribute value into the corresponding attribute item until the attribute item between the last two separators is obtained and the previous step is returned.
After the step of converting the attribute value of the first data transmission object into the data type of the second data transmission object and setting the data type into the attribute of the second data transmission object when the comparison result is the same, the method further comprises:
and calling a setting value method of the open source tool to obtain a setting value attribute value, comparing the setting value attribute value with the attribute value of the second data transmission object, and outputting a comparison result.
Before the step of initializing by using the reflection toolkit, the method further comprises the following steps:
initializing a class method accessor object, initializing the attribute corresponding relation between a fetching method and a number, and between a setting method and the number, and storing the initialized fetching method accessor object and the number in a cache.
Before the step of obtaining the domain corresponding to the corresponding field from the class corresponding to the second data transmission object, the method further includes:
all domain lists in the class are initialized and put into the cache for storage.
Please refer to fig. 6, which is a functional block diagram of an application server for installing a program for accessing attribute values from Java objects according to a preferred embodiment of the present invention. In this embodiment, the program for installing and accessing property values from Java objects may be divided into one or more modules, and the one or more modules are stored in the memory and executed by one or more processors (in this embodiment, the processors), so as to complete the present invention. For example, in fig. 6, an application server that installs a program that accesses property values from Java objects may be partitioned into a configuration module 31, a reflection module 32, a comparison module 33, and a conversion module 34. The module referred to in the present invention refers to a series of computer program segments capable of performing specific functions, and is more suitable than a program for describing the execution process of the program for accessing property values from Java objects in the application server for accessing property values from Java objects. The following description will specifically describe the functionality of the modules 31-34.
The configuration module 31 is configured to configure attribute correspondence of all fields in the first data transmission object and the second data transmission object in the configuration file.
And the reflection module 32 is configured to obtain the attribute value of the first data transmission object through the reflection toolkit for each pair of attribute correspondence relationships.
The comparison module 33 is configured to invoke a value taking method of the open source tool to obtain a reference attribute value, compare the reference attribute value with the attribute value of the first data transmission object, and output a comparison result.
And the conversion module 34 is used for converting the attribute value of the first data transmission object into the data type of the second data transmission object and setting the data type into the attribute of the second data transmission object when the comparison results are the same.
The reflection module 32 includes an initialization unit, a separation unit, a numbering unit, and a judgment unit, wherein:
the first initialization unit is configured to initialize the method accessor object of the class corresponding to the first data transmission object by using the reflection toolkit.
The first separating unit is used for dividing all expressions of the first data transmission object by using the separators to obtain a first attribute item of the expression.
The first numbering unit is used for obtaining the name of the taking method of the attribute item through splicing, numbering the taking method and obtaining the attribute value of the corresponding item.
The first judging unit is used for judging whether attribute items exist in the expression of the second data transmission object: if yes, obtaining the next attribute item of the expression and returning to the previous step; and if not, ending the value taking.
The comparing module 33 includes a type comparing unit and an output unit, wherein:
and the type comparison unit is used for comparing whether the corresponding data are the same according to the attribute value of the first data transmission object and the type of the reference attribute value, and adding different field names and corresponding values thereof into a returned result hash table.
And the output unit is used for outputting the hash table of the returned result to the error log if the hash table of the returned result is not empty.
Further, the type comparing unit is specifically configured to compare whether the corresponding data are the same according to the type of the attribute value and the reference attribute value of the first data transmission object, and if the attribute value and the reference attribute value of the first data transmission object are of the data type, compare whether the data of the attribute value and the reference attribute value of the first data transmission object are the same; if the attribute value and the reference attribute value of the first data transmission object are of the list type, traversing each element in the two lists, and respectively comparing values at the same position in the lists; and if the attribute value and the reference attribute value of the first data transmission object are of the hash table type, traversing each element in the two hash tables, and comparing the attribute values corresponding to the same field code.
The conversion module 34 includes a type conversion unit, a second initialization unit, a second partitioning unit, a second numbering unit, and a second judgment unit, wherein:
the type conversion unit is used for acquiring the domain and the data type corresponding to the corresponding field from the class corresponding to the second data transmission object when the comparison results are the same; the data type of the attribute value is converted into the data type of the field.
The second initialization unit is configured to initialize the method accessor object of the class corresponding to the second data transmission object by using the reflection toolkit.
And the second partitioning unit is used for partitioning the expression of the second data transmission object by using the separators to obtain the attribute item of the expression.
And the second numbering unit is used for obtaining the name of the setting method of the changed field through splicing, numbering the setting method and setting the field value.
The second judging unit is configured to judge whether there is an attribute item in the expression of the second data transmission object: if so, acquiring the next attribute item of the expression according to the previous segmentation and returning to the previous step; and setting the attribute value into the corresponding attribute item until the attribute item between the last two separators is obtained and the previous step is returned.
The application server further comprises a processing module, which is used for calling a setting value method of the open source tool to obtain a setting value attribute value, comparing the setting value attribute value with the attribute value of the second data transmission object and outputting a comparison result.
Further, the application server also comprises an initial processing module, which is used for initializing the method accessor object of the class, initializing the attribute corresponding relation between the fetching method and the serial number, and between the setting method and the serial number, and storing the initialized fetching method and serial number in a cache; and initializing all domain lists in the class and storing the domain lists in a cache.
In summary, in the method, the server, and the storage medium for accessing attribute values from Java objects provided by the present invention, in a program application, a high performance transformation tool is used to configure the attribute correspondence of all fields of two data transmission objects in a configuration file, for each pair of fields, an attribute value of one data transmission object is obtained first, then converted into a data type of the other data transmission object, and then set into an attribute of the other data transmission object, so that the efficiency of accessing/retrieving an attribute value from a data transmission object is improved, and a performance bottleneck caused by high concurrence is avoided; and finally, comparing the running results of the open source tool OGNL to ensure the correctness of the high-performance conversion tool. Meanwhile, the method has the advantage of 'indirectly calling get/set method' of reflactasm high-performance reflection, and in order to avoid the problem of 'slow initialization', the content of the first initialization of the reflactasm kit is cached, and then the reflactasm kit can be directly and quickly used.
Of course, it will be understood by those skilled in the art that all or part of the processes of the methods of the above embodiments may be implemented by instructing relevant hardware (such as a processor, a controller, etc.) through a computer program, and the program may be stored in a computer readable storage medium, and when executed, the program may include the processes of the above method embodiments. The storage medium may be a memory, a magnetic disk, an optical disk, etc.
It is to be understood that the invention is not limited to the examples described above, but that modifications and variations may be effected thereto by those of ordinary skill in the art in light of the foregoing description, and that all such modifications and variations are intended to be within the scope of the invention as defined by the appended claims.

Claims (9)

1. A method for accessing attribute values from Java objects, comprising the steps of:
configuring attribute corresponding relations of all fields in the first data transmission object and the second data transmission object in a configuration file;
for each pair of attribute corresponding relations, acquiring an attribute value of the first data transmission object through a reflection toolkit;
calling a value taking method of the open source tool to obtain a reference attribute value, comparing the reference attribute value with an attribute value of the first data transmission object and outputting a comparison result;
when the comparison result is the same, converting the attribute value of the first data transmission object into the data type of the second data transmission object, and setting the data type into the attribute of the second data transmission object;
for each pair of attribute correspondences, obtaining the attribute value of the first data transmission object through the reflection toolkit comprises:
initializing a method accessor object of a class corresponding to the first data transmission object by using a reflection toolkit;
dividing all expressions of a first data transmission object by using separators to obtain a first attribute item of the expression;
obtaining the name of the method for taking out the attribute item through splicing, numbering the method for taking out and obtaining the attribute value of the corresponding item;
judging whether attribute items exist in the expression of the second data transmission object: if yes, obtaining the next attribute item of the expression and returning to the previous step; and if not, ending the value taking.
2. The method according to claim 1, wherein the step of calling the value-taking method of the open source tool to obtain a reference attribute value, comparing the reference attribute value with the attribute value of the first data transmission object, and outputting the comparison result comprises:
comparing whether the corresponding data are the same according to the types of the attribute value and the reference attribute value of the first data transmission object, and adding different field names and corresponding values thereof into a returned result hash table;
and if the hash table of the returned result is not empty, outputting the hash table of the returned result to the error log.
3. The method of claim 2, wherein the step of comparing whether the corresponding data is identical according to the type of the attribute value of the first data transmission object and the reference attribute value comprises:
if the attribute value and the reference attribute value of the first data transmission object are of the data type, comparing whether the data of the attribute value and the reference attribute value of the first data transmission object are equal;
if the attribute value and the reference attribute value of the first data transmission object are of the list type, traversing each element in the two lists, and respectively comparing values at the same position in the lists;
and if the attribute value and the reference attribute value of the first data transmission object are of the hash table type, traversing each element in the two hash tables, and comparing the attribute values corresponding to the same field code.
4. The method of claim 1, wherein the step of converting the attribute value of the first data transmission object into the data type of the second data transmission object and setting the attribute value into the attribute of the second data transmission object when the comparison result is the same comprises:
when the comparison result is the same, acquiring the domain and the data type corresponding to the corresponding field from the class corresponding to the second data transmission object; converting the data type of the attribute value into the data type of the field;
initializing a method accessor object of a class corresponding to the second data transmission object using a reflection toolkit;
dividing the expression of the second data transmission object by using the separators to obtain the attribute items of the expression;
obtaining the name of a setting method of the changed field through splicing, numbering the setting method and setting a field value;
judging whether attribute items exist in the expression of the second data transmission object: if so, acquiring the next attribute item of the expression according to the previous segmentation and returning to the previous step; and setting the attribute value into the corresponding attribute item until the attribute item between the last two separators is obtained and the previous step is returned.
5. The method of claim 1, wherein after the step of converting the attribute value of the first data transmission object into the data type of the second data transmission object and setting the attribute value into the attribute of the second data transmission object when the comparison result is the same, the method further comprises:
and calling a setting value method of the open source tool to obtain a setting value attribute value, comparing the setting value attribute value with the attribute value of the second data transmission object, and outputting a comparison result.
6. The method of claim 4, further comprising, prior to the step of initializing using a reflection toolkit:
initializing a class method accessor object, initializing the attribute corresponding relation between a fetching method and a number, and between a setting method and the number, and storing the initialized fetching method accessor object and the number in a cache.
7. The method according to claim 4, further comprising, before the step of obtaining the domain corresponding to the corresponding field from the class corresponding to the second data transfer object, the step of:
all domain lists in the class are initialized and put into the cache for storage.
8. An application server for accessing attribute values from Java objects, comprising: a processor, a memory, a communication bus; the memory has stored thereon a computer readable program executable by the processor;
the communication bus realizes connection communication between the processor and the memory;
the processor, when executing the computer readable program, performs the steps in a method for accessing property values from Java objects as claimed in any of claims 1 to 7.
9. A computer readable storage medium, storing one or more programs which are executable by one or more processors to perform the steps of the method of accessing property values from Java objects as claimed in any one of claims 1 to 7.
CN201711037346.9A 2017-10-30 2017-10-30 Method, server and storage medium for accessing attribute value from Java object Active CN107766039B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711037346.9A CN107766039B (en) 2017-10-30 2017-10-30 Method, server and storage medium for accessing attribute value from Java object

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711037346.9A CN107766039B (en) 2017-10-30 2017-10-30 Method, server and storage medium for accessing attribute value from Java object

Publications (2)

Publication Number Publication Date
CN107766039A CN107766039A (en) 2018-03-06
CN107766039B true CN107766039B (en) 2020-04-10

Family

ID=61270523

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711037346.9A Active CN107766039B (en) 2017-10-30 2017-10-30 Method, server and storage medium for accessing attribute value from Java object

Country Status (1)

Country Link
CN (1) CN107766039B (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109725953A (en) * 2018-12-11 2019-05-07 山东浪潮通软信息科技有限公司 A kind of data interconnection method and system based on Java reflection technology
CN109901822B (en) * 2019-01-08 2022-08-12 平安科技(深圳)有限公司 Object conversion method and device, storage medium and server
CN109992581B (en) * 2019-02-20 2023-05-26 平安科技(深圳)有限公司 HashMap-based data acquisition method and device, computer equipment and storage medium
CN110321289A (en) * 2019-06-24 2019-10-11 平安科技(深圳)有限公司 A kind of batch testing method and device of DTO class
CN110532526B (en) * 2019-07-23 2024-04-26 平安科技(深圳)有限公司 Data conversion method, electronic device and computer readable storage medium
CN110990050B (en) * 2019-11-25 2023-10-13 泰康保险集团股份有限公司 Model attribute value printing control method, device, medium and equipment
CN111124382A (en) * 2019-12-17 2020-05-08 北京金山云网络技术有限公司 Attribute assignment method and device in Java and server
CN114398033B (en) * 2021-12-22 2024-05-14 陕西法士特齿轮有限责任公司 Interface and data stripping design method

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1746844A (en) * 2005-09-29 2006-03-15 浪潮电子信息产业股份有限公司 Method for monitoring and managing machine group system of cross-operation platform
CN101699397A (en) * 2009-10-09 2010-04-28 上海宝信软件股份有限公司 Method for binding Java and XML data
CN107197024A (en) * 2017-06-09 2017-09-22 努比亚技术有限公司 Single table access and control method, user terminal, server and storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1746844A (en) * 2005-09-29 2006-03-15 浪潮电子信息产业股份有限公司 Method for monitoring and managing machine group system of cross-operation platform
CN101699397A (en) * 2009-10-09 2010-04-28 上海宝信软件股份有限公司 Method for binding Java and XML data
CN107197024A (en) * 2017-06-09 2017-09-22 努比亚技术有限公司 Single table access and control method, user terminal, server and storage medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
java不同对象之间同名属性值复制;白开水Luis;《https://blog.csdn.net/zhanglu0223/article/details/78017906》;20170918;第1-2页 *
对象转换利器Dozer;ningandjin;《iteye.com/blog/ningandjiao-198938》;20131214;第1-4页 *

Also Published As

Publication number Publication date
CN107766039A (en) 2018-03-06

Similar Documents

Publication Publication Date Title
CN107766039B (en) Method, server and storage medium for accessing attribute value from Java object
US10956403B2 (en) Verifying data consistency
EP3336690A1 (en) Extensible data transformation authoring and validation system
US8108437B2 (en) Sortable hash table
US10740184B2 (en) Journal-less recovery for nested crash-consistent storage systems
US11075991B2 (en) Partitioning data according to relative differences indicated by a cover tree
CN106909597B (en) Database migration method and device
US20100174991A1 (en) Maintaining data coherency within related multi-perspective user interfaces via session-less queries
US11934674B2 (en) Method, electronic device, and computer program product for storing and accessing data across multiple servers utilizing metadata of a distributed hash table
US11531525B2 (en) System and method for packaging standalone application modules into re-usable application and infrastructure resources
US10698637B2 (en) Stale block resynchronization in NVM based systems
US8341368B2 (en) Automatic reallocation of structured external storage structures
US8886900B2 (en) Legacy data management
US11635948B2 (en) Systems and methods for mapping software applications interdependencies
CN112395437B (en) 3D model loading method and device, electronic equipment and storage medium
US11281666B2 (en) Interception of database queries for delegation to an in memory data grid
CN109753506B (en) Data distributed storage method, device, terminal and storage medium
CN107357853B (en) Method and device for operating REDIS console and computer system
US11580128B2 (en) Preventing DBMS deadlock by eliminating shared locking
US10114864B1 (en) List element query support and processing
US9836315B1 (en) De-referenced package execution
CA3089289C (en) System and methods for loading objects from hash chains
US10402391B2 (en) Processing method, device and system for data of distributed storage system
US20130081007A1 (en) Providing continuous application availability during application update
US11880350B2 (en) Identifying resource lock ownership across a clustered computing environment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant