View Javadoc

1   /***
2    * Copyright 2009 ATG DUST Project Licensed under the Apache License, Version
3    * 2.0 (the "License"); you may not use this file except in compliance with the
4    * License. You may obtain a copy of the License at
5    * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6    * or agreed to in writing, software distributed under the License is
7    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8    * KIND, either express or implied. See the License for the specific language
9    * governing permissions and limitations under the License.
10   */
11  
12  package atg.service.idgen;
13  
14  import java.sql.ResultSet;
15  import java.sql.SQLException;
16  import java.sql.Statement;
17  
18  import atg.nucleus.ServiceException;
19  
20  /***
21   * This IDGenerator is intended to be used by unit tests. It will manage it's
22   * own database schema rather than assuming the tables already exist. Otherwise
23   * it's the same functionality as the SQLIdGenerator.
24   * 
25   * @author adamb
26   * @version $Id: //test/UnitTests/base/main/src/Java/atg/service/idgen/
27   *          InitializingSQLIdGenerator.java#1 $
28   */
29  public class InitializingSQLIdGenerator extends SQLIdGenerator implements
30      InitializingIdGenerator {
31  
32    IdGeneratorInitializer     mInitializer;
33  
34    /***
35     * The SQL statement required to create the table used by this component.
36     */
37    public static final String CREATE_STATEMENT = " create table das_id_generator ("
38                                                    + "id_space_name   varchar(60) not null,"
39                                                    + "seed    numeric(19,0)   not null,"
40                                                    + " batch_size      integer not null,"
41                                                    + " prefix  varchar(10),"
42                                                    + " suffix  varchar(10),"
43                                                    + "primary key (id_space_name)) ";
44  
45    /***
46     * Ensures that the required tables for this id generator exist.
47     */
48    @Override
49    public void doStartService() throws ServiceException {
50      if (mInitializer == null)
51        mInitializer = new IdGeneratorInitializer(this);
52      try {
53        mInitializer.initialize();
54      } catch (SQLException e) {
55        throw new ServiceException(e);
56      }
57    }
58  
59    /***
60     * Returns the create statement appropriate for the current database
61     */
62    public String getCreateStatement() {
63      // TODO Add DBCheck and return DB2 syntax
64      return CREATE_STATEMENT; 
65    }
66  }