In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article to share with you is about the implementation principle of J-Hi query filter is what, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after some gains, not much to say, follow Xiaobian to see it.
J-Hi designed its own query filter instead of directly adopting Hibernate's Criteria for two reasons:
Hibernate's Criteria function is very powerful, but it is still relatively cumbersome to use. So J-Hi wanted to design a query filter that was easy for users to use.
J-Hi is a multi-framework platform across ORM, and cannot stick to a product that is only applicable to Hibernate. Therefore, from a design perspective, J-Hi must have an intermediate layer for query filtering functionality to make it possible to accommodate multiple ORM frameworks.
Let's look at what to consider specifically for SQL queries
1. Field name Field name of database table
Operators such as greater than, less than... Special operators such as like and in are included
3, NO NO operator is a complement to the operator, only in and lik will also have no
4. The specific value of the field type corresponding to the value, such as the string should be quoted, and the date should be converted.
5, null null value is a special value, such as the expression form IS NULL or IS NOT NULL
The relationship between two query conditions includes three types of AND OR NOT
7. The superior level controls the superior level of query conditions through left and right brackets
8, 8, wildcard If it is like operator, you can control the matching condition of the value by % on the left or right side or both sides of the value.
For java, it is nothing more than considering how to implement the above description in an object-oriented way.
Let's start with an example:
Filter filter = FilterFactory.getSimpleFilter("name", "Ma Chao");
First, all filters must be created by FilterFactory. The parameters are
name: string of attribute names of POJOs, which can be passed through. cascade such as (org.id);
value: filtered value to be filtered
oprtion: operator, provides a variety of operators, see javadoc for details
relation: a relation between two filters, such as AND / OR / NOT
Filters can accumulate filter conditions through the addCondition method, for example:
filter.addCondition("name", "Zhao Yun", Filter.OPERATOR_EQ,Filter.RELATION_OR);
Calling addCondition () returns the cumulative Filter, so you can keep calling addCondition () instead of creating a new Flter for each filter condition.
You can also merge two filter joins together using the addFilter method
otherFilter.addFilter(filter, Filter.RELATION_AND);
Because a filter can have multiple query criteria, the two filters are automatically bracketed when they are merged by addFilter(). SQL is:
(otherFilter's query criteria) and (name like '% Ma Chao %' or name ='Zhao Yun')
Corresponding to addFilter, J-Hi also provides the removeFilter function, which aims to delete the subfilters that have been added through the target filter.
otherFilter.remove(filter);
For string operations, if no operator is added, the system defaults to the like operator, and wildcards are added on both sides. In order to solve the wildcard problem, J-Hi provides
Filter likeFilter = FilterFactory.getLikeFilter("name", "Ma Chao", Filter.RELATION_AND, LikeFilter. LIKE_CONTROLER_LEFT );
The corresponding SQL name is: name like '% Ma Chao'
If you filter for null or non-null
FilterFactory.getSimpleFilter(propertyName, null, Filter.OPERATOR_EQ); FilterFactory.getSimpleFilter(propertyName, null, Filter.OPERATOR_NOT_EQ);
The corresponding SQL statements are: propertyName IS NULL ; propertyName IS NOT NULL
If do include (IN) do filter
FilterFactory.getInFilter(propertyName, coll);
where coll is an object of the java.util.Collection interface
In addition, J-Hi also provides a sorter.
Sorter sorter = SorterFactory.getSimpleSort(propertyName, Sorter.ORDER_DESC); Sorter.addSort(properyName1, Sorter.ORDER_ASC);
First, all sorters must be created by SorterFactory. Sorters can be accumulated by addSort method. You can also merge two sorter joins together by adding Sort
Specific call methods such as:
HiUserManager userMgr = (HiUserManager)SpringContextHolder.getBean(HiUser.class); userMger.getObjects(filter,sorter);
Summary: J-Hi's query filters are not as powerful as Hibernate's Criteria and do not support outer joins and aggregations. The reason is that this large amount of data statistics is not a good solution for ORM framework implementation efficiency, and moreover, implementing the above functions increases the complexity of user operations. J-Hi's query filter does not perform the above functions for the above two reasons.
The above is what the implementation principle of J-Hi query filter is. Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.