Skip to content

Commit 7dd38d3

Browse files
committed
Revert "feat: Added isShouldClearContext configuration to invoke clear() for EM"
This reverts commit c5ac022.
1 parent 14964ec commit 7dd38d3

File tree

2 files changed

+6
-25
lines changed

2 files changed

+6
-25
lines changed

graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/GraphQLJpaQueryDataFetcher.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,12 @@ class GraphQLJpaQueryDataFetcher extends QraphQLJpaBaseDataFetcher {
5353
private final static Logger logger = LoggerFactory.getLogger(GraphQLJpaQueryDataFetcher.class);
5454

5555
private boolean defaultDistinct = true;
56-
private boolean isShouldClearContext = true;
5756

5857
protected static final String HIBERNATE_QUERY_PASS_DISTINCT_THROUGH = "hibernate.query.passDistinctThrough";
5958
protected static final String ORG_HIBERNATE_CACHEABLE = "org.hibernate.cacheable";
6059
protected static final String ORG_HIBERNATE_FETCH_SIZE = "org.hibernate.fetchSize";
6160
protected static final String ORG_HIBERNATE_READ_ONLY = "org.hibernate.readOnly";
6261
protected static final String JAVAX_PERSISTENCE_FETCHGRAPH = "javax.persistence.fetchgraph";
63-
protected static final String HIBERNATE_CACHE_USE_QUERY_CACHE = "hibernate.cache.use_query_cache";
6462

6563
private GraphQLJpaQueryDataFetcher(EntityManager entityManager, EntityType<?> entityType, boolean toManyDefaultOptional) {
6664
super(entityManager, entityType, toManyDefaultOptional);
@@ -69,11 +67,9 @@ private GraphQLJpaQueryDataFetcher(EntityManager entityManager, EntityType<?> en
6967
public GraphQLJpaQueryDataFetcher(EntityManager entityManager,
7068
EntityType<?> entityType,
7169
boolean defaultDistinct,
72-
boolean toManyDefaultOptional,
73-
boolean isShouldClearContext) {
70+
boolean toManyDefaultOptional) {
7471
super(entityManager, entityType, toManyDefaultOptional);
7572
this.defaultDistinct = defaultDistinct;
76-
this.isShouldClearContext = isShouldClearContext;
7773
}
7874

7975
public boolean isDefaultDistinct() {
@@ -130,24 +126,20 @@ public Object get(DataFetchingEnvironment environment) {
130126
// Let' try reduce overhead and disable all caching
131127
query.setHint(ORG_HIBERNATE_READ_ONLY, true);
132128
query.setHint(ORG_HIBERNATE_FETCH_SIZE, 1000);
133-
query.setHint(ORG_HIBERNATE_CACHEABLE, true);
129+
query.setHint(ORG_HIBERNATE_CACHEABLE, false);
134130

135131
// Let's not pass distinct if enabled to have better performance
136132
if(isDistinct) {
137133
query.setHint(HIBERNATE_QUERY_PASS_DISTINCT_THROUGH, false);
138134
}
139135

140-
if(isShouldClearContext) {
141-
entityManager.clear();
142-
}
143-
144136
if (logger.isDebugEnabled()) {
145137
logger.info("JPQL Query String: {}", getJPQLQueryString(query));
146138
}
147139

148140
// Let's execute query
149141
List<?> resultList = query.getResultList();
150-
142+
151143
// Let's remove any duplicate references for root entities
152144
if(isDistinct) {
153145
resultList = resultList.stream()
@@ -258,10 +250,6 @@ public Page(Integer page, Integer size) {
258250
}
259251
}
260252

261-
public boolean isShouldClearContext() {
262-
return isShouldClearContext;
263-
}
264-
265253
protected String getJPQLQueryString(TypedQuery<?> query) {
266254
try {
267255
Object queryImpl = query.unwrap(TypedQuery.class);
@@ -273,11 +261,10 @@ protected String getJPQLQueryString(TypedQuery<?> query) {
273261

274262
return queryStringField.get(queryImpl)
275263
.toString();
276-
277264
} catch (Exception ignored) {
278265
logger.error("Error getting JPQL string", ignored);
279266
}
280267

281-
return null;
268+
return null;
282269
}
283270
}

graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/GraphQLJpaSchemaBuilder.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ public class GraphQLJpaSchemaBuilder implements GraphQLSchemaBuilder {
114114
private boolean isUseDistinctParameter = false;
115115
private boolean isDefaultDistinct = true;
116116
// the many end is a collection, and it is always optional by default (empty collection)
117-
private boolean toManyDefaultOptional = true;
118-
private boolean isShouldClearContext = true;
117+
private boolean toManyDefaultOptional = true;
119118

120119
public GraphQLJpaSchemaBuilder(EntityManager entityManager) {
121120
this.entityManager = entityManager;
@@ -207,8 +206,7 @@ private GraphQLFieldDefinition getQueryFieldSelectDefinition(EntityType<?> entit
207206
.dataFetcher(new GraphQLJpaQueryDataFetcher(entityManager,
208207
entityType,
209208
isDefaultDistinct,
210-
toManyDefaultOptional,
211-
isShouldClearContext))
209+
toManyDefaultOptional))
212210
.argument(paginationArgument)
213211
.argument(getWhereArgument(entityType));
214212
if (isUseDistinctParameter) {
@@ -1165,9 +1163,5 @@ public boolean isToManyDefaultOptional() {
11651163
public void setToManyDefaultOptional(boolean toManyDefaultOptional) {
11661164
this.toManyDefaultOptional = toManyDefaultOptional;
11671165
}
1168-
1169-
public void setShouldClearContext(boolean isShouldClearContext) {
1170-
this.isShouldClearContext = isShouldClearContext;
1171-
}
11721166

11731167
}

0 commit comments

Comments
 (0)