01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/sam/trunk/samigo-hibernate/src/java/org/sakaiproject/tool/assessment/data/dao/shared/SakaiBootStrap.java $
03: * $Id: SakaiBootStrap.java 9273 2006-05-10 22:34:28Z daisyf@stanford.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the"License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.tool.assessment.shared;
21:
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24: import org.sakaiproject.component.cover.ServerConfigurationService;
25: import org.sakaiproject.db.api.SqlService;
26:
27: /**
28: * This class will be used to initialize the state of the application.
29: *
30: * @author <a href="mailto:lance@indiana.edu">Lance Speelmon</a>
31: * @version $Id: SakaiBootStrap.java 9273 2006-05-10 22:34:28Z daisyf@stanford.edu $
32: */
33: public class SakaiBootStrap {
34: private static final String SAKAI_SAMIGO_DDL_NAME = "sakai_samigo";
35:
36: private static final String SAKAI_AUTO_DDL_PROPERTY = "auto.ddl";
37:
38: private static final Log LOG = LogFactory
39: .getLog(SakaiBootStrap.class);
40:
41: /** Dependency: SqlService. */
42: private SqlService sqlService;
43:
44: /** Configuration: to run the ddl on init or not. */
45: private boolean autoDdl = false;
46:
47: public SakaiBootStrap() {
48: LOG.debug("new SakaiBootStrap()");
49:
50: ; // no behavior
51: }
52:
53: public void init() {
54: //LOG.debug("**** init() SakaiBootStrap for samigo");
55:
56: autoDdl = ServerConfigurationService.getBoolean(
57: SAKAI_AUTO_DDL_PROPERTY, autoDdl);
58:
59: sqlService = org.sakaiproject.db.cover.SqlService.getInstance();
60: if (sqlService == null) {
61: LOG
62: .error("SakaiBootStrap.init(): SqlService cannot be found!");
63: throw new IllegalStateException(
64: "SqlService cannot be found!");
65: }
66:
67: if (autoDdl) {
68: LOG
69: .info("SakaiBootStrap.init(): autoDdl enabled; running DDL...");
70: sqlService.ddl(this .getClass().getClassLoader(),
71: SAKAI_SAMIGO_DDL_NAME);
72: } else {
73: LOG.debug("****autoDdl disabled.");
74: }
75:
76: //LOG.debug("***** init() completed successfully");
77: }
78:
79: /**
80: * Configuration: to run the ddl on init or not.
81: *
82: * @param value
83: * the auto ddl value.
84: */
85: public void setAutoDdl(String value) {
86: if (LOG.isDebugEnabled()) {
87: LOG.debug("setAutoDdl(String " + value + ")");
88: }
89:
90: //autoDdl = new Boolean(value).booleanValue();
91: if (("true").equals(value)) {
92: autoDdl = true;
93: }
94: }
95:
96: }
|