diff --git a/jOOQ-demo-oss/jOOQ-demo-java/src/test/java/org/jooq/demo/java/Demo17Policies.java b/jOOQ-demo-oss/jOOQ-demo-java/src/test/java/org/jooq/demo/java/Demo17Policies.java new file mode 100644 index 0000000..0889fce --- /dev/null +++ b/jOOQ-demo-oss/jOOQ-demo-java/src/test/java/org/jooq/demo/java/Demo17Policies.java @@ -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/ + } +} diff --git a/jOOQ-demo-oss/jOOQ-demo-kotlin/src/test/kotlin/org/jooq/demo/kotlin/Demo17Policies.kt b/jOOQ-demo-oss/jOOQ-demo-kotlin/src/test/kotlin/org/jooq/demo/kotlin/Demo17Policies.kt new file mode 100644 index 0000000..335b414 --- /dev/null +++ b/jOOQ-demo-oss/jOOQ-demo-kotlin/src/test/kotlin/org/jooq/demo/kotlin/Demo17Policies.kt @@ -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/ + } +} diff --git a/jOOQ-demo-oss/jOOQ-demo-scala/src/test/scala/org/jooq/demo/skala/Demo17Policies.scala b/jOOQ-demo-oss/jOOQ-demo-scala/src/test/scala/org/jooq/demo/skala/Demo17Policies.scala new file mode 100644 index 0000000..45371cb --- /dev/null +++ b/jOOQ-demo-oss/jOOQ-demo-scala/src/test/scala/org/jooq/demo/skala/Demo17Policies.scala @@ -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/ + } +} diff --git a/jOOQ-demo-pro/jOOQ-demo-java/src/test/java/org/jooq/demo/java/Demo17Policies.java b/jOOQ-demo-pro/jOOQ-demo-java/src/test/java/org/jooq/demo/java/Demo17Policies.java new file mode 100644 index 0000000..15b81c2 --- /dev/null +++ b/jOOQ-demo-pro/jOOQ-demo-java/src/test/java/org/jooq/demo/java/Demo17Policies.java @@ -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/ + } +} diff --git a/jOOQ-demo-pro/jOOQ-demo-kotlin/src/test/kotlin/org/jooq/demo/kotlin/Demo17Policies.kt b/jOOQ-demo-pro/jOOQ-demo-kotlin/src/test/kotlin/org/jooq/demo/kotlin/Demo17Policies.kt new file mode 100644 index 0000000..9521332 --- /dev/null +++ b/jOOQ-demo-pro/jOOQ-demo-kotlin/src/test/kotlin/org/jooq/demo/kotlin/Demo17Policies.kt @@ -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/ + } +} diff --git a/jOOQ-demo-pro/jOOQ-demo-scala/src/test/scala/org/jooq/demo/skala/Demo17Policies.scala b/jOOQ-demo-pro/jOOQ-demo-scala/src/test/scala/org/jooq/demo/skala/Demo17Policies.scala new file mode 100644 index 0000000..03092af --- /dev/null +++ b/jOOQ-demo-pro/jOOQ-demo-scala/src/test/scala/org/jooq/demo/skala/Demo17Policies.scala @@ -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/ + } +}