Skip to content

Commit 73bcdb8

Browse files
author
Gerald Unterrainer
committed
add tenant-test table and start formulating sql-queries
bump version
1 parent 411760d commit 73bcdb8

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

Diff for: pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<modelVersion>4.0.0</modelVersion>
1919
<artifactId>http-server</artifactId>
20-
<version>0.2.9</version>
20+
<version>0.2.10</version>
2121
<name>HttpServer</name>
2222
<packaging>jar</packaging>
2323

Diff for: src/main/java/info/unterrainer/commons/httpserver/daos/BasicJpqlDao.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,6 @@ else if (!orderBy.isBlank())
252252
if (type != null)
253253
t = type;
254254

255-
if (query.contains("nullo.id"))
256-
System.out.println("");
257255
TypedQuery<T> q = em.createQuery(query, t);
258256
if (lockPessimistic)
259257
q.setLockMode(LockModeType.PESSIMISTIC_WRITE);
@@ -264,6 +262,20 @@ else if (!orderBy.isBlank())
264262
return q;
265263
}
266264

265+
private boolean isAllowed(final info.unterrainer.commons.httpserver.daos.QueryBuilder query,
266+
final EntityManager em) {
267+
String tenantReferenceField = "testId";
268+
String tenantIdField = "tenantId";
269+
Long tenantId = 55L;
270+
BasicJpa tenantJpa = null;
271+
getQuery(em, "o",
272+
"RIGHT JOIN " + tenantJpa.getClass().getSimpleName() + " tenantTable on o.id = tenantTable."
273+
+ tenantReferenceField,
274+
"tenantTable." + tenantReferenceField + " IS NULL OR tenantTable." + tenantIdField + " = :tenantId",
275+
null, type, null, false, null);
276+
return true;
277+
}
278+
267279
Query getCountQuery(final EntityManager em, final String selectClause, final String joinClause,
268280
final String whereClause, final Map<String, Object> params, final Set<AsyncState> asyncStates) {
269281
String query = "SELECT COUNT(" + selectClause + ") FROM %s AS o";

Diff for: src/test/resources/db/info/unterrainer/commons/httpserver/changelog-1.xml

+32
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,36 @@
4949
</createTable>
5050
</changeSet>
5151

52+
<changeSet author="GUN" id="1.2">
53+
<createTable tableName="test_permission"
54+
remarks="Contains tenant-ids for test-entries.">
55+
<column name="id" type="BIGINT" autoIncrement="true">
56+
<constraints nullable="false" primaryKey="true"
57+
primaryKeyName="pk_test_permission" unique="true"
58+
uniqueConstraintName="uc_test_permission_id" />
59+
</column>
60+
61+
<column name="testId" type="BIGINT">
62+
<constraints nullable="true" />
63+
</column>
64+
65+
<column name="tenantId" type="BIGINT">
66+
<constraints nullable="true" />
67+
</column>
68+
69+
<column name="createdOn" type="TIMESTAMP(6)">
70+
<constraints nullable="true" />
71+
</column>
72+
<column name="editedOn" type="TIMESTAMP(6)">
73+
<constraints nullable="true" />
74+
</column>
75+
</createTable>
76+
77+
<addForeignKeyConstraint
78+
baseColumnNames="testId" baseTableName="test_permission"
79+
constraintName="fk_test_permission_test_id"
80+
referencedColumnNames="id" referencedTableName="test"
81+
onDelete="CASCADE" onUpdate="RESTRICT" />
82+
</changeSet>
83+
5284
</databaseChangeLog>

0 commit comments

Comments
 (0)