This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-9480-43c398229d64be3931838aee0c2c08ea323018a1
in repository https://gitbox.apache.org/repos/asf/texera.git

commit 0e1e741bb72b4f5a3e15a2321e85f4dc1660d37e
Author: Xinyuan Lin <[email protected]>
AuthorDate: Tue Nov 17 05:21:55 2026 +0000

    refactor: narrow resource access queries (#9480)
    
    ### What changes were proposed in this PR?
    
    Select only the fields consumed by sharing and repository lookups.
    **+129/−101 lines** across six Scala files.
    
    - Workflow, dataset, and model sharing read the owner and grantee fields
    they use. The owner's email comes from one join, and all three grants
    find a registered grantee through `OwnerAccess.registeredUid`. Access
    listings still populate the same response fields.
    - The S3 proxy and computing-unit mount share a lookup for dataset and
    model IDs. Both reject ambiguous repository names.
    - File resolution reads the resource ID, repository name, and version
    hash. It still checks read access before looking up a version.
    
    ### Any related issues, documentation, discussions?
    
    Closes #9478.
    
    ### How was this PR tested?
    
    All 175 existing tests passed across eight suites on JDK 17 with freshly
    generated jOOQ classes.
    
    An additional 21 local PostgreSQL probe cases matched on main and the
    patch. Across 241 captured SELECTs, 119 read fewer columns. The
    predicates, parameters, and order matched, with equality replacing
    single-value `IN` where the old DAO generated it. Checks covered
    placeholder accounts, exact-case email lookup, owner and grant
    precedence, ambiguous repository names, and duplicate version names.
    Scalafix on all five affected modules, scoped Scalafmt, and `git diff
    --check` passed.
    
    After review, the grantee lookup checks the placeholder flag in SQL, and
    the owner's email comes from a join. All 180 cases in nine suites, now
    including `OwnerAccessSpec`, passed again. A 22-case local probe of
    `ownerEmail`, `grant`, `accessList`, and `revoke` matched main, covering
    an owner without an email, placeholder, unknown, and wrong-case
    grantees, and the owner's own access row. Scalafmt and Scalafix passed
    for `Auth`, `Resource`, `FileService`, `AccessControlService`, and
    `WorkflowExecutionService`.
    
    ```text
    sbt "DAO/jooqGenerate" "WorkflowExecutionService/testOnly 
*WorkflowAccessResourceSpec" "Auth/testOnly *OwnerAccessSpec 
*WorkflowAccessSpec" "Resource/testOnly *ResourceAccessSpec" 
"FileService/testOnly *DatasetAccessResourceSpec *ModelAccessResourceSpec 
*S3ProxyServletSpec" "AccessControlService/testOnly 
*ComputingUnitMountResourceSpec" "WorkflowCore/testOnly *FileResolverSpec"
    ```
    
    ### Was this PR authored or co-authored using generative AI tooling?
    
    Generated-by: Codex (GPT-6), Claude Code (Claude Opus 5.5)
---
 .../resource/ComputingUnitMountResource.scala      | 20 ++---
 .../user/workflow/WorkflowAccessResource.scala     | 42 ++++++----
 .../org/apache/texera/auth/util/OwnerAccess.scala  | 16 +++-
 .../texera/service/resource/ResourceAccess.scala   | 92 +++++++++++++---------
 .../texera/amber/core/storage/FileResolver.scala   | 36 ++++-----
 .../texera/service/util/S3ProxyServlet.scala       | 24 +++---
 6 files changed, 129 insertions(+), 101 deletions(-)

diff --git 
a/access-control-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitMountResource.scala
 
b/access-control-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitMountResource.scala
index b521bdf821..4ed8c61dfe 100644
--- 
a/access-control-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitMountResource.scala
+++ 
b/access-control-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitMountResource.scala
@@ -32,7 +32,6 @@ import org.apache.texera.dao.SqlServer
 import org.apache.texera.dao.SqlServer.withTransaction
 import org.apache.texera.dao.jooq.generated.Tables.{DATASET_VERSION, 
MODEL_VERSION}
 import org.apache.texera.dao.jooq.generated.enums.PrivilegeEnum
-import org.apache.texera.dao.jooq.generated.tables.daos.{DatasetDao, ModelDao}
 import org.apache.texera.service.resource.ComputingUnitMountResource._
 import org.apache.texera.service.util.{
   ComputingUnitNodeLocator,
@@ -40,8 +39,6 @@ import org.apache.texera.service.util.{
   MounterClient
 }
 
-import scala.jdk.CollectionConverters._
-
 /**
   * The mount authority: this service decides whether a user may act on a 
computing unit, so
   * it is where a mount request is authorized before being forwarded to that 
unit's node.
@@ -164,23 +161,20 @@ class ComputingUnitMountResource(
       uid: Integer
   ): Unit =
     withTransaction(SqlServer.getInstance().createDSLContext()) { ctx =>
-      val datasets = new 
DatasetDao(ctx.configuration()).fetchByRepositoryName(repositoryName)
-      val models = new 
ModelDao(ctx.configuration()).fetchByRepositoryName(repositoryName)
-
-      val readable = (datasets.asScala.toList, models.asScala.toList) match {
-        case (dataset :: Nil, Nil) =>
-          ResourceAccess.userHasReadAccess(ctx, ResourceTables.Dataset, 
dataset.getDid, uid) &&
+      val readable = ResourceAccess.repositoryIds(ctx, repositoryName) match {
+        case (did :: Nil, Nil) =>
+          ResourceAccess.userHasReadAccess(ctx, ResourceTables.Dataset, did, 
uid) &&
             ctx.fetchExists(
               DATASET_VERSION,
               DATASET_VERSION.DID
-                .eq(dataset.getDid)
+                .eq(did)
                 .and(DATASET_VERSION.VERSION_HASH.eq(commitHash))
             )
-        case (Nil, model :: Nil) =>
-          ResourceAccess.userHasReadAccess(ctx, ResourceTables.Model, 
model.getMid, uid) &&
+        case (Nil, mid :: Nil) =>
+          ResourceAccess.userHasReadAccess(ctx, ResourceTables.Model, mid, 
uid) &&
             ctx.fetchExists(
               MODEL_VERSION,
-              
MODEL_VERSION.MID.eq(model.getMid).and(MODEL_VERSION.VERSION_HASH.eq(commitHash))
+              
MODEL_VERSION.MID.eq(mid).and(MODEL_VERSION.VERSION_HASH.eq(commitHash))
             )
         case _ => false
       }
diff --git 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowAccessResource.scala
 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowAccessResource.scala
index ce10a3b380..b6925ec7fd 100644
--- 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowAccessResource.scala
+++ 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowAccessResource.scala
@@ -26,11 +26,7 @@ import 
org.apache.texera.auth.util.WorkflowAccess.{getPrivilege, hasWriteAccess,
 import org.apache.texera.dao.SqlServer
 import org.apache.texera.dao.jooq.generated.Tables._
 import org.apache.texera.dao.jooq.generated.enums.PrivilegeEnum
-import org.apache.texera.dao.jooq.generated.tables.daos.{
-  UserDao,
-  WorkflowOfUserDao,
-  WorkflowUserAccessDao
-}
+import org.apache.texera.dao.jooq.generated.tables.daos.WorkflowUserAccessDao
 import org.apache.texera.dao.jooq.generated.tables.pojos.WorkflowUserAccess
 import org.apache.texera.web.model.common.AccessEntry
 import 
org.apache.texera.web.resource.dashboard.user.workflow.WorkflowAccessResource.context
@@ -52,10 +48,16 @@ object WorkflowAccessResource {
 @RolesAllowed(Array("REGULAR", "ADMIN"))
 @Path("/access/workflow")
 class WorkflowAccessResource() {
-  final private val userDao = new UserDao(context.configuration())
-  final private val workflowOfUserDao = new 
WorkflowOfUserDao(context.configuration)
   final private val workflowUserAccessDao = new 
WorkflowUserAccessDao(context.configuration)
 
+  private def ownerUid(wid: Integer): Integer =
+    context
+      .select(WORKFLOW_OF_USER.UID)
+      .from(WORKFLOW_OF_USER)
+      .where(WORKFLOW_OF_USER.WID.eq(wid))
+      .fetch(WORKFLOW_OF_USER.UID)
+      .get(0)
+
   /**
     * This method returns the owner of a workflow
     *
@@ -65,7 +67,14 @@ class WorkflowAccessResource() {
   @GET
   @Path("/owner/{wid}")
   def getOwner(@PathParam("wid") wid: Integer): String = {
-    
userDao.fetchOneByUid(workflowOfUserDao.fetchByWid(wid).get(0).getUid).getEmail
+    context
+      .select(USER.EMAIL)
+      .from(WORKFLOW_OF_USER)
+      .join(USER)
+      .on(USER.UID.eq(WORKFLOW_OF_USER.UID))
+      .where(WORKFLOW_OF_USER.WID.eq(wid))
+      .fetch(USER.EMAIL)
+      .get(0)
   }
 
   /**
@@ -91,7 +100,7 @@ class WorkflowAccessResource() {
       .where(
         WORKFLOW_USER_ACCESS.WID
           .eq(wid)
-          
.and(WORKFLOW_USER_ACCESS.UID.notEqual(workflowOfUserDao.fetchByWid(wid).get(0).getUid))
+          .and(WORKFLOW_USER_ACCESS.UID.notEqual(ownerUid(wid)))
       )
       .fetchInto(classOf[AccessEntry])
   }
@@ -126,11 +135,9 @@ class WorkflowAccessResource() {
       throw new ForbiddenException(s"You do not have permission to modify 
workflow $wid")
     }
 
-    val targetUser = userDao.fetchOneByEmail(email)
-    if (targetUser == null || targetUser.getIsPlaceholder) {
-      throw new BadRequestException(s"No registered user with email $email")
-    }
-    val userUid = targetUser.getUid
+    val userUid = OwnerAccess
+      .registeredUid(context, email)
+      .getOrElse(throw new BadRequestException(s"No registered user with email 
$email"))
     if (isOwner(wid, userUid)) {
       // amber is on javax JAX-RS, so it raises its own ForbiddenException 
with the shared message.
       throw new ForbiddenException(OwnerAccess.ownerChangeRefused)
@@ -165,7 +172,12 @@ class WorkflowAccessResource() {
       @Auth user: SessionUser
   ): Unit = {
     try {
-      val targetUserUid = userDao.fetchOneByEmail(email).getUid
+      val targetUserUid = context
+        .select(USER.UID)
+        .from(USER)
+        .where(USER.EMAIL.eq(email))
+        .fetchOne()
+        .value1()
 
       // Prevent owner from revoking their own access
       if (isOwner(wid, targetUserUid)) {
diff --git 
a/common/auth/src/main/scala/org/apache/texera/auth/util/OwnerAccess.scala 
b/common/auth/src/main/scala/org/apache/texera/auth/util/OwnerAccess.scala
index 45b37dbf61..22292eafa8 100644
--- a/common/auth/src/main/scala/org/apache/texera/auth/util/OwnerAccess.scala
+++ b/common/auth/src/main/scala/org/apache/texera/auth/util/OwnerAccess.scala
@@ -18,9 +18,11 @@
 package org.apache.texera.auth.util
 
 import jakarta.ws.rs.ForbiddenException
+import org.apache.texera.dao.jooq.generated.Tables.USER
 import org.apache.texera.dao.jooq.generated.enums.PrivilegeEnum
+import org.jooq.DSLContext
 
-/** The rule every shared resource applies to its owner. */
+/** The rules every shared resource applies to its owner and to the users it 
is shared with. */
 object OwnerAccess {
 
   /** The owner always has WRITE; anyone else has what they were granted, or 
NONE.
@@ -34,4 +36,16 @@ object OwnerAccess {
   /** Refuses any change to the owner's own access. */
   def requireNotOwner(isOwner: Boolean): Unit =
     if (isOwner) throw new ForbiddenException(ownerChangeRefused)
+
+  /** The uid of the registered account with this email, or None when the 
email is unknown or
+    * belongs to a placeholder; neither can be granted access.
+    */
+  def registeredUid(ctx: DSLContext, email: String): Option[Integer] =
+    Option(
+      ctx
+        .select(USER.UID)
+        .from(USER)
+        .where(USER.EMAIL.eq(email).and(USER.IS_PLACEHOLDER.isFalse))
+        .fetchOne(USER.UID)
+    )
 }
diff --git 
a/common/resource/src/main/scala/org/apache/texera/service/resource/ResourceAccess.scala
 
b/common/resource/src/main/scala/org/apache/texera/service/resource/ResourceAccess.scala
index edf5364caf..11093a7cc2 100644
--- 
a/common/resource/src/main/scala/org/apache/texera/service/resource/ResourceAccess.scala
+++ 
b/common/resource/src/main/scala/org/apache/texera/service/resource/ResourceAccess.scala
@@ -22,7 +22,7 @@ package org.apache.texera.service.resource
 import jakarta.ws.rs.{BadRequestException, ForbiddenException}
 import jakarta.ws.rs.core.Response
 import org.apache.texera.auth.util.OwnerAccess
-import org.apache.texera.dao.jooq.generated.Tables.USER
+import org.apache.texera.dao.jooq.generated.Tables.{DATASET, MODEL, USER}
 import org.apache.texera.dao.jooq.generated.enums.PrivilegeEnum
 import org.apache.texera.dao.jooq.generated.tables.daos.UserDao
 import org.apache.texera.dao.jooq.generated.tables.pojos.User
@@ -41,6 +41,24 @@ object ResourceAccess {
   /** One shared grant, as returned by the access-list endpoints. */
   case class AccessEntry(email: String, name: String, privilege: EnumType) {}
 
+  /** All matching IDs in each resource table, so mounts can reject ambiguous 
legacy names. */
+  private[service] def repositoryIds(
+      ctx: DSLContext,
+      repositoryName: String
+  ): (List[Integer], List[Integer]) = {
+    val datasetIds = ctx
+      .select(DATASET.DID)
+      .from(DATASET)
+      .where(DATASET.REPOSITORY_NAME.eq(repositoryName))
+      .fetch(DATASET.DID)
+    val modelIds = ctx
+      .select(MODEL.MID)
+      .from(MODEL)
+      .where(MODEL.REPOSITORY_NAME.eq(repositoryName))
+      .fetch(MODEL.MID)
+    (datasetIds.asScala.toList, modelIds.asScala.toList)
+  }
+
   def isPublic[R <: Record, A <: Record](
       ctx: DSLContext,
       resource: ResourceTables[R, A],
@@ -55,12 +73,11 @@ object ResourceAccess {
     ).flatMap(record => Option(record.value1()))
       .exists(_.booleanValue())
 
-  def userOwns[R <: Record, A <: Record](
+  private def ownerUid[R <: Record, A <: Record](
       ctx: DSLContext,
       resource: ResourceTables[R, A],
-      id: Integer,
-      uid: Integer
-  ): Boolean =
+      id: Integer
+  ): Option[Integer] =
     Option(
       ctx
         .select(resource.ownerUidField)
@@ -68,7 +85,14 @@ object ResourceAccess {
         .where(resource.idField.eq(id))
         .fetchOne()
     ).flatMap(record => Option(record.value1()))
-      .contains(uid)
+
+  def userOwns[R <: Record, A <: Record](
+      ctx: DSLContext,
+      resource: ResourceTables[R, A],
+      id: Integer,
+      uid: Integer
+  ): Boolean =
+    ownerUid(ctx, resource, id).contains(uid)
 
   /** The owner always has WRITE, whatever their own access row says. */
   def privilegeOf[R <: Record, A <: Record](
@@ -113,15 +137,7 @@ object ResourceAccess {
       id: Integer
   ): User = {
     val userDao = new UserDao(ctx.configuration())
-    Option(
-      ctx
-        .select(resource.ownerUidField)
-        .from(resource.table)
-        .where(resource.idField.eq(id))
-        .fetchOne()
-    ).flatMap(record => Option(record.value1()))
-      .map(ownerUid => userDao.fetchOneByUid(ownerUid))
-      .orNull
+    ownerUid(ctx, resource, id).map(userDao.fetchOneByUid).orNull
   }
 
   /**
@@ -136,7 +152,15 @@ object ResourceAccess {
       requesterUid: Integer
   ): String = {
     requireReadAccess(ctx, resource, id, requesterUid)
-    Option(owner(ctx, resource, id)).map(_.getEmail).getOrElse("")
+    Option(
+      ctx
+        .select(USER.EMAIL)
+        .from(resource.table)
+        .join(USER)
+        .on(USER.UID.eq(resource.ownerUidField))
+        .where(resource.idField.eq(id))
+        .fetchOne()
+    ).map(_.value1()).getOrElse("")
   }
 
   /**
@@ -153,12 +177,6 @@ object ResourceAccess {
       requesterUid: Integer
   ): java.util.List[AccessEntry] = {
     requireReadAccess(ctx, resource, id, requesterUid)
-    val ownerUid = ctx
-      .select(resource.ownerUidField)
-      .from(resource.table)
-      .where(resource.idField.eq(id))
-      .fetchOne()
-      .value1()
 
     ctx
       .select(USER.EMAIL, USER.NAME, resource.privilegeField)
@@ -168,7 +186,7 @@ object ResourceAccess {
       .where(
         resource.accessIdField
           .eq(id)
-          .and(resource.accessUidField.notEqual(ownerUid))
+          .and(resource.accessUidField.notEqual(ownerUid(ctx, resource, 
id).orNull))
       )
       .fetchInto(classOf[AccessEntry])
   }
@@ -195,7 +213,7 @@ object ResourceAccess {
   ): List[D] = {
     // (id, entry) pairs so the public pass can skip ids already granted, 
without re-querying
     val granted: List[(Integer, D)] = ctx
-      .select()
+      .select((resource.table.fields().toSeq ++ Seq(resource.privilegeField, 
USER.EMAIL)): _*)
       .from(
         resource.table
           .leftJoin(resource.accessTable)
@@ -209,23 +227,22 @@ object ResourceAccess {
       .toList
       .flatMap { record =>
         val entity = record.into(resource.table).into(pojoClass)
-        val isOwner = record.into(resource.table).get(resource.ownerUidField) 
== uid
+        val isOwner = record.get(resource.ownerUidField) == uid
         val privilege =
           OwnerAccess.privilege(
             isOwner,
-            record.into(resource.accessTable).get(resource.privilegeField)
+            record.get(resource.privilegeField)
           )
-        fromGrant(entity, record.into(USER).getEmail, privilege, isOwner)
+        fromGrant(entity, record.get(USER.EMAIL), privilege, isOwner)
           .map(entry => (idOf(entity), entry))
       }
 
-    val grantedIds = granted.map(_._1).toSet
-
     val public =
       if (!includePublic) Nil
-      else
+      else {
+        val grantedIds = granted.map(_._1).toSet
         ctx
-          .select()
+          .select((resource.table.fields().toSeq :+ USER.EMAIL): _*)
           .from(
             resource.table
               .leftJoin(USER)
@@ -238,8 +255,9 @@ object ResourceAccess {
           .flatMap { record =>
             val entity = record.into(resource.table).into(pojoClass)
             if (grantedIds.contains(idOf(entity))) None
-            else fromPublic(entity, record.into(USER).getEmail)
+            else fromPublic(entity, record.get(USER.EMAIL))
           }
+      }
 
     granted.map(_._2) ++ public
   }
@@ -256,11 +274,9 @@ object ResourceAccess {
       requesterUid: Integer
   ): Response = {
     requireWriteAccess(ctx, resource, id, requesterUid)
-    val grantee = new UserDao(ctx.configuration()).fetchOneByEmail(email)
-    if (grantee == null || grantee.getIsPlaceholder) {
-      throw new BadRequestException(s"No registered user with email $email")
-    }
-    val granteeUid = grantee.getUid
+    val granteeUid = OwnerAccess
+      .registeredUid(ctx, email)
+      .getOrElse(throw new BadRequestException(s"No registered user with email 
$email"))
     OwnerAccess.requireNotOwner(userOwns(ctx, resource, id, granteeUid))
     val granted = PrivilegeEnum.valueOf(privilege)
 
@@ -291,7 +307,7 @@ object ResourceAccess {
       requesterUid: Integer
   ): Response = {
     requireWriteAccess(ctx, resource, id, requesterUid)
-    val granteeUid = new 
UserDao(ctx.configuration()).fetchOneByEmail(email).getUid
+    val granteeUid = 
ctx.select(USER.UID).from(USER).where(USER.EMAIL.eq(email)).fetchOne().value1()
     OwnerAccess.requireNotOwner(userOwns(ctx, resource, id, granteeUid))
 
     ctx
diff --git 
a/common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/FileResolver.scala
 
b/common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/FileResolver.scala
index 724be9ab21..20b452ab6f 100644
--- 
a/common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/FileResolver.scala
+++ 
b/common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/FileResolver.scala
@@ -27,12 +27,6 @@ import 
org.apache.texera.dao.jooq.generated.tables.DatasetVersion.DATASET_VERSIO
 import org.apache.texera.dao.jooq.generated.tables.Model.MODEL
 import org.apache.texera.dao.jooq.generated.tables.ModelVersion.MODEL_VERSION
 import org.apache.texera.dao.jooq.generated.tables.User.USER
-import org.apache.texera.dao.jooq.generated.tables.pojos.{
-  Dataset,
-  DatasetVersion,
-  Model,
-  ModelVersion
-}
 import org.apache.texera.service.resource.{ResourceAccess, ResourceTables}
 import org.jooq.{DSLContext, Record}
 
@@ -226,28 +220,29 @@ object FileResolver {
         .createDSLContext()
     ) { ctx =>
       val dataset = ctx
-        .select(DATASET.fields: _*)
+        .select(DATASET.DID, DATASET.REPOSITORY_NAME)
         .from(DATASET)
         .leftJoin(USER)
         .on(USER.UID.eq(DATASET.OWNER_UID))
         .where(USER.EMAIL.eq(ownerEmail))
         .and(DATASET.NAME.eq(datasetName))
-        .fetchOneInto(classOf[Dataset])
+        .fetchOne()
 
-      if (dataset == null || !readableBy(ctx, ResourceTables.Dataset, 
dataset.getDid, reader)) {
+      if (dataset == null || !readableBy(ctx, ResourceTables.Dataset, 
dataset.value1(), reader)) {
         throw new FileNotFoundException(s"Dataset file $fileName not found.")
       }
 
       val datasetVersion = ctx
-        .selectFrom(DATASET_VERSION)
-        .where(DATASET_VERSION.DID.eq(dataset.getDid))
+        .select(DATASET_VERSION.VERSION_HASH)
+        .from(DATASET_VERSION)
+        .where(DATASET_VERSION.DID.eq(dataset.value1()))
         .and(DATASET_VERSION.NAME.eq(versionName))
-        .fetchOneInto(classOf[DatasetVersion])
+        .fetchOne()
 
       if (datasetVersion == null) {
         throw new FileNotFoundException(s"Dataset file $fileName not found.")
       }
-      (dataset.getRepositoryName, datasetVersion.getVersionHash)
+      (dataset.value2(), datasetVersion.value1())
     }
 
   /**
@@ -271,28 +266,29 @@ object FileResolver {
         .createDSLContext()
     ) { ctx =>
       val model = ctx
-        .select(MODEL.fields: _*)
+        .select(MODEL.MID, MODEL.REPOSITORY_NAME)
         .from(MODEL)
         .leftJoin(USER)
         .on(USER.UID.eq(MODEL.OWNER_UID))
         .where(USER.EMAIL.eq(ownerEmail))
         .and(MODEL.NAME.eq(modelName))
-        .fetchOneInto(classOf[Model])
+        .fetchOne()
 
-      if (model == null || !readableBy(ctx, ResourceTables.Model, 
model.getMid, reader)) {
+      if (model == null || !readableBy(ctx, ResourceTables.Model, 
model.value1(), reader)) {
         throw new FileNotFoundException(s"Model file $fileName not found.")
       }
 
       val modelVersion = ctx
-        .selectFrom(MODEL_VERSION)
-        .where(MODEL_VERSION.MID.eq(model.getMid))
+        .select(MODEL_VERSION.VERSION_HASH)
+        .from(MODEL_VERSION)
+        .where(MODEL_VERSION.MID.eq(model.value1()))
         .and(MODEL_VERSION.NAME.eq(versionName))
-        .fetchOneInto(classOf[ModelVersion])
+        .fetchOne()
 
       if (modelVersion == null) {
         throw new FileNotFoundException(s"Model file $fileName not found.")
       }
-      (model.getRepositoryName, modelVersion.getVersionHash)
+      (model.value2(), modelVersion.value1())
     }
 
   /**
diff --git 
a/file-service/src/main/scala/org/apache/texera/service/util/S3ProxyServlet.scala
 
b/file-service/src/main/scala/org/apache/texera/service/util/S3ProxyServlet.scala
index 81685ca507..680d10142c 100644
--- 
a/file-service/src/main/scala/org/apache/texera/service/util/S3ProxyServlet.scala
+++ 
b/file-service/src/main/scala/org/apache/texera/service/util/S3ProxyServlet.scala
@@ -25,8 +25,11 @@ import org.apache.texera.auth.JwtParser
 import org.apache.texera.common.config.StorageConfig
 import org.apache.texera.dao.SqlServer
 import org.apache.texera.dao.SqlServer.withTransaction
-import org.apache.texera.dao.jooq.generated.tables.daos.{DatasetDao, ModelDao}
-import org.apache.texera.service.resource.{DatasetAccessResource, 
ModelAccessResource}
+import org.apache.texera.service.resource.{
+  DatasetAccessResource,
+  ModelAccessResource,
+  ResourceAccess
+}
 import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
 import software.amazon.awssdk.auth.signer.AwsS3V4Signer
 import software.amazon.awssdk.auth.signer.params.AwsS3V4SignerParams
@@ -145,19 +148,12 @@ class S3ProxyServlet extends HttpServlet with LazyLogging 
{
     */
   private def authorizedToRead(uid: Integer, repositoryName: String): Boolean =
     withTransaction(SqlServer.getInstance().createDSLContext()) { ctx =>
-      val datasets = new DatasetDao(ctx.configuration())
-        .fetchByRepositoryName(repositoryName)
-        .asScala
-        .toList
-      val models = new ModelDao(ctx.configuration())
-        .fetchByRepositoryName(repositoryName)
-        .asScala
-        .toList
+      val (datasets, models) = ResourceAccess.repositoryIds(ctx, 
repositoryName)
       (datasets, models) match {
-        case (dataset :: Nil, Nil) =>
-          DatasetAccessResource.userHasReadAccess(ctx, dataset.getDid, uid)
-        case (Nil, model :: Nil) =>
-          ModelAccessResource.userHasReadAccess(ctx, model.getMid, uid)
+        case (did :: Nil, Nil) =>
+          DatasetAccessResource.userHasReadAccess(ctx, did, uid)
+        case (Nil, mid :: Nil) =>
+          ModelAccessResource.userHasReadAccess(ctx, mid, uid)
         case (Nil, Nil) =>
           false
         case _ =>

Reply via email to