From ed74f973409570fd36465bd2983ae730983c62ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Mon, 4 Jul 2022 13:15:51 +0200 Subject: [PATCH] MAINT: change handling of exceptions --- conf/core/server.conf | 6 +- .../java/org/caosdb/server/query/Query.java | 60 ++++++++++--------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/conf/core/server.conf b/conf/core/server.conf index 246be9aa..b00b6b76 100644 --- a/conf/core/server.conf +++ b/conf/core/server.conf @@ -67,7 +67,7 @@ MYSQL_DATABASE_NAME=caosdb # User name for connecting to mysql MYSQL_USER_NAME=caosdb # Password for the user -MYSQL_USER_PASSWORD=caosdb +MYSQL_USER_PASSWORD=random1234 # Schema of mysql procedures and tables which is required by this CaosDB instance MYSQL_SCHEMA_VERSION=v5.0 @@ -169,8 +169,8 @@ ADMIN_EMAIL= BUGTRACKER_URI= # If set to true MySQL stores transaction benchmarks for all SQL queries. Used for benchmarking and debugging. -TRANSACTION_BENCHMARK_ENABLED=FALSE -#TRANSACTION_BENCHMARK_ENABLED=TRUE +#TRANSACTION_BENCHMARK_ENABLED=FALSE +TRANSACTION_BENCHMARK_ENABLED=TRUE # Location of the configuration file for the CaosDB cache. CACHE_CONF_LOC=./conf/core/cache.ccf # Set this option to true to lobally disable caching. Used for debugging. diff --git a/src/main/java/org/caosdb/server/query/Query.java b/src/main/java/org/caosdb/server/query/Query.java index 2697b77c..be76324e 100644 --- a/src/main/java/org/caosdb/server/query/Query.java +++ b/src/main/java/org/caosdb/server/query/Query.java @@ -377,7 +377,6 @@ public class Query implements QueryInterface, ToElementable, TransactionInterfac * have the RETRIEVE:ENTITY permission for a particular QueryTemplate it will be ignored. * * @param resultSet - * @throws SQLException * @throws QueryException */ public void applyQueryTemplates(final QueryInterface query, final String resultSet) @@ -677,41 +676,46 @@ public class Query implements QueryInterface, ToElementable, TransactionInterfac * @throws ParsingException */ public Query execute(final Access access) throws ParsingException { - parse(); - setAccess(access); - if (useCache()) { - this.resultSet = getCached(getCacheKey()); - } + try { + parse(); + setAccess(access); + if (useCache()) { + this.resultSet = getCached(getCacheKey()); + } - if (this.resultSet == null) { - executeNoCache(access); - if (this.cachable) { - setCache(getCacheKey(), this.resultSet); + if (this.resultSet == null) { + executeNoCache(access); + if (this.cachable) { + setCache(getCacheKey(), this.resultSet); + } + this.logger.debug("Uncached query {}", this.query); + } else { + this.logger.debug("Using cached result for {}", this.query); + this.cached = true; } - this.logger.debug("Uncached query {}", this.query); - } else { - this.logger.debug("Using cached result for {}", this.query); - this.cached = true; - } - // Fill resulting entities into container - if (this.container != null && this.type == Type.FIND) { - for (final IdVersionPair p : this.resultSet) { + // Fill resulting entities into container + if (this.container != null && this.type == Type.FIND) { + for (final IdVersionPair p : this.resultSet) { - if (p.id > 99) { - final Entity e = new RetrieveEntity(p.id, p.version); + if (p.id > 99) { + final Entity e = new RetrieveEntity(p.id, p.version); - // if query has select-clause: - if (this.selections != null && !this.selections.isEmpty()) { - e.addSelections(this.selections); + // if query has select-clause: + if (this.selections != null && !this.selections.isEmpty()) { + e.addSelections(this.selections); + } + this.container.add(e); } - this.container.add(e); } } + + } catch (final SQLException e) { + e.printStackTrace(); + throw new TransactionException(e); } return this; } - /** Remove all cached queries from the cache. */ public static void clearCache() { cacheETag = UUID.randomUUID().toString(); @@ -745,7 +749,7 @@ public class Query implements QueryInterface, ToElementable, TransactionInterfac return (List<IdVersionPair>) cache.get(key); } - protected void executeNoCache(final Access access) { + protected void executeNoCache(final Access access) throws SQLException { try { final String tabname = executeStrategy(this.versioned); filterEntitiesWithoutRetrievePermission(tabname); @@ -792,9 +796,9 @@ public class Query implements QueryInterface, ToElementable, TransactionInterfac * * @param resultSet * @throws SQLException - * @throws TransactionException */ - public void filterEntitiesWithoutRetrievePermission(final String resultSet) { + public void filterEntitiesWithoutRetrievePermission(final String resultSet) + throws SQLException { if (!filterEntitiesWithoutRetrievePermisions) { return; } -- GitLab