Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-11640 - NamedQuery doesn't log comment when UPDATE/DELETE
HHH-11906 - Add support for MySQL query optimizer hints
- Loading branch information
1 parent
08cd580
commit 72506a6
Showing
16 changed files
with
539 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
hibernate-core/src/main/java/org/hibernate/dialect/hint/IndexQueryHintHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.dialect.hint; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Adds an INDEX query hint as follows: | ||
* | ||
* <code> | ||
* SELECT * | ||
* FROM TEST | ||
* USE INDEX (hint1, hint2) | ||
* WHERE X=1 | ||
* </code> | ||
* | ||
* @author Vlad Mihalcea | ||
*/ | ||
public class IndexQueryHintHandler implements QueryHintHandler { | ||
|
||
public static final IndexQueryHintHandler INSTANCE = new IndexQueryHintHandler(); | ||
|
||
private static final Pattern QUERY_PATTERN = Pattern.compile( "^(select.*?from.*?)(where.*?)$" ); | ||
|
||
@Override | ||
public String addQueryHints(String query, String hints) { | ||
Matcher matcher = QUERY_PATTERN.matcher( query ); | ||
if ( matcher.matches() && matcher.groupCount() > 1 ) { | ||
String startToken = matcher.group( 1 ); | ||
String endToken = matcher.group( 2 ); | ||
|
||
return new StringBuilder( startToken ) | ||
.append( " USE INDEX (" ) | ||
.append( hints ) | ||
.append( ") " ) | ||
.append( endToken ) | ||
.toString(); | ||
} | ||
else { | ||
return query; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
hibernate-core/src/main/java/org/hibernate/dialect/hint/QueryHintHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.dialect.hint; | ||
|
||
/** | ||
* Contract defining how query hints get applied. | ||
* | ||
* @author Vlad Mihalcea | ||
*/ | ||
public interface QueryHintHandler { | ||
|
||
/** | ||
* Add query hints to the given query. | ||
* | ||
* @param query original query | ||
* @param hints hints to be applied | ||
* @return query with hints | ||
*/ | ||
String addQueryHints(String query, String hints); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.