KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > generation > mivisitor > DataStoreIdAdder


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.generation.mivisitor;
19
20 import org.objectweb.speedo.metadata.SpeedoClass;
21 import org.objectweb.speedo.metadata.SpeedoIdentity;
22 import org.objectweb.speedo.metadata.SpeedoExtension;
23 import org.objectweb.speedo.api.SpeedoException;
24 import org.objectweb.speedo.api.SpeedoProperties;
25
26 /**
27  * Assign a default value for the datastore identifier: polymorphid
28  *
29  * @author S.Chassande-Barrioz
30  */

31 public class DataStoreIdAdder extends AbstractMetaInfoVisitor {
32     public void visitClass(SpeedoClass sc) throws SpeedoException {
33         super.visitClass(sc);
34         if ((sc.identityType == SpeedoIdentity.CONTAINER_ID)
35             && (sc.getExtension(SpeedoProperties.VENDOR_NAME, SpeedoProperties.ID) == null)) {
36             //if no sql-seq-name, add an id extension with long
37
if (sc.getExtension(SpeedoProperties.VENDOR_NAME, SpeedoProperties.SQL_SEQ_NAME) == null) {
38                 sc.addExtension(new SpeedoExtension(SpeedoProperties.VENDOR_NAME,
39                         SpeedoProperties.ID, SpeedoProperties.ID_LONG, sc));
40             } else {
41                 //else, add an id extension with sequence
42
sc.addExtension(new SpeedoExtension(SpeedoProperties.VENDOR_NAME,
43                         SpeedoProperties.ID, SpeedoProperties.ID_SEQUENCE, sc));
44             }
45         }
46         //datastore
47
if ((sc.identityType == SpeedoIdentity.CONTAINER_ID)) {
48             //no id but a sql-seq-name
49
if (sc.getExtension(SpeedoProperties.VENDOR_NAME, SpeedoProperties.ID) == null
50                     && sc.getExtension(SpeedoProperties.VENDOR_NAME, SpeedoProperties.SQL_SEQ_NAME) != null){
51                 //add a datastoreSequence to the speedo class
52
sc.datastoreSequence = sc.getExtension(SpeedoProperties.VENDOR_NAME, SpeedoProperties.SQL_SEQ_NAME).value;
53             } else if (sc.getExtension(SpeedoProperties.VENDOR_NAME, SpeedoProperties.ID).value.equals(SpeedoProperties.ID_SEQUENCE)){
54                 SpeedoExtension se = sc.getExtension(SpeedoProperties.VENDOR_NAME, SpeedoProperties.SQL_SEQ_NAME);
55                 if (se != null) {
56                     sc.datastoreSequence = se.value;
57                 } else {
58                     se = sc.getExtension(SpeedoProperties.VENDOR_NAME, SpeedoProperties.SQL_NAME);
59                     if (se == null) {
60                         sc.datastoreSequence = sc.name.toUpperCase();
61                     } else {
62                         sc.datastoreSequence = se.value;
63                     }
64                     sc.datastoreSequence += "_SEQ";
65                 }
66             }
67         }
68     }
69 }
70
Popular Tags