001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.cocoon.components.modules.database;
019:
020: import java.sql.Connection;
021: import java.sql.Statement;
022: import java.sql.SQLException;
023: import java.util.Map;
024: import org.apache.avalon.framework.component.Component;
025: import org.apache.avalon.framework.configuration.Configuration;
026: import org.apache.avalon.framework.configuration.ConfigurationException;
027:
028: /**
029: * Abstraction layer to encapsulate different DBMS behaviour for key
030: * attribute columns.
031: *
032: * @author <a href="mailto:haul@apache.org">Christian Haul</a>
033: * @version CVS $Id: AutoIncrementModule.java 433543 2006-08-22 06:22:54Z crossley $
034: * */
035: public interface AutoIncrementModule extends Component {
036:
037: String ROLE = AutoIncrementModule.class.getName();
038:
039: /**
040: * Return key attribute value of last inserted row.
041: *
042: * @param tableConf Table's configuration from resource description.
043: * @param columnConf column's configuration from resource description.
044: * @param modeConf this mode's configuration from resource description.
045: * @param conn Connection
046: * @param stmt Statement that was executed to insert the last row.
047: * @param objectModel The objectModel
048: * @return value representing the last key value value.
049: * */
050: Object getPostValue(Configuration tableConf,
051: Configuration columnConf, Configuration modeConf,
052: Connection conn, Statement stmt, Map objectModel)
053: throws SQLException, ConfigurationException;
054:
055: /**
056: * Boolean whether the key attribute column needs to be included
057: * in the insert query.
058: *
059: * @return true if the column is needed, false if the column
060: * should be skipped.
061: * */
062: boolean includeInQuery();
063:
064: /**
065: * Boolean whether the key attribute needs to be included in the
066: * insert query as an attribute value (no subquery).
067: *
068: * @return true if a value is needed, false if a subquery
069: * expression is used or the column is skipped altogether.
070: * */
071: boolean includeAsValue();
072:
073: /**
074: * Provide the value for the key attribute column.
075: *
076: * If a value for the key value column is needed (i.e. the column
077: * is not skipped), this value is computed here.
078: *
079: * @param tableConf Table's configuration from resource description.
080: * @param columnConf column's configuration from resource description.
081: * @param modeConf this mode's configuration from resource description.
082: * @param conn Connection
083: * @param objectModel The objectModel
084: * @return exact value for key attribute column
085: * */
086: Object getPreValue(Configuration tableConf,
087: Configuration columnConf, Configuration modeConf,
088: Connection conn, Map objectModel) throws SQLException,
089: ConfigurationException;
090:
091: /**
092: * Provide subquery string for the key attribute column.
093: *
094: * If a value for the autoincrement column is needed (i.e. the
095: * column is not skipped), and the value can be determined through
096: * a nested subquery, this function provides the subquery as a
097: * string.
098: *
099: * @return subquery string for autoincrement column.
100: */
101: String getSubquery(Configuration tableConf,
102: Configuration columnConf, Configuration modeConf)
103: throws ConfigurationException;
104:
105: }
|