001/* 002 * Copyright (c) 2026, Oracle and/or its affiliates. 003 * 004 * Licensed under the Universal Permissive License Version 1.0 as shown at 005 * https://oss.oracle.com/licenses/upl/ 006 */ 007package com.oracle.database.selectai; 008 009import com.oracle.database.selectai.impl.DatabaseAdminFactory; 010import com.oracle.database.selectai.model.DbConnectionConfig; 011import com.oracle.database.selectai.model.SelectAIException; 012import com.oracle.database.selectai.model.SelectAIOptions; 013 014import javax.sql.DataSource; 015import java.util.List; 016 017/** 018 * Administrative API contract for privileged database setup operations used by 019 * Select AI. 020 * <p> 021 * Normal application code should use {@link SelectAI}. Use 022 * {@code DatabaseAdmin} only from setup or administrative workflows that run 023 * with database users authorized to change package privileges, data-access 024 * settings, or network ACL entries. 025 */ 026public interface DatabaseAdmin extends AutoCloseable { 027 /** 028 * Creates a DatabaseAdmin client from database connection configuration. 029 * <p> 030 * For a complete runnable sample source, see 031 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/databaseadmin/GrantPrivilegesSample.html"> 032 * GrantPrivilegesSample source</a>. 033 * 034 * @param dbConnectionConfig database connection configuration 035 * @return DatabaseAdmin client 036 * @throws IllegalArgumentException when {@code dbConnectionConfig} is null 037 * @throws SelectAIException when the database connection cannot be initialized 038 */ 039 static DatabaseAdmin create(DbConnectionConfig dbConnectionConfig) throws SelectAIException { 040 return DatabaseAdminFactory.create(dbConnectionConfig); 041 } 042 043 /** 044 * Creates a DatabaseAdmin client from database connection configuration and 045 * SDK execution options. 046 * <p> 047 * For a complete runnable sample source, see 048 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/databaseadmin/CreateDatabaseAdminWithOptionsSample.html"> 049 * CreateDatabaseAdminWithOptionsSample source</a>. 050 * 051 * @param dbConnectionConfig database connection configuration 052 * @param options SDK execution options; {@code null} uses {@link SelectAIOptions#defaults()} 053 * @return DatabaseAdmin client 054 * @throws IllegalArgumentException when {@code dbConnectionConfig} is null 055 * @throws SelectAIException when the database connection cannot be initialized 056 */ 057 static DatabaseAdmin create(DbConnectionConfig dbConnectionConfig, SelectAIOptions options) 058 throws SelectAIException { 059 return DatabaseAdminFactory.create(dbConnectionConfig, options); 060 } 061 062 /** 063 * Creates a DataSource-backed DatabaseAdmin client. 064 * <p> 065 * For a complete runnable sample source, see 066 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/databaseadmin/CreateDatabaseAdminDataSourceSample.html"> 067 * CreateDatabaseAdminDataSourceSample source</a>. 068 * 069 * @param dataSource DataSource used to obtain JDBC connections 070 * @return DatabaseAdmin client 071 * @throws IllegalArgumentException when {@code dataSource} is null 072 */ 073 static DatabaseAdmin create(DataSource dataSource) { 074 return DatabaseAdminFactory.create(dataSource); 075 } 076 077 /** 078 * Creates a DataSource-backed DatabaseAdmin client with SDK execution options. 079 * <p> 080 * For a complete runnable sample source, see 081 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/databaseadmin/CreateDatabaseAdminDataSourceWithOptionsSample.html"> 082 * CreateDatabaseAdminDataSourceWithOptionsSample source</a>. 083 * 084 * @param dataSource DataSource used to obtain JDBC connections 085 * @param options SDK execution options; {@code null} uses {@link SelectAIOptions#defaults()} 086 * @return DatabaseAdmin client 087 * @throws IllegalArgumentException when {@code dataSource} is null 088 */ 089 static DatabaseAdmin create(DataSource dataSource, SelectAIOptions options) { 090 return DatabaseAdminFactory.create(dataSource, options); 091 } 092 093 /** 094 * Allows Select AI features to send table data or vector-search document 095 * content to the model when a feature needs that data. 096 * <p> 097 * For a complete runnable sample source, see 098 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/databaseadmin/EnableSelectAIDataAccessSample.html"> 099 * EnableSelectAIDataAccessSample source</a>. 100 * 101 * @return {@code true} when the database accepts the enable request 102 * @throws SelectAIException when the database rejects or cannot execute the enable request 103 */ 104 boolean enableDataAccess() throws SelectAIException; 105 106 /** 107 * Prevents Select AI features from sending table data or vector-search 108 * document content to the model when those features would otherwise use it. 109 * <p> 110 * For a complete runnable sample source, see 111 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/databaseadmin/DisableSelectAIDataAccessSample.html"> 112 * DisableSelectAIDataAccessSample source</a>. 113 * 114 * @return {@code true} when the database accepts the disable request 115 * @throws SelectAIException when the database rejects or cannot execute the disable request 116 */ 117 boolean disableDataAccess() throws SelectAIException; 118 119 /** 120 * Grants required Select AI package privileges to the specified database users. 121 * <p> 122 * For a complete runnable sample source, see 123 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/databaseadmin/GrantPrivilegesSample.html"> 124 * GrantPrivilegesSample source</a>. 125 * 126 * @param selectAIUsers database users whose package privileges are granted 127 * @return {@code false} when the user list is null or empty; otherwise 128 * {@code true} when the grant requests complete 129 * @throws SelectAIException when package grants cannot be applied 130 */ 131 boolean grantPrivileges(List<String> selectAIUsers) throws SelectAIException; 132 133 /** 134 * Revokes required Select AI package privileges from the specified database users. 135 * <p> 136 * For a complete runnable sample source, see 137 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/databaseadmin/RevokePrivilegesSample.html"> 138 * RevokePrivilegesSample source</a>. 139 * 140 * @param selectAIUsers database users whose package privileges are revoked 141 * @return {@code false} when the user list is null or empty; otherwise 142 * {@code true} when the revoke requests complete 143 * @throws SelectAIException when package grants cannot be revoked 144 */ 145 boolean revokePrivileges(List<String> selectAIUsers) throws SelectAIException; 146 147 /** 148 * Grants HTTP network ACL access for the specified database users. 149 * <p> 150 * For a complete runnable sample source, see 151 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/databaseadmin/GrantHttpAccessSample.html"> 152 * GrantHttpAccessSample source</a>. 153 * 154 * @param selectAIUsers database users whose HTTP access is granted 155 * @param host host name or host pattern to add to the ACL 156 * @return {@code false} when the user list is null or empty; otherwise 157 * {@code true} when the grant requests complete 158 * @throws IllegalArgumentException when {@code host} is null or blank 159 * @throws SelectAIException when network ACL updates cannot be applied 160 */ 161 boolean grantHttpAccess(List<String> selectAIUsers, String host) throws SelectAIException; 162 163 /** 164 * Revokes HTTP network ACL access for the specified database users. 165 * <p> 166 * For a complete runnable sample source, see 167 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/databaseadmin/RevokeHttpAccessSample.html"> 168 * RevokeHttpAccessSample source</a>. 169 * 170 * @param selectAIUsers database users whose HTTP access is revoked 171 * @param host host name or host pattern to remove from the ACL 172 * @return {@code false} when the user list is null or empty; otherwise 173 * {@code true} when the revoke requests complete 174 * @throws IllegalArgumentException when {@code host} is null or blank 175 * @throws SelectAIException when network ACL updates cannot be revoked 176 */ 177 boolean revokeHttpAccess(List<String> selectAIUsers, String host) throws SelectAIException; 178 179 /** 180 * Grants network ACL privileges to the specified database users. 181 * <p> 182 * For a complete runnable sample source, see 183 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/databaseadmin/GrantNetworkAccessSample.html"> 184 * GrantNetworkAccessSample source</a>. 185 * 186 * @param selectAIUsers database users whose network access is granted 187 * @param host host name or host pattern to add to the ACL 188 * @param privileges network ACL privileges to grant, such as {@code http} or {@code connect} 189 * @param lowerPort optional lower port; pass {@code null} when not needed 190 * @param upperPort optional upper port; pass {@code null} when not needed 191 * @return {@code false} when the user list is null or empty; otherwise 192 * {@code true} when the grant requests complete 193 * @throws IllegalArgumentException when {@code host} is null or blank, 194 * {@code privileges} has no non-blank values, a port is outside 195 * {@code 0..65535}, or {@code lowerPort} is greater than {@code upperPort} 196 * @throws SelectAIException when network ACL updates cannot be applied 197 */ 198 boolean grantNetworkAccess(List<String> selectAIUsers, String host, 199 List<String> privileges, Integer lowerPort, 200 Integer upperPort) throws SelectAIException; 201 202 /** 203 * Revokes network ACL privileges for the specified database users. 204 * <p> 205 * For a complete runnable sample source, see 206 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/databaseadmin/RevokeNetworkAccessSample.html"> 207 * RevokeNetworkAccessSample source</a>. 208 * 209 * @param selectAIUsers database users whose network access is revoked 210 * @param host host name or host pattern to remove from the ACL 211 * @param privileges network ACL privileges to revoke, such as {@code http} or {@code connect} 212 * @param lowerPort optional lower port; pass {@code null} when not needed 213 * @param upperPort optional upper port; pass {@code null} when not needed 214 * @return {@code false} when the user list is null or empty; otherwise 215 * {@code true} when the revoke requests complete 216 * @throws IllegalArgumentException when {@code host} is null or blank, 217 * {@code privileges} has no non-blank values, a port is outside 218 * {@code 0..65535}, or {@code lowerPort} is greater than {@code upperPort} 219 * @throws SelectAIException when network ACL updates cannot be revoked 220 */ 221 boolean revokeNetworkAccess(List<String> selectAIUsers, String host, 222 List<String> privileges, Integer lowerPort, 223 Integer upperPort) throws SelectAIException; 224 225 /** 226 * Releases resources owned by this DatabaseAdmin client. 227 * <p> 228 * For a complete runnable sample source, see 229 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/databaseadmin/CloseDatabaseAdminSample.html"> 230 * CloseDatabaseAdminSample source</a>. 231 * 232 * @throws SelectAIException when an owned JDBC connection cannot be closed 233 */ 234 @Override 235 void close() throws SelectAIException; 236}