Home » 2020 » Dezember

Archiv für den Monat: Dezember 2020

Criteria API – Tutorials

Basics: https://www.baeldung.com/hibernate-criteria-queries

Overview: https://www.baeldung.com/learn-jpa-hibernate

Alternativ: https://www.objectdb.com/java/jpa/query/criteria

Speziell:

Oder man nimmt JPQL:

https://thorben-janssen.com/jpql/

Criteria API: Join mit Filter auf beiden joined Tables

Der Knackpunkt is dieser:

Mit

Root<TabelleA> root = query.from(TabelleA.class)

wird die Ausgangstabelle (root) bezeichnet.

Mit

Join<TabelleA, TablleB> join = root.join(TabelleA.bRef);

wir TabelleB hinzu ge-joined.

Wichig Referenzen (z.B. der Filter auf das Feld feldXY) müssen nun von join aus gehen:

join.get(TablleB.feldXY)

Oder die ganze Where-Clause:

.where(criteriaBuilder.equal(root.get(TabelleA.id), "id000001"),
 criteriaBuilder.like( join.get(TablleB.feldXY), "%gesuchterInhalt%"))

 

Ganze Beispiel

CriteriaBuilder criteriaBuilder = ippDaoProvider.getEntityManager().getCriteriaBuilder();
CriteriaQuery<TabelleA> query = criteriaBuilder.createQuery(TabelleA.class);
Root<TabelleA> root = query.from(TabelleA.class);
Join<TabelleA, TablleB> join = root.join(TabelleA.bRef);

query.select(root).where(criteriaBuilder.equal(root.get(TabelleA.id), "id000001"),
        criteriaBuilder.like( join.get(TablleB.feldXY), "%gesuchterInhalt%"));

List<TabelleA> aList =  daoProvider.getTableADao().find(query);

 

 

Eclipse RCP JUnit tests with SWT checks

The basing question:
How to do JUnit tests for RCP classes that create SWT GUI?

Vorgehen/Hinweise:

  • The „Run As“ dialog of Eclipse offers a „Run as Plugin“ option which must be used if OSGI features are used in the test.
  • If OSGI features are needed (e.g. an OSGI service is part of the game) than OSGI a BundleContext  has to be set up. Read OSGI Component Testing (Integration testing / “black-box-testing”) and perhaps OSGI BundleContext.java.
    If this is done, then a Bundle can be invoked/setup by FrameworkUtil.getBundle(AnyClassInTheTestPlugin.java)

To read:

OSGI Component Testing

OSGI BundleContext.java    –> siehe Mindmap unten!

Eclipse-test-plugin

Testing OSGI Based Applications –> PDF Version

Bundle Context

 

Setting up Eclipse like context for dependency injection:

If the class A has an annotation like

@Inject
C c;

Then a class A can be retrieved that has an object of C already injected like that:

IEclipseContext context = EclipseContextFactory.create("test context");
context.set(C.class, new C(...));
A a = ContextInjectionFactory.make(A.class, context);

 

Problem while running on Linux Jenkins

org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed]

 

xxx

MS Access – Not in Query

In Oracle würde man schreiben:

select feldA
from Table1
where feldA not in (select feldB from Table2);

Pendent in MS Access:

SELECT feldA
FROM Table1
LEFT JOIN Table2
ON Table1.[feldA]=Table2.[feldB];