Skip to content

Commit 5e4a6fd

Browse files
Limit/Offset MQL translation
1 parent 7573ef2 commit 5e4a6fd

File tree

10 files changed

+844
-15
lines changed

10 files changed

+844
-15
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2025-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.mongodb.hibernate;
18+
19+
import com.mongodb.hibernate.dialect.MongoDialect;
20+
import java.util.concurrent.atomic.AtomicInteger;
21+
import org.hibernate.dialect.Dialect;
22+
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
23+
import org.hibernate.engine.spi.SessionFactoryImplementor;
24+
import org.hibernate.sql.ast.SqlAstTranslator;
25+
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
26+
import org.hibernate.sql.ast.tree.MutationStatement;
27+
import org.hibernate.sql.ast.tree.select.SelectStatement;
28+
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
29+
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
30+
import org.hibernate.sql.model.ast.TableMutation;
31+
import org.hibernate.sql.model.jdbc.JdbcMutationOperation;
32+
33+
public final class TestDialect extends Dialect {
34+
private final AtomicInteger selectTranslatingCounter = new AtomicInteger();
35+
private final Dialect delegate;
36+
37+
public TestDialect(DialectResolutionInfo info) {
38+
super(info);
39+
delegate = new MongoDialect(info);
40+
}
41+
42+
@Override
43+
public SqlAstTranslatorFactory getSqlAstTranslatorFactory() {
44+
return new SqlAstTranslatorFactory() {
45+
@Override
46+
public SqlAstTranslator<JdbcOperationQuerySelect> buildSelectTranslator(
47+
SessionFactoryImplementor sessionFactory, SelectStatement statement) {
48+
selectTranslatingCounter.incrementAndGet();
49+
return delegate.getSqlAstTranslatorFactory().buildSelectTranslator(sessionFactory, statement);
50+
}
51+
52+
@Override
53+
public SqlAstTranslator<? extends JdbcOperationQueryMutation> buildMutationTranslator(
54+
SessionFactoryImplementor sessionFactory, MutationStatement statement) {
55+
return delegate.getSqlAstTranslatorFactory().buildMutationTranslator(sessionFactory, statement);
56+
}
57+
58+
@Override
59+
public <O extends JdbcMutationOperation> SqlAstTranslator<O> buildModelMutationTranslator(
60+
TableMutation<O> mutation, SessionFactoryImplementor sessionFactory) {
61+
return delegate.getSqlAstTranslatorFactory().buildModelMutationTranslator(mutation, sessionFactory);
62+
}
63+
};
64+
}
65+
66+
public int getSelectTranslatingCounter() {
67+
return selectTranslatingCounter.get();
68+
}
69+
}

src/integrationTest/java/com/mongodb/hibernate/query/select/Book.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ class Book {
4343
this.publishYear = publishYear;
4444
this.outOfStock = outOfStock;
4545
}
46+
47+
@Override
48+
public String toString() {
49+
return "Book{" + "id=" + id + '}';
50+
}
4651
}

0 commit comments

Comments
 (0)