Skip to content

Commit 3bb570f

Browse files
authored
use bounded parameter type, CUBA 6.9 (#2)
1 parent e96eeab commit 3bb570f

7 files changed

Lines changed: 286 additions & 195 deletions

File tree

.idea/workspace.xml

Lines changed: 199 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
buildscript {
3-
ext.cubaVersion = '6.8.0'
3+
ext.cubaVersion = '6.9.2'
44
repositories {
55

66
maven {
@@ -33,7 +33,7 @@ def coreModule = project(":${modulePrefix}-core")
3333
def guiModule = project(":${modulePrefix}-gui")
3434
def webModule = project(":${modulePrefix}-web")
3535

36-
def servletApi = 'org.apache.tomcat:tomcat-servlet-api:8.0.26'
36+
def servletApi = 'javax.servlet:javax.servlet-api:3.1.0'
3737

3838

3939
apply(plugin: 'idea')
@@ -46,8 +46,8 @@ def bintrayRepositoryUrl = "https://api.bintray.com/maven/mariodavid/cuba-compon
4646
cuba {
4747
artifact {
4848
group = 'de.diedavids.cuba.entitysoftreference'
49-
version = "0.2.0"
50-
isSnapshot = false
49+
version = "0.3.0"
50+
isSnapshot = true
5151
}
5252
tomcat {
5353
dir = "$project.rootDir/deploy/tomcat"
Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1 @@
1-
-- begin DDCESF_CUSTOMER
2-
create table DDCESF_CUSTOMER (
3-
ID varchar(36) not null,
4-
VERSION integer not null,
5-
CREATE_TS timestamp,
6-
CREATED_BY varchar(50),
7-
UPDATE_TS timestamp,
8-
UPDATED_BY varchar(50),
9-
DELETE_TS timestamp,
10-
DELETED_BY varchar(50),
11-
--
12-
NAME varchar(255),
13-
--
14-
primary key (ID)
15-
)^
16-
-- end DDCESF_CUSTOMER
17-
-- begin DDCESF_COMMENT
18-
create table DDCESF_COMMENT (
19-
ID varchar(36) not null,
20-
VERSION integer not null,
21-
CREATE_TS timestamp,
22-
CREATED_BY varchar(50),
23-
UPDATE_TS timestamp,
24-
UPDATED_BY varchar(50),
25-
DELETE_TS timestamp,
26-
DELETED_BY varchar(50),
27-
--
28-
TEXT varchar(255),
29-
COMMENTABLE varchar(255),
30-
--
31-
primary key (ID)
32-
)^
33-
-- end DDCESF_COMMENT
34-
-- begin DDCESF_ORDER
35-
create table DDCESF_ORDER (
36-
ID integer not null,
37-
UUID varchar(36),
38-
--
39-
ORDER_DATE date,
40-
--
41-
primary key (ID)
42-
)^
43-
-- end DDCESF_ORDER
1+

modules/core/src/de/diedavids/cuba/entitysoftreference/SoftReferenceServiceBean.groovy

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package de.diedavids.cuba.entitysoftreference;
2+
3+
import com.haulmont.cuba.core.EntityManager;
4+
import com.haulmont.cuba.core.Persistence;
5+
import com.haulmont.cuba.core.Query;
6+
import com.haulmont.cuba.core.Transaction;
7+
import com.haulmont.cuba.core.entity.Entity;
8+
import com.haulmont.cuba.core.global.Metadata;
9+
import org.springframework.stereotype.Service;
10+
11+
import javax.inject.Inject;
12+
import java.util.Collection;
13+
import java.util.List;
14+
15+
@Service(SoftReferenceService.NAME)
16+
17+
public class SoftReferenceServiceBean implements SoftReferenceService {
18+
19+
@Inject
20+
private Persistence persistence;
21+
22+
@Inject
23+
Metadata metadata;
24+
25+
private Query createPolymorphicQuery(EntityManager em, Class<? extends Entity> polymorphicEntityClass,
26+
String attribute,
27+
Entity softReference,
28+
String view) {
29+
String tableName = getTableNameFromEntityClass(polymorphicEntityClass);
30+
Query query = em.createQuery("select e from " + tableName + " e where e." + attribute + " = :softReference");
31+
query.setParameter("softReference", softReference, false);
32+
33+
if (view != null) {
34+
query.setView(polymorphicEntityClass, view);
35+
}
36+
37+
return query;
38+
}
39+
40+
@Override
41+
public boolean doSoftReferencesExist(Class<? extends Entity> polymorphicEntityClass, Entity softReference, String attribute) {
42+
return !loadEntitiesForSoftReference(polymorphicEntityClass, softReference, attribute).isEmpty();
43+
}
44+
45+
@Override
46+
public <T extends Entity> Collection<T> loadEntitiesForSoftReference(Class<T> polymorphicEntityClass, Entity softReference, String attribute) {
47+
return loadEntitiesForSoftReference(polymorphicEntityClass, softReference, attribute, null);
48+
}
49+
50+
@Override
51+
public int countEntitiesForSoftReference(Class<? extends Entity> polymorphicEntityClass, Entity softReference, String attribute) {
52+
return loadEntitiesForSoftReference(polymorphicEntityClass, softReference, attribute).size();
53+
}
54+
55+
@Override
56+
public <T extends Entity> Collection<T> loadEntitiesForSoftReference(Class<T> polymorphicEntityClass,
57+
Entity softReference,
58+
String attribute,
59+
String view) {
60+
Transaction tx = persistence.createTransaction();
61+
EntityManager em = persistence.getEntityManager();
62+
Query query = createPolymorphicQuery(em, polymorphicEntityClass, attribute, softReference, view);
63+
List result = query.getResultList();
64+
65+
tx.commit();
66+
67+
return result;
68+
}
69+
70+
private String getTableNameFromEntityClass(Class<? extends Entity> polymorphicEntityClass) {
71+
return metadata.getClass(polymorphicEntityClass).getName();
72+
}
73+
}

modules/global/src/de/diedavids/cuba/entitysoftreference/SoftReferenceService.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
public interface SoftReferenceService {
1010
String NAME = "ddcesf_SoftReferenceService";
1111

12-
boolean doSoftReferencesExist(Class<Entity> polymorphicEntityClass, Entity softReference, String attribute);
12+
boolean doSoftReferencesExist(Class<? extends Entity> polymorphicEntityClass, Entity softReference, String attribute);
1313

14-
Collection<Entity> loadEntitiesForSoftReference(Class<Entity> polymorphicEntityClass, Entity softReference, String attribute);
15-
Collection<Entity> loadEntitiesForSoftReference(Class<Entity> polymorphicEntityClass, Entity softReference, String attribute, String view);
14+
<T extends Entity> Collection<T> loadEntitiesForSoftReference(Class<T> polymorphicEntityClass, Entity softReference, String attribute);
1615

17-
int countEntitiesForSoftReference(Class<Entity> polymorphicEntityClass, Entity softReference, String attribute);
16+
<T extends Entity> Collection<T> loadEntitiesForSoftReference(Class<T> polymorphicEntityClass, Entity softReference, String attribute, String view);
17+
18+
int countEntitiesForSoftReference(Class<? extends Entity> polymorphicEntityClass, Entity softReference, String attribute);
1819
}

studio-settings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
<functionalitySettings>
44
<functionality id="oneToOneIndex"
55
state="ENABLE"/>
6+
<functionality id="joinedInheritanceDeleteCascade"
7+
state="ENABLE"/>
8+
<functionality id="newFkConstraintNaming"
9+
state="ENABLE"/>
610
</functionalitySettings>
711
</studio>

0 commit comments

Comments
 (0)