001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.common.function.v1;
009:
010: //base classes
011: import java.sql.Connection;
012: import java.sql.SQLException;
013:
014: //project specific classes
015: import org.jfolder.common.SelfArgumentlessConstructor;
016: import org.jfolder.common.StandardDataTypes;
017: import org.jfolder.common.UnexpectedSystemException;
018: import org.jfolder.common.function.BaseCommonFunctionCompatibilityTag;
019: import org.jfolder.common.function.WebPageTagInstanceViewContext;
020: import org.jfolder.common.tagging.AppraiseConceptTagContext;
021: import org.jfolder.common.tagging.ConceptTagCharacteristic;
022: import org.jfolder.common.tagging.ConceptTagConstraint;
023: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
024: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
025: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
026: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
027: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
028: import org.jfolder.common.tagging.InitializeConceptTagContext;
029: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
030: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
031: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
032: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
033: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
034: import org.jfolder.common.utils.misc.MiscHelper;
035: import org.jfolder.platforms.stores.base.ApplicationDataSourceResolver;
036: import org.jfolder.platforms.stores.base.SystemStore;
037: import org.jfolder.platforms.stores.base.SystemStoreFactory;
038: import org.jfolder.services.config.ApplicationStoreSet;
039: import org.jfolder.services.config.ConfigService;
040: import org.jfolder.services.config.ConfigServiceCallerFactory;
041:
042: //other classes
043:
044: abstract class BaseCommonFunctionDbAccessTag extends
045: BaseCommonFunctionCompatibilityTag implements
046: SelfArgumentlessConstructor {
047: //
048: //
049: //
050: public abstract void executeActions(
051: DetermineValueAndClassConceptTagContext inDvacctc)
052: throws DetermineValueAndClassConceptTagException;
053:
054: //
055: //
056: //
057: public abstract ConceptTagCharacteristic getDataSourceCtchar();
058:
059: public final void determineValueAndClass(
060: DetermineValueAndClassConceptTagContext inDvacctc) {
061: //
062: try {
063: ConceptTagCharacteristic localDsCtchar = getDataSourceCtchar();
064: if (localDsCtchar.getValueLength() > 0) {
065: determineValueAndClassWithConnectionNotRegistered(inDvacctc);
066: } else {
067: executeActions(inDvacctc);
068: }
069: //
070: if (!inDvacctc.isDetermineExceptionPresent()) {
071: inDvacctc
072: .setDetermineValueAndClass(ValueAndClassForConceptTag
073: .newNothing());
074: }
075: } catch (DetermineValueAndClassConceptTagException dvaccte) {
076: inDvacctc.setDetermineException(dvaccte);
077: }
078: }
079:
080: //
081: //
082: public final void determineValueAndClassWithConnectionNotRegistered(
083: DetermineValueAndClassConceptTagContext inDvacctc) {
084:
085: Connection conn = null;
086: try {
087: String dataSource = getDataSourceCtchar().getValueAsString(
088: 0, inDvacctc);
089: //
090: //
091: //
092: ConfigService cs = ConfigServiceCallerFactory
093: .getConfigService();
094: ApplicationStoreSet ass = ApplicationStoreSet
095: .newInstance(cs);
096: //
097: //String actualDataSource = ass.getReferenceHandle(
098: // ass.getIndexOfActualName(dataSource));
099: //
100: ApplicationDataSourceResolver adsr = SystemStoreFactory
101: .getApplicationDataSourceResolver();
102: conn = SystemStore.getGeneralConnection(adsr
103: .getActualDataSourceName(dataSource));
104: conn.setAutoCommit(false);
105: //
106: //
107: ConceptTagFlagsHelper.createCurrentDataSource(inDvacctc,
108: dataSource);
109: ConceptTagFlagsHelper.createCurrentDataSourceConnection(
110: inDvacctc, conn);
111: //
112:
113: //
114: //generic call here
115: executeActions(inDvacctc);
116: //
117: //for (int i = 0; i < this.actionCtchar.getValueLength(); i++) {
118: // this.actionCtchar.getDetermineValueAndClass(i, inDvacctc);
119: //}
120:
121: //
122: //ConceptTagFlagsHelper.removeCurrentDataSourceConnection(
123: // inDvacctc);
124: //ConceptTagFlagsHelper.removeCurrentDataSource(inDvacctc);
125:
126: //
127: //
128: conn.commit();
129: //
130: //
131:
132: } catch (SQLException sqle1) {
133: try {
134: if (conn != null) {
135: conn.rollback();
136: }
137: } catch (SQLException sqle) {
138: //do nothing, first exception already returned
139: }
140: inDvacctc.setDetermineException(sqle1);
141: } catch (DetermineValueAndClassConceptTagException dvaccte) {
142: try {
143: if (conn != null) {
144: conn.rollback();
145: }
146: } catch (SQLException sqle) {
147: //do nothing, first exception already returned
148: }
149: inDvacctc.setDetermineException(dvaccte);
150: } catch (RuntimeException re) {
151: try {
152: if (conn != null) {
153: conn.rollback();
154: }
155: } catch (SQLException sqle) {
156: //do nothing, first exception already returned
157: }
158: MiscHelper.writeMessage(this .getClass(), re);
159: inDvacctc.setDetermineException(re);
160: } finally {
161: try {
162: //
163: if (ConceptTagFlagsHelper
164: .isCurrentDataSourceConnectionPresent(inDvacctc)) {
165: //
166: ConceptTagFlagsHelper
167: .removeCurrentDataSourceConnection(inDvacctc);
168: }
169: //
170: if (ConceptTagFlagsHelper
171: .isCurrentDataSourcePresent(inDvacctc)) {
172: //
173: ConceptTagFlagsHelper
174: .removeCurrentDataSource(inDvacctc);
175: }
176: //
177: SystemStore.closeSQLObjects(conn, null, null);
178: } catch (UnexpectedSystemException use) {
179: if (!inDvacctc.isDetermineExceptionPresent()) {
180: inDvacctc.setDetermineException(use);
181: }
182: }
183: }
184: }
185: }
|