Specific embodiment
It to apparatus and method provided in an embodiment of the present invention and is described in detail with reference to the accompanying drawing.Although being shown in attached drawing
The preferred embodiment of the disclosure is shown, however, it is to be appreciated that may be realized in various forms the disclosure without that should be explained here
The embodiment stated is limited.On the contrary, these embodiments are provided so that this disclosure will be more thorough and complete, and can
The scope of the present disclosure is fully disclosed to those skilled in the art.Structure of the invention is illustrated so that Java is programmed as an example below
Think of and embodiment.
Java language is used widely at present, particularly starts to support that source code is added in 5.0 version of Java language
Special grammar metadata.Class, method, variable, parameter and packet in Java language etc. can be marked, and be supported customized
Java mark.Different with Javadoc, Java mark can obtain marked content by reflection.In the compilation process of Java source code
In, note can be annotated processor and handle and generate the message comprising information or additional Java sound code file or resource, together
The Java sound code file of Shi Xinzeng may also can be compiled and handle and modify the code itself being annotated.In addition, Java language
Java reflection mechanism is provided, for observing and modifying the behavior of program at runtime.In Java, reflection allows in compiling duration
Between do not know the title of pipeline joint, check class, interface, word at runtime in the case where field (fields, i.e. member variable), method
Section and method.It also allows to carry out to instantiate the calling of new object and distinct methods according to judging result.One of the invention or
Multiple embodiments explain with reflection mechanism the unified programming realized suitable for multiple database frame using the note of Java.
Fig. 1 shows program assembly 100 according to an embodiment of the invention, and program assembly 100 can be one solely here
Vertical SDK component or plug-in unit can be embedded in application APP, to call the function of SDK component preprogrammed, such as logarithm
According to library access operation.One or more embodiment according to the invention, configuration device 102 is integrated in program assembly 100, when uncommon
When program assembly 100 is integrated into application APP by prestige, configuration device 102 can be according to the characteristic of application APP, to journey
The program and operating mechanism of sequence component 100 carry out suitability configuration.Here application APP can be it is known can be in intelligence
Any application run in energy terminal, and intelligent terminal may be the calculating dress including such as computer, mobile phone, plate etc.
It sets.
As shown in Figure 1, program assembly 100 includes program 101 and configuration device 102.It is stored in program 101 and utilizes system
One explains the original data model class Original_Class of mark, for realizing scheduled function.Here unified explain can
To be customized note, such as customized Java mark.It shows as follows and utilizes the customized initial data mould for explaining mark
An example of type class Original_Class:
In this embodiment, IAPDatabaseTable is explained using unified, IAPDatabaseField is labelled with database mould
Type class Message class, defines the operating parameters such as method, attribute in model class.
Configuration device 102 includes determination type module 104, annotation processor 106, database manipulation interface 108 and anti-
Penetrate processor 110.When SDK component 100 to be integrated into application APP and be compiled, determination type module 104 is determined
Load database framework type DB_Frame used by the application APP of the SDK component 100.Here database framework
Type can be general any type on APP known in the art, such as SQlite, ormLite, greenDAO etc..
As an example, determination type module 104 can further judge the original data model class Original_ in SDK component
Whether Class matches with identified database framework type DB_Frame, and matching here refers to whether database framework props up
Hold original data model class and its unified note.Such as when database framework DB_Frame supports the unified note or when number
When not needing to explain at runtime according to library frame DB_Frame, then it is assumed that original data model class and database framework type DB_
Frame matching.
If original data model class Original_Class and database framework type DB_Frame in program 101 are not
Matching, annotation processor 106 are based on original data model class Original_Class and generate and database framework type DB_
The matched new annotation model class New_class of Frame, and by new annotation model class New_class storage into program 101, this
In original data model class and new annotation model class realize the same predetermined function of SDK component.An example according to the invention,
When generating new annotation model class New_class, annotation processor 106 scans original data model class Original_Class's
It is unified to explain, which is explained and is converted to the specific note for meeting database framework type DB_Frame, it is new for marking
Annotation model class New_class.Meanwhile using an identifier field by new annotation model class, example associated with initial data class
Such as, identifier is added in the class name of initial data class.
As an example, Fig. 2A is shown when application APP is using ormLite database framework, by annotation processor
The 106 class conversions realized.As shown, in this example, SDK component 100 is a message case module, for storing message,
Wherein the message case module has original data model class Message, there is defined the title of message (title) and disappears
It ceases content (content), in addition, the message utilizes customized unified note@IAPDatabaseTable ,@
IAPDatabaseField is labeled database involved in class and method attribute.Due to the customized unified note@
IAPDatabaseTable ,@IAPDatabaseField are not the database framework ormLite that current application program APP is used
The note supported, therefore during compiling, annotation processor 106 scans in message case module with unified annotation model class
Message class explains@IAPDatabaseTable for unified, and@IAPDatabaseField is converted into ormLite respectively and is propped up
Note@DatabaseTable, the@DatabaseField held, while creating new annotation model class GenMessage class, the new note
Solution model class class name is made of archetype class class name Message prefixing " Gen ".
When application APP operation and it is desirable that call SDK component to realize predetermined function when, database manipulation interface 108
The call request Call_SDK to SDK component from application APP is received, and passes through component database operation interface 108
The database manipulation for the database framework that incoming application APP uses specifically is requested, such as is stored.
It is to be herein pointed out SDK component 100 is to utilize archetype class when executing specific database manipulation
What Original_Class was realized, but actual database storage is real by application APP database framework such as (ormLite)
It is existing.For this purpose, reflection processor 110 in response to call request Call_SDK, the database framework class that will be used with application APP
The class object of the corresponding new annotation model class New_class of type sends the database framework of application APP to.Such as Fig. 2 B institute
Show, by taking the application APP using ormLite database framework as an example, reflection processor 110 utilizes database manipulation interface
108 receive the call request Call_SDK of the application APP, and the annotation model class that can determine that current APP is supported is
OrmLite data model class.Therefore, reflection processor 110 traverses original data model class, to obtain the class object of model class,
The parameter value for each parameter that the class object includes parameter in class and SDK component is generated when executing specific database manipulation.
It still by taking message box sub-component above as an example, is handled by reflection, reflection processor 110 is available to original data model class
Message header (title) and content (content) in class object (Message.class) and the class object it is specific
Acquired parameter occurrence is encapsulated into the individual features in new annotation model class GenMessage by value, reflection processor 110
In parameter title and content.Then, processor 110 is reflected by the class object GenMessage.class of new annotation model class
The ormLite database framework in application APP is sent to, to realize database in the storage operation to message.
It is to be herein pointed out be only explained by taking Message message class as an example above, still, original data model
Class Original_Class is not limited to a kind of entity class, can also comprising other types of class and greater number of entity class,
In operation, reflection processor 110 can traverse each object in all entity class and class, and be transformed into new annotation model class
In New_class.
In addition it should be pointed out that determination type module 104 is nor essential in configuration device 102 in this example
Component, such as configuration device 102 directly can receive database framework used by the application APP that user specifies from external
Type DB_Frame, and the original data model class Original_Class in determining program component 100 and specified in turn
Whether database framework type DB_Frame matches.
Fig. 3 shows original data model class Original_Class and database framework type DB_ in SDK component
The matched example of Frame, wherein using message case module as the example of SDK component.As shown, APP here is adopted
It with SQLite database framework, does not need to explain at runtime, therefore in the compilation phase, annotation processor 106 does not need pair
Unified explain does any conversion.In APP operation, original data model class can be directly used by database manipulation interface
Each object in Message.
Fig. 4 is shown to be handled with the execution stage in application APP, SDK component, annotation processor and reflection in compiling
Operation chart between device, what needs to be explained here is that, purpose for ease of description, SDK component, annotation processor and
It is separately positioned for reflecting processor.
As shown in 1.1 in figure, is worked out in advance in the program 101 of SDK component and explained target initial data mould with unified
Type class Original_Class.Such as message case module shown in Fig. 2A, wherein with customized unified note
IAPDatabaseTable ,@IAPDatabaseField are labelled with the Message class of original data model class.Such as 1.2 institute in figure
Show, it, can be by database framework type DB_ that APP is supported when it is desirable that SDK component is integrated into APP in the compilation phase
Frame sends annotation processor to.As shown in 1.3 in figure, annotation processor is generated according to database framework type DB_Frame
Support the corresponding new annotation model class of database framework DB_Frame.As shown in Figure 2 A, in database framework type DB_
When Frame is ormLite, annotation processor is scanned with the unified model class Message class explained in SDK component, will wherein
It is unified explain@IAPDatabaseTable ,@IAPDatabaseField is converted into supporting the new note@of ormLite
DatabaseTable ,@DatabaseField, and data model class GenMessage class is created, the new annotation model class class name
It is made of model class class name Message prefixing identifier " Gen ".Then 1.4, annotation processor is by the data model of creation
Class GenMessage class returns to SDK component, such as is stored in program 101.
When APP operation is for example wished to call SDK component to realize that predetermined function such as message stores, such as 2.1 institute in figure
Show, APP issues call request call_SDK to SDK component by database manipulation interface, and SDK component operates original data model
Class such as Message class operates to execute message storage, and the title and content of operating result such as message are stored in Message class
Title and content attribute in.Meanwhile as shown in 2.2, number of the reflection processor based on the current APP for issuing call request
According to library framework type DB_Frame, new annotation model class New_ corresponding with type DB_Frame is searched from program 101
class.For example, as shown in Figure 2 B, when APP support be ormLite database framework when, reflection processor can determine it is corresponding
New annotation model class is ormLite.Then, as shown in 2.3, reflection processor obtains the Class object of archetype class for example
Message.class, to generate the Class object such as GenMessage.class of new annotation model class.As an example,
The process for generating the Class object of new annotation model class by reflection processor is as follows:
(1), it is obtained from the mapping relations of the class object of archetype class and the class object of new annotation model class caching new
Class (class) object of annotation model class.If caching is not present, mould is obtained from the class object of archetype class by reflection
The class name of type class, addition identifier such as " Gen " form the class name of new annotation model class afterwards, then, by reflection based on original
The class object of model class generates the class object of new annotation model class, and by the class object of archetype class and new annotation model class
Class object mapping relations deposit mapped cache in.
(2), the member variable name and field (Field) object of archetype class and new annotation model class are obtained from caching
Mapping relations, any caching is not present, then the member in archetype class or new annotation model class is obtained by reflection
The mapping relations of variable name and field object write-in caching;
(3), new annotation model class members variable name is traversed, to each member variable name, from the member of archetype class
Field object is obtained in the mapping relations of variable name and field object caching, and is obtained on archetype class object together by reflection
The value of name member variable, and the member variable value of archetype class object is passed through into reflection setting to new annotation model class object
On member variable of the same name.
Back to shown in Fig. 4, as shown in 2.4, after being handled by reflection, reflection processor returns to the class of new annotation model class
Object GenMessage.class.To be explained under the ormLite database framework of APP based on new as shown in 2.5 and 2.6
The class object GenMessage.class of model class realizes the practical operation to database, and APP can deposit operation such as message
The result of storage returns.
Fig. 5 shows the flow chart of configuration SDK component according to an embodiment of the invention, for purposes of illustration only, with shown below
In example, by taking message case module as an example, and APP is respectively adopted bis- kinds of database frameworks of ormLite and SQLite and carries out data
Library operation.It is packaged in message case module and utilizes the customized unified original data model for explaining mark of Java language
Class, for example,
As shown in figure 5, in step 502, when expectation integrates the message box sub-portfolio in APP, in the APP compilation phase,
Determine that expectation loads database framework type DB_Frame used by the application APP of message case module, as previously mentioned,
It wherein determines that framework type DB_Frame can both be realized by the way that user is specified, can also voluntarily judge to realize.Before subsequent process
To step 504, judge whether database framework type DB_Frame matches with original data model class Original_Class.
If database framework DB_Frame and original data model class Original_Class that current APP is used are mismatched, such as
Current APP then arrives step 506 using ormLite frame before process.
In step 506, explained using the unification of annotation processor scanning original data model class Original_Class, with
The unification is explained to the specific note for being converted to the database framework type DB_Frame for meeting current APP, it is described for marking
New annotation model class New_class.Meanwhile it is using an identifier field that new annotation model class is associated with initial data class.
Example as shown in Figure 2 A, when current APP uses ormLite database framework, annotation processor 106 scans message box subgroup
Part explains@IAPDatabaseTable for unified, and@IAPDatabaseField is converted into the note that ormLite is supported respectively
@DatabaseTable ,@DatabaseField are solved, while creating new annotation model class GenMessage class, the new annotation model
Class class name is made of model class class name Message prefixing " Gen ".In turn, the process of compilation of entire APP is completed.If in step
When rapid 504 database frameworks for determining that current APP is used are matched with original data model class Original_Class, such as currently
When APP is using SQLite frame, then woth no need to explain conversion process, the process of compilation of entire APP is done directly.
In step 508, in the application APP operation phase, asked by database manipulation interface from the calling of APP
It asks, such as message storage operation.In step 510, it is based on call request, the determining database framework with current application program APP
The data model class to match.As previously described in example, it if current APP uses SQLite frame, can be directly based upon original
Data model class Original_Class carries out data storage operations, as shown in Figure 3;And if current APP uses ormLite frame
Frame then advances to step 512.As previously mentioned, conversion has new annotation model class in advance in SDK component in the compilation phase
OrmLite data model class, as shown in Figure 2 B, therefore in step 512, using reflection mechanism, in response to call request, will with answer
The ormLite in application APP is sent to the new annotation model class of the corresponding ormLite of ormLite frame that program uses
Database framework.It for the message case module in this example, is handled by reflection, reflection processor is available to arrive initial data
Message header (title) and content (content) in the class object (Message.class) of model class and the class object
Occurrence, reflection processor acquired parameter occurrence is encapsulated into the corresponding spy in new annotation model class GenMessage
It levies in parameter title and content.Then, in step 514, processor is reflected by the class object of new annotation model class
GenMessage.class sends the ormLite database framework in application APP to, to realize database to message
Storage operation.
Using the solution of the present invention, can be automatically generated by annotation processor for disparate databases frame (such as
SQlite, ormLite) new annotation model class, then actual database operation in using Java reflection mechanism obtain generate
It is new to explain class object, thus on the basis of same set of unified note, using original data model class, it is switched to different numbers
According to progress actual database operation under the frame of library.
According to the present invention, which can be installed on any terminal, such as computer, mobile phone etc..Fig. 6 example
Property shows a kind of intelligent terminal comprising is stored with the memory and processor of application APP, wherein the processor can be held
The stored application program of row is with accessing data base.One or more embodiment according to the invention, application APP quilt
Be programmed for including plug-in unit to realize scheduled function, wherein the plug-in unit include: database manipulation interface and reflection processor,
Then middle database manipulation interface, is asked for receiving the call request to plug-in unit from application program in response to the calling
Ask, reflection processor by the plug-in unit, with the corresponding new annotation model class of database framework type of application APP use
The database framework that the application program uses is sent to, wherein the new annotation model class is based on using by the plug-in unit
The unified original data model class for explaining mark generate, to realize the function of the plug-in unit.In one example, at reflection
It manages device and obtains characteristic parameter and its parameter value in original data model class, and acquired parameter value is encapsulated as the new note
The parameter value of individual features parameter in model class, wherein the parameter value in the original data model class is described program component
It operates the original data model class and generates.It is to be herein pointed out in addition to processor shown in fig. 6, memory and
Realize that the intelligent terminal of program assembly execution generally according to its actual functional capability, may be used also except nonvolatile memory, in embodiment
To include other hardware, this is repeated no more.
Although it is to be herein pointed out the present invention is described in conjunction with above preferred embodiment, it is apparent that the present invention is unlimited
In this.In addition, each module in Fig. 1 may include processor, electronic equipment, hardware device, electronic component, logic circuit, deposit
Reservoir, software code, firmware code etc. or their any combination.Technical staff will also be appreciated that in conjunction with public herein
Various illustrative logic blocks, module and the method and step for opening content description can be implemented as electronic hardware, computer software
Or both combination.It taking software implementation as an example, is to be deposited by processor by non-volatile as the equipment on a logical meaning
Corresponding computer program instructions read what operation in memory was formed in reservoir.Another embodiment of the present invention provides it is machine readable
Machine readable instructions are stored on medium, which execute computer and be disclosed herein when being computer-executed
Any method above-mentioned.Specifically, system or device equipped with machine readable media can be provided, it is machine readable at this
It stores the software program code for realizing the function of any embodiment in above-described embodiment on medium, and makes the computer of the system
Read and execute the machine readable instructions being stored in the machine readable media.In this case, it is read from machine readable media
The function of any one of above-described embodiment embodiment, therefore machine readable code and storage can be achieved in program code taken itself
The machine readable media of machine readable code constitutes a part of the invention.
It should be noted that above-mentioned each process is all necessary with step or module not all in the structure chart of device
, certain steps or module can be ignored according to the actual needs.Each step execution sequence be not it is fixed, can be according to need
It is adjusted.System structure described in the various embodiments described above can be physical structure, be also possible to logical construction, that is, have
A little modules may be realized by same physical entity, be realized alternatively, some modules may divide by multiple physical entities, alternatively, can be with
It is realized jointly by certain components in multiple autonomous devices.
Detailed displaying and explanation carried out to the present invention above by attached drawing and preferred embodiment, however the present invention is not limited to
These embodiments having revealed that, base could be aware that with above-mentioned multiple embodiment those skilled in the art, can combine above-mentioned difference
Code audit means in embodiment obtain the more embodiments of the present invention, these embodiments also protection scope of the present invention it
It is interior.