| 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.SQLException; |
| 15 | |
| 16 | import atg.nucleus.ServiceException; |
| 17 | |
| 18 | /** |
| 19 | * This IDGenerator is intended to be used by unit tests. It will manage it's |
| 20 | * own database schema rather than assuming the tables already exist. Otherwise |
| 21 | * it's the same functionality as the ObfuscatedSQLIdGenerator. |
| 22 | * |
| 23 | * @author adamb |
| 24 | * @version $Id: //test/UnitTests/base/main/src/Java/atg/service/idgen/ |
| 25 | * InitializingSQLIdGenerator.java#1 $ |
| 26 | */ |
| 27 | public class InitializingObfuscatedSQLIdGenerator extends |
| 28 | ObfuscatedSQLIdGenerator implements InitializingIdGenerator { |
| 29 | |
| 30 | IdGeneratorInitializer mInitializer; |
| 31 | |
| 32 | /** |
| 33 | * The SQL statement required to create the table used by this component. |
| 34 | */ |
| 35 | public static final String CREATE_STATEMENT = "create table das_secure_id_gen" |
| 36 | + " (id_space_name varchar2(60) not null," |
| 37 | + "seed number(19,0) not null," |
| 38 | + "batch_size integer not null," |
| 39 | + "ids_per_batch integer null," |
| 40 | + "prefix varchar2(10)," |
| 41 | + "suffix varchar2(10)," |
| 42 | + "constraint das_secure_id_ge_p primary key (id_space_name))"; |
| 43 | |
| 44 | /** |
| 45 | * Ensures that the required tables for this id generator exist. |
| 46 | */ |
| 47 | @Override |
| 48 | public void doStartService() throws ServiceException { |
| 49 | if (mInitializer == null) |
| 50 | mInitializer = new IdGeneratorInitializer(this); |
| 51 | try { |
| 52 | mInitializer.initialize(); |
| 53 | } catch (SQLException e) { |
| 54 | throw new ServiceException(e); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns the create statement appropriate for the current database |
| 60 | */ |
| 61 | public String getCreateStatement() { |
| 62 | return CREATE_STATEMENT; |
| 63 | } |
| 64 | } |