Skip to content

Commit

Permalink
[#10] Add a Policy example
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Jan 11, 2024
1 parent 0ff641e commit 9f078f7
Show file tree
Hide file tree
Showing 6 changed files with 392 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.jooq.demo.java;

import org.jooq.DSLContext;
import org.jooq.demo.AbstractDemo;
import org.jooq.impl.*;
import org.junit.Test;

import static org.jooq.demo.java.db.Tables.CUSTOMER;
import static org.jooq.demo.java.db.Tables.PAYMENT;
import static org.jooq.demo.java.db.Tables.RENTAL;
import static org.jooq.impl.DSL.sum;

public class Demo17Policies extends AbstractDemo {

@Test
public void testPolicy() {
title("Policies allow for filtering out data in DML statements");

// Computed columns are a commercial only feature

//
// // Queries run with this configuration will only be able to access CUSTOMER_ID = 1 on the CUSTOMER and PAYMENT tables
// DSLContext c = ctx.configuration().derive(
// new DefaultPolicyProvider()
// .append(CUSTOMER, CUSTOMER.CUSTOMER_ID.eq(1L))
// .append(PAYMENT, PAYMENT.CUSTOMER_ID.eq(1L))
// ).dsl();
//
// c.select(PAYMENT.customer().FIRST_NAME, PAYMENT.customer().LAST_NAME, PAYMENT.AMOUNT)
// .from(PAYMENT)
// .fetch();
//
//

// More information here:
// - https://www.jooq.org/doc/latest/manual/sql-building/queryparts/policies/
}

@Test
public void testPolicyInheritance() {
title("Policies can be inherited between tables");

// Computed columns are a commercial only feature

//
// // Queries run with this configuration will only be able to access CUSTOMER_ID = 1 on the CUSTOMER table
// // This policy is inherited by various other tables by path specification
// DSLContext c1 = ctx.configuration().derive(
// new DefaultPolicyProvider()
// .append(CUSTOMER, CUSTOMER.CUSTOMER_ID.eq(1L),
// PAYMENT.customer(),
// RENTAL.customer())
// ).dsl();
//
// c1.select(sum(PAYMENT.AMOUNT))
// .from(PAYMENT)
// .fetch();
//
//

// More information here:
// - https://www.jooq.org/doc/latest/manual/sql-building/queryparts/policies/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.jooq.demo.kotlin

import org.jooq.demo.AbstractDemo
import org.jooq.demo.kotlin.db.tables.references.CUSTOMER
import org.jooq.demo.kotlin.db.tables.references.PAYMENT
import org.jooq.demo.kotlin.db.tables.references.RENTAL
import org.jooq.impl.DSL
import org.jooq.impl.*
import org.junit.Test

class Demo17Policies : AbstractDemo() {

@Test
fun testPolicy() {
title("Policies allow for filtering out data in DML statements")

// Computed columns are a commercial only feature

//
// // Queries run with this configuration will only be able to access CUSTOMER_ID = 1 on the CUSTOMER and PAYMENT tables
// val c = ctx.configuration().derive(
// DefaultPolicyProvider()
// .append(CUSTOMER, CUSTOMER.CUSTOMER_ID.eq(1L))
// .append(PAYMENT, PAYMENT.CUSTOMER_ID.eq(1L))
// ).dsl()
//
// c.select(
// PAYMENT.customer().FIRST_NAME,
// PAYMENT.customer().LAST_NAME,
// PAYMENT.AMOUNT
// )
// .from(PAYMENT)
// .fetch()
//
//

// More information here:
// - https://www.jooq.org/doc/latest/manual/sql-building/queryparts/policies/
}

@Test
fun testPolicyInheritance() {
title("Policies can be inherited between tables")

// Computed columns are a commercial only feature

//
// // Queries run with this configuration will only be able to access CUSTOMER_ID = 1 on the CUSTOMER table
// // This policy is inherited by various other tables by path specification
// val c1 = ctx.configuration().derive(
// DefaultPolicyProvider()
// .append(
// CUSTOMER, CUSTOMER.CUSTOMER_ID.eq(1L),
// PAYMENT.customer(),
// RENTAL.customer()
// )
// ).dsl()
//
// c1.select(DSL.sum(PAYMENT.AMOUNT))
// .from(PAYMENT)
// .fetch()
//
//

// More information here:
// - https://www.jooq.org/doc/latest/manual/sql-building/queryparts/policies/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.jooq.demo.scala

import org.jooq.DSLContext
import org.jooq.demo.AbstractDemo
import org.jooq.demo.AbstractDemo._
import org.jooq.impl._
import org.junit.Test
import org.jooq.demo.skala.db.Tables._
import org.jooq.impl.DSL.sum


class Demo17Policies extends AbstractDemo {

@Test
def testPolicy(): Unit = {
title("Policies allow for filtering out data in DML statements")

// Computed columns are a commercial only feature

//
// // Queries run with this configuration will only be able to access CUSTOMER_ID = 1 on the CUSTOMER and PAYMENT tables
// val c = ctx.configuration.derive(new DefaultPolicyProvider()
// .append(CUSTOMER, CUSTOMER.CUSTOMER_ID.eq(1L))
// .append(PAYMENT, PAYMENT.CUSTOMER_ID.eq(1L))
// ).dsl
//
// c.select(
// PAYMENT.customer.FIRST_NAME,
// PAYMENT.customer.LAST_NAME,
// PAYMENT.AMOUNT)
// .from(PAYMENT)
// .fetch
//
//

// More information here:
// - https://www.jooq.org/doc/latest/manual/sql-building/queryparts/policies/
}

@Test
def testPolicyInheritance(): Unit = {
title("Policies can be inherited between tables")

// Computed columns are a commercial only feature

//
// // Queries run with this configuration will only be able to access CUSTOMER_ID = 1 on the CUSTOMER table
// // This policy is inherited by various other tables by path specification
// val c1 = ctx.configuration.derive(new DefaultPolicyProvider()
// .append(CUSTOMER, CUSTOMER.CUSTOMER_ID.eq(1L),
// PAYMENT.customer,
// RENTAL.customer
// )
// ).dsl
//
// c1.select(sum(PAYMENT.AMOUNT))
// .from(PAYMENT)
// .fetch
//

// More information here:
// - https://www.jooq.org/doc/latest/manual/sql-building/queryparts/policies/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.jooq.demo.java;

import org.jooq.DSLContext;
import org.jooq.demo.AbstractDemo;
import org.jooq.impl.*;
import org.junit.Test;

import static org.jooq.demo.java.db.Tables.CUSTOMER;
import static org.jooq.demo.java.db.Tables.PAYMENT;
import static org.jooq.demo.java.db.Tables.RENTAL;
import static org.jooq.impl.DSL.sum;

public class Demo17Policies extends AbstractDemo {

@Test
public void testPolicy() {
title("Policies allow for filtering out data in DML statements");

// Computed columns are a commercial only feature
/* [pro] */

// Queries run with this configuration will only be able to access CUSTOMER_ID = 1 on the CUSTOMER and PAYMENT tables
DSLContext c = ctx.configuration().derive(
new DefaultPolicyProvider()
.append(CUSTOMER, CUSTOMER.CUSTOMER_ID.eq(1L))
.append(PAYMENT, PAYMENT.CUSTOMER_ID.eq(1L))
).dsl();

c.select(PAYMENT.customer().FIRST_NAME, PAYMENT.customer().LAST_NAME, PAYMENT.AMOUNT)
.from(PAYMENT)
.fetch();

/* [/pro] */

// More information here:
// - https://www.jooq.org/doc/latest/manual/sql-building/queryparts/policies/
}

@Test
public void testPolicyInheritance() {
title("Policies can be inherited between tables");

// Computed columns are a commercial only feature
/* [pro] */

// Queries run with this configuration will only be able to access CUSTOMER_ID = 1 on the CUSTOMER table
// This policy is inherited by various other tables by path specification
DSLContext c1 = ctx.configuration().derive(
new DefaultPolicyProvider()
.append(CUSTOMER, CUSTOMER.CUSTOMER_ID.eq(1L),
PAYMENT.customer(),
RENTAL.customer())
).dsl();

c1.select(sum(PAYMENT.AMOUNT))
.from(PAYMENT)
.fetch();

/* [/pro] */

// More information here:
// - https://www.jooq.org/doc/latest/manual/sql-building/queryparts/policies/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.jooq.demo.kotlin

import org.jooq.demo.AbstractDemo
import org.jooq.demo.kotlin.db.tables.references.CUSTOMER
import org.jooq.demo.kotlin.db.tables.references.PAYMENT
import org.jooq.demo.kotlin.db.tables.references.RENTAL
import org.jooq.impl.DSL
import org.jooq.impl.*
import org.junit.Test

class Demo17Policies : AbstractDemo() {

@Test
fun testPolicy() {
title("Policies allow for filtering out data in DML statements")

// Computed columns are a commercial only feature
/* [pro] */

// Queries run with this configuration will only be able to access CUSTOMER_ID = 1 on the CUSTOMER and PAYMENT tables
val c = ctx.configuration().derive(
DefaultPolicyProvider()
.append(CUSTOMER, CUSTOMER.CUSTOMER_ID.eq(1L))
.append(PAYMENT, PAYMENT.CUSTOMER_ID.eq(1L))
).dsl()

c.select(
PAYMENT.customer().FIRST_NAME,
PAYMENT.customer().LAST_NAME,
PAYMENT.AMOUNT
)
.from(PAYMENT)
.fetch()

/* [/pro] */

// More information here:
// - https://www.jooq.org/doc/latest/manual/sql-building/queryparts/policies/
}

@Test
fun testPolicyInheritance() {
title("Policies can be inherited between tables")

// Computed columns are a commercial only feature
/* [pro] */

// Queries run with this configuration will only be able to access CUSTOMER_ID = 1 on the CUSTOMER table
// This policy is inherited by various other tables by path specification
val c1 = ctx.configuration().derive(
DefaultPolicyProvider()
.append(
CUSTOMER, CUSTOMER.CUSTOMER_ID.eq(1L),
PAYMENT.customer(),
RENTAL.customer()
)
).dsl()

c1.select(DSL.sum(PAYMENT.AMOUNT))
.from(PAYMENT)
.fetch()

/* [/pro] */

// More information here:
// - https://www.jooq.org/doc/latest/manual/sql-building/queryparts/policies/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.jooq.demo.scala

import org.jooq.DSLContext
import org.jooq.demo.AbstractDemo
import org.jooq.demo.AbstractDemo._
import org.jooq.impl._
import org.junit.Test
import org.jooq.demo.skala.db.Tables._
import org.jooq.impl.DSL.sum


class Demo17Policies extends AbstractDemo {

@Test
def testPolicy(): Unit = {
title("Policies allow for filtering out data in DML statements")

// Computed columns are a commercial only feature
/* [pro] */

// Queries run with this configuration will only be able to access CUSTOMER_ID = 1 on the CUSTOMER and PAYMENT tables
val c = ctx.configuration.derive(new DefaultPolicyProvider()
.append(CUSTOMER, CUSTOMER.CUSTOMER_ID.eq(1L))
.append(PAYMENT, PAYMENT.CUSTOMER_ID.eq(1L))
).dsl

c.select(
PAYMENT.customer.FIRST_NAME,
PAYMENT.customer.LAST_NAME,
PAYMENT.AMOUNT)
.from(PAYMENT)
.fetch

/* [/pro] */

// More information here:
// - https://www.jooq.org/doc/latest/manual/sql-building/queryparts/policies/
}

@Test
def testPolicyInheritance(): Unit = {
title("Policies can be inherited between tables")

// Computed columns are a commercial only feature
/* [pro] */

// Queries run with this configuration will only be able to access CUSTOMER_ID = 1 on the CUSTOMER table
// This policy is inherited by various other tables by path specification
val c1 = ctx.configuration.derive(new DefaultPolicyProvider()
.append(CUSTOMER, CUSTOMER.CUSTOMER_ID.eq(1L),
PAYMENT.customer,
RENTAL.customer
)
).dsl

c1.select(sum(PAYMENT.AMOUNT))
.from(PAYMENT)
.fetch
/* [/pro] */

// More information here:
// - https://www.jooq.org/doc/latest/manual/sql-building/queryparts/policies/
}
}

0 comments on commit 9f078f7

Please sign in to comment.