1 25 26 package org.objectweb.speedo.generation.jdo; 27 28 import java.util.Iterator ; 29 30 import org.objectweb.speedo.api.SpeedoException; 31 import org.objectweb.speedo.api.SpeedoProperties; 32 import org.objectweb.speedo.generation.lib.AbstractGeneratorComponent; 33 import org.objectweb.speedo.metadata.SpeedoClass; 34 import org.objectweb.speedo.metadata.SpeedoExtension; 35 import org.objectweb.speedo.metadata.SpeedoIdentity; 36 import org.objectweb.speedo.metadata.SpeedoPackage; 37 import org.objectweb.speedo.sequence.lib.SpeedoSequence; 38 import org.objectweb.speedo.metadata.SpeedoXMLDescriptor; 39 40 43 public class SequenceGenerator extends AbstractGeneratorComponent { 44 45 public final static String LOGGER_NAME 46 = SpeedoProperties.LOGGER_NAME + ".generation.jorm"; 47 48 public boolean init() throws SpeedoException { 49 if (scp.getXmldescriptor().isEmpty()) { 50 return false; 51 } 52 logger = scp.loggerFactory.getLogger(LOGGER_NAME); 53 return true; 54 } 55 56 public void process() throws SpeedoException { 57 if (scp.getXmldescriptor().isEmpty()) { 58 return; 59 } 60 for (Iterator itDesc = scp.getXmldescriptor().values().iterator(); itDesc.hasNext();) { 62 addSerializeSequence((SpeedoXMLDescriptor) itDesc.next()); 63 } 64 } 65 66 private void addSerializeSequence(SpeedoXMLDescriptor desc) 67 throws SpeedoException { 68 for (Iterator itPack = desc.jdoPackage.values().iterator(); itPack.hasNext();) { 70 SpeedoPackage sp = (SpeedoPackage) itPack.next(); 71 for (Iterator itSequence = sp.jdoSequence.values().iterator(); itSequence.hasNext();) { 72 SpeedoSequence jdoSequence = (SpeedoSequence) itSequence.next(); 73 desc.mos.add(jdoSequence); 74 } 75 for (Iterator itClass = sp.jdoClass.values().iterator(); itClass.hasNext();) { 76 SpeedoClass speedoClass = (SpeedoClass) itClass.next(); 77 if (speedoClass.identityType == SpeedoIdentity.CONTAINER_ID 79 && speedoClass.getExtension(SpeedoProperties.VENDOR_NAME, 80 SpeedoProperties.ID).value.equals(SpeedoProperties.ID_SEQUENCE)) { 81 SpeedoSequence newSequence = new SpeedoSequence(); 83 String name; 84 SpeedoExtension se = speedoClass.getExtension( 86 SpeedoProperties.VENDOR_NAME, SpeedoProperties.SQL_SEQ_NAME); 87 if (se != null) { 88 name = se.value; 89 } else { 90 se = speedoClass.getExtension( 91 SpeedoProperties.VENDOR_NAME, SpeedoProperties.SQL_NAME); 92 if (se == null) { 93 name = speedoClass.name.toUpperCase(); 94 } else { 95 name = se.value; 96 } 97 name += "_SEQ"; 98 } 99 newSequence.name = name; 100 newSequence.datastoreName = name; 101 102 se = speedoClass.getExtension( 104 SpeedoProperties.VENDOR_NAME, SpeedoProperties.SQL_SEQ_INC); 105 if (se != null) { 106 newSequence.increment = new Integer (se.value); 108 } else { 109 newSequence.increment = new Integer (1); 110 } 111 112 se = speedoClass.getExtension( 114 SpeedoProperties.VENDOR_NAME, SpeedoProperties.SQL_SEQ_START); 115 if (se != null) { 116 newSequence.start = new Integer (se.value); 118 } 119 120 se = speedoClass.getExtension( 122 SpeedoProperties.VENDOR_NAME, SpeedoProperties.SQL_SEQ_CACHE); 123 if (se != null) { 124 newSequence.cache = new Integer (se.value); 126 } 127 128 se = speedoClass.getExtension( 130 SpeedoProperties.VENDOR_NAME, SpeedoProperties.SQL_SEQ_ALLOCATOR); 131 if (se != null) { 132 newSequence.factoryClass = se.value; 134 } 135 newSequence.packageName = sp.name; 137 newSequence.strategy = SpeedoSequence.NON_TRANSACTIONAL; 139 sp.addSequence(newSequence); 141 desc.mos.add(newSequence); 143 } 144 } 145 } 146 } 147 } 148 | Popular Tags |