001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/trunk/component/src/java/org/sakaiproject/tool/assessment/services/PersistenceService.java $
003: * $Id: PersistenceService.java 9275 2006-05-10 22:58:35Z lydial@stanford.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the"License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.assessment.services;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: import org.sakaiproject.spring.SpringBeanLocator;
026: import org.sakaiproject.tool.assessment.facade.AssessmentFacadeQueriesAPI;
027: import org.sakaiproject.tool.assessment.facade.AssessmentGradingFacadeQueriesAPI;
028: import org.sakaiproject.tool.assessment.facade.AuthzQueriesFacadeAPI;
029: import org.sakaiproject.tool.assessment.facade.ItemFacadeQueriesAPI;
030: import org.sakaiproject.tool.assessment.facade.PublishedAssessmentFacadeQueriesAPI;
031: import org.sakaiproject.tool.assessment.facade.QuestionPoolFacadeQueriesAPI;
032: import org.sakaiproject.tool.assessment.facade.SectionFacadeQueriesAPI;
033: import org.sakaiproject.tool.assessment.facade.TypeFacadeQueriesAPI;
034: import org.sakaiproject.tool.assessment.facade.authz.AuthorizationFacadeQueriesAPI;
035: import org.sakaiproject.tool.assessment.facade.util.PagingUtilQueriesAPI;
036: import org.sakaiproject.section.api.SectionAwareness;
037: import org.sakaiproject.component.cover.ComponentManager;
038:
039: /**
040: * @author jlannan
041: *
042: * To change the template for this generated type comment go to
043: * Window>Preferences>Java>Code Generation>Code and Comments
044: */
045: public class PersistenceService {
046:
047: private static Log log = LogFactory
048: .getLog(PersistenceService.class);
049: private QuestionPoolFacadeQueriesAPI questionPoolFacadeQueries;
050: private TypeFacadeQueriesAPI typeFacadeQueries;
051: private SectionFacadeQueriesAPI sectionFacadeQueries;
052: private ItemFacadeQueriesAPI itemFacadeQueries;
053: private AssessmentFacadeQueriesAPI assessmentFacadeQueries;
054: private PublishedAssessmentFacadeQueriesAPI publishedAssessmentFacadeQueries;
055: private AssessmentGradingFacadeQueriesAPI assessmentGradingFacadeQueries;
056: private AuthorizationFacadeQueriesAPI authorizationFacadeQueries;
057: private PagingUtilQueriesAPI pagingUtilQueries;
058: private AuthzQueriesFacadeAPI authzQueriesFacade;
059: private SectionAwareness sectionAwareness;
060:
061: private static PersistenceService INSTANCE;
062:
063: public static PersistenceService getInstance() {
064: if (INSTANCE != null) {
065: return INSTANCE;
066: } else {
067: return (PersistenceService) ComponentManager
068: .get("PersistenceService");
069: /*
070: SpringBeanLocator locator = SpringBeanLocator.getInstance();
071: return INSTANCE = (PersistenceService)locator.getBean("PersistenceService");
072: //return INSTANCE = (PersistenceService) ApplicationContextLocator.getInstance().getBean("PersistenceService");
073: */
074: }
075: }
076:
077: private Integer deadlockInterval; // in ms
078:
079: public void setDeadlockInterval(Integer deadlockInterval) {
080: this .deadlockInterval = deadlockInterval;
081: }
082:
083: public Integer getDeadlockInterval() {
084: return deadlockInterval;
085: }
086:
087: private Integer retryCount; // in ms
088:
089: public void setRetryCount(Integer retryCount) {
090: this .retryCount = retryCount;
091: }
092:
093: public Integer getRetryCount() {
094: return retryCount;
095: }
096:
097: public QuestionPoolFacadeQueriesAPI getQuestionPoolFacadeQueries() {
098: return questionPoolFacadeQueries;
099: }
100:
101: public void setQuestionPoolFacadeQueries(
102: QuestionPoolFacadeQueriesAPI questionPoolFacadeQueries) {
103: this .questionPoolFacadeQueries = questionPoolFacadeQueries;
104: }
105:
106: public TypeFacadeQueriesAPI getTypeFacadeQueries() {
107: return typeFacadeQueries;
108: }
109:
110: public void setTypeFacadeQueries(
111: TypeFacadeQueriesAPI typeFacadeQueries) {
112: this .typeFacadeQueries = typeFacadeQueries;
113: }
114:
115: public SectionFacadeQueriesAPI getSectionFacadeQueries() {
116: return sectionFacadeQueries;
117: }
118:
119: public void setSectionFacadeQueries(
120: SectionFacadeQueriesAPI sectionFacadeQueries) {
121: this .sectionFacadeQueries = sectionFacadeQueries;
122: }
123:
124: public ItemFacadeQueriesAPI getItemFacadeQueries() {
125: return itemFacadeQueries;
126: }
127:
128: public void setItemFacadeQueries(
129: ItemFacadeQueriesAPI itemFacadeQueries) {
130: this .itemFacadeQueries = itemFacadeQueries;
131: }
132:
133: public AssessmentFacadeQueriesAPI getAssessmentFacadeQueries() {
134: return assessmentFacadeQueries;
135: //return (AssessmentFacadeQueriesAPI)ComponentManager.get(org.sakaiproject.tool.assessment.facade.AssessmentFacadeQueriesAPI.class);
136: }
137:
138: public void setAssessmentFacadeQueries(
139: AssessmentFacadeQueriesAPI assessmentFacadeQueries) {
140: this .assessmentFacadeQueries = assessmentFacadeQueries;
141: }
142:
143: public PublishedAssessmentFacadeQueriesAPI getPublishedAssessmentFacadeQueries() {
144: return publishedAssessmentFacadeQueries;
145: }
146:
147: public void setPublishedAssessmentFacadeQueries(
148: PublishedAssessmentFacadeQueriesAPI publishedAssessmentFacadeQueries) {
149: this .publishedAssessmentFacadeQueries = publishedAssessmentFacadeQueries;
150: }
151:
152: public AssessmentGradingFacadeQueriesAPI getAssessmentGradingFacadeQueries() {
153: return assessmentGradingFacadeQueries;
154: }
155:
156: public void setAssessmentGradingFacadeQueries(
157: AssessmentGradingFacadeQueriesAPI assessmentGradingFacadeQueries) {
158: this .assessmentGradingFacadeQueries = assessmentGradingFacadeQueries;
159: }
160:
161: public AuthorizationFacadeQueriesAPI getAuthorizationFacadeQueries() {
162: return authorizationFacadeQueries;
163: }
164:
165: public void setAuthorizationFacadeQueries(
166: AuthorizationFacadeQueriesAPI authorizationFacadeQueries) {
167: this .authorizationFacadeQueries = authorizationFacadeQueries;
168: }
169:
170: public PagingUtilQueriesAPI getPagingUtilQueries() {
171: return pagingUtilQueries;
172: }
173:
174: public void setPagingUtilQueries(
175: PagingUtilQueriesAPI pagingUtilQueries) {
176: this .pagingUtilQueries = pagingUtilQueries;
177: }
178:
179: public AuthzQueriesFacadeAPI getAuthzQueriesFacade() {
180: return authzQueriesFacade;
181: }
182:
183: public void setAuthzQueriesFacade(
184: AuthzQueriesFacadeAPI authzQueriesFacade) {
185: this .authzQueriesFacade = authzQueriesFacade;
186: }
187:
188: public SectionAwareness getSectionAwareness() {
189: return sectionAwareness;
190:
191: }
192:
193: public void setSectionAwareness(SectionAwareness sectionAwareness) {
194: this .sectionAwareness = sectionAwareness;
195: }
196:
197: public int retryDeadlock(Exception e, int retryCount) {
198: log.warn("Error saving to db...retry again....");
199: String errorMessage = e.getMessage();
200: log.warn(errorMessage);
201: int index = errorMessage.indexOf("ORA-00060"); // deadlock
202: int index2 = errorMessage.indexOf("SQL state [61000]"); // oracle deadlock
203: int index3 = errorMessage.indexOf("SQL state [41000]"); // mysql deadlock
204: if (index > -1 || index2 > -1 || index3 > -1) {
205: retryCount--;
206: try {
207: int ideadlockInterval = deadlockInterval.intValue();
208: Thread.currentThread().sleep(ideadlockInterval);
209: } catch (InterruptedException ex) {
210: log.warn(ex.getMessage());
211: }
212: } else
213: retryCount = 0;
214: return retryCount;
215: }
216:
217: }
|