Method, device and terminal for connecting geoserver with hive database and storage medium

The plugin, developed using the Java SPI mechanism, solves the problem of connecting GeoServer and Hive databases, enabling flexible database connections and data publishing, reducing system coupling, and improving adaptability and the convenience of user-defined functions.

CN114595257BActive Publication Date: 2025-11-18AERIAL PHOTOGRAMMETRY & REMOTE SENSING CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210248268.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-14
Publication Date
2025-11-18
Estimated Expiration
2042-03-14

AI Technical Summary

Technical Problem

The existing GeoServer cannot directly connect to the Hive database, and the existing connection technology is highly coupled with the system, making deployment and feature expansion difficult.

Method used

A plugin based on the Java SPI mechanism is developed. The plugin obtains the connection parameters of the Hive database, establishes a data source object, and realizes the connection between GeoServer and Hive database through the database identifier and driver class name.

Benefits of technology

It enables flexible connection between GeoServer and Hive database, reduces code coupling, and improves system adaptability and the convenience of user-defined functions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114595257B_ABST
    Figure CN114595257B_ABST
Patent Text Reader

Abstract

The embodiment of the application discloses a method for connecting GeoServer and a hive database, which comprises the following steps: obtaining connection parameters of a data source to be connected through a plug-in; sending the connection parameters to the GeoServer through the plug-in to determine a database corresponding to the connection parameters; establishing a data source object corresponding to the database through the plug-in; the data source object comprises a database identifier and a database driver class name; and establishing a connection between the GeoServer and the database based on the database identifier and the database driver class name through the plug-in. The method makes the GeoServer capable of publishing contents in the database, and has the characteristics of high cohesion and low coupling and good plug-and-play characteristics because the method is realized in the plug-in mode.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of software system integration and function extension, and particularly relates to a method and device for connecting GeoServer and a hive database, a terminal and a storage medium. BACKGROUND

[0002] GeoServer is an open source software server written in Java, allowing users to share and edit geospatial data. It is designed to enable interoperability, and it uses open standards to publish data from any major spatial data source.

[0003] GeoServer needs to connect a data source to obtain data when publishing data. The data sources supported by GeoServer mainly include two types, namely databases and file systems. It is known that the database types supported by GeoServer mainly include PostGis, MySQL, H2, Db2, SQL Server and other traditional relational databases. However, with the increasing amount of engineering data, when developing a big data platform, a Hive database based on Hadoop needs to be used as storage, and table data in the Hive needs to be published as a service for front-end calling. At present, there is no tool or technology that can support GeoServer to publish Hive table data. Moreover, the existing connection database technology and GeoServer code are mixed, and have high coupling. SUMMARY

[0004] Based on the above background, the present application provides a method for connecting GeoServer and a hive database, comprising:

[0005] obtaining connection parameters of the hive database through a plug-in, and sending the connection parameters to GeoServer;

[0006] establishing a data source object corresponding to the hive database through the plug-in; the data source object includes a database identifier and a database driver class name;

[0007] establishing a connection between the GeoServer and the hive database based on the database identifier and the database driver class name through the plug-in.

[0008] Further, the connection parameters include an IP address, a port, a database name and a password.

[0009] Further, the database identifier is obtained by the following way:

[0010] obtaining a database ID by reading the IP address, the port and the database name in the connection parameters;

[0011] According to a preset rule, the address, the port, the database name and the database ID are combined into the database identifier by means of string concatenation.

[0012] Further, the data source object further comprises a data source name.

[0013] The method further comprises:

[0014] The data source name is acquired by the plug-in.

[0015] The data source name is loaded onto a front-end page to form a database link composed of the data source name; the database link is used to enter the hive database.

[0016] Further, the data source object further comprises a data source description.

[0017] The method further comprises:

[0018] The data source description is acquired by the plug-in and loaded onto the front-end page to be used to interpret the database link.

[0019] Further, the plug-in is obtained based on a Java SPI (Service Provider Interface) mechanism.

[0020] Further, the database identifier is used to establish a connection between the GeoServer and the database.

[0021] The database driver class name is used to register the driver of the database to load the driver class of the database.

[0022] Further, the application embodiment further provides a device for connecting a GeoServer and a hive database, comprising:

[0023] A parameter acquisition module is configured to acquire connection parameters of the hive database by a plug-in and send the connection parameters to the GeoServer.

[0024] A data source creation module is configured to create a data source object corresponding to the hive database according to the connection parameters by the plug-in; the data source object comprises a database identifier and a database driver class name.

[0025] A connection module is configured to establish a connection between the GeoServer and the hive database based on the database identifier and the database driver class name by the plug-in.

[0026] Furthermore, embodiments of this application also provide a computer terminal, including a processor and a memory, wherein the memory stores a computer program, and the computer program, when run on the processor, executes a method for connecting GeoServer to a Hive database as described in any of the above embodiments.

[0027] Furthermore, embodiments of this application also provide a readable storage medium storing a computer program that, when run on a processor, executes a method for connecting a GeoServer to a Hive database as described in any of the above embodiments. Attached Figure Description

[0028] To more clearly illustrate the technical solution of the present invention, the accompanying drawings used in the embodiments will be briefly described below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope of protection of the present invention. In the various drawings, similar components are numbered similarly.

[0029] Figure 1 This application shows a schematic diagram of the network topology connecting GeoServer and the Hive database.

[0030] Figure 2 This application illustrates a connection process diagram of GeoServer connecting to a Hive database.

[0031] Figure 3 The diagram illustrates the process of obtaining the database identifier in this application.

[0032] Figure 4 This diagram shows a browser interface after the database connection of this application is established;

[0033] Figure 5 This application illustrates a schematic diagram of the table data flow in a Hive database where a GeoServer publishes a connection.

[0034] Figure 6 A schematic diagram of the structure of a GeoServer database connection device according to this application is shown. Detailed Implementation

[0035] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments.

[0036] The components of the embodiments of the invention described and illustrated herein can typically be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.

[0037] In the following, the terms “comprising,” “having,” and their cognates, which may be used in various embodiments of the invention, are intended only to indicate a particular feature, number, step, operation, element, component, or combination thereof, and should not be construed as excluding, firstly, the presence of one or more other features, numbers, steps, operations, elements, components, or combinations thereof, or adding the possibility of one or more features, numbers, steps, operations, elements, components, or combinations thereof.

[0038] Furthermore, the terms "first," "second," and "third" are used only to distinguish descriptions and should not be interpreted as indicating or implying relative importance.

[0039] Unless otherwise specified, all terms used herein (including technical and scientific terms) shall have the same meaning as commonly understood by one of ordinary skill in the art to which the various embodiments of the invention pertain. Terms (such as those defined in commonly used dictionaries) shall be interpreted as having the same meaning as in their contextual meaning in the relevant technical field and shall not be interpreted as having an idealized or overly formal meaning, unless clearly defined in the various embodiments of the invention.

[0040] Example 1

[0041] like Figure 1 The diagram shows the network topology diagram of the GeoServer and database connection in this application.

[0042] In this embodiment, GeoServer can be understood as a data service platform. Its core function is to process and unify table data or file data from heterogeneous data sources into a standard, universal format, and then share it for users to download and use. This requires obtaining various data from the database, i.e., establishing connections. However, different application scenarios require different database connections, necessitating switching between them. If all methods for connecting to different databases were written into GeoServer, the code would be highly redundant, resulting in deep coupling between the database connection code and the GeoServer main system. During GeoServer deployment, it would be necessary to remove those database connection methods based on user needs. Therefore, in this embodiment, a plugin developed based on the Java SPI (Service Provider Interface) mechanism is used to implement the functions of connecting GeoServer to the database and publishing data. Furthermore, its plug-and-play nature greatly facilitates GeoServer's adaptation to various environments and allows users to customize its functionality.

[0043] Example 2

[0044] This embodiment provides the plugin workflow and logic of this application. For example... Figure 2 As shown in the flowchart.

[0045] Step S100: Obtain the connection parameters of the Hive database through the plugin, and send the connection parameters to GeoServer;

[0046] The plugin in this embodiment is developed using the Java-based SPI mechanism. It implements the DataStoreFactorySPI interface based on the JDBCDataStoreFactory class of GeoTools and obtains connection parameters using six methods: getDriverClassName, getDatabaseID, getDisplayName, getDescription, getJDBCUrl, and createDataSource. In this step, when a user needs to connect to the database, they will inevitably enter connection parameters in the browser. These parameters include: IP address, port, database name, username, and password. Subsequently, the plugin can transmit this data to GeoServer to identify the data source type of the connection parameters. In this embodiment, the connection parameters are identified as Hive type.

[0047] Step S200: The plugin establishes a data source object corresponding to the Hive database based on the connection parameters; the data source object includes a database identifier and a database driver class name.

[0048] After obtaining the connection parameters, it is necessary to create a data source object corresponding to the Hive database based on the connection parameters. To achieve this, the createDataSource method needs to be called to create a new data source object. This data source object includes a database identifier and a database driver class name. These two parameters are used to establish the connection between GeoServer and the target database. The database identifier can be understood as the link ultimately used to connect to the database.

[0049] For detailed instructions, please refer to the following: Figure 3 The diagram shows the process of obtaining database identifiers.

[0050] Step S201: Obtain the database ID by reading the IP address, port, and database name from the connection parameters.

[0051] In this step of the embodiment, when the createDataSource method is called, the getJDBCUrl method and the getDriverClassName method will be executed automatically. The getJDBCUrl method is used to obtain the database identifier. The getDatabaseID method is executed to obtain the database ID by passing the address, port and database name in the connection parameters.

[0052] Step S202: According to preset rules, the address, port, database name and database ID are combined into the database identifier by string concatenation.

[0053] The specific preset rule can be shown in the following code snippet:

[0054] "jdbc:"+databaseID+": / / "+address+":"+port+" / "+databasename;

[0055] As shown above, the address, port, database name, and database ID are combined into a database identifier by string concatenation. This database identifier is then returned to the newly created data source object, thus establishing a connection between GeoServer and the target database through the data source object.

[0056] Specifically, the process of obtaining the database identifier can be as follows: for example, if the obtained address is 10.120.10.10, the port is 6300, the database name is hive1, and the database ID is 360, then the final identifier obtained is "jdbc:360: / / 10.120.10.10:6300 / hive1". Obviously, this final database identifier is a link pointing to the Hive database. Through this link, a connection between GeoServer and the database can be established.

[0057] While obtaining the database identifier, the createDataSource method also runs the getDriverClassName method. This method is used to obtain the startup class name of the target database. In this embodiment, for the Hive database, the driver class name returned by this method can be "org.apache.hive.jdbc.HiveDriver" or a similar derived class name, depending on the class name stored locally in the database. After obtaining the class name, the driver can be registered in GeoServe according to the class name, so that the Hive database driver class is loaded into the JVM (Java Virtual Machine).

[0058] Step S300: The plugin establishes a connection with the GeoServer and the Hive database based on the database identifier and the database driver class name.

[0059] After obtaining the database identifier and database driver class name of the Hive database, a connection can be established between GeoServer and the database. Specifically, a link identified by the data source name will appear in the browser. Users can click this link to establish a connection between GeoServer and the Hive database, access table data in the database, and perform operations such as publishing. The data source name is obtained by the getDisplayName method, which loads the data source name onto the front-end page. At the same time, the getDescription method will also obtain the data source description and load it onto the front-end page to interpret the data source object.

[0060] In this embodiment, the data source name of the Hive database is Hive. After the connection is established, a link named Hive will appear in the data source area of ​​the browser page. This link can be clicked to access the Hive database. Similarly, there will be a non-link string after the link, which is the data source description, such as "Hive database". This means that the link is used to connect to the Hive database. If the data source link is changed to another database, a similar name and description will be displayed.

[0061] Its specific effects are as follows Figure 4 As shown, the new data source page on the right contains various data source links. The one highlighted in the box is the data source established in this embodiment that connects to the Hive database, along with its description. After successfully establishing the data source, simply clicking the link will allow access to the Hive database table data, and thus, data publishing.

[0062] This embodiment also provides a method for publishing table data in a Hive database using GeoServer, such as... Figure 5 The flowchart described herein shows the steps involved.

[0063] Step S500: Select the registered data source.

[0064] Combination Figure 4 Understandably, pre-registered data sources will appear on the new data source side. These data sources identify databases or other services that have been successfully connected. In this example, we take the connected Hive database as an example. Select this data source to connect to the Hive database.

[0065] Step S501: Select the table data to be published.

[0066] After connecting to the database, locate the table data that needs to be published and return it to the front end.

[0067] Step S502: Enter the service name and corresponding service parameters.

[0068] Generally speaking, the published data is in a standard format, such as JSON or CSV, which requires special conversion. The format of the table data in the above steps is the service name and corresponding service parameters that need to be entered in this step.

[0069] Step S503: Publish the data.

[0070] Once the data in the above table has been converted, it can be published.

[0071] After completing the above steps, the connection between GeoServer and the Hive database is established, and the data source of the database is registered in GeoServer. Then, the table data can be converted into JSON or CSV format to publish the table data in the connected Hive database. After publication, other users can request the table data in the database in JSON or CSV format.

[0072] Example 3

[0073] This embodiment also provides a device for connecting GeoServer to a Hive database, such as... Figure 6 As shown, it includes a parameter acquisition module 10, a data source creation module 20, and a connection module 30.

[0074] The parameter acquisition module 10 is used to acquire the connection parameters of the Hive database through a plugin and send the connection parameters to GeoServer.

[0075] The data source creation module 20 is used to create a data source object corresponding to the Hive database through the plugin based on the connection parameters; the data source object includes a database identifier and a database driver class name.

[0076] The connection module 30 is used to establish a connection with the GeoServer and the Hive database through the plugin based on the database identifier and the database driver class name.

[0077] Embodiments of this application also provide a computer terminal, including a processor and a memory, wherein the memory stores a computer program, and the computer program, when run on the processor, executes any of the methods for connecting GeoServer and Hive databases described in the above embodiments.

[0078] Embodiments of this application also provide a readable storage medium storing a computer program that, when run on a processor, executes a method for connecting a GeoServer to a Hive database as described in the above embodiments.

[0079] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that, as an alternative implementation, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0080] In addition, the functional modules or units in the various embodiments of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0081] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a smartphone, personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0082] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for connecting GeoServer to a Hive database, characterized in that, include: Obtain the connection parameters of the Hive database through the plugin, and send the connection parameters to GeoServer; The plugin creates a data source object corresponding to the Hive database based on the connection parameters; the data source object includes a database identifier and a database driver class name. The plugin establishes a connection with the GeoServer and the Hive database based on the database identifier and the database driver class name. The connection parameters include IP address, port, database name, and password; The database ID is obtained by reading the IP address, port, and database name from the connection parameters; According to preset rules, the address, port, database name, and database ID are combined into the database identifier by string concatenation.

2. The method for connecting GeoServer and Hive database according to claim 1, characterized in that, The data source object also includes a data source name; The method also includes: The data source name is obtained through the plugin; The data source name is loaded onto the front-end page to form a database link consisting of the data source name; the database link is used to access the Hive database.

3. The method for connecting GeoServer and Hive database according to claim 2, characterized in that, The data source object also includes a data source description; The method also includes: The plugin obtains the data source description and loads it onto the front-end page to interpret the database connection.

4. A method for connecting GeoServer to a Hive database according to any one of claims 1 to 2, characterized in that, The plugin is based on Java's SPI (Service Provider Interface) mechanism.

5. The method for connecting GeoServer and Hive database according to claim 1, characterized in that, The database identifier is used to establish a connection between GeoServer and the database; The database driver class name is used to register the driver for the database in order to load the driver class for the database.

6. A device for connecting GeoServer to a Hive database, characterized in that, include: The parameter acquisition module is used to obtain the connection parameters of the Hive database through the plugin and send the connection parameters to GeoServer; The data source creation module is used to create a data source object corresponding to the Hive database based on the connection parameters through the plugin; the data source object includes a database identifier and a database driver class name. The connection module is used to establish a connection with the GeoServer and the Hive database through the plugin based on the database identifier and the database driver class name; The connection parameters include IP address, port, database name, and password; The database ID is obtained by reading the IP address, port, and database name from the connection parameters; According to preset rules, the address, port, database name, and database ID are combined into the database identifier by string concatenation.

7. A computer terminal, characterized in that, It includes a processor and a memory, the memory storing a computer program that, when run on the processor, executes a method for connecting a GeoServer to a Hive database according to any one of claims 1 to 5.

8. A readable storage medium, characterized in that, It stores a computer program that, when run on a processor, executes a method for connecting a GeoServer to a Hive database as described in any one of claims 1 to 5.