1 21 package oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors; 23 24 import javax.persistence.SequenceGenerator; 25 import javax.persistence.TableGenerator; 26 27 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.objects.MetadataAccessibleObject; 28 29 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataConstants; 30 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataDescriptor; 31 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProcessor; 32 33 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.sequencing.MetadataTableGenerator; 34 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.sequencing.MetadataSequenceGenerator; 35 36 42 public abstract class NonRelationshipAccessor extends MetadataAccessor { 43 46 public NonRelationshipAccessor(MetadataAccessibleObject accessibleObject, MetadataProcessor processor, MetadataDescriptor descriptor) { 47 super(accessibleObject, processor, descriptor); 48 } 49 50 53 public NonRelationshipAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor) { 54 super(accessibleObject, classAccessor); 55 } 56 57 61 protected void processSequenceGenerator() { 62 SequenceGenerator sequenceGenerator = getAnnotation(SequenceGenerator.class); 63 64 if (sequenceGenerator != null) { 65 processSequenceGenerator(new MetadataSequenceGenerator(sequenceGenerator, getJavaClassName())); 67 } 68 } 69 70 74 protected void processSequenceGenerator(MetadataSequenceGenerator sequenceGenerator) { 75 String name = sequenceGenerator.getName(); 77 78 if (name.equals(MetadataConstants.DEFAULT_TABLE_GENERATOR)) { 79 m_validator.throwSequenceGeneratorUsingAReservedName(MetadataConstants.DEFAULT_TABLE_GENERATOR, sequenceGenerator.getLocation()); 80 } 81 82 if (m_project.hasConflictingSequenceGenerator(sequenceGenerator)) { 84 MetadataSequenceGenerator otherSequenceGenerator = m_project.getSequenceGenerator(name); 85 if (sequenceGenerator.loadedFromAnnotations() && otherSequenceGenerator.loadedFromXML()) { 86 return; 88 } else { 89 m_validator.throwConflictingSequenceGeneratorsSpecified(name, sequenceGenerator.getLocation(), otherSequenceGenerator.getLocation()); 90 } 91 } 92 93 if (m_project.hasTableGenerator(name)) { 94 MetadataTableGenerator otherTableGenerator = m_project.getTableGenerator(name); 95 m_validator.throwConflictingSequenceAndTableGeneratorsSpecified(name, sequenceGenerator.getLocation(), otherTableGenerator.getLocation()); 96 } 97 98 for (MetadataTableGenerator otherTableGenerator : m_project.getTableGenerators()) { 99 if (otherTableGenerator.getPkColumnValue().equals(sequenceGenerator.getSequenceName())) { 100 m_validator.throwConflictingSequenceNameAndTablePkColumnValueSpecified(sequenceGenerator.getSequenceName(), sequenceGenerator.getLocation(), otherTableGenerator.getLocation()); 101 } 102 } 103 104 m_project.addSequenceGenerator(sequenceGenerator); 105 } 106 107 111 protected void processTableGenerator() { 112 TableGenerator tableGenerator = getAnnotation(TableGenerator.class); 113 114 if (tableGenerator != null) { 115 processTableGenerator(new MetadataTableGenerator(tableGenerator, getJavaClassName())); 117 } 118 } 119 120 124 protected void processTableGenerator(MetadataTableGenerator tableGenerator) { 125 String name = tableGenerator.getName(); 127 128 if (name.equals(MetadataConstants.DEFAULT_SEQUENCE_GENERATOR)) { 129 m_validator.throwTableGeneratorUsingAReservedName(MetadataConstants.DEFAULT_SEQUENCE_GENERATOR, tableGenerator.getLocation()); 130 } 131 132 if (m_project.hasConflictingTableGenerator(tableGenerator)) { 134 MetadataTableGenerator otherTableGenerator = m_project.getTableGenerator(name); 135 if (tableGenerator.loadedFromAnnotations() && otherTableGenerator.loadedFromXML()) { 136 return; 138 } else { 139 m_validator.throwConflictingTableGeneratorsSpecified(name, tableGenerator.getLocation(), otherTableGenerator.getLocation()); 140 } 141 } 142 143 if (m_project.hasSequenceGenerator(tableGenerator.getName())) { 144 MetadataSequenceGenerator otherSequenceGenerator = m_project.getSequenceGenerator(name); 145 m_validator.throwConflictingSequenceAndTableGeneratorsSpecified(name, otherSequenceGenerator.getLocation(), tableGenerator.getLocation()); 146 } 147 148 for (MetadataSequenceGenerator otherSequenceGenerator : m_project.getSequenceGenerators()) { 149 if (otherSequenceGenerator.getSequenceName().equals(tableGenerator.getPkColumnValue())) { 150 m_validator.throwConflictingSequenceNameAndTablePkColumnValueSpecified(otherSequenceGenerator.getSequenceName(), otherSequenceGenerator.getLocation(), tableGenerator.getLocation()); 151 } 152 } 153 154 m_project.addTableGenerator(tableGenerator); 156 } 157 } 158 | Popular Tags |