forked from Blazebit/blaze-persistence
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Blazebit#724] Test and fix for select fetching of optional correlati…
…on basis
- Loading branch information
Showing
4 changed files
with
189 additions
and
11 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
96 changes: 96 additions & 0 deletions
96
...src/test/java/com/blazebit/persistence/view/testsuite/fetch/subview/SubviewFetchTest.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,96 @@ | ||
/* | ||
* Copyright 2014 - 2019 Blazebit. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.blazebit.persistence.view.testsuite.fetch.subview; | ||
|
||
import com.blazebit.persistence.CriteriaBuilder; | ||
import com.blazebit.persistence.testsuite.base.jpa.category.NoDatanucleus; | ||
import com.blazebit.persistence.testsuite.base.jpa.category.NoEclipselink; | ||
import com.blazebit.persistence.testsuite.base.jpa.category.NoOpenJPA; | ||
import com.blazebit.persistence.testsuite.entity.Document; | ||
import com.blazebit.persistence.testsuite.entity.Person; | ||
import com.blazebit.persistence.testsuite.tx.TxVoidWork; | ||
import com.blazebit.persistence.view.EntityViewManager; | ||
import com.blazebit.persistence.view.EntityViewSetting; | ||
import com.blazebit.persistence.view.EntityViews; | ||
import com.blazebit.persistence.view.spi.EntityViewConfiguration; | ||
import com.blazebit.persistence.view.testsuite.AbstractEntityViewTest; | ||
import com.blazebit.persistence.view.testsuite.fetch.subview.model.DocumentSelectSubviewTestView; | ||
import com.blazebit.persistence.view.testsuite.fetch.subview.model.PersonSelectSubview; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
import javax.persistence.EntityManager; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* | ||
* @author Christian Beikov | ||
* @since 1.2.0 | ||
*/ | ||
public class SubviewFetchTest extends AbstractEntityViewTest { | ||
|
||
protected Document doc1; | ||
|
||
@Override | ||
public void setUpOnce() { | ||
cleanDatabase(); | ||
transactional(new TxVoidWork() { | ||
@Override | ||
public void work(EntityManager em) { | ||
doc1 = new Document("doc1"); | ||
|
||
Person o1 = new Person("pers1"); | ||
|
||
doc1.setOwner(o1); | ||
|
||
doc1.getStrings().add("s1"); | ||
doc1.getStrings().add("s2"); | ||
|
||
em.persist(o1); | ||
|
||
em.persist(doc1); | ||
|
||
o1.setPartnerDocument(doc1); | ||
} | ||
}); | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
doc1 = cbf.create(em, Document.class).where("name").eq("doc1").fetch("partners").getResultList().get(0); | ||
} | ||
|
||
@Test | ||
// NOTE: Eclipselink and Datanucleus don't support the single valued id access optimization which causes a cyclic join dependency | ||
@Category({ NoDatanucleus.class, NoOpenJPA.class, NoEclipselink.class }) | ||
public void testSubqueryFetch() { | ||
EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration(); | ||
cfg.addEntityView(DocumentSelectSubviewTestView.class); | ||
cfg.addEntityView(PersonSelectSubview.class); | ||
EntityViewManager evm = cfg.createEntityViewManager(cbf); | ||
|
||
CriteriaBuilder<Document> criteria = cbf.create(em, Document.class, "d").orderByAsc("id"); | ||
EntityViewSetting<DocumentSelectSubviewTestView, CriteriaBuilder<DocumentSelectSubviewTestView>> setting = EntityViewSetting.create(DocumentSelectSubviewTestView.class); | ||
CriteriaBuilder<DocumentSelectSubviewTestView> cb = evm.applySetting(setting, criteria); | ||
List<DocumentSelectSubviewTestView> results = cb.getResultList(); | ||
|
||
assertEquals(1, results.size()); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...lazebit/persistence/view/testsuite/fetch/subview/model/DocumentSelectSubviewTestView.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,36 @@ | ||
/* | ||
* Copyright 2014 - 2019 Blazebit. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.blazebit.persistence.view.testsuite.fetch.subview.model; | ||
|
||
import com.blazebit.persistence.testsuite.entity.Document; | ||
import com.blazebit.persistence.view.EntityView; | ||
import com.blazebit.persistence.view.IdMapping; | ||
|
||
/** | ||
* | ||
* @author Christian Beikov | ||
* @since 1.4.0 | ||
*/ | ||
@EntityView(Document.class) | ||
public interface DocumentSelectSubviewTestView { | ||
|
||
@IdMapping | ||
public Long getId(); | ||
|
||
public PersonSelectSubview getResponsiblePerson(); | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...java/com/blazebit/persistence/view/testsuite/fetch/subview/model/PersonSelectSubview.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,42 @@ | ||
/* | ||
* Copyright 2014 - 2019 Blazebit. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.blazebit.persistence.view.testsuite.fetch.subview.model; | ||
|
||
import com.blazebit.persistence.testsuite.entity.Document; | ||
import com.blazebit.persistence.testsuite.entity.Person; | ||
import com.blazebit.persistence.view.EntityView; | ||
import com.blazebit.persistence.view.FetchStrategy; | ||
import com.blazebit.persistence.view.IdMapping; | ||
import com.blazebit.persistence.view.Mapping; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* | ||
* @author Christian Beikov | ||
* @since 1.4.0 | ||
*/ | ||
@EntityView(Person.class) | ||
public interface PersonSelectSubview { | ||
|
||
@IdMapping | ||
public Long getId(); | ||
|
||
@Mapping(fetch = FetchStrategy.SELECT) | ||
public Set<Document> getOwnedDocuments(); | ||
|
||
} |