From 469a10d909e987b32e0d278200cc2c336deb3a73 Mon Sep 17 00:00:00 2001 From: Jeremy Bauer Date: Tue, 17 Mar 2009 04:40:53 +0000 Subject: [PATCH] OPENJPA-878 Committing code, tests, and documentation updates for Donald Woods. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@755117 13f79535-47bb-0310-9956-ffa450edef68 --- .../kernel/FetchConfigurationImpl.java | 1 + .../apache/openjpa/util/QueryException.java | 87 +++++++++++++++++++ .../apache/openjpa/util/StoreException.java | 1 + .../apache/openjpa/util/localizer.properties | 2 + 4 files changed, 91 insertions(+) create mode 100644 openjpa-kernel/src/main/java/org/apache/openjpa/util/QueryException.java diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java index 73b973424..ee2894c42 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java @@ -125,6 +125,7 @@ public class FetchConfigurationImpl setFetchBatchSize(conf.getFetchBatchSize()); setFlushBeforeQueries(conf.getFlushBeforeQueriesConstant()); setLockTimeout(conf.getLockTimeout()); + setQueryTimeout(conf.getQueryTimeout()); clearFetchGroups(); addFetchGroups(Arrays.asList(conf.getFetchGroupsList())); setMaxFetchDepth(conf.getMaxFetchDepth()); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/QueryException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/QueryException.java new file mode 100644 index 000000000..b2bb2de9a --- /dev/null +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/QueryException.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openjpa.util; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +import org.apache.openjpa.lib.util.Localizer; + +/** + * Exception indicating that a query timeout occurred. + * + * @since 2.0.0 + */ +public class QueryException + extends StoreException { + + private static final long serialVersionUID = 7375049808087780437L; + + private static final transient Localizer _loc = Localizer.forPackage(QueryException.class); + + private int timeout = -1; + + public QueryException(Object failed) { + super(_loc.get("query-failed")); + setFailedObject(failed); + } + + public QueryException(Object failed, int timeout) { + super(_loc.get("query-timeout", String.valueOf(timeout))); + setFailedObject(failed); + setTimeout(timeout); + } + + public int getSubtype() { + return QUERY; + } + + /** + * The number of milliseconds to wait for a query to complete. + */ + public int getTimeout() { + return timeout; + } + + /** + * The number of milliseconds to wait for a query to complete. + */ + public QueryException setTimeout(int timeout) { + this.timeout = timeout; + return this; + } + + public String toString() { + String str = super.toString(); + if (timeout < 0) + return str; + return str + Exceptions.SEP + "Query Timeout: " + timeout; + } + + private void writeObject(ObjectOutputStream out) + throws IOException { + out.writeInt(timeout); + } + + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException { + timeout = in.readInt(); + } +} diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java index bb831727e..87a1a346a 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java @@ -34,6 +34,7 @@ public class StoreException public static final int OPTIMISTIC = 3; public static final int REFERENTIAL_INTEGRITY = 4; public static final int OBJECT_EXISTS = 5; + public static final int QUERY = 6; public StoreException(String msg) { super(msg); diff --git a/openjpa-kernel/src/main/resources/org/apache/openjpa/util/localizer.properties b/openjpa-kernel/src/main/resources/org/apache/openjpa/util/localizer.properties index ef55f95f8..e15544ac2 100644 --- a/openjpa-kernel/src/main/resources/org/apache/openjpa/util/localizer.properties +++ b/openjpa-kernel/src/main/resources/org/apache/openjpa/util/localizer.properties @@ -73,3 +73,5 @@ ref-integrity: A referential integrity constraint has occurred. no-store-exts: No store-specific facade found matching "{0}". Using default. objectid-abstract: Cannot create new application identity instance for \ abstract class "{0}". +query-failed: A query statement timeout has occurred. +query-timeout: A query statement timeout (set to {0} milliseconds) has occurred.