org.jooq.impl.SQLDataType Java Examples

The following examples show how to use org.jooq.impl.SQLDataType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: V8__CreateRolePermissions.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try (Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("role_permissions"))
                .column(field("role_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("permission_id", SQLDataType.BIGINT.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("role_id"), field("permission_id")),
                        constraint().foreignKey(field("role_id")).references(table("roles"), field("role_id")).onDeleteCascade(),
                        constraint().foreignKey(field("permission_id")).references(table("permissions"), field("permission_id")).onDeleteCascade()
                ).getSQL();
        stmt.execute(ddl);
    }
}
 
Example #2
Source File: V3__CreateApplications.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try (Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("applications"))
                .column(field("application_id", SQLDataType.BIGINT.identity(true)))
                .column(field("name", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("virtual_path", SQLDataType.VARCHAR(50).nullable(false)))
                .column(field("pass_to", SQLDataType.VARCHAR(255).nullable(false)))
                .column(field("top_page", SQLDataType.VARCHAR(255).nullable(false)))
                .column(field("description", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("write_protected", SQLDataType.BOOLEAN.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("application_id")),
                        constraint().unique(field("name")),
                        constraint().unique(field("virtual_path"))
                ).getSQL();

        stmt.execute(ddl);
    }

}
 
Example #3
Source File: V6__CreateRealms.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try (Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("realms"))
                .column(field("realm_id", SQLDataType.BIGINT.identity(true)))
                .column(field("name", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("url", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("application_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("description", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("write_protected", SQLDataType.BOOLEAN.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("realm_id")),
                        constraint().unique(field("name")),
                        constraint().foreignKey(field("application_id")).references(table("applications"), field("application_id")).onDeleteCascade()
                ).getSQL();
        stmt.execute(ddl);
    }
}
 
Example #4
Source File: V10__CreatePasswordCredentials.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
private void createPasswordCredentials(Connection connection) throws SQLException {
    try (Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("password_credentials"))
                .column(field("user_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("password", SQLDataType.VARBINARY(256).nullable(false)))
                .column(field("salt", SQLDataType.VARCHAR(16).nullable(false)))
                .column(field("initial", SQLDataType.BOOLEAN.nullable(false)))
                .column(field("created_at", SQLDataType.TIMESTAMP.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("user_id")),
                        constraint().foreignKey(field("user_id")).references(table("users"), field("user_id")).onDeleteCascade()
                ).getSQL();
        stmt.execute(ddl);

    }
}
 
Example #5
Source File: V22__AlterInvitations.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try(Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.alterTable(table("oidc_invitations"))
                .renameColumn(field("oidc_sub")).to(field("oidc_payload", SQLDataType.CLOB))
                .getSQL();
        if (create.configuration().dialect() == SQLDialect.MYSQL) {
            Matcher m = Pattern.compile("\\s+RENAME\\s+COLUMN\\s+(\\w+)\\s+TO\\s+", Pattern.CASE_INSENSITIVE).matcher(ddl);
            StringBuffer sb = new StringBuffer();
            if (m.find()) {
                m.appendReplacement(sb, " change " + m.group(1) + " ");
                m.appendTail(sb);
                sb.append(" text not null");
                ddl = sb.toString();
            }
        }

        stmt.execute(ddl);
    }
}
 
Example #6
Source File: V10__CreatePasswordCredentials.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
private void createPasswordResetChallenges(Connection connection) throws SQLException {
    try (Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("password_reset_challenges"))
                .column(field("id", SQLDataType.BIGINT.identity(true)))
                .column(field("user_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("code", SQLDataType.VARCHAR(64).nullable(false)))
                .column(field("expires_at", SQLDataType.TIMESTAMP.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("id"))
                )
                .getSQL();

        stmt.execute(ddl);

        stmt.execute(
                create.createIndex(name("idx_pass_reset_challenges_01"))
                        .on(table("password_reset_challenges"), field("code"))
                        .getSQL());

    }
}
 
Example #7
Source File: V15__CreateOidcUsers.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try(Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("oidc_users"))
                .column(field("oidc_provider_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("user_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("oidc_sub", SQLDataType.VARCHAR(255).nullable(false)))
                .constraints(
                        constraint().primaryKey(field("oidc_provider_id"), field("user_id")),
                        constraint().foreignKey(field("oidc_provider_id")).references(table("oidc_providers"), field("oidc_provider_id")).onDeleteCascade(),
                        constraint().foreignKey(field("user_id")).references(table("users"), field("user_id")).onDeleteCascade()
                ).getSQL();
        stmt.execute(ddl);
    }
}
 
Example #8
Source File: V14__CreateCertificateCredentials.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try(Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("certificate_credentials"))
                .column(field("user_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("client_dn", SQLDataType.VARCHAR(150).nullable(false)))
                .column(field("certificate", SQLDataType.BLOB.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("user_id")),
                        constraint().foreignKey(field("user_id")).references(table("users"), field("user_id")).onDeleteCascade()
                ).getSQL();
        stmt.execute(ddl);
    }
}
 
Example #9
Source File: V7__CreateMemberships.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try (Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("memberships"))
                .column(field("user_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("group_id", SQLDataType.BIGINT.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("user_id"), field("group_id")),
                        constraint().foreignKey(field("user_id")).references(table("users"), field("user_id")).onDeleteCascade(),
                        constraint().foreignKey(field("group_id")).references(table("groups"), field("group_id")).onDeleteCascade()
                ).getSQL();
        stmt.execute(ddl);
    }
}
 
Example #10
Source File: V18__CreateUserLocks.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try(Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("user_locks"))
                .column(field("user_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("lock_level", SQLDataType.VARCHAR(10).nullable(false)))
                .column(field("locked_at", SQLDataType.TIMESTAMP.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("user_id")),
                        constraint().foreignKey(field("user_id")).references(table("users"), field("user_id")).onDeleteCascade()
                ).getSQL();
        stmt.execute(ddl);
    }
}
 
Example #11
Source File: V21__CreateUserProfiles.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
private void createProfileVerification(Connection connection) throws SQLException {
    DSLContext create = DSL.using(connection);

    try (Statement stmt = connection.createStatement()) {
        String ddl = create.createTable(table("user_profile_verifications"))
                .column(field("user_profile_field_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("user_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("code", SQLDataType.VARCHAR(255).nullable(false)))
                .column(field("expires_at", SQLDataType.TIMESTAMP.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("user_profile_field_id"), field("user_id")),
                        constraint().foreignKey(field("user_profile_field_id"))
                                .references(table("user_profile_fields"), field("user_profile_field_id")).onDeleteCascade(),
                        constraint().foreignKey(field("user_id"))
                                .references(table("users"), field("user_id")).onDeleteCascade()
                )
                .getSQL();
        stmt.execute(ddl);
    }
}
 
Example #12
Source File: V4__CreateRoles.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try (Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("roles"))
                .column(field("role_id", SQLDataType.BIGINT.identity(true)))
                .column(field("name", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("description", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("write_protected", SQLDataType.BOOLEAN.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("role_id")),
                        constraint().unique(field("name"))
                ).getSQL();
        stmt.execute(ddl);
    }

}
 
Example #13
Source File: V2__CreateGroups.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try (Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("groups"))
                .column(field("group_id", SQLDataType.BIGINT.identity(true)))
                .column(field("name", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("description", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("write_protected", SQLDataType.BOOLEAN.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("group_id")),
                        constraint().unique(field("name"))
                ).getSQL();
        stmt.execute(ddl);
    }
}
 
Example #14
Source File: V19__CreateUserSessions.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try(Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("user_sessions"))
                .column(field("user_session_id", SQLDataType.BIGINT.identity(true)))
                .column(field("user_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("token", SQLDataType.VARCHAR(36).nullable(false)))
                .column(field("remote_address", SQLDataType.VARCHAR(255)))
                .column(field("user_agent", SQLDataType.VARCHAR(255)))
                .column(field("created_at", SQLDataType.TIMESTAMP.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("user_session_id")),
                        constraint().unique(field("token")),
                        constraint().foreignKey(field("user_id")).references(table("users"), field("user_id")).onDeleteCascade()
                ).getSQL();
        stmt.execute(ddl);
    }
}
 
Example #15
Source File: V5__CreatePermissions.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try (Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("permissions"))
                .column(field("permission_id", SQLDataType.BIGINT.identity(true)))
                .column(field("name", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("description", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("write_protected", SQLDataType.BOOLEAN.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("permission_id")),
                        constraint().unique(field("name"))
                ).getSQL();
        stmt.execute(ddl);
    }
}
 
Example #16
Source File: V21__CreateUserProfiles.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
private void createProfileFields(Connection connection) throws SQLException {
    DSLContext create = DSL.using(connection);
    try (Statement stmt = connection.createStatement()) {
        String ddl = create.createTable(table("user_profile_fields"))
                .column(field("user_profile_field_id", SQLDataType.BIGINT.identity(true)))
                .column(field("name", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("json_name", SQLDataType.VARCHAR(100).nullable(true)))
                .column(field("is_required", SQLDataType.BOOLEAN.nullable(false)))
                .column(field("is_identity", SQLDataType.BOOLEAN.nullable(false)))
                .column(field("regular_expression", SQLDataType.VARCHAR(255).nullable(true)))
                .column(field("min_length", SQLDataType.SMALLINT.nullable(true)))
                .column(field("max_length", SQLDataType.SMALLINT.nullable(true)))
                .column(field("needs_verification", SQLDataType.BOOLEAN.nullable(false)))
                .column(field("position", SQLDataType.TINYINT.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("user_profile_field_id")),
                        constraint().unique(field("name")),
                        constraint().unique(field("json_name"))
                ).getSQL();
        stmt.execute(ddl);
    }
}
 
Example #17
Source File: V21__CreateUserProfiles.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
private void createProfileValues(Connection connection) throws SQLException {
    DSLContext create = DSL.using(connection);

    try (Statement stmt = connection.createStatement()) {
        String ddl = create.createTable(table("user_profile_values"))
                .column(field("user_profile_field_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("user_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("value", SQLDataType.VARCHAR(255).nullable(false)))
                .constraints(
                        constraint().primaryKey(field("user_profile_field_id"), field("user_id")),
                        constraint().foreignKey(field("user_profile_field_id"))
                                .references(table("user_profile_fields"), field("user_profile_field_id")),
                        constraint().foreignKey(field("user_id"))
                                .references(table("users"), field("user_id"))
                )
                .getSQL();
        stmt.execute(ddl);
    }
}
 
Example #18
Source File: V1__CreateUsers.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try (Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("users"))
                .column(field("user_id", SQLDataType.BIGINT.identity(true)))
                .column(field("account", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("write_protected", SQLDataType.BOOLEAN.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("user_id")),
                        constraint().unique(field("account"))
                ).getSQL();
        stmt.execute(ddl);

        stmt.execute(
                create.createIndex(name("idx_users_01"))
                        .on(table("users"), field("account"))
                        .getSQL()
        );
    }
}
 
Example #19
Source File: V9__CreateAssinments.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try (Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("assignments"))
                .column(field("group_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("role_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("realm_id", SQLDataType.BIGINT.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("group_id"), field("role_id"), field("realm_id")),
                        constraint().foreignKey(field("group_id")).references(table("groups"), field("group_id")).onDeleteCascade(),
                        constraint().foreignKey(field("role_id")).references(table("roles"), field("role_id")).onDeleteCascade(),
                        constraint().foreignKey(field("realm_id")).references(table("realms"), field("realm_id")).onDeleteCascade()
                ).getSQL();
        stmt.execute(ddl);
    }
}
 
Example #20
Source File: PgExpressionHandler.java    From FROST-Server with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public FieldWrapper visit(Divide node) {
    List<Expression> params = node.getParameters();
    FieldWrapper p1 = params.get(0).accept(this);
    FieldWrapper p2 = params.get(1).accept(this);
    if (p1 instanceof TimeFieldWrapper) {
        TimeFieldWrapper ti1 = (TimeFieldWrapper) p1;
        return ti1.div(p2);
    }
    if (p2 instanceof TimeFieldWrapper) {
        throw new IllegalArgumentException("Can not devide by a TimeExpression.");
    }
    Field<Number> n1 = p1.getFieldAsType(Number.class, true);
    Field<Number> n2 = p2.getFieldAsType(Number.class, true);
    return new SimpleFieldWrapper(n1.divide(n2).coerce(SQLDataType.DOUBLE));
}
 
Example #21
Source File: V13__CreateOidcProviders.java    From bouncr with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try(Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("oidc_providers"))
                .column(field("oidc_provider_id", SQLDataType.BIGINT.identity(true)))
                .column(field("name", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("client_id", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("client_secret", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("scope", SQLDataType.VARCHAR(100)))
                .column(field("response_type", SQLDataType.VARCHAR(100)))
                .column(field("authorization_endpoint", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("token_endpoint", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("token_endpoint_auth_method", SQLDataType.VARCHAR(10).nullable(false)))
                .constraints(
                        constraint().primaryKey(field("oidc_provider_id")),
                        constraint().unique(field("name"))
                        ).getSQL();
        stmt.execute(ddl);
    }
}
 
Example #22
Source File: ContainerSchemaDefinition.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Create the Missing Containers table.
 */
private void createUnhealthyContainersTable() {
  dslContext.createTableIfNotExists(UNHEALTHY_CONTAINERS_TABLE_NAME)
      .column(CONTAINER_ID, SQLDataType.BIGINT.nullable(false))
      .column(CONTAINER_STATE, SQLDataType.VARCHAR(16).nullable(false))
      .column("in_state_since", SQLDataType.BIGINT.nullable(false))
      .column("expected_replica_count", SQLDataType.INTEGER.nullable(false))
      .column("actual_replica_count", SQLDataType.INTEGER.nullable(false))
      .column("replica_delta", SQLDataType.INTEGER.nullable(false))
      .column("reason", SQLDataType.VARCHAR(500).nullable(true))
      .constraint(DSL.constraint("pk_container_id")
          .primaryKey(CONTAINER_ID, CONTAINER_STATE))
      .constraint(DSL.constraint(UNHEALTHY_CONTAINERS_TABLE_NAME + "ck1")
          .check(field(name("container_state"))
              .in(UnHealthyContainerStates.values())))
      .execute();
}
 
Example #23
Source File: PgExpressionHandler.java    From FROST-Server with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public FieldWrapper visit(STRelate node) {
    Expression p1 = node.getParameters().get(0);
    Expression p2 = node.getParameters().get(1);
    Expression p3 = node.getParameters().get(2);
    FieldWrapper e1 = p1.accept(this);
    FieldWrapper e2 = p2.accept(this);
    FieldWrapper e3 = p3.accept(this);
    Field<Geometry> g1 = e1.getFieldAsType(Geometry.class, true);
    Field<Geometry> g2 = e2.getFieldAsType(Geometry.class, true);
    Field<String> g3 = e3.getFieldAsType(String.class, true);
    if (g1 == null || g2 == null || g3 == null) {
        throw new IllegalArgumentException("STRelate requires two geometries and a string, got " + e1 + ", " + e2 + " & " + e3);
    }
    return new SimpleFieldWrapper(DSL.condition(DSL.function("ST_Relate", SQLDataType.BOOLEAN, g1, g2, g3)));
}
 
Example #24
Source File: V16__CreateOidcApplications.java    From bouncr with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void migrate(Context context) throws Exception {
    Connection connection = context.getConnection();
    try(Statement stmt = connection.createStatement()) {
        DSLContext create = DSL.using(connection);
        String ddl = create.createTable(table("oidc_applications"))
                .column(field("oidc_application_id", SQLDataType.BIGINT.identity(true)))
                .column(field("name", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("client_id", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("client_secret", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("private_key", SQLDataType.BLOB.nullable(false)))
                .column(field("public_key", SQLDataType.BLOB.nullable(false)))
                .column(field("home_url", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("callback_url", SQLDataType.VARCHAR(100).nullable(false)))
                .column(field("description", SQLDataType.VARCHAR(255).nullable(false)))
                .constraints(
                        constraint().primaryKey(field("oidc_application_id")),
                        constraint().unique(field("name"))
                )
                .getSQL();

        stmt.execute(ddl);

        ddl = create.createTable(table("oidc_application_scopes"))
                .column(field("oidc_application_id", SQLDataType.BIGINT.nullable(false)))
                .column(field("permission_id", SQLDataType.BIGINT.nullable(false)))
                .constraints(
                        constraint().primaryKey(field("oidc_application_id"), field("permission_id")),
                        constraint().foreignKey(field("oidc_application_id"))
                                .references(table("oidc_applications"), field("oidc_application_id")).onDeleteCascade(),
                        constraint().foreignKey(field("permission_id"))
                                .references(table("permissions"), field("permission_id")).onDeleteCascade()
                )
                .getSQL();
        stmt.execute(ddl);
    }
}
 
Example #25
Source File: V1__CreateUserLicense.java    From bouncr with Eclipse Public License 1.0 5 votes vote down vote up
private void createUserLicense(DSLContext create, Statement stmt) throws SQLException {
    String ddl = create.createTable(table("user_licenses"))
            .column(field("user_license_id", SQLDataType.BIGINT.identity(true)))
            .column(field("user_id", SQLDataType.BIGINT.nullable(false)))
            .column(field("license_key", SQLDataType.VARBINARY(16).nullable(false)))
            .constraints(
                    constraint().primaryKey(field("user_license_id")),
                    constraint().foreignKey(field("user_id")).references(table("users"), field("user_id"))
                            .onDeleteCascade(),
                    constraint().unique(field("license_key"))
            ).getSQL();
    stmt.execute(ddl);
}
 
Example #26
Source File: V1__CreateUserLicense.java    From bouncr with Eclipse Public License 1.0 5 votes vote down vote up
private void createLastActivity(DSLContext create, Statement stmt) throws SQLException {
    String ddl = create.createTable(table("license_last_activities"))
            .column(field("license_last_activity_id", SQLDataType.BIGINT.identity(true)))
            .column(field("user_license_id", SQLDataType.BIGINT.nullable(false)))
            .column(field("user_agent", SQLDataType.VARCHAR(255)))
            .column(field("last_used_at", SQLDataType.TIMESTAMP.nullable(false)))
            .constraints(
                    constraint().primaryKey(field("license_last_activity_id")),
                    constraint().unique(field("user_license_id"))
            ).getSQL();
    stmt.execute(ddl);
}
 
Example #27
Source File: PgExpressionHandler.java    From FROST-Server with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public FieldWrapper visit(Modulo node) {
    List<Expression> params = node.getParameters();
    FieldWrapper p1 = params.get(0).accept(this);
    FieldWrapper p2 = params.get(1).accept(this);
    Field<? extends Number> n1 = p1.getFieldAsType(Number.class, true);
    Field<? extends Number> n2 = p2.getFieldAsType(Number.class, true);
    if (n1.getType().equals(Double.class)) {
        n1 = n1.cast(SQLDataType.NUMERIC);
    }
    if (n2.getType().equals(Double.class)) {
        n2 = n2.cast(SQLDataType.NUMERIC);
    }
    return new SimpleFieldWrapper(n1.mod(n2));
}
 
Example #28
Source File: PgExpressionHandler.java    From FROST-Server with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public FieldWrapper visit(Time node) {
    Expression param = node.getParameters().get(0);
    FieldWrapper input = param.accept(this);
    if (input instanceof TimeFieldWrapper) {
        TimeFieldWrapper timeExpression = (TimeFieldWrapper) input;
        if (!timeExpression.isUtc()) {
            throw new IllegalArgumentException("Constants passed to the time() function have to be in UTC.");
        }
        return new SimpleFieldWrapper(timeExpression.getDateTime().cast(SQLDataType.TIME));
    }
    throw new IllegalArgumentException("Time can only be used on times, not on " + input.getClass().getName());
}
 
Example #29
Source File: PgExpressionHandler.java    From FROST-Server with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public FieldWrapper visit(GeoDistance node) {
    Expression p1 = node.getParameters().get(0);
    Expression p2 = node.getParameters().get(1);
    FieldWrapper e1 = p1.accept(this);
    FieldWrapper e2 = p2.accept(this);
    Field<Geometry> g1 = e1.getFieldAsType(Geometry.class, true);
    Field<Geometry> g2 = e2.getFieldAsType(Geometry.class, true);
    if (g1 == null || g2 == null) {
        throw new IllegalArgumentException("GeoDistance requires two geometries, got " + e1 + " & " + e2);
    }
    return new SimpleFieldWrapper(DSL.function("ST_Distance", SQLDataType.NUMERIC, g1, g2));
}
 
Example #30
Source File: PgExpressionHandler.java    From FROST-Server with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public FieldWrapper visit(GeoLength node) {
    Expression p1 = node.getParameters().get(0);
    FieldWrapper e1 = p1.accept(this);
    Field<Geometry> g1 = e1.getFieldAsType(Geometry.class, true);
    if (g1 == null) {
        throw new IllegalArgumentException("GeoLength requires a geometry, got " + e1);
    }
    return new SimpleFieldWrapper(DSL.function("ST_Length", SQLDataType.NUMERIC, g1));
}