Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/PoVoGenerator/Generator/src/org/litesoft/generator/GeneratePOGO.java

Diff revisions: vs.
  @@ -1,1294 +1,1293 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.generator;
3 -
4 - import org.litesoft.aokeyhole.objects.AttributeMetaData;
5 - import org.litesoft.aokeyhole.objects.*;
6 - import org.litesoft.aokeyhole.objects.attributes.*;
7 - import org.litesoft.aokeyhole.objects.properties.*;
8 - import org.litesoft.bo.attributes.*;
9 - import org.litesoft.codegen.*;
10 - import org.litesoft.commonfoundation.base.*;
11 - import org.litesoft.commonfoundation.typeutils.Objects;
12 - import org.litesoft.commonfoundation.typeutils.*;
13 - import org.litesoft.orsup.lazyeval.*;
14 -
15 - import java.util.*;
16 -
17 - public class GeneratePOGO extends AbstractPOFileGenerator {
18 - public static final String[] IMPLIMENTS_HAS_ATTRIBUTES = {"HasAttributes"};
19 -
20 - private static final AttributeType[] PAIRED_TYPES = new AttributeType[]{A_CommonPairedToOne.TYPE, A_PairedToOne.TYPE};
21 - private static final AttributeType[] BRIDGE_TYPES = new AttributeType[]{A_VariableBridgeToOneLeft.TYPE, A_BridgeToOneLeft.TYPE, A_BridgeToOneRight.TYPE};
22 -
23 - public GeneratePOGO( ErrorSinc pErrorSinc, ObjectMetaData pObjectMetaData, ObjectRef pObjectRef, ObjectRef pParentObjectRef, boolean pIsParent ) {
24 - super( pErrorSinc, pObjectMetaData, pObjectRef, "GO", pParentObjectRef, pIsParent );
25 - }
26 -
27 - @Override
28 - protected void LLaddImports() {
29 - boolean zHasAttributes = (getAttributes().length != 0);
30 - addImports( //
31 - zHasAttributes ? "org.litesoft.bo.attributes.*" : null, //
32 - "org.litesoft.core.util.*", //
33 - "org.litesoft.orsup.base.*", //
34 - zHasAttributes ? "org.litesoft.orsup.otherattributeaccessors.*" : null, //
35 - !mIsParent ? "org.litesoft.orsup.selection.*" : null, //
36 - "org.litesoft.orsup.transact.*", //
37 - null );
38 - }
39 -
40 - @Override
41 - protected void LLaddClassDefinition() {
42 - String[] zImplements = (getAttributes().length != 0) ? IMPLIMENTS_HAS_ATTRIBUTES : null;
43 - makeClassAbstract();
44 - if ( mIsParent ) {
45 - addClassDefinition( mClassName + "<T extends " + mObjectName + ">", getExtends( "org.litesoft.orsup.nonpublic.PersistentObjectImpl" ) + "<T>",
46 - zImplements );
47 - } else {
48 - addClassDefinition( mClassName, getExtends( "org.litesoft.orsup.nonpublic.PersistentObjectImpl" ) + "<" + mObjectName + ">", zImplements );
49 - }
50 - }
51 -
52 - @Override
53 - protected void LLaddClassBody() {
54 - addTopValidOptions( mObjectName + "Names.po" );
55 - if ( mIsParent ) {
56 - constructorsParent();
57 - } else {
58 - addLine( "private static final ConstructionControl CONSTRUCTION_CONTROL = new ConstructionControl();" );
59 - addBlankLine();
60 - addStaticMethodPublic( "SimpleFromIdentifier", "from" );
61 - addLine( "return " + mObjectName + "MetaData.INSTANCE;" );
62 - addMethodEnd();
63 - constructorsRegular();
64 - addRecordVersion();
65 - }
66 -
67 - LLaddAttributes( true );
68 -
69 - addMyMetaData();
70 - }
71 -
72 - private void constructorsParent() {
73 - addConstructorProtected( mClassName, "MetaDataForPO pMetaDataForPO", "Transaction pTransaction" );
74 - addLine( "super( pMetaDataForPO, pTransaction );" );
75 - addMethodEnd();
76 -
77 - addConstructorProtected( mClassName, "MetaDataForPO pMetaDataForPO", "ConstructionControl pConstructionControlExpected",
78 - "ConstructionControl pConstructionControlActual" );
79 - addLine( "super( pMetaDataForPO, pConstructionControlExpected, pConstructionControlActual );" );
80 - addBlockEnd();
81 - }
82 -
83 - private String getSequenceNumberSource() {
84 - for ( AttributeProxy zAttribute : getAttributes() ) {
85 - if ( !zAttribute.isVirtual() ) {
86 - if ( A_PairedToOne.TYPE.equals( zAttribute.getAttributeSetType() ) ) {
87 - String zToOne = ClassName.simpleIfPackage( zAttribute.getToOneFullyQualifiedName(), mPackage + "." );
88 - return zToOne + ".class";
89 - }
90 - }
91 - }
92 - return "getClass()";
93 - }
94 -
95 - private void constructorsRegular() {
96 - addConstructorProtected( mClassName, "Transaction pTransaction" );
97 - addLine( "super( " + mObjectName + "MetaData.INSTANCE, pTransaction );" );
98 - addLine( "mID = getNextSequenceNumber( " + getSequenceNumberSource() + " );" );
99 - addLine( "registerWithTransaction();" );
100 - addLine( "setDefaults();" );
101 - addMethodEnd();
102 -
103 - addConstructorProtected( mClassName, "ConstructionControl pConstructionControl" );
104 - addLine( "super( " + mObjectName + "MetaData.INSTANCE, CONSTRUCTION_CONTROL, pConstructionControl );" );
105 - addBlockEnd();
106 - }
107 -
108 - private void addRecordVersion() {
109 - addBlankLine();
110 - addLine( "public static final AttributeAccessorSCD CD_RecordVersion = new AttributeAccessor_RecordVersion();" );
111 - addBlankLine();
112 - addLine( "protected final RecordVersionHelper mRecordVersion = new RecordVersionHelper();" );
113 - addBlankLine();
114 - addMethodPublic( "Long", "getRecordVersion" );
115 - addLine( "return mRecordVersion.getRecordVersion();" );
116 - addMethodEnd();
117 - makeClassPrivate();
118 - makeClassStatic();
119 - addClassDefinition( "AttributeAccessor_RecordVersion", "AttributeAccessorSCD_RecordVersion<" + mObjectName + ">" );
120 - addConstructorPublic( "AttributeAccessor_RecordVersion" );
121 - addLine( "super( \"RecordVersion\", \"RecordVersion\" );" );
122 - addMethodEnd();
123 - addLine( "@Override" );
124 - addMethodProtected( "RecordVersionHelper", "getRecordVersionHelper", mObjectName + " pPO" );
125 - addLine( "return pPO.mRecordVersion;" );
126 - addBlockEnd();
127 - addBlockEnd();
128 - }
129 -
130 - public String getTableName() {
131 - return mObjectMetaData.getPropertyManager().get_String( PMD_TableName.NAME, mObjectName );
132 - }
133 -
134 - public String getDisplayValueFormat() {
135 - return quote( Strings.noEmpty( mObjectMetaData.getPropertyManager().get_String( PMD_DisplayValueFormat.NAME, "" ) ) );
136 - }
137 -
138 - private void addMyMetaData() {
139 - addBlankLine();
140 - makeClassStatic();
141 - makeClassPackageFriendly();
142 - if ( mIsParent ) {
143 - makeClassAbstract();
144 - addClassDefinition( "MyMetaData<T extends " + mObjectName + ">", getExtends( "org.litesoft.orsup.nonpublic.PersistentObjectImpl" ) + "MetaData<T>" );
145 - addConstructorPackageFriendly( "MyMetaData", "String pIdentifierName", "String pTableName", "AttributeAccessorKeySet pAttributeAccessorKeySet",
146 - "AttributeAccessorSCD... pAccessorSCDs" );
147 - addLine( "this( null, pIdentifierName, pTableName, pAttributeAccessorKeySet, pAccessorSCDs );" );
148 - addMethodEnd();
149 - addConstructorPackageFriendly( "MyMetaData", "AttributeAccessorSCD[] pAccessorSCDs", "String pIdentifierName", "String pTableName",
150 - "AttributeAccessorKeySet pAttributeAccessorKeySet", "AttributeAccessorSCD... pMoreAccessorSCDs" );
151 - addMDattributes( "super( join( pAccessorSCDs, pMoreAccessorSCDs ), pIdentifierName, pTableName, pAttributeAccessorKeySet", null );
152 - addBlockEnd();
153 - } else {
154 - addClassDefinition( "MyMetaData", getExtends( "org.litesoft.orsup.nonpublic.PersistentObjectImpl" ) + "MetaData<" + mObjectName + ">" );
155 - addPSFS( "OBJECT_NAME", mObjectName );
156 - addPSFS( "TABLE_NAME", getTableName() );
157 - addBlankLine();
158 -
159 - addConstructorPackageFriendly( "MyMetaData" );
160 - addMDattributes( "super( OBJECT_NAME, TABLE_NAME, new AttributeAccessorKeySet( CD_ID )", "RecordVersion" );
161 - addIndexes();
162 - addMethodEnd();
163 -
164 - addLine( "@Override" );
165 - addMethodPublic( "Class", "getPOclass" );
166 - addLine( "return " + mObjectName + ".class;" );
167 - addMethodEnd();
168 -
169 - addLine( "@Override" );
170 - addMethodPublic( mObjectName, "createNew", "Transaction pTransaction" );
171 - addLine( "return new " + mObjectName + "( pTransaction );" );
172 - addMethodEnd();
173 -
174 - addLine( "@Override" );
175 - addMethodPublic( mObjectName, "createPOfromFinder" );
176 - addLine( "return new " + mObjectName + "( CONSTRUCTION_CONTROL );" );
177 - addMethodEnd();
178 -
179 - addLine( "@Override" );
180 - addMethodPublic( "String", "getDisplayValueFormat" );
181 - addLine( "return " + getDisplayValueFormat() + ";" );
182 - addMethodEnd();
183 -
184 - addLine( "@Override" );
185 - addMethodPublic( "String", "getRecordVersionAttributeName" );
186 - addLine( "return CD_RecordVersion.getName();" );
187 - addBlockEnd();
188 -
189 - String zOrderBy = Strings.noEmpty( mObjectMetaData.getPropertyManager().get_String( PMD_OrderByAttribute.NAME, null ) );
190 - if ( zOrderBy != null ) {
191 - addBlankLine();
192 - addLine( "@Override" );
193 - addMethodPublic( "String", "getDefaultOrderByAttributeName" );
194 - addLine( "return \"" + zOrderBy + "\";" );
195 - addBlockEnd();
196 - }
197 - }
198 - String zTimeTracked = mObjectMetaData.getPropertyManager().get_String( PMD_TimeTracked.NAME, PMD_TimeTracked.NONE );
199 - if ( PMD_TimeTracked.CREATED.equals( zTimeTracked ) || PMD_TimeTracked.BOTH.equals( zTimeTracked ) ) {
200 - addSpecialTimestampMDmethods( "Created", "Creation" );
201 - }
202 - if ( PMD_TimeTracked.LAST_MOD.equals( zTimeTracked ) || PMD_TimeTracked.BOTH.equals( zTimeTracked ) ) {
203 - addSpecialTimestampMDmethods( "LastModified", "Transaction" );
204 - }
205 - addClassEnd();
206 - }
207 -
208 - private void addSpecialTimestampMDmethods( String pAttributeName, String pMethodName ) {
209 - addBlankLine();
210 - addLine( "@Override" );
211 - addMethodPublic( "String", "get" + pMethodName + "TimestampAttributeName" );
212 - addLine( "return CD_" + pAttributeName + ".getName();" );
213 - addMethodEnd();
214 -
215 - addLine( "@Override" );
216 - addMethodProtected( "void", "set" + pMethodName + "Timestamp", mObjectName + " pPersistentObject", "java.sql.Timestamp pTransactionTimeStamp" );
217 - addLine( "pPersistentObject.LLset" + pAttributeName + "( TypeConverter.to_SimpleTimestamp( pTransactionTimeStamp ) );" );
218 - addBlockEnd();
219 - }
220 -
221 - private void addIndexes() {
222 - List<AttributeMetaData> zAttributes = new ArrayList<AttributeMetaData>( mObjectMetaData.getSortedAttributes() );
223 - for ( ObjectMetaData zOMD = mObjectMetaData; zOMD.getParentName() != null; ) {
224 - ObjectMetaData zParentOMD = zOMD.getSystemMetaData().getObject( zOMD.getParentName() );
225 - if ( zParentOMD == null ) {
226 - throw new IllegalStateException( "Parent Name '" + zOMD.getParentName() + "' but no Parent on: " + zOMD );
227 - }
228 - zAttributes.addAll( zParentOMD.getSortedAttributes() );
229 - zOMD = zParentOMD;
230 - }
231 - Collections.sort( zAttributes );
232 -
233 - List<Index> zIndexes = new ArrayList<Index>();
234 -
235 - for ( Integer zGroup : getUniqueGroups( zAttributes ) ) {
236 - Index zIndex = new Index( getTableName(), "MUG", zGroup, true );
237 - for ( AttributeMetaData zAttribute : zAttributes ) {
238 - if ( zGroup.equals( zAttribute.getPropertyManager().get_Integer( PMD_UniqueGroup.NAME, null ) ) ) {
239 - zIndex.addAttribute( zAttribute.getName() );
240 - }
241 - }
242 - zIndexes.add( zIndex );
243 - }
244 -
245 - int zAutoIndexes = 0;
246 - for ( AttributeMetaData zAttribute : zAttributes ) {
247 - if ( isToOnePersisted( zAttribute ) && !alreadyIndexed( zIndexes, zAttribute.getName() ) ) {
248 - zIndexes.add( new Index( getTableName(), "21A", ++zAutoIndexes, false ).addAttribute( zAttribute.getName() ) );
249 - }
250 - }
251 -
252 - if ( !zIndexes.isEmpty() ) {
253 - int i = zIndexes.size() - 1;
254 - if ( i == 0 ) {
255 - addLine( "setIndexes( " + zIndexes.get( 0 ) + " );" );
256 - } else {
257 - addLine( "setIndexes( " + zIndexes.get( i-- ) + ", //" );
258 - while ( i > 0 ) {
259 - addLine( " " + zIndexes.get( i-- ) + ", //" );
260 - }
261 - addLine( " " + zIndexes.get( i ) + " );" );
262 - }
263 - }
264 - }
265 -
266 - private boolean isToOnePersisted( AttributeMetaData pAttribute ) {
267 - if ( !pAttribute.isVirtual() ) {
268 - AttributeType zType = pAttribute.getAttributeSet().getType();
269 - return zType.getFAT().isToOne() && !A_PairedToOne.TYPE.equals( zType );
270 - }
271 - return false;
272 - }
273 -
274 - private boolean alreadyIndexed( List<Index> pIndexes, String pAttributeName ) {
275 - for ( Index zIndex : pIndexes ) {
276 - if ( zIndex.isJustFor( pAttributeName ) ) {
277 - return true;
278 - }
279 - }
280 - return false;
281 - }
282 -
283 - private List<Integer> getUniqueGroups( List<AttributeMetaData> pAttributes ) {
284 - List<Integer> zUniqueGroups = new ArrayList<Integer>();
285 - for ( AttributeMetaData zAttribute : pAttributes ) {
286 - Integer zGroupID = zAttribute.getPropertyManager().get_Integer( PMD_UniqueGroup.NAME, null );
287 - if ( zGroupID != null ) {
288 - if ( zGroupID < 1 ) {
289 - throw new IllegalArgumentException( "Unique Group may only be Positive!" );
290 - }
291 - if ( !zUniqueGroups.contains( zGroupID ) ) {
292 - zUniqueGroups.add( zGroupID );
293 - }
294 - }
295 - }
296 - Collections.sort( zUniqueGroups );
297 - return zUniqueGroups;
298 - }
299 -
300 - private static class Index {
301 - private String mTableName;
302 - private String mType;
303 - private int mNumber;
304 - private boolean mUnique;
305 - private List<String> mAttributeNames = new ArrayList<String>();
306 -
307 - public Index( String pTableName, String pType, int pNumber, boolean pUnique ) {
308 - mTableName = pTableName;
309 - mType = pType;
310 - mNumber = pNumber;
311 - mUnique = pUnique;
312 - }
313 -
314 - @Override
315 - public String toString() {
316 - StringBuilder sb =
317 - new StringBuilder().append( "new Index( \"" ).append( mTableName ).append( mType ).append( "IDX" ).append( mNumber ).append( "\", null, " )
318 - .append( mUnique );
319 - for ( String zAttributeName : mAttributeNames ) {
320 - sb.append( ", CD_" ).append( zAttributeName );
321 - }
322 - return sb.append( " )" ).toString();
323 - }
324 -
325 - public Index addAttribute( String pName ) {
326 - mAttributeNames.add( pName );
327 - return this;
328 - }
329 -
330 - public boolean isJustFor( String pAttributeName ) {
331 - return (mAttributeNames.size() == 1) && pAttributeName.equals( mAttributeNames.get( 0 ) );
332 - }
333 - }
334 -
335 - private void addMDattributes( String pFirstLine, String pPlus ) {
336 - AttributeProxy[] zAttributes = getAttributes();
337 - if ( (zAttributes.length == 0) && (pPlus == null) ) {
338 - addLine( pFirstLine + " );" );
339 - return;
340 - }
341 -
342 - addLine( pFirstLine + ", //" );
343 -
344 - indentPlus( 7 );
345 -
346 - int zMaxLength = Strings.deNull( pPlus ).length();
347 -
348 - for ( AttributeProxy zAttribute : zAttributes ) {
349 - zMaxLength = Math.max( zMaxLength, zAttribute.getName().length() );
350 - }
351 -
352 - CDhelper zHelper = new CDhelper( zMaxLength );
353 -
354 - if ( pPlus != null ) {
355 - zHelper.addCD( "", pPlus, false );
356 - }
357 -
358 - if ( zAttributes.length != 0 ) {
359 - addCDs( zHelper, zAttributes, "", SELECT_ID );
360 - addCDs( zHelper, zAttributes, "Injected", SELECT_INJECTED );
361 - addCDs( zHelper, zAttributes, "Regular", SELECT_SIMPLE_REGULAR );
362 - addCDs( zHelper, zAttributes, "Virtual", SELECT_SIMPLE_VIRTUAL );
363 - addCDs( zHelper, zAttributes, "Bridge", SELECT_BRIDGE, true );
364 - addCDs( zHelper, zAttributes, "Paired", SELECT_PAIRED, true );
365 - addCDs( zHelper, zAttributes, "ToOne", SELECT_TOONE_REGULAR );
366 - addCDs( zHelper, zAttributes, "ToOne Virtual", SELECT_TOONE_VIRTUAL );
367 - addCDs( zHelper, zAttributes, "ToMany", SELECT_TOMANY );
368 - addCDs( zHelper, zAttributes, "????", SELECT_REMAINING );
369 - }
370 - zHelper.fini();
371 -
372 - indentMinus( 7 );
373 - }
374 -
375 - private void addCDs( CDhelper pHelper, AttributeProxy[] pAttributes, String pSectionTitle, AttributeSelector pSelector ) {
376 - addCDs( pHelper, pAttributes, pSectionTitle, pSelector, null );
377 - }
378 -
379 - private void addCDs( CDhelper pHelper, AttributeProxy[] pAttributes, String pSectionTitle, AttributeSelector pSelector, Boolean pRequired ) {
380 - for ( AttributeProxy zAttribute : pAttributes ) {
381 - String zAttributeName = zAttribute.getName();
382 - if ( pHelper.notProcessed( zAttributeName ) && pSelector.selects( zAttribute ) ) {
383 - pSectionTitle = pHelper.addCD( pSectionTitle, zAttributeName, (pRequired == null) ? zAttribute.isRequired() : pRequired );
384 - }
385 - }
386 - }
387 -
388 - private interface AttributeSelector {
389 - boolean selects( AttributeProxy zAttribute );
390 - }
391 -
392 - public static final AttributeSelector SELECT_ID = new AttributeSelector() {
393 - @Override
394 - public boolean selects( AttributeProxy pAttribute ) {
395 - return A_ID.TYPE.equals( pAttribute.getAttributeSetType() );
396 - }
397 - };
398 -
399 - public static final AttributeSelector SELECT_INJECTED = new AttributeSelector() {
400 - @Override
401 - public boolean selects( AttributeProxy pAttribute ) {
402 - return pAttribute.isInjected();
403 - }
404 - };
405 -
406 - public static final AttributeSelector SELECT_SIMPLE_REGULAR = new AttributeSelector() {
407 - @Override
408 - public boolean selects( AttributeProxy pAttribute ) {
409 - return !pAttribute.isVirtual() && pAttribute.getAttributeSetType().getFAT().isSimple();
410 - }
411 - };
412 -
413 - public static final AttributeSelector SELECT_SIMPLE_VIRTUAL = new AttributeSelector() {
414 - @Override
415 - public boolean selects( AttributeProxy pAttribute ) {
416 - return pAttribute.isVirtual() && pAttribute.getAttributeSetType().getFAT().isSimple();
417 - }
418 - };
419 -
420 - public static final AttributeSelector SELECT_BRIDGE = new AttributeSelector() {
421 - @Override
422 - public boolean selects( AttributeProxy pAttribute ) {
423 - return Objects.isOneOf( pAttribute.getAttributeSetType(), BRIDGE_TYPES );
424 - }
425 - };
426 -
427 - public static final AttributeSelector SELECT_PAIRED = new AttributeSelector() {
428 - @Override
429 - public boolean selects( AttributeProxy pAttribute ) {
430 - return Objects.isOneOf( pAttribute.getAttributeSetType(), PAIRED_TYPES );
431 - }
432 - };
433 -
434 - public static final AttributeSelector SELECT_TOONE_REGULAR = new AttributeSelector() {
435 - @Override
436 - public boolean selects( AttributeProxy pAttribute ) {
437 - return !pAttribute.isVirtual() && pAttribute.getAttributeSetType().getFAT().isToOne();
438 - }
439 - };
440 -
441 - public static final AttributeSelector SELECT_TOONE_VIRTUAL = new AttributeSelector() {
442 - @Override
443 - public boolean selects( AttributeProxy pAttribute ) {
444 - return pAttribute.isVirtual() && pAttribute.getAttributeSetType().getFAT().isToOne();
445 - }
446 - };
447 -
448 - public static final AttributeSelector SELECT_TOMANY = new AttributeSelector() {
449 - @Override
450 - public boolean selects( AttributeProxy pAttribute ) {
451 - return pAttribute.getAttributeSetType().getFAT().isToMany();
452 - }
453 - };
454 -
455 - public static final AttributeSelector SELECT_REMAINING = new AttributeSelector() {
456 - @Override
457 - public boolean selects( AttributeProxy pAttribute ) {
458 - return true;
459 - }
460 - };
461 -
462 - private class CDhelper {
463 - private Set<String> mNamesProcessed = new HashSet<String>();
464 - private int mMaxLength;
465 - private String mSectionTitle = null;
466 - private String mPrevName = null;
467 - private boolean mPrevRequired;
468 -
469 - public CDhelper( int pMaxLength ) {
470 - mMaxLength = pMaxLength + 2;
471 - }
472 -
473 - private void processPrev( boolean pMore ) {
474 - if ( mPrevName != null ) {
475 - if ( mSectionTitle != null ) {
476 - addBlankLine();
477 - if ( mSectionTitle.length() != 0 ) {
478 - addLine( "// " + mSectionTitle );
479 - }
480 - mSectionTitle = null;
481 - }
482 - StringBuilder sb = new StringBuilder();
483 - sb.append( "CD_" ).append( mPrevName );
484 - int zDots = mMaxLength - mPrevName.length();
485 - mPrevName = null;
486 - if ( pMore ) {
487 - sb.append( ", /* " );
488 - } else {
489 - sb.append( " /* ." );
490 - }
491 - while ( zDots-- > 0 ) {
492 - sb.append( '.' );
493 - }
494 - if ( mPrevRequired ) {
495 - sb.append( " Required" );
496 - }
497 - sb.append( " */" );
498 - if ( !pMore ) {
499 - sb.append( " );" );
500 - }
501 - addLine( sb.toString() );
502 - }
503 - }
504 -
505 - public String addCD( String pSectionTitle, String pAttributeName, boolean pRequired ) {
506 - processPrev( true );
507 - mSectionTitle = pSectionTitle;
508 - mPrevName = pAttributeName;
509 - mPrevRequired = pRequired;
510 - mNamesProcessed.add( pAttributeName );
511 - return null;
512 - }
513 -
514 - public void fini() {
515 - processPrev( false );
516 - }
517 -
518 - public boolean notProcessed( String pAttributeName ) {
519 - return !mNamesProcessed.contains( pAttributeName );
520 - }
521 - }
522 -
523 - @Override
524 - protected void LLaddAttribute( AttributeProxy pAttribute ) {
525 - FundamentalAttributeType zFAT = pAttribute.getAttributeSetType().getFAT();
526 - switch ( zFAT ) {
527 - default:
528 - mErrorSinc.addError( "CurrentlyUnsupportedAttributeType FAT", "of: " + zFAT, pAttribute.toString(), mObjectMetaData.toStringForError() );
529 - break;
530 - case Simple:
531 - addAttributeSimple( pAttribute );
532 - break;
533 - case ToOne:
534 - addAttributeToOne( pAttribute );
535 - break;
536 - case ToMany:
537 - addAttributeToMany( pAttribute );
538 - break;
539 - }
540 - }
541 -
542 - private void addAttributeSimple( AttributeProxy pAttribute ) {
543 - Class zSimpleDataTypeClass = pAttribute.getSimpleDataType();
544 - if ( zSimpleDataTypeClass == null ) {
545 - mErrorSinc.addError( "CurrentlyUnsupportedAttributeType", pAttribute.toString(), mObjectMetaData.toStringForError() );
546 - return;
547 - }
548 - String zSimpleDataTypeSimpleName = ClassName.simple( zSimpleDataTypeClass );
549 - String zSimpleDataType = ClassName.simpleIfPackage( zSimpleDataTypeClass, JAVA_LANG_PACKAGE );
550 -
551 - String zDBtype = null;
552 - LiteSoftToJDBCtypeSupport zJDBCtypeSupport = !pAttribute.isVirtual() ? LiteSoftToJDBCtypeSupport.get( zSimpleDataTypeClass ) : null;
553 - if ( (zJDBCtypeSupport != null) ) {
554 - Class<?> zClass = zJDBCtypeSupport.getJDBC();
555 - if ( NonPersistable.class.equals( zClass ) ) {
556 - mErrorSinc.addError( "CurrentlyUnsupportedAttributeType", pAttribute.toString(), mObjectMetaData.toStringForError() );
557 - return;
558 - }
559 - zDBtype = zClass.getName();
560 - }
561 -
562 - String zName = pAttribute.getName();
563 - addLine( "public static final AttributeAccessorSCD CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
564 - addBlankLine();
565 - String zExtends;
566 - String zNonImportableFeature = null;
567 - Mutability zMutability = pAttribute.getMutability();
568 - AttributeType zAttributeType = pAttribute.getAttributeSetType();
569 - if ( A_ID.TYPE.equals( zAttributeType ) || pAttribute.isSysSetOnly() ) {
570 - zNonImportableFeature = "NonImportableFeature";
571 - zMutability = Mutability.RO;
572 - } else if ( pAttribute.getPropertyManager().get_boolean( PMD_CachedCalculatedValue.NAME ) ) {
573 - zNonImportableFeature = "NonImportableFeature";
574 - }
575 -
576 - String zNotes = pAttribute.getNotes();
577 -
578 - boolean zEncrypted = A_Password.TYPE.equals( zAttributeType );
579 - String zCaseControl = Strings.noEmpty( pAttribute.getPropertyManager().get_String( PMD_Case.NAME, null ) );
580 -
581 - String zCharacterCaseIgnored = PMD_Case.IGNORED.equals( zCaseControl ) ? "CharacterCaseIgnored" : null;
582 -
583 - if ( pAttribute.isVirtual() ) {
584 - addNotes( zNotes );
585 - zExtends = "Virtual";
586 - addAbstractMethodPublic( zSimpleDataType, "get" + zName );
587 - addBlankLine();
588 -
589 - addAbstractMethodProtected( "void", "LLclear" + zName );
590 - addBlankLine();
591 -
592 - if ( !Mutability.RO.equals( zMutability ) ) {
593 - addAbstractMethodProtected( "void", "LLset" + zName, zSimpleDataType + " p" + zName );
594 - addBlankLine();
595 -
596 - addMethodPublic( "void", "set" + zName, zSimpleDataType + " p" + zName );
597 - addLine( "verifyMutability( CD_" + zName + ", get" + zName + "(), p" + zName + " );" );
598 - addLine( "LLset" + zName + "( p" + zName + ");" );
599 - addMethodEnd();
600 - }
601 - } else {
602 - zExtends = "Persisted";
603 -
604 - if ( zJDBCtypeSupport == null ) {
605 - addLine( "private " + zSimpleDataType + " m" + zName + ";" + (zEncrypted ? " // Encrypted" : "") );
606 - } else {
607 - String zLazyEvalName = zJDBCtypeSupport.getLazyEval().getName();
608 - addLine( "final " + zLazyEvalName + " m" + zName + " = new " + zLazyEvalName + "();" );
609 - }
610 - addBlankLine();
611 -
612 - addNotes( zNotes );
613 - addMethodPublic( zSimpleDataType, "get" + zName );
614 - if ( zJDBCtypeSupport != null ) {
615 - addLine( "return m" + zName + ".get" + zSimpleDataTypeSimpleName + "();" );
616 - } else {
617 - if ( zEncrypted ) {
618 - addLine( "return fromEncrypted( LLget" + zName + "() );" );
619 - addMethodEnd();
620 -
621 - addMethodPublic( zSimpleDataType, "LLget" + zName );
622 - }
623 - addLine( "return m" + zName + ";" );
624 - }
625 - addMethodEnd();
626 -
627 - if ( Mutability.RO.equals( zMutability ) ) {
628 - addMethodProtected( "void", "LLset" + zName, zSimpleDataType + " p" + zName );
629 - } else {
630 - addMethodPublic( "void", "set" + zName, zSimpleDataType + " p" + zName );
631 - if ( zEncrypted ) {
632 - addLine( "LLset" + zName + "( toEncrypted( p" + zName + " ) );" );
633 - addMethodEnd();
634 -
635 - addMethodProtected( "void", "LLset" + zName, zSimpleDataType + " p" + zName );
636 - }
637 - }
638 - if ( zJDBCtypeSupport == null ) {
639 - addLine( "verifyMutability( CD_" + zName + ", m" + zName + ", p" + zName + " );" );
640 -
641 - if ( PMD_Case.UPPERED.equals( zCaseControl ) ) {
642 - addLine( "m" + zName + " = toUpperCase( p" + zName + " );" );
643 - } else if ( PMD_Case.LOWERED.equals( zCaseControl ) ) {
644 - addLine( "m" + zName + " = toLowerCase( p" + zName + " );" );
645 - } else {
646 - addLine( "m" + zName + " = p" + zName + ";" );
647 - }
648 - } else {
649 - addLine( "verifyMutability( CD_" + zName + ", m" + zName + ".get" + zSimpleDataTypeSimpleName + "(), p" + zName + " );" );
650 - addLine( "m" + zName + ".set" + zSimpleDataTypeSimpleName + "( p" + zName + " );" );
651 - }
652 - addMethodEnd();
653 - }
654 - makeClassPrivate();
655 - makeClassStatic();
656 - zExtends = "AttributeAccessorSCDsimple" + zExtends +
657 - (Mutability.RO.equals( zMutability ) ? (pAttribute.isSysSetOnly() ? "SysSetOnly" : "ReadOnly") : "Regular");
658 - zExtends += "<" + mObjectName + ">";
659 - addClassDefinition( "AttributeAccessor_" + zName, zExtends, zNonImportableFeature, zCharacterCaseIgnored );
660 -
661 - addConstructorPublic( "AttributeAccessor_" + zName );
662 - String zBaseLine = "super( \"" + zName + "\"";
663 - if ( !pAttribute.isVirtual() ) {
664 - zBaseLine += ", \"" + pAttribute.getColumnName() + "\"";
665 - }
666 - String zTypeExtra = createAttributeTypedCall( pAttribute, "PO", zBaseLine, ";" );
667 - addMethodEnd();
668 -
669 - if ( !Mutability.RO.equals( zMutability ) ) {
670 - String zDefaultValue = pAttribute.getPropertyManager().get_String( PMD_DefaultValue.NAME, null );
671 - if ( zDefaultValue != null ) {
672 - addLine( "@Override" );
673 - addMethodPublic( "Object", "getDefault" );
674 - if ( pAttribute.getBoAttributeType().dataNeedsQuoting() ) {
675 - zDefaultValue = quote( zDefaultValue );
676 - }
677 - addLine( "return " + zDefaultValue + ";" );
678 - addMethodEnd();
679 - }
680 - }
681 -
682 - addLine( "@Override" );
683 - addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
684 - addLine( "return pPO.get" + zName + "();" );
685 -
686 - if ( pAttribute.isVirtual() ) {
687 - if ( !Mutability.RO.equals( zMutability ) ) {
688 - addMethodEnd();
689 - addLine( "@Override" );
690 - addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
691 - addLine( "pPO.set" + zName + "( to_" + zSimpleDataTypeSimpleName + "( " + zTypeExtra + "pValue ) );" );
692 - }
693 - addMethodEnd();
694 -
695 - addLine( "@Override" );
696 - addMethodProtected( "void", "LL_clearVirtualValueOnPO", mObjectName + " pPO" );
697 - addLine( "pPO.LLclear" + zName + "();" );
698 - } else if ( zJDBCtypeSupport == null ) {
699 - if ( Mutability.RO.equals( zMutability ) ) {
700 - addMethodEnd();
701 - addLine( "@Override" );
702 - addMethodPublic( "void", "db_setValueOnPO", mObjectName + " pPO", "Object pValue" );
703 - addLine( "pPO.LLset" + zName + "( to_" + zSimpleDataTypeSimpleName + "( " + zTypeExtra + "pValue ) );" );
704 - } else {
705 - addMethodEnd();
706 - addLine( "@Override" );
707 - addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
708 - addLine( "pPO.set" + zName + "( to_" + zSimpleDataTypeSimpleName + "( " + zTypeExtra + "pValue ) );" );
709 -
710 - if ( zEncrypted ) {
711 - addMethodEnd();
712 - addLine( "@Override" );
713 - addMethodPublic( "Object", "db_getValueOnPO", mObjectName + " pPO" );
714 - addLine( "return pPO.LLget" + zName + "();" );
715 -
716 - addMethodEnd();
717 - addLine( "@Override" );
718 - addMethodPublic( "void", "db_setValueOnPO", mObjectName + " pPO", "Object pValue" );
719 - addLine( "pPO.LLset" + zName + "( to_" + zSimpleDataTypeSimpleName + "( pValue ) );" );
720 - }
721 - }
722 - } else {
723 - if ( !Mutability.RO.equals( zMutability ) ) {
724 - addMethodEnd();
725 - addLine( "@Override" );
726 - addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
727 - addLine( "pPO.set" + zName + "( to_" + zSimpleDataTypeSimpleName + "( " + zTypeExtra + "pValue ) );" );
728 - }
729 - addMethodEnd();
730 - String zMethodSuffix = zDBtype.replace( '.', '_' );
731 - addLine( "@Override" );
732 - addMethodPublic( "Object", "db_getValueOnPO", mObjectName + " pPO" );
733 - addLine( "return pPO.m" + zName + ".get_" + zMethodSuffix + "();" );
734 - addMethodEnd();
735 - addLine( "@Override" );
736 - addMethodPublic( "void", "db_setValueOnPO", mObjectName + " pPO", "Object pValue" );
737 - addLine( "pPO.m" + zName + ".set_" + zMethodSuffix + "( " + zJDBCtypeSupport.getTypeConverterMethod() + "( " + "pValue ) );" );
738 - }
739 - addBlockEnd();
740 - addClassEnd();
741 - }
742 -
743 - private void addAttributeToOne( AttributeProxy pAttribute ) {
744 - if ( pAttribute.isVirtual() ) {
745 - addAttributeToOneVirtual( pAttribute );
746 - return;
747 - }
748 - AttributeType zType = pAttribute.getAttributeSetType();
749 - if ( A_Blob.TYPE.equals( zType ) ) {
750 - addAttributeToBlob( pAttribute );
751 - return;
752 - }
753 - if ( A_CommonPairedToOne.TYPE.equals( zType ) ) {
754 - addAttributeToOneCommonPaired( pAttribute );
755 - return;
756 - }
757 - if ( A_PairedToOne.TYPE.equals( zType ) ) {
758 - addAttributeToOnePaired( pAttribute );
759 - return;
760 - }
761 - if ( A_ToOne.TYPE.equals( zType ) ) {
762 - addAttributeToOneRegular( pAttribute );
763 - return;
764 - }
765 - if ( A_VariableBridgeToOneLeft.TYPE.equals( zType ) ) {
766 - addAttributeToOneVariableBridgeLeft( pAttribute );
767 - return;
768 - }
769 - if ( A_VariableToOne.TYPE.equals( zType ) ) {
770 - addAttributeToOneVariable( pAttribute );
771 - return;
772 - }
773 - if ( A_BridgeToOneLeft.TYPE.equals( zType ) || A_BridgeToOneRight.TYPE.equals( zType ) ) {
774 - addAttributeToOneBridge( pAttribute );
775 - return;
776 - }
777 - throw new Error( "Currently Unsupported To One Type: " + zType + " on " + pAttribute + " on " + mObjectName );
778 - }
779 -
780 - private void addToOneRegular( AttributeProxy pAttribute, boolean pRequired, boolean pCascadeDeleteThem ) {
781 - String zName = pAttribute.getName();
782 - String zToOne = ClassName.simpleIfPackage( pAttribute.getToOneFullyQualifiedName(), mPackage + "." );
783 - String zGenericType = "<" + mObjectName + "," + zToOne + ">";
784 - String zAAtype = "AttributeAccessorSCDtoOneRegular" + zGenericType;
785 - addLine( "public static final " + zAAtype + " CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
786 - addBlankLine();
787 -
788 - String zLLtype = "org.litesoft.orsup.lazyload.LazyLoadToOneRegular" + zGenericType;
789 - addLine( "protected " + zLLtype + " m" + zName + " = //" );
790 - addLine( " new " + zLLtype + "( (" + mObjectName + ") this, CD_" + zName + " );" );
791 - addBlankLine();
792 -
793 - addMethodPublic( zToOne, "get" + zName );
794 - addLine( "return processLazyLoadAccess( m" + zName + " );" );
795 - addMethodEnd();
796 -
797 - Mutability zMutability = pAttribute.getMutability();
798 - if ( !Mutability.RO.equals( zMutability ) ) {
799 - addMethodPublic( "void", "set" + zName, zToOne + " p" + zName );
800 - addLine( "processLazyLoadMutation( m" + zName + ", p" + zName + " );" );
801 - addMethodEnd();
802 - }
803 -
804 - makeClassPrivate();
805 - makeClassStatic();
806 - addClassDefinition( "AttributeAccessor_" + zName, zAAtype );
807 -
808 - addConstructorPublic( "AttributeAccessor_" + zName );
809 - addLine( "super( \"" + zName + "\", \"" + zName + "_id\", " + zToOne + ".class, \"ID\", \"" + pAttribute.getToOneBackReference() + "\", " + //
810 - pCascadeDeleteThem + ", " + //
811 - pRequired + ", Mutability." + zMutability + " );" );
812 - addMethodEnd();
813 -
814 - addLine( "@Override" );
815 - addMethodPublic( zLLtype, "getValueHolder", mObjectName + " pPO" );
816 - addLine( "return pPO.m" + zName + ";" );
817 - addMethodEnd();
818 -
819 - addLine( "@Override" );
820 - addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
821 - addLine( "return pPO.get" + zName + "();" );
822 - addMethodEnd();
823 -
824 - addLine( "@Override" );
825 - addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
826 -
827 - if ( Mutability.RO.equals( zMutability ) ) {
828 - addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
829 - } else {
830 - addLine( "pPO.set" + zName + "( to_PO( pPO, " + zToOne + ".class, pValue ) );" );
831 - }
832 - addMethodEnd();
833 -
834 - addLine( "@Override" );
835 - addMethodPublic( "Object", "db_getValueOnPO", mObjectName + " pPO" );
836 - addLine( "return pPO.m" + zName + ".db_getValue();" );
837 - addMethodEnd();
838 - addLine( "@Override" );
839 - addMethodPublic( "void", "db_setValueOnPO", mObjectName + " pPO", "Object pValue" );
840 - addLine( "pPO.m" + zName + ".db_setValue( to_Long( " + "pValue ) );" );
841 - addBlockEnd();
842 - addClassEnd();
843 - }
844 -
845 - private void addToOneVariable( AttributeProxy pAttribute, boolean pRequired ) {
846 - String zName = pAttribute.getName();
847 - String zGeneraicType = "<" + mObjectName + ">";
848 - String zAAtype = "AttributeAccessorSCDtoOneVariable" + zGeneraicType;
849 - addLine( "public static final " + zAAtype + " CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
850 - addBlankLine();
851 -
852 - String zLLtype = "org.litesoft.orsup.lazyload.LazyLoadToOneVariable" + zGeneraicType;
853 - addLine( "protected " + zLLtype + " m" + zName + " = //" );
854 - addLine( " new " + zLLtype + "( (" + mObjectName + ") this, CD_" + zName + " );" );
855 - addBlankLine();
856 -
857 - addMethodPublic( "org.litesoft.orsup.nonpublic.PersistentObjectImpl", "get" + zName );
858 - addLine( "return processLazyLoadAccess( m" + zName + " );" );
859 - addMethodEnd();
860 -
861 - makeClassPrivate();
862 - makeClassStatic();
863 - addClassDefinition( "AttributeAccessor_" + zName, zAAtype );
864 -
865 - Mutability zMutability = pAttribute.getMutability();
866 -
867 - addConstructorPublic( "AttributeAccessor_" + zName );
868 - addLine( "super( \"" + zName + "\", \"" + zName + "\", " + pRequired + ", Mutability." + zMutability + " );" );
869 - addMethodEnd();
870 -
871 - addLine( "@Override" );
872 - addMethodPublic( zLLtype, "getValueHolder", mObjectName + " pPO" );
873 - addLine( "return pPO.m" + zName + ";" );
874 - addMethodEnd();
875 -
876 - addLine( "@Override" );
877 - addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
878 - addLine( "return pPO.get" + zName + "();" );
879 - addBlockEnd();
880 - addClassEnd();
881 - }
882 -
883 - private void addAttributeToOneVirtual( AttributeProxy pAttribute ) {
884 - String zName = pAttribute.getName();
885 - String zToOne = ClassName.simpleIfPackage( pAttribute.getToOneFullyQualifiedName(), mPackage + "." );
886 - String zGenericType = "<" + mObjectName + "," + zToOne + ">";
887 - String zAAtype = "AttributeAccessorSCDtoOneVirtual" + zGenericType;
888 - addLine( "public static final " + zAAtype + " CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
889 - addBlankLine();
890 -
891 - addAbstractMethodPublic( zToOne, "get" + zName );
892 - addBlankLine();
893 -
894 - addAbstractMethodProtected( "void", "LLclear" + zName );
895 - addBlankLine();
896 -
897 - Mutability zMutability = pAttribute.getMutability();
898 - if ( !Mutability.RO.equals( zMutability ) ) {
899 - addAbstractMethodProtected( "void", "LLset" + zName, zToOne + " p" + zName );
900 - addBlankLine();
901 -
902 - addMethodPublic( "void", "set" + zName, zToOne + " p" + zName );
903 - addLine( "verifyMutability( CD_" + zName + ", get" + zName + "(), p" + zName + " );" );
904 - addLine( "LLset" + zName + "( p" + zName + ");" );
905 - addMethodEnd();
906 - }
907 -
908 - makeClassPrivate();
909 - makeClassStatic();
910 - addClassDefinition( "AttributeAccessor_" + zName, zAAtype );
911 -
912 - addConstructorPublic( "AttributeAccessor_" + zName );
913 - addLine( "super( \"" + zName + "\", " + zToOne + ".class, " + (pAttribute.isRequired() ? "true" : "false") + ", Mutability." + zMutability + " );" );
914 - addMethodEnd();
915 -
916 - addLine( "@Override" );
917 - addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
918 - addLine( "return pPO.get" + zName + "();" );
919 - addMethodEnd();
920 -
921 - addLine( "@Override" );
922 - addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
923 -
924 - if ( Mutability.RO.equals( zMutability ) ) {
925 - addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
926 - } else {
927 - addLine( "pPO.set" + zName + "( to_PO( pPO, " + zToOne + ".class, pValue ) );" );
928 - }
929 - addMethodEnd();
930 -
931 - addLine( "@Override" );
932 - addMethodProtected( "void", "LL_clearVirtualValueOnPO", mObjectName + " pPO" );
933 - addLine( "pPO.LLclear" + zName + "();" );
934 - addBlockEnd();
935 - addClassEnd();
936 - }
937 -
938 - private void addAttributeToBlob( AttributeProxy pAttribute ) {
939 - // A_Blob.TYPE, pPersisted
940 - throw new Error( "Blob's can not currently be generated for " + pAttribute + " on " + mObjectName );
941 - }
942 -
943 - private void addAttributeToOneCommonPaired( AttributeProxy pAttribute ) {
944 - // A_CommonPairedToOne.TYPE, pPersisted - String (To ObjectName) PMD_UniqueGroup, PMD_ColumnName, implicitly Required! & Changeable?
945 - String zName = pAttribute.getName();
946 - String zGenericType = "<" + mObjectName + ">";
947 - String zAAtype = "AttributeAccessorSCDtoOneCommonPaired" + zGenericType;
948 - addLine( "public static final " + zAAtype + " CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
949 - addBlankLine();
950 -
951 - String zLLtype = "org.litesoft.orsup.lazyload.LazyLoadToOneCommonPaired" + zGenericType;
952 - addLine( "protected " + zLLtype + " m" + zName + " = //" );
953 - addLine( " new " + zLLtype + "( (" + mObjectName + ") this, CD_" + zName + " );" );
954 - addBlankLine();
955 -
956 - addMethodPublic( "org.litesoft.orsup.nonpublic.PersistentObjectImpl", "get" + zName );
957 - addLine( "return processLazyLoadAccess( m" + zName + " );" );
958 - addMethodEnd();
959 -
960 - addMethodPublic( "void", "set" + zName, "org.litesoft.orsup.nonpublic.PersistentObjectImpl p" + zName );
961 - addLine( "processLazyLoadMutation( m" + zName + ", p" + zName + " );" );
962 - addMethodEnd();
963 -
964 - addMethodProtected( "void", "replacing" + zName, "org.litesoft.orsup.nonpublic.PersistentObjectImpl pOld" + zName,
965 - "org.litesoft.orsup.nonpublic.PersistentObjectImpl pNew" + zName );
966 - addMethodEnd();
967 -
968 - makeClassPrivate();
969 - makeClassStatic();
970 - addClassDefinition( "AttributeAccessor_" + zName, zAAtype );
971 -
972 - addConstructorPublic( "AttributeAccessor_" + zName );
973 - addLine( "super( \"" + zName + "\", \"" + zName + "\" );" );
974 - addMethodEnd();
975 -
976 - addLine( "@Override" );
977 - addMethodPublic( zLLtype, "getValueHolder", mObjectName + " pPO" );
978 - addLine( "return pPO.m" + zName + ";" );
979 - addMethodEnd();
980 -
981 - addLine( "@Override" );
982 - addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
983 - addLine( "return pPO.get" + zName + "();" );
984 - addMethodEnd();
985 -
986 - addLine( "@Override" );
987 - addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
988 - addLine( "pPO.set" + zName + "( (org.litesoft.orsup.nonpublic.PersistentObjectImpl)pValue );" );
989 - addMethodEnd();
990 -
991 - addLine( "@Override" );
992 - addMethodPublic( "void", "pairReplaced", mObjectName + " pPO", "org.litesoft.orsup.nonpublic.PersistentObjectImpl pOld" + zName,
993 - "org.litesoft.orsup.nonpublic.PersistentObjectImpl pNew" + zName );
994 - addLine( "pPO.replacing" + zName + "( pOld" + zName + ", pNew" + zName + " );" );
995 - addBlockEnd();
996 - addClassEnd();
997 - }
998 -
999 - private void addAttributeToOnePaired( AttributeProxy pAttribute ) {
1000 - // A_PairedToOne.TYPE, pPersisted - Not Really Persisted - MetaData Driven for Object Reference;
1001 - String zName = pAttribute.getName();
1002 - String zToOne = ClassName.simpleIfPackage( pAttribute.getToOneFullyQualifiedName(), mPackage + "." );
1003 - String zGenericType = "<" + mObjectName + "," + zToOne + ">";
1004 - String zAAtype = "AttributeAccessorSCDtoOnePaired" + zGenericType;
1005 - addLine( "public static final " + zAAtype + " CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
1006 - addBlankLine();
1007 -
1008 - String zLLtype = "org.litesoft.orsup.lazyload.LazyLoadToOnePaired" + zGenericType;
1009 - addLine( "protected " + zLLtype + " m" + zName + " = //" );
1010 - addLine( " new " + zLLtype + "( (" + mObjectName + ") this, CD_" + zName + " );" );
1011 - addBlankLine();
1012 -
1013 - addMethodPublic( zToOne, "get" + zName );
1014 - addLine( "return processLazyLoadAccess( m" + zName + " );" );
1015 - addMethodEnd();
1016 -
1017 - makeClassPrivate();
1018 - makeClassStatic();
1019 - addClassDefinition( "AttributeAccessor_" + zName, zAAtype );
1020 -
1021 - addConstructorPublic( "AttributeAccessor_" + zName );
1022 - addLine( "super( \"" + zName + "\", " + zToOne + ".class );" );
1023 - addMethodEnd();
1024 -
1025 - addLine( "@Override" );
1026 - addMethodPublic( zLLtype, "getValueHolder", mObjectName + " pPO" );
1027 - addLine( "return pPO.m" + zName + ";" );
1028 - addMethodEnd();
1029 -
1030 - addLine( "@Override" );
1031 - addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
1032 - addLine( "return pPO.get" + zName + "();" );
1033 - addBlockEnd();
1034 - addClassEnd();
1035 - }
1036 -
1037 - private void addAttributeToOneRegular( AttributeProxy pAttribute ) {
1038 - addToOneRegular( pAttribute, pAttribute.isRequired(), pAttribute.getPropertyManager().get_boolean( PMD_CascadeDeleteThem.NAME ) );
1039 - }
1040 -
1041 - private void addAttributeToOneVariable( AttributeProxy pAttribute ) {
1042 - addToOneVariable( pAttribute, pAttribute.isRequired() ); // todo: , pAttribute.getPropertyManager().get_boolean( PMD_CascadeDeleteThem.NAME ) );
1043 - }
1044 -
1045 - private void addAttributeToOneBridge( AttributeProxy pAttribute ) {
1046 - // A_BridgeToOneRight.TYPE, pPersisted
1047 - // A_BridgeToOneLeft.TYPE, pPersisted
1048 - addToOneRegular( pAttribute, true, false );
1049 - }
1050 -
1051 - private void addAttributeToOneVariableBridgeLeft( AttributeProxy pAttribute ) {
1052 - addToOneVariable( pAttribute, true );
1053 - }
1054 -
1055 - private void addAttributeToMany( AttributeProxy pAttribute ) {
1056 - if ( pAttribute.isVirtual() ) {
1057 - addAttributeToManyVirtual( pAttribute );
1058 - return;
1059 - }
1060 - AttributeProxy pBackReferenceAttributeProxy = pAttribute.getToManyBackReferenceAttributeProxy();
1061 - AttributeType zBackType = (pBackReferenceAttributeProxy != null) ? pBackReferenceAttributeProxy.getAttributeSetType() : null;
1062 - if ( A_ToOne.TYPE.equals( zBackType ) ) {
1063 - addAttributeToManyRegular( pAttribute );
1064 - return;
1065 - }
1066 - if ( A_VariableBridgeToOneLeft.TYPE.equals( zBackType ) ) {
1067 - addAttributeToManyVariableBridgeLeft( pAttribute );
1068 - return;
1069 - }
1070 - if ( A_VariableToOne.TYPE.equals( zBackType ) ) {
1071 - addAttributeToManyVariable( pAttribute );
1072 - return;
1073 - }
1074 - if ( A_BridgeToOneLeft.TYPE.equals( zBackType ) || A_BridgeToOneRight.TYPE.equals( zBackType ) ) {
1075 - addAttributeToManyBridge( pAttribute );
1076 - return;
1077 - }
1078 - throw new Error( "Currently Unsupported To Many, Back Type: " + zBackType + " on " + pAttribute + " on " + mObjectName );
1079 - }
1080 -
1081 - private void addToMany( String pForm, AttributeProxy pAttribute, boolean pCascadeDeleteThem ) {
1082 - String zName = pAttribute.getName();
1083 - String zToMany = ClassName.simpleIfPackage( pAttribute.getToManyFullyQualifiedName(), mPackage + "." );
1084 - String zGenericType = "<" + mObjectName + "," + zToMany + ">";
1085 - String zAAtype = "AttributeAccessorSCDtoMany" + pForm + zGenericType;
1086 - addLine( "public static final " + zAAtype + " CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
1087 - addBlankLine();
1088 -
1089 - String zLLtype = "org.litesoft.orsup.lazyload.LazyLoadToMany" + pForm + zGenericType;
1090 - addLine( "protected " + zLLtype + " m" + zName + " = //" );
1091 - addLine( " new " + zLLtype + "( (" + mObjectName + ") this, CD_" + zName + " );" );
1092 - addBlankLine();
1093 -
1094 - addMethodPublic( "java.util.List<" + zToMany + ">", "get" + zName );
1095 - addLine( "return processLazyLoadAccess( m" + zName + " );" );
1096 - addMethodEnd();
1097 -
1098 - Mutability zMutability = pAttribute.getMutability();
1099 - if ( !Mutability.RO.equals( zMutability ) ) {
1100 - addMethodPublic( "void", "set" + zName, "java.util.List<" + zToMany + "> p" + zName );
1101 - addLine( "processLazyLoadMutation( m" + zName + ", p" + zName + " );" );
1102 - addMethodEnd();
1103 -
1104 - addMethodPublic( "void", "add" + zName, zToMany + " p" + zName );
1105 - addLine( "processLazyLoadMutationAdd( m" + zName + ", p" + zName + " );" );
1106 - addMethodEnd();
1107 -
1108 - addMethodPublic( "void", "remove" + zName, zToMany + " p" + zName );
1109 - addLine( "processLazyLoadMutationRemove( m" + zName + ", p" + zName + " );" );
1110 - addMethodEnd();
1111 - }
1112 -
1113 - makeClassPrivate();
1114 - makeClassStatic();
1115 - addClassDefinition( "AttributeAccessor_" + zName, zAAtype );
1116 -
1117 - addConstructorPublic( "AttributeAccessor_" + zName );
1118 -
1119 - String zOrderBy = Strings.noEmpty( pAttribute.getPropertyManager().get_String( PMD_OrderByAttribute.NAME, null ) );
1120 - if ( zOrderBy != null ) {
1121 - zOrderBy = "\"" + zOrderBy + "\"";
1122 - }
1123 - if ( "Variable".equals( pForm ) ) {
1124 - addLine( "super( \"" + zName + "\", " + zToMany + ".class, \"" + pAttribute.getToManyBackReference() + "\", " + //
1125 - zOrderBy + ", " + //
1126 - pCascadeDeleteThem + ", " + pAttribute.isRequired() + ", " + //
1127 - "Mutability." + zMutability + " );" );
1128 - } else {
1129 - addLine( "super( \"" + zName + "\", \"ID\", " + zToMany + ".class, \"" + pAttribute.getToManyBackReference() + "\", " + //
1130 - zOrderBy + ", " + //
1131 - "Mutability." + zMutability + ", " + pAttribute.isRequired() + ", " + //
1132 - pCascadeDeleteThem + " );" );
1133 - }
1134 - addMethodEnd();
1135 -
1136 - addLine( "@Override" );
1137 - addMethodPublic( zLLtype, "getValueHolder", mObjectName + " pPO" );
1138 - addLine( "return pPO.m" + zName + ";" );
1139 - addMethodEnd();
1140 -
1141 - addLine( "@Override" );
1142 - addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
1143 - addLine( "return pPO.get" + zName + "();" );
1144 - addMethodEnd();
1145 -
1146 - addLine( "@Override" );
1147 - addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
1148 -
1149 - if ( Mutability.RO.equals( zMutability ) ) {
1150 - addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
1151 - } else {
1152 - addLine( "pPO.set" + zName + "( to_POs( pPO, " + zToMany + ".class, pValue ) );" );
1153 - }
1154 - addMethodEnd();
1155 -
1156 - addLine( "@Override" );
1157 - addMethodPublic( "void", "addValueOnPO", mObjectName + " pPO", "Object pValue" );
1158 -
1159 - if ( Mutability.RO.equals( zMutability ) ) {
1160 - addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
1161 - } else {
1162 - addLine( "pPO.add" + zName + "( to_PO( pPO, " + zToMany + ".class, pValue ) );" );
1163 - }
1164 - addMethodEnd();
1165 -
1166 - addLine( "@Override" );
1167 - addMethodPublic( "void", "removeValueOnPO", mObjectName + " pPO", "Object pValue" );
1168 -
1169 - if ( Mutability.RO.equals( zMutability ) ) {
1170 - addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
1171 - } else {
1172 - addLine( "pPO.remove" + zName + "( to_PO( pPO, " + zToMany + ".class, pValue ) );" );
1173 - }
1174 - addBlockEnd();
1175 - addClassEnd();
1176 - }
1177 -
1178 - private void addToManyRegular( AttributeProxy pAttribute, boolean pCascadeDeleteThem ) {
1179 - addToMany( "Regular", pAttribute, pCascadeDeleteThem );
1180 - }
1181 -
1182 - private void addToManyVariable( AttributeProxy pAttribute, boolean pCascadeDeleteThem ) {
1183 - addToMany( "Variable", pAttribute, pCascadeDeleteThem );
1184 - }
1185 -
1186 - private void addAttributeToManyVirtual( AttributeProxy pAttribute ) {
1187 - String zName = pAttribute.getName();
1188 - String zToMany = ClassName.simpleIfPackage( pAttribute.getToManyFullyQualifiedName(), mPackage + "." );
1189 - String zGenericType = "<" + mObjectName + "," + zToMany + ">";
1190 - String zAAtype = "AttributeAccessorSCDtoManyVirtual" + zGenericType;
1191 - addLine( "public static final " + zAAtype + " CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
1192 - addBlankLine();
1193 -
1194 - addAbstractMethodPublic( "java.util.List<" + zToMany + ">", "get" + zName );
1195 - addBlankLine();
1196 -
1197 - addAbstractMethodProtected( "void", "LLclear" + zName );
1198 - addBlankLine();
1199 -
1200 - Mutability zMutability = pAttribute.getMutability();
1201 - if ( !Mutability.RO.equals( zMutability ) ) {
1202 - addAbstractMethodProtected( "void", "LLset" + zName, "java.util.List<" + zToMany + ">" + " p" + zName );
1203 - addBlankLine();
1204 -
1205 - addMethodPublic( "void", "set" + zName, "java.util.List<" + zToMany + ">" + " p" + zName );
1206 - addLine( "verifyMutability( CD_" + zName + ", get" + zName + "(), p" + zName + " );" );
1207 - addLine( "LLset" + zName + "( p" + zName + ");" );
1208 - addMethodEnd();
1209 -
1210 - addAbstractMethodProtected( "void", "LLadd" + zName, zToMany + " p" + zName );
1211 - addBlankLine();
1212 -
1213 - addMethodPublic( "void", "add" + zName, zToMany + " p" + zName );
1214 - addLine( "verifyMutability( CD_" + zName + ", null, p" + zName + " );" );
1215 - addLine( "LLadd" + zName + "( p" + zName + ");" );
1216 - addMethodEnd();
1217 -
1218 - addAbstractMethodProtected( "void", "LLremove" + zName, zToMany + " p" + zName );
1219 - addBlankLine();
1220 -
1221 - addMethodPublic( "void", "remove" + zName, zToMany + " p" + zName );
1222 - addLine( "verifyMutability( CD_" + zName + ", null, p" + zName + " );" );
1223 - addLine( "LLremove" + zName + "( p" + zName + ");" );
1224 - addMethodEnd();
1225 - }
1226 -
1227 - makeClassPrivate();
1228 - makeClassStatic();
1229 - addClassDefinition( "AttributeAccessor_" + zName, zAAtype );
1230 -
1231 - addConstructorPublic( "AttributeAccessor_" + zName );
1232 - addLine( "super( \"" + zName + "\", " + zToMany + ".class, " + (pAttribute.isRequired() ? "true" : "false") + ", Mutability." + zMutability + " );" );
1233 - addMethodEnd();
1234 -
1235 - addLine( "@Override" );
1236 - addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
1237 - addLine( "return pPO.get" + zName + "();" );
1238 - addMethodEnd();
1239 -
1240 - addLine( "@Override" );
1241 - addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
1242 -
1243 - if ( Mutability.RO.equals( zMutability ) ) {
1244 - addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
1245 - } else {
1246 - addLine( "pPO.set" + zName + "( to_POs( pPO, " + zToMany + ".class, pValue ) );" );
1247 - }
1248 - addMethodEnd();
1249 -
1250 - addLine( "@Override" );
1251 - addMethodPublic( "void", "addValueOnPO", mObjectName + " pPO", "Object pValue" );
1252 -
1253 - if ( Mutability.RO.equals( zMutability ) ) {
1254 - addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
1255 - } else {
1256 - addLine( "pPO.add" + zName + "( to_PO( pPO, " + zToMany + ".class, pValue ) );" );
1257 - }
1258 - addMethodEnd();
1259 -
1260 - addLine( "@Override" );
1261 - addMethodPublic( "void", "removeValueOnPO", mObjectName + " pPO", "Object pValue" );
1262 -
1263 - if ( Mutability.RO.equals( zMutability ) ) {
1264 - addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
1265 - } else {
1266 - addLine( "pPO.remove" + zName + "( to_PO( pPO, " + zToMany + ".class, pValue ) );" );
1267 - }
1268 - addMethodEnd();
1269 -
1270 - addLine( "@Override" );
1271 - addMethodProtected( "void", "LL_clearVirtualValueOnPO", mObjectName + " pPO" );
1272 - addLine( "pPO.LLclear" + zName + "();" );
1273 - addBlockEnd();
1274 - addClassEnd();
1275 - }
1276 -
1277 - private void addAttributeToManyRegular( AttributeProxy pAttribute ) {
1278 - addToManyRegular( pAttribute, pAttribute.getToManyBackReferenceAttributeProxy().isRequired() ); // CascadeDeleteThem if Other End Required
1279 - }
1280 -
1281 - private void addAttributeToManyVariable( AttributeProxy pAttribute ) {
1282 - // A_VariableToOne.TYPE, pPersisted
1283 - addToManyVariable( pAttribute, pAttribute.getToManyBackReferenceAttributeProxy().isRequired() ); // CascadeDeleteThem if Other End Required
1284 - }
1285 -
1286 - private void addAttributeToManyBridge( AttributeProxy pAttribute ) {
1287 - addToManyRegular( pAttribute, true );
1288 - }
1289 -
1290 - private void addAttributeToManyVariableBridgeLeft( AttributeProxy pAttribute ) {
1291 - // A_VariableBridgeToOneLeft.TYPE, pPersisted - String (Var2One) PMD_Changeable & PMD_UniqueGroup & PMD_ColumnName implicitly Required!
1292 - addToManyVariable( pAttribute, true );
1293 - }
1294 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.generator;
3 +
4 + import org.litesoft.aokeyhole.objects.AttributeMetaData;
5 + import org.litesoft.aokeyhole.objects.*;
6 + import org.litesoft.aokeyhole.objects.attributes.*;
7 + import org.litesoft.aokeyhole.objects.properties.*;
8 + import org.litesoft.bo.attributes.*;
9 + import org.litesoft.codegen.*;
10 + import org.litesoft.commonfoundation.base.*;
11 + import org.litesoft.commonfoundation.typeutils.Objects;
12 + import org.litesoft.orsup.lazyeval.*;
13 +
14 + import java.util.*;
15 +
16 + public class GeneratePOGO extends AbstractPOFileGenerator {
17 + public static final String[] IMPLIMENTS_HAS_ATTRIBUTES = {"HasAttributes"};
18 +
19 + private static final AttributeType[] PAIRED_TYPES = new AttributeType[]{A_CommonPairedToOne.TYPE, A_PairedToOne.TYPE};
20 + private static final AttributeType[] BRIDGE_TYPES = new AttributeType[]{A_VariableBridgeToOneLeft.TYPE, A_BridgeToOneLeft.TYPE, A_BridgeToOneRight.TYPE};
21 +
22 + public GeneratePOGO( ErrorSinc pErrorSinc, ObjectMetaData pObjectMetaData, ObjectRef pObjectRef, ObjectRef pParentObjectRef, boolean pIsParent ) {
23 + super( pErrorSinc, pObjectMetaData, pObjectRef, "GO", pParentObjectRef, pIsParent );
24 + }
25 +
26 + @Override
27 + protected void LLaddImports() {
28 + boolean zHasAttributes = (getAttributes().length != 0);
29 + addImports( //
30 + zHasAttributes ? "org.litesoft.bo.attributes.*" : null, //
31 + "org.litesoft.core.util.*", //
32 + "org.litesoft.orsup.base.*", //
33 + zHasAttributes ? "org.litesoft.orsup.otherattributeaccessors.*" : null, //
34 + !mIsParent ? "org.litesoft.orsup.selection.*" : null, //
35 + "org.litesoft.orsup.transact.*", //
36 + null );
37 + }
38 +
39 + @Override
40 + protected void LLaddClassDefinition() {
41 + String[] zImplements = (getAttributes().length != 0) ? IMPLIMENTS_HAS_ATTRIBUTES : null;
42 + makeClassAbstract();
43 + if ( mIsParent ) {
44 + addClassDefinition( mClassName + "<T extends " + mObjectName + ">", getExtends( "org.litesoft.orsup.nonpublic.PersistentObjectImpl" ) + "<T>",
45 + zImplements );
46 + } else {
47 + addClassDefinition( mClassName, getExtends( "org.litesoft.orsup.nonpublic.PersistentObjectImpl" ) + "<" + mObjectName + ">", zImplements );
48 + }
49 + }
50 +
51 + @Override
52 + protected void LLaddClassBody() {
53 + addTopValidOptions( mObjectName + "Names.po" );
54 + if ( mIsParent ) {
55 + constructorsParent();
56 + } else {
57 + addLine( "private static final ConstructionControl CONSTRUCTION_CONTROL = new ConstructionControl();" );
58 + addBlankLine();
59 + addStaticMethodPublic( "SimpleFromIdentifier", "from" );
60 + addLine( "return " + mObjectName + "MetaData.INSTANCE;" );
61 + addMethodEnd();
62 + constructorsRegular();
63 + addRecordVersion();
64 + }
65 +
66 + LLaddAttributes( true );
67 +
68 + addMyMetaData();
69 + }
70 +
71 + private void constructorsParent() {
72 + addConstructorProtected( mClassName, "MetaDataForPO pMetaDataForPO", "Transaction pTransaction" );
73 + addLine( "super( pMetaDataForPO, pTransaction );" );
74 + addMethodEnd();
75 +
76 + addConstructorProtected( mClassName, "MetaDataForPO pMetaDataForPO", "ConstructionControl pConstructionControlExpected",
77 + "ConstructionControl pConstructionControlActual" );
78 + addLine( "super( pMetaDataForPO, pConstructionControlExpected, pConstructionControlActual );" );
79 + addBlockEnd();
80 + }
81 +
82 + private String getSequenceNumberSource() {
83 + for ( AttributeProxy zAttribute : getAttributes() ) {
84 + if ( !zAttribute.isVirtual() ) {
85 + if ( A_PairedToOne.TYPE.equals( zAttribute.getAttributeSetType() ) ) {
86 + String zToOne = ClassName.simpleIfPackage( zAttribute.getToOneFullyQualifiedName(), mPackage + "." );
87 + return zToOne + ".class";
88 + }
89 + }
90 + }
91 + return "getClass()";
92 + }
93 +
94 + private void constructorsRegular() {
95 + addConstructorProtected( mClassName, "Transaction pTransaction" );
96 + addLine( "super( " + mObjectName + "MetaData.INSTANCE, pTransaction );" );
97 + addLine( "mID = getNextSequenceNumber( " + getSequenceNumberSource() + " );" );
98 + addLine( "registerWithTransaction();" );
99 + addLine( "setDefaults();" );
100 + addMethodEnd();
101 +
102 + addConstructorProtected( mClassName, "ConstructionControl pConstructionControl" );
103 + addLine( "super( " + mObjectName + "MetaData.INSTANCE, CONSTRUCTION_CONTROL, pConstructionControl );" );
104 + addBlockEnd();
105 + }
106 +
107 + private void addRecordVersion() {
108 + addBlankLine();
109 + addLine( "public static final AttributeAccessorSCD CD_RecordVersion = new AttributeAccessor_RecordVersion();" );
110 + addBlankLine();
111 + addLine( "protected final RecordVersionHelper mRecordVersion = new RecordVersionHelper();" );
112 + addBlankLine();
113 + addMethodPublic( "Long", "getRecordVersion" );
114 + addLine( "return mRecordVersion.getRecordVersion();" );
115 + addMethodEnd();
116 + makeClassPrivate();
117 + makeClassStatic();
118 + addClassDefinition( "AttributeAccessor_RecordVersion", "AttributeAccessorSCD_RecordVersion<" + mObjectName + ">" );
119 + addConstructorPublic( "AttributeAccessor_RecordVersion" );
120 + addLine( "super( \"RecordVersion\", \"RecordVersion\" );" );
121 + addMethodEnd();
122 + addLine( "@Override" );
123 + addMethodProtected( "RecordVersionHelper", "getRecordVersionHelper", mObjectName + " pPO" );
124 + addLine( "return pPO.mRecordVersion;" );
125 + addBlockEnd();
126 + addBlockEnd();
127 + }
128 +
129 + public String getTableName() {
130 + return mObjectMetaData.getPropertyManager().get_String( PMD_TableName.NAME, mObjectName );
131 + }
132 +
133 + public String getDisplayValueFormat() {
134 + return quote( ConstrainTo.significantOrNull( mObjectMetaData.getPropertyManager().get_String( PMD_DisplayValueFormat.NAME, "" ) ) );
135 + }
136 +
137 + private void addMyMetaData() {
138 + addBlankLine();
139 + makeClassStatic();
140 + makeClassPackageFriendly();
141 + if ( mIsParent ) {
142 + makeClassAbstract();
143 + addClassDefinition( "MyMetaData<T extends " + mObjectName + ">", getExtends( "org.litesoft.orsup.nonpublic.PersistentObjectImpl" ) + "MetaData<T>" );
144 + addConstructorPackageFriendly( "MyMetaData", "String pIdentifierName", "String pTableName", "AttributeAccessorKeySet pAttributeAccessorKeySet",
145 + "AttributeAccessorSCD... pAccessorSCDs" );
146 + addLine( "this( null, pIdentifierName, pTableName, pAttributeAccessorKeySet, pAccessorSCDs );" );
147 + addMethodEnd();
148 + addConstructorPackageFriendly( "MyMetaData", "AttributeAccessorSCD[] pAccessorSCDs", "String pIdentifierName", "String pTableName",
149 + "AttributeAccessorKeySet pAttributeAccessorKeySet", "AttributeAccessorSCD... pMoreAccessorSCDs" );
150 + addMDattributes( "super( join( pAccessorSCDs, pMoreAccessorSCDs ), pIdentifierName, pTableName, pAttributeAccessorKeySet", null );
151 + addBlockEnd();
152 + } else {
153 + addClassDefinition( "MyMetaData", getExtends( "org.litesoft.orsup.nonpublic.PersistentObjectImpl" ) + "MetaData<" + mObjectName + ">" );
154 + addPSFS( "OBJECT_NAME", mObjectName );
155 + addPSFS( "TABLE_NAME", getTableName() );
156 + addBlankLine();
157 +
158 + addConstructorPackageFriendly( "MyMetaData" );
159 + addMDattributes( "super( OBJECT_NAME, TABLE_NAME, new AttributeAccessorKeySet( CD_ID )", "RecordVersion" );
160 + addIndexes();
161 + addMethodEnd();
162 +
163 + addLine( "@Override" );
164 + addMethodPublic( "Class", "getPOclass" );
165 + addLine( "return " + mObjectName + ".class;" );
166 + addMethodEnd();
167 +
168 + addLine( "@Override" );
169 + addMethodPublic( mObjectName, "createNew", "Transaction pTransaction" );
170 + addLine( "return new " + mObjectName + "( pTransaction );" );
171 + addMethodEnd();
172 +
173 + addLine( "@Override" );
174 + addMethodPublic( mObjectName, "createPOfromFinder" );
175 + addLine( "return new " + mObjectName + "( CONSTRUCTION_CONTROL );" );
176 + addMethodEnd();
177 +
178 + addLine( "@Override" );
179 + addMethodPublic( "String", "getDisplayValueFormat" );
180 + addLine( "return " + getDisplayValueFormat() + ";" );
181 + addMethodEnd();
182 +
183 + addLine( "@Override" );
184 + addMethodPublic( "String", "getRecordVersionAttributeName" );
185 + addLine( "return CD_RecordVersion.getName();" );
186 + addBlockEnd();
187 +
188 + String zOrderBy = ConstrainTo.significantOrNull( mObjectMetaData.getPropertyManager().get_String( PMD_OrderByAttribute.NAME, null ) );
189 + if ( zOrderBy != null ) {
190 + addBlankLine();
191 + addLine( "@Override" );
192 + addMethodPublic( "String", "getDefaultOrderByAttributeName" );
193 + addLine( "return \"" + zOrderBy + "\";" );
194 + addBlockEnd();
195 + }
196 + }
197 + String zTimeTracked = mObjectMetaData.getPropertyManager().get_String( PMD_TimeTracked.NAME, PMD_TimeTracked.NONE );
198 + if ( PMD_TimeTracked.CREATED.equals( zTimeTracked ) || PMD_TimeTracked.BOTH.equals( zTimeTracked ) ) {
199 + addSpecialTimestampMDmethods( "Created", "Creation" );
200 + }
201 + if ( PMD_TimeTracked.LAST_MOD.equals( zTimeTracked ) || PMD_TimeTracked.BOTH.equals( zTimeTracked ) ) {
202 + addSpecialTimestampMDmethods( "LastModified", "Transaction" );
203 + }
204 + addClassEnd();
205 + }
206 +
207 + private void addSpecialTimestampMDmethods( String pAttributeName, String pMethodName ) {
208 + addBlankLine();
209 + addLine( "@Override" );
210 + addMethodPublic( "String", "get" + pMethodName + "TimestampAttributeName" );
211 + addLine( "return CD_" + pAttributeName + ".getName();" );
212 + addMethodEnd();
213 +
214 + addLine( "@Override" );
215 + addMethodProtected( "void", "set" + pMethodName + "Timestamp", mObjectName + " pPersistentObject", "java.sql.Timestamp pTransactionTimeStamp" );
216 + addLine( "pPersistentObject.LLset" + pAttributeName + "( TypeConverter.to_SimpleTimestamp( pTransactionTimeStamp ) );" );
217 + addBlockEnd();
218 + }
219 +
220 + private void addIndexes() {
221 + List<AttributeMetaData> zAttributes = new ArrayList<AttributeMetaData>( mObjectMetaData.getSortedAttributes() );
222 + for ( ObjectMetaData zOMD = mObjectMetaData; zOMD.getParentName() != null; ) {
223 + ObjectMetaData zParentOMD = zOMD.getSystemMetaData().getObject( zOMD.getParentName() );
224 + if ( zParentOMD == null ) {
225 + throw new IllegalStateException( "Parent Name '" + zOMD.getParentName() + "' but no Parent on: " + zOMD );
226 + }
227 + zAttributes.addAll( zParentOMD.getSortedAttributes() );
228 + zOMD = zParentOMD;
229 + }
230 + Collections.sort( zAttributes );
231 +
232 + List<Index> zIndexes = new ArrayList<Index>();
233 +
234 + for ( Integer zGroup : getUniqueGroups( zAttributes ) ) {
235 + Index zIndex = new Index( getTableName(), "MUG", zGroup, true );
236 + for ( AttributeMetaData zAttribute : zAttributes ) {
237 + if ( zGroup.equals( zAttribute.getPropertyManager().get_Integer( PMD_UniqueGroup.NAME, null ) ) ) {
238 + zIndex.addAttribute( zAttribute.getName() );
239 + }
240 + }
241 + zIndexes.add( zIndex );
242 + }
243 +
244 + int zAutoIndexes = 0;
245 + for ( AttributeMetaData zAttribute : zAttributes ) {
246 + if ( isToOnePersisted( zAttribute ) && !alreadyIndexed( zIndexes, zAttribute.getName() ) ) {
247 + zIndexes.add( new Index( getTableName(), "21A", ++zAutoIndexes, false ).addAttribute( zAttribute.getName() ) );
248 + }
249 + }
250 +
251 + if ( !zIndexes.isEmpty() ) {
252 + int i = zIndexes.size() - 1;
253 + if ( i == 0 ) {
254 + addLine( "setIndexes( " + zIndexes.get( 0 ) + " );" );
255 + } else {
256 + addLine( "setIndexes( " + zIndexes.get( i-- ) + ", //" );
257 + while ( i > 0 ) {
258 + addLine( " " + zIndexes.get( i-- ) + ", //" );
259 + }
260 + addLine( " " + zIndexes.get( i ) + " );" );
261 + }
262 + }
263 + }
264 +
265 + private boolean isToOnePersisted( AttributeMetaData pAttribute ) {
266 + if ( !pAttribute.isVirtual() ) {
267 + AttributeType zType = pAttribute.getAttributeSet().getType();
268 + return zType.getFAT().isToOne() && !A_PairedToOne.TYPE.equals( zType );
269 + }
270 + return false;
271 + }
272 +
273 + private boolean alreadyIndexed( List<Index> pIndexes, String pAttributeName ) {
274 + for ( Index zIndex : pIndexes ) {
275 + if ( zIndex.isJustFor( pAttributeName ) ) {
276 + return true;
277 + }
278 + }
279 + return false;
280 + }
281 +
282 + private List<Integer> getUniqueGroups( List<AttributeMetaData> pAttributes ) {
283 + List<Integer> zUniqueGroups = new ArrayList<Integer>();
284 + for ( AttributeMetaData zAttribute : pAttributes ) {
285 + Integer zGroupID = zAttribute.getPropertyManager().get_Integer( PMD_UniqueGroup.NAME, null );
286 + if ( zGroupID != null ) {
287 + if ( zGroupID < 1 ) {
288 + throw new IllegalArgumentException( "Unique Group may only be Positive!" );
289 + }
290 + if ( !zUniqueGroups.contains( zGroupID ) ) {
291 + zUniqueGroups.add( zGroupID );
292 + }
293 + }
294 + }
295 + Collections.sort( zUniqueGroups );
296 + return zUniqueGroups;
297 + }
298 +
299 + private static class Index {
300 + private String mTableName;
301 + private String mType;
302 + private int mNumber;
303 + private boolean mUnique;
304 + private List<String> mAttributeNames = new ArrayList<String>();
305 +
306 + public Index( String pTableName, String pType, int pNumber, boolean pUnique ) {
307 + mTableName = pTableName;
308 + mType = pType;
309 + mNumber = pNumber;
310 + mUnique = pUnique;
311 + }
312 +
313 + @Override
314 + public String toString() {
315 + StringBuilder sb =
316 + new StringBuilder().append( "new Index( \"" ).append( mTableName ).append( mType ).append( "IDX" ).append( mNumber ).append( "\", null, " )
317 + .append( mUnique );
318 + for ( String zAttributeName : mAttributeNames ) {
319 + sb.append( ", CD_" ).append( zAttributeName );
320 + }
321 + return sb.append( " )" ).toString();
322 + }
323 +
324 + public Index addAttribute( String pName ) {
325 + mAttributeNames.add( pName );
326 + return this;
327 + }
328 +
329 + public boolean isJustFor( String pAttributeName ) {
330 + return (mAttributeNames.size() == 1) && pAttributeName.equals( mAttributeNames.get( 0 ) );
331 + }
332 + }
333 +
334 + private void addMDattributes( String pFirstLine, String pPlus ) {
335 + AttributeProxy[] zAttributes = getAttributes();
336 + if ( (zAttributes.length == 0) && (pPlus == null) ) {
337 + addLine( pFirstLine + " );" );
338 + return;
339 + }
340 +
341 + addLine( pFirstLine + ", //" );
342 +
343 + indentPlus( 7 );
344 +
345 + int zMaxLength = ConstrainTo.notNull( pPlus ).length();
346 +
347 + for ( AttributeProxy zAttribute : zAttributes ) {
348 + zMaxLength = Math.max( zMaxLength, zAttribute.getName().length() );
349 + }
350 +
351 + CDhelper zHelper = new CDhelper( zMaxLength );
352 +
353 + if ( pPlus != null ) {
354 + zHelper.addCD( "", pPlus, false );
355 + }
356 +
357 + if ( zAttributes.length != 0 ) {
358 + addCDs( zHelper, zAttributes, "", SELECT_ID );
359 + addCDs( zHelper, zAttributes, "Injected", SELECT_INJECTED );
360 + addCDs( zHelper, zAttributes, "Regular", SELECT_SIMPLE_REGULAR );
361 + addCDs( zHelper, zAttributes, "Virtual", SELECT_SIMPLE_VIRTUAL );
362 + addCDs( zHelper, zAttributes, "Bridge", SELECT_BRIDGE, true );
363 + addCDs( zHelper, zAttributes, "Paired", SELECT_PAIRED, true );
364 + addCDs( zHelper, zAttributes, "ToOne", SELECT_TOONE_REGULAR );
365 + addCDs( zHelper, zAttributes, "ToOne Virtual", SELECT_TOONE_VIRTUAL );
366 + addCDs( zHelper, zAttributes, "ToMany", SELECT_TOMANY );
367 + addCDs( zHelper, zAttributes, "????", SELECT_REMAINING );
368 + }
369 + zHelper.fini();
370 +
371 + indentMinus( 7 );
372 + }
373 +
374 + private void addCDs( CDhelper pHelper, AttributeProxy[] pAttributes, String pSectionTitle, AttributeSelector pSelector ) {
375 + addCDs( pHelper, pAttributes, pSectionTitle, pSelector, null );
376 + }
377 +
378 + private void addCDs( CDhelper pHelper, AttributeProxy[] pAttributes, String pSectionTitle, AttributeSelector pSelector, Boolean pRequired ) {
379 + for ( AttributeProxy zAttribute : pAttributes ) {
380 + String zAttributeName = zAttribute.getName();
381 + if ( pHelper.notProcessed( zAttributeName ) && pSelector.selects( zAttribute ) ) {
382 + pSectionTitle = pHelper.addCD( pSectionTitle, zAttributeName, (pRequired == null) ? zAttribute.isRequired() : pRequired );
383 + }
384 + }
385 + }
386 +
387 + private interface AttributeSelector {
388 + boolean selects( AttributeProxy zAttribute );
389 + }
390 +
391 + public static final AttributeSelector SELECT_ID = new AttributeSelector() {
392 + @Override
393 + public boolean selects( AttributeProxy pAttribute ) {
394 + return A_ID.TYPE.equals( pAttribute.getAttributeSetType() );
395 + }
396 + };
397 +
398 + public static final AttributeSelector SELECT_INJECTED = new AttributeSelector() {
399 + @Override
400 + public boolean selects( AttributeProxy pAttribute ) {
401 + return pAttribute.isInjected();
402 + }
403 + };
404 +
405 + public static final AttributeSelector SELECT_SIMPLE_REGULAR = new AttributeSelector() {
406 + @Override
407 + public boolean selects( AttributeProxy pAttribute ) {
408 + return !pAttribute.isVirtual() && pAttribute.getAttributeSetType().getFAT().isSimple();
409 + }
410 + };
411 +
412 + public static final AttributeSelector SELECT_SIMPLE_VIRTUAL = new AttributeSelector() {
413 + @Override
414 + public boolean selects( AttributeProxy pAttribute ) {
415 + return pAttribute.isVirtual() && pAttribute.getAttributeSetType().getFAT().isSimple();
416 + }
417 + };
418 +
419 + public static final AttributeSelector SELECT_BRIDGE = new AttributeSelector() {
420 + @Override
421 + public boolean selects( AttributeProxy pAttribute ) {
422 + return Objects.isOneOf( pAttribute.getAttributeSetType(), BRIDGE_TYPES );
423 + }
424 + };
425 +
426 + public static final AttributeSelector SELECT_PAIRED = new AttributeSelector() {
427 + @Override
428 + public boolean selects( AttributeProxy pAttribute ) {
429 + return Objects.isOneOf( pAttribute.getAttributeSetType(), PAIRED_TYPES );
430 + }
431 + };
432 +
433 + public static final AttributeSelector SELECT_TOONE_REGULAR = new AttributeSelector() {
434 + @Override
435 + public boolean selects( AttributeProxy pAttribute ) {
436 + return !pAttribute.isVirtual() && pAttribute.getAttributeSetType().getFAT().isToOne();
437 + }
438 + };
439 +
440 + public static final AttributeSelector SELECT_TOONE_VIRTUAL = new AttributeSelector() {
441 + @Override
442 + public boolean selects( AttributeProxy pAttribute ) {
443 + return pAttribute.isVirtual() && pAttribute.getAttributeSetType().getFAT().isToOne();
444 + }
445 + };
446 +
447 + public static final AttributeSelector SELECT_TOMANY = new AttributeSelector() {
448 + @Override
449 + public boolean selects( AttributeProxy pAttribute ) {
450 + return pAttribute.getAttributeSetType().getFAT().isToMany();
451 + }
452 + };
453 +
454 + public static final AttributeSelector SELECT_REMAINING = new AttributeSelector() {
455 + @Override
456 + public boolean selects( AttributeProxy pAttribute ) {
457 + return true;
458 + }
459 + };
460 +
461 + private class CDhelper {
462 + private Set<String> mNamesProcessed = new HashSet<String>();
463 + private int mMaxLength;
464 + private String mSectionTitle = null;
465 + private String mPrevName = null;
466 + private boolean mPrevRequired;
467 +
468 + public CDhelper( int pMaxLength ) {
469 + mMaxLength = pMaxLength + 2;
470 + }
471 +
472 + private void processPrev( boolean pMore ) {
473 + if ( mPrevName != null ) {
474 + if ( mSectionTitle != null ) {
475 + addBlankLine();
476 + if ( mSectionTitle.length() != 0 ) {
477 + addLine( "// " + mSectionTitle );
478 + }
479 + mSectionTitle = null;
480 + }
481 + StringBuilder sb = new StringBuilder();
482 + sb.append( "CD_" ).append( mPrevName );
483 + int zDots = mMaxLength - mPrevName.length();
484 + mPrevName = null;
485 + if ( pMore ) {
486 + sb.append( ", /* " );
487 + } else {
488 + sb.append( " /* ." );
489 + }
490 + while ( zDots-- > 0 ) {
491 + sb.append( '.' );
492 + }
493 + if ( mPrevRequired ) {
494 + sb.append( " Required" );
495 + }
496 + sb.append( " */" );
497 + if ( !pMore ) {
498 + sb.append( " );" );
499 + }
500 + addLine( sb.toString() );
501 + }
502 + }
503 +
504 + public String addCD( String pSectionTitle, String pAttributeName, boolean pRequired ) {
505 + processPrev( true );
506 + mSectionTitle = pSectionTitle;
507 + mPrevName = pAttributeName;
508 + mPrevRequired = pRequired;
509 + mNamesProcessed.add( pAttributeName );
510 + return null;
511 + }
512 +
513 + public void fini() {
514 + processPrev( false );
515 + }
516 +
517 + public boolean notProcessed( String pAttributeName ) {
518 + return !mNamesProcessed.contains( pAttributeName );
519 + }
520 + }
521 +
522 + @Override
523 + protected void LLaddAttribute( AttributeProxy pAttribute ) {
524 + FundamentalAttributeType zFAT = pAttribute.getAttributeSetType().getFAT();
525 + switch ( zFAT ) {
526 + default:
527 + mErrorSinc.addError( "CurrentlyUnsupportedAttributeType FAT", "of: " + zFAT, pAttribute.toString(), mObjectMetaData.toStringForError() );
528 + break;
529 + case Simple:
530 + addAttributeSimple( pAttribute );
531 + break;
532 + case ToOne:
533 + addAttributeToOne( pAttribute );
534 + break;
535 + case ToMany:
536 + addAttributeToMany( pAttribute );
537 + break;
538 + }
539 + }
540 +
541 + private void addAttributeSimple( AttributeProxy pAttribute ) {
542 + Class zSimpleDataTypeClass = pAttribute.getSimpleDataType();
543 + if ( zSimpleDataTypeClass == null ) {
544 + mErrorSinc.addError( "CurrentlyUnsupportedAttributeType", pAttribute.toString(), mObjectMetaData.toStringForError() );
545 + return;
546 + }
547 + String zSimpleDataTypeSimpleName = ClassName.simple( zSimpleDataTypeClass );
548 + String zSimpleDataType = ClassName.simpleIfPackage( zSimpleDataTypeClass, JAVA_LANG_PACKAGE );
549 +
550 + String zDBtype = null;
551 + LiteSoftToJDBCtypeSupport zJDBCtypeSupport = !pAttribute.isVirtual() ? LiteSoftToJDBCtypeSupport.get( zSimpleDataTypeClass ) : null;
552 + if ( (zJDBCtypeSupport != null) ) {
553 + Class<?> zClass = zJDBCtypeSupport.getJDBC();
554 + if ( NonPersistable.class.equals( zClass ) ) {
555 + mErrorSinc.addError( "CurrentlyUnsupportedAttributeType", pAttribute.toString(), mObjectMetaData.toStringForError() );
556 + return;
557 + }
558 + zDBtype = zClass.getName();
559 + }
560 +
561 + String zName = pAttribute.getName();
562 + addLine( "public static final AttributeAccessorSCD CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
563 + addBlankLine();
564 + String zExtends;
565 + String zNonImportableFeature = null;
566 + Mutability zMutability = pAttribute.getMutability();
567 + AttributeType zAttributeType = pAttribute.getAttributeSetType();
568 + if ( A_ID.TYPE.equals( zAttributeType ) || pAttribute.isSysSetOnly() ) {
569 + zNonImportableFeature = "NonImportableFeature";
570 + zMutability = Mutability.RO;
571 + } else if ( pAttribute.getPropertyManager().get_boolean( PMD_CachedCalculatedValue.NAME ) ) {
572 + zNonImportableFeature = "NonImportableFeature";
573 + }
574 +
575 + String zNotes = pAttribute.getNotes();
576 +
577 + boolean zEncrypted = A_Password.TYPE.equals( zAttributeType );
578 + String zCaseControl = ConstrainTo.significantOrNull( pAttribute.getPropertyManager().get_String( PMD_Case.NAME, null ) );
579 +
580 + String zCharacterCaseIgnored = PMD_Case.IGNORED.equals( zCaseControl ) ? "CharacterCaseIgnored" : null;
581 +
582 + if ( pAttribute.isVirtual() ) {
583 + addNotes( zNotes );
584 + zExtends = "Virtual";
585 + addAbstractMethodPublic( zSimpleDataType, "get" + zName );
586 + addBlankLine();
587 +
588 + addAbstractMethodProtected( "void", "LLclear" + zName );
589 + addBlankLine();
590 +
591 + if ( !Mutability.RO.equals( zMutability ) ) {
592 + addAbstractMethodProtected( "void", "LLset" + zName, zSimpleDataType + " p" + zName );
593 + addBlankLine();
594 +
595 + addMethodPublic( "void", "set" + zName, zSimpleDataType + " p" + zName );
596 + addLine( "verifyMutability( CD_" + zName + ", get" + zName + "(), p" + zName + " );" );
597 + addLine( "LLset" + zName + "( p" + zName + ");" );
598 + addMethodEnd();
599 + }
600 + } else {
601 + zExtends = "Persisted";
602 +
603 + if ( zJDBCtypeSupport == null ) {
604 + addLine( "private " + zSimpleDataType + " m" + zName + ";" + (zEncrypted ? " // Encrypted" : "") );
605 + } else {
606 + String zLazyEvalName = zJDBCtypeSupport.getLazyEval().getName();
607 + addLine( "final " + zLazyEvalName + " m" + zName + " = new " + zLazyEvalName + "();" );
608 + }
609 + addBlankLine();
610 +
611 + addNotes( zNotes );
612 + addMethodPublic( zSimpleDataType, "get" + zName );
613 + if ( zJDBCtypeSupport != null ) {
614 + addLine( "return m" + zName + ".get" + zSimpleDataTypeSimpleName + "();" );
615 + } else {
616 + if ( zEncrypted ) {
617 + addLine( "return fromEncrypted( LLget" + zName + "() );" );
618 + addMethodEnd();
619 +
620 + addMethodPublic( zSimpleDataType, "LLget" + zName );
621 + }
622 + addLine( "return m" + zName + ";" );
623 + }
624 + addMethodEnd();
625 +
626 + if ( Mutability.RO.equals( zMutability ) ) {
627 + addMethodProtected( "void", "LLset" + zName, zSimpleDataType + " p" + zName );
628 + } else {
629 + addMethodPublic( "void", "set" + zName, zSimpleDataType + " p" + zName );
630 + if ( zEncrypted ) {
631 + addLine( "LLset" + zName + "( toEncrypted( p" + zName + " ) );" );
632 + addMethodEnd();
633 +
634 + addMethodProtected( "void", "LLset" + zName, zSimpleDataType + " p" + zName );
635 + }
636 + }
637 + if ( zJDBCtypeSupport == null ) {
638 + addLine( "verifyMutability( CD_" + zName + ", m" + zName + ", p" + zName + " );" );
639 +
640 + if ( PMD_Case.UPPERED.equals( zCaseControl ) ) {
641 + addLine( "m" + zName + " = toUpperCase( p" + zName + " );" );
642 + } else if ( PMD_Case.LOWERED.equals( zCaseControl ) ) {
643 + addLine( "m" + zName + " = toLowerCase( p" + zName + " );" );
644 + } else {
645 + addLine( "m" + zName + " = p" + zName + ";" );
646 + }
647 + } else {
648 + addLine( "verifyMutability( CD_" + zName + ", m" + zName + ".get" + zSimpleDataTypeSimpleName + "(), p" + zName + " );" );
649 + addLine( "m" + zName + ".set" + zSimpleDataTypeSimpleName + "( p" + zName + " );" );
650 + }
651 + addMethodEnd();
652 + }
653 + makeClassPrivate();
654 + makeClassStatic();
655 + zExtends = "AttributeAccessorSCDsimple" + zExtends +
656 + (Mutability.RO.equals( zMutability ) ? (pAttribute.isSysSetOnly() ? "SysSetOnly" : "ReadOnly") : "Regular");
657 + zExtends += "<" + mObjectName + ">";
658 + addClassDefinition( "AttributeAccessor_" + zName, zExtends, zNonImportableFeature, zCharacterCaseIgnored );
659 +
660 + addConstructorPublic( "AttributeAccessor_" + zName );
661 + String zBaseLine = "super( \"" + zName + "\"";
662 + if ( !pAttribute.isVirtual() ) {
663 + zBaseLine += ", \"" + pAttribute.getColumnName() + "\"";
664 + }
665 + String zTypeExtra = createAttributeTypedCall( pAttribute, "PO", zBaseLine, ";" );
666 + addMethodEnd();
667 +
668 + if ( !Mutability.RO.equals( zMutability ) ) {
669 + String zDefaultValue = pAttribute.getPropertyManager().get_String( PMD_DefaultValue.NAME, null );
670 + if ( zDefaultValue != null ) {
671 + addLine( "@Override" );
672 + addMethodPublic( "Object", "getDefault" );
673 + if ( pAttribute.getBoAttributeType().dataNeedsQuoting() ) {
674 + zDefaultValue = quote( zDefaultValue );
675 + }
676 + addLine( "return " + zDefaultValue + ";" );
677 + addMethodEnd();
678 + }
679 + }
680 +
681 + addLine( "@Override" );
682 + addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
683 + addLine( "return pPO.get" + zName + "();" );
684 +
685 + if ( pAttribute.isVirtual() ) {
686 + if ( !Mutability.RO.equals( zMutability ) ) {
687 + addMethodEnd();
688 + addLine( "@Override" );
689 + addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
690 + addLine( "pPO.set" + zName + "( to_" + zSimpleDataTypeSimpleName + "( " + zTypeExtra + "pValue ) );" );
691 + }
692 + addMethodEnd();
693 +
694 + addLine( "@Override" );
695 + addMethodProtected( "void", "LL_clearVirtualValueOnPO", mObjectName + " pPO" );
696 + addLine( "pPO.LLclear" + zName + "();" );
697 + } else if ( zJDBCtypeSupport == null ) {
698 + if ( Mutability.RO.equals( zMutability ) ) {
699 + addMethodEnd();
700 + addLine( "@Override" );
701 + addMethodPublic( "void", "db_setValueOnPO", mObjectName + " pPO", "Object pValue" );
702 + addLine( "pPO.LLset" + zName + "( to_" + zSimpleDataTypeSimpleName + "( " + zTypeExtra + "pValue ) );" );
703 + } else {
704 + addMethodEnd();
705 + addLine( "@Override" );
706 + addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
707 + addLine( "pPO.set" + zName + "( to_" + zSimpleDataTypeSimpleName + "( " + zTypeExtra + "pValue ) );" );
708 +
709 + if ( zEncrypted ) {
710 + addMethodEnd();
711 + addLine( "@Override" );
712 + addMethodPublic( "Object", "db_getValueOnPO", mObjectName + " pPO" );
713 + addLine( "return pPO.LLget" + zName + "();" );
714 +
715 + addMethodEnd();
716 + addLine( "@Override" );
717 + addMethodPublic( "void", "db_setValueOnPO", mObjectName + " pPO", "Object pValue" );
718 + addLine( "pPO.LLset" + zName + "( to_" + zSimpleDataTypeSimpleName + "( pValue ) );" );
719 + }
720 + }
721 + } else {
722 + if ( !Mutability.RO.equals( zMutability ) ) {
723 + addMethodEnd();
724 + addLine( "@Override" );
725 + addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
726 + addLine( "pPO.set" + zName + "( to_" + zSimpleDataTypeSimpleName + "( " + zTypeExtra + "pValue ) );" );
727 + }
728 + addMethodEnd();
729 + String zMethodSuffix = zDBtype.replace( '.', '_' );
730 + addLine( "@Override" );
731 + addMethodPublic( "Object", "db_getValueOnPO", mObjectName + " pPO" );
732 + addLine( "return pPO.m" + zName + ".get_" + zMethodSuffix + "();" );
733 + addMethodEnd();
734 + addLine( "@Override" );
735 + addMethodPublic( "void", "db_setValueOnPO", mObjectName + " pPO", "Object pValue" );
736 + addLine( "pPO.m" + zName + ".set_" + zMethodSuffix + "( " + zJDBCtypeSupport.getTypeConverterMethod() + "( " + "pValue ) );" );
737 + }
738 + addBlockEnd();
739 + addClassEnd();
740 + }
741 +
742 + private void addAttributeToOne( AttributeProxy pAttribute ) {
743 + if ( pAttribute.isVirtual() ) {
744 + addAttributeToOneVirtual( pAttribute );
745 + return;
746 + }
747 + AttributeType zType = pAttribute.getAttributeSetType();
748 + if ( A_Blob.TYPE.equals( zType ) ) {
749 + addAttributeToBlob( pAttribute );
750 + return;
751 + }
752 + if ( A_CommonPairedToOne.TYPE.equals( zType ) ) {
753 + addAttributeToOneCommonPaired( pAttribute );
754 + return;
755 + }
756 + if ( A_PairedToOne.TYPE.equals( zType ) ) {
757 + addAttributeToOnePaired( pAttribute );
758 + return;
759 + }
760 + if ( A_ToOne.TYPE.equals( zType ) ) {
761 + addAttributeToOneRegular( pAttribute );
762 + return;
763 + }
764 + if ( A_VariableBridgeToOneLeft.TYPE.equals( zType ) ) {
765 + addAttributeToOneVariableBridgeLeft( pAttribute );
766 + return;
767 + }
768 + if ( A_VariableToOne.TYPE.equals( zType ) ) {
769 + addAttributeToOneVariable( pAttribute );
770 + return;
771 + }
772 + if ( A_BridgeToOneLeft.TYPE.equals( zType ) || A_BridgeToOneRight.TYPE.equals( zType ) ) {
773 + addAttributeToOneBridge( pAttribute );
774 + return;
775 + }
776 + throw new Error( "Currently Unsupported To One Type: " + zType + " on " + pAttribute + " on " + mObjectName );
777 + }
778 +
779 + private void addToOneRegular( AttributeProxy pAttribute, boolean pRequired, boolean pCascadeDeleteThem ) {
780 + String zName = pAttribute.getName();
781 + String zToOne = ClassName.simpleIfPackage( pAttribute.getToOneFullyQualifiedName(), mPackage + "." );
782 + String zGenericType = "<" + mObjectName + "," + zToOne + ">";
783 + String zAAtype = "AttributeAccessorSCDtoOneRegular" + zGenericType;
784 + addLine( "public static final " + zAAtype + " CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
785 + addBlankLine();
786 +
787 + String zLLtype = "org.litesoft.orsup.lazyload.LazyLoadToOneRegular" + zGenericType;
788 + addLine( "protected " + zLLtype + " m" + zName + " = //" );
789 + addLine( " new " + zLLtype + "( (" + mObjectName + ") this, CD_" + zName + " );" );
790 + addBlankLine();
791 +
792 + addMethodPublic( zToOne, "get" + zName );
793 + addLine( "return processLazyLoadAccess( m" + zName + " );" );
794 + addMethodEnd();
795 +
796 + Mutability zMutability = pAttribute.getMutability();
797 + if ( !Mutability.RO.equals( zMutability ) ) {
798 + addMethodPublic( "void", "set" + zName, zToOne + " p" + zName );
799 + addLine( "processLazyLoadMutation( m" + zName + ", p" + zName + " );" );
800 + addMethodEnd();
801 + }
802 +
803 + makeClassPrivate();
804 + makeClassStatic();
805 + addClassDefinition( "AttributeAccessor_" + zName, zAAtype );
806 +
807 + addConstructorPublic( "AttributeAccessor_" + zName );
808 + addLine( "super( \"" + zName + "\", \"" + zName + "_id\", " + zToOne + ".class, \"ID\", \"" + pAttribute.getToOneBackReference() + "\", " + //
809 + pCascadeDeleteThem + ", " + //
810 + pRequired + ", Mutability." + zMutability + " );" );
811 + addMethodEnd();
812 +
813 + addLine( "@Override" );
814 + addMethodPublic( zLLtype, "getValueHolder", mObjectName + " pPO" );
815 + addLine( "return pPO.m" + zName + ";" );
816 + addMethodEnd();
817 +
818 + addLine( "@Override" );
819 + addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
820 + addLine( "return pPO.get" + zName + "();" );
821 + addMethodEnd();
822 +
823 + addLine( "@Override" );
824 + addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
825 +
826 + if ( Mutability.RO.equals( zMutability ) ) {
827 + addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
828 + } else {
829 + addLine( "pPO.set" + zName + "( to_PO( pPO, " + zToOne + ".class, pValue ) );" );
830 + }
831 + addMethodEnd();
832 +
833 + addLine( "@Override" );
834 + addMethodPublic( "Object", "db_getValueOnPO", mObjectName + " pPO" );
835 + addLine( "return pPO.m" + zName + ".db_getValue();" );
836 + addMethodEnd();
837 + addLine( "@Override" );
838 + addMethodPublic( "void", "db_setValueOnPO", mObjectName + " pPO", "Object pValue" );
839 + addLine( "pPO.m" + zName + ".db_setValue( to_Long( " + "pValue ) );" );
840 + addBlockEnd();
841 + addClassEnd();
842 + }
843 +
844 + private void addToOneVariable( AttributeProxy pAttribute, boolean pRequired ) {
845 + String zName = pAttribute.getName();
846 + String zGeneraicType = "<" + mObjectName + ">";
847 + String zAAtype = "AttributeAccessorSCDtoOneVariable" + zGeneraicType;
848 + addLine( "public static final " + zAAtype + " CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
849 + addBlankLine();
850 +
851 + String zLLtype = "org.litesoft.orsup.lazyload.LazyLoadToOneVariable" + zGeneraicType;
852 + addLine( "protected " + zLLtype + " m" + zName + " = //" );
853 + addLine( " new " + zLLtype + "( (" + mObjectName + ") this, CD_" + zName + " );" );
854 + addBlankLine();
855 +
856 + addMethodPublic( "org.litesoft.orsup.nonpublic.PersistentObjectImpl", "get" + zName );
857 + addLine( "return processLazyLoadAccess( m" + zName + " );" );
858 + addMethodEnd();
859 +
860 + makeClassPrivate();
861 + makeClassStatic();
862 + addClassDefinition( "AttributeAccessor_" + zName, zAAtype );
863 +
864 + Mutability zMutability = pAttribute.getMutability();
865 +
866 + addConstructorPublic( "AttributeAccessor_" + zName );
867 + addLine( "super( \"" + zName + "\", \"" + zName + "\", " + pRequired + ", Mutability." + zMutability + " );" );
868 + addMethodEnd();
869 +
870 + addLine( "@Override" );
871 + addMethodPublic( zLLtype, "getValueHolder", mObjectName + " pPO" );
872 + addLine( "return pPO.m" + zName + ";" );
873 + addMethodEnd();
874 +
875 + addLine( "@Override" );
876 + addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
877 + addLine( "return pPO.get" + zName + "();" );
878 + addBlockEnd();
879 + addClassEnd();
880 + }
881 +
882 + private void addAttributeToOneVirtual( AttributeProxy pAttribute ) {
883 + String zName = pAttribute.getName();
884 + String zToOne = ClassName.simpleIfPackage( pAttribute.getToOneFullyQualifiedName(), mPackage + "." );
885 + String zGenericType = "<" + mObjectName + "," + zToOne + ">";
886 + String zAAtype = "AttributeAccessorSCDtoOneVirtual" + zGenericType;
887 + addLine( "public static final " + zAAtype + " CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
888 + addBlankLine();
889 +
890 + addAbstractMethodPublic( zToOne, "get" + zName );
891 + addBlankLine();
892 +
893 + addAbstractMethodProtected( "void", "LLclear" + zName );
894 + addBlankLine();
895 +
896 + Mutability zMutability = pAttribute.getMutability();
897 + if ( !Mutability.RO.equals( zMutability ) ) {
898 + addAbstractMethodProtected( "void", "LLset" + zName, zToOne + " p" + zName );
899 + addBlankLine();
900 +
901 + addMethodPublic( "void", "set" + zName, zToOne + " p" + zName );
902 + addLine( "verifyMutability( CD_" + zName + ", get" + zName + "(), p" + zName + " );" );
903 + addLine( "LLset" + zName + "( p" + zName + ");" );
904 + addMethodEnd();
905 + }
906 +
907 + makeClassPrivate();
908 + makeClassStatic();
909 + addClassDefinition( "AttributeAccessor_" + zName, zAAtype );
910 +
911 + addConstructorPublic( "AttributeAccessor_" + zName );
912 + addLine( "super( \"" + zName + "\", " + zToOne + ".class, " + (pAttribute.isRequired() ? "true" : "false") + ", Mutability." + zMutability + " );" );
913 + addMethodEnd();
914 +
915 + addLine( "@Override" );
916 + addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
917 + addLine( "return pPO.get" + zName + "();" );
918 + addMethodEnd();
919 +
920 + addLine( "@Override" );
921 + addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
922 +
923 + if ( Mutability.RO.equals( zMutability ) ) {
924 + addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
925 + } else {
926 + addLine( "pPO.set" + zName + "( to_PO( pPO, " + zToOne + ".class, pValue ) );" );
927 + }
928 + addMethodEnd();
929 +
930 + addLine( "@Override" );
931 + addMethodProtected( "void", "LL_clearVirtualValueOnPO", mObjectName + " pPO" );
932 + addLine( "pPO.LLclear" + zName + "();" );
933 + addBlockEnd();
934 + addClassEnd();
935 + }
936 +
937 + private void addAttributeToBlob( AttributeProxy pAttribute ) {
938 + // A_Blob.TYPE, pPersisted
939 + throw new Error( "Blob's can not currently be generated for " + pAttribute + " on " + mObjectName );
940 + }
941 +
942 + private void addAttributeToOneCommonPaired( AttributeProxy pAttribute ) {
943 + // A_CommonPairedToOne.TYPE, pPersisted - String (To ObjectName) PMD_UniqueGroup, PMD_ColumnName, implicitly Required! & Changeable?
944 + String zName = pAttribute.getName();
945 + String zGenericType = "<" + mObjectName + ">";
946 + String zAAtype = "AttributeAccessorSCDtoOneCommonPaired" + zGenericType;
947 + addLine( "public static final " + zAAtype + " CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
948 + addBlankLine();
949 +
950 + String zLLtype = "org.litesoft.orsup.lazyload.LazyLoadToOneCommonPaired" + zGenericType;
951 + addLine( "protected " + zLLtype + " m" + zName + " = //" );
952 + addLine( " new " + zLLtype + "( (" + mObjectName + ") this, CD_" + zName + " );" );
953 + addBlankLine();
954 +
955 + addMethodPublic( "org.litesoft.orsup.nonpublic.PersistentObjectImpl", "get" + zName );
956 + addLine( "return processLazyLoadAccess( m" + zName + " );" );
957 + addMethodEnd();
958 +
959 + addMethodPublic( "void", "set" + zName, "org.litesoft.orsup.nonpublic.PersistentObjectImpl p" + zName );
960 + addLine( "processLazyLoadMutation( m" + zName + ", p" + zName + " );" );
961 + addMethodEnd();
962 +
963 + addMethodProtected( "void", "replacing" + zName, "org.litesoft.orsup.nonpublic.PersistentObjectImpl pOld" + zName,
964 + "org.litesoft.orsup.nonpublic.PersistentObjectImpl pNew" + zName );
965 + addMethodEnd();
966 +
967 + makeClassPrivate();
968 + makeClassStatic();
969 + addClassDefinition( "AttributeAccessor_" + zName, zAAtype );
970 +
971 + addConstructorPublic( "AttributeAccessor_" + zName );
972 + addLine( "super( \"" + zName + "\", \"" + zName + "\" );" );
973 + addMethodEnd();
974 +
975 + addLine( "@Override" );
976 + addMethodPublic( zLLtype, "getValueHolder", mObjectName + " pPO" );
977 + addLine( "return pPO.m" + zName + ";" );
978 + addMethodEnd();
979 +
980 + addLine( "@Override" );
981 + addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
982 + addLine( "return pPO.get" + zName + "();" );
983 + addMethodEnd();
984 +
985 + addLine( "@Override" );
986 + addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
987 + addLine( "pPO.set" + zName + "( (org.litesoft.orsup.nonpublic.PersistentObjectImpl)pValue );" );
988 + addMethodEnd();
989 +
990 + addLine( "@Override" );
991 + addMethodPublic( "void", "pairReplaced", mObjectName + " pPO", "org.litesoft.orsup.nonpublic.PersistentObjectImpl pOld" + zName,
992 + "org.litesoft.orsup.nonpublic.PersistentObjectImpl pNew" + zName );
993 + addLine( "pPO.replacing" + zName + "( pOld" + zName + ", pNew" + zName + " );" );
994 + addBlockEnd();
995 + addClassEnd();
996 + }
997 +
998 + private void addAttributeToOnePaired( AttributeProxy pAttribute ) {
999 + // A_PairedToOne.TYPE, pPersisted - Not Really Persisted - MetaData Driven for Object Reference;
1000 + String zName = pAttribute.getName();
1001 + String zToOne = ClassName.simpleIfPackage( pAttribute.getToOneFullyQualifiedName(), mPackage + "." );
1002 + String zGenericType = "<" + mObjectName + "," + zToOne + ">";
1003 + String zAAtype = "AttributeAccessorSCDtoOnePaired" + zGenericType;
1004 + addLine( "public static final " + zAAtype + " CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
1005 + addBlankLine();
1006 +
1007 + String zLLtype = "org.litesoft.orsup.lazyload.LazyLoadToOnePaired" + zGenericType;
1008 + addLine( "protected " + zLLtype + " m" + zName + " = //" );
1009 + addLine( " new " + zLLtype + "( (" + mObjectName + ") this, CD_" + zName + " );" );
1010 + addBlankLine();
1011 +
1012 + addMethodPublic( zToOne, "get" + zName );
1013 + addLine( "return processLazyLoadAccess( m" + zName + " );" );
1014 + addMethodEnd();
1015 +
1016 + makeClassPrivate();
1017 + makeClassStatic();
1018 + addClassDefinition( "AttributeAccessor_" + zName, zAAtype );
1019 +
1020 + addConstructorPublic( "AttributeAccessor_" + zName );
1021 + addLine( "super( \"" + zName + "\", " + zToOne + ".class );" );
1022 + addMethodEnd();
1023 +
1024 + addLine( "@Override" );
1025 + addMethodPublic( zLLtype, "getValueHolder", mObjectName + " pPO" );
1026 + addLine( "return pPO.m" + zName + ";" );
1027 + addMethodEnd();
1028 +
1029 + addLine( "@Override" );
1030 + addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
1031 + addLine( "return pPO.get" + zName + "();" );
1032 + addBlockEnd();
1033 + addClassEnd();
1034 + }
1035 +
1036 + private void addAttributeToOneRegular( AttributeProxy pAttribute ) {
1037 + addToOneRegular( pAttribute, pAttribute.isRequired(), pAttribute.getPropertyManager().get_boolean( PMD_CascadeDeleteThem.NAME ) );
1038 + }
1039 +
1040 + private void addAttributeToOneVariable( AttributeProxy pAttribute ) {
1041 + addToOneVariable( pAttribute, pAttribute.isRequired() ); // todo: , pAttribute.getPropertyManager().get_boolean( PMD_CascadeDeleteThem.NAME ) );
1042 + }
1043 +
1044 + private void addAttributeToOneBridge( AttributeProxy pAttribute ) {
1045 + // A_BridgeToOneRight.TYPE, pPersisted
1046 + // A_BridgeToOneLeft.TYPE, pPersisted
1047 + addToOneRegular( pAttribute, true, false );
1048 + }
1049 +
1050 + private void addAttributeToOneVariableBridgeLeft( AttributeProxy pAttribute ) {
1051 + addToOneVariable( pAttribute, true );
1052 + }
1053 +
1054 + private void addAttributeToMany( AttributeProxy pAttribute ) {
1055 + if ( pAttribute.isVirtual() ) {
1056 + addAttributeToManyVirtual( pAttribute );
1057 + return;
1058 + }
1059 + AttributeProxy pBackReferenceAttributeProxy = pAttribute.getToManyBackReferenceAttributeProxy();
1060 + AttributeType zBackType = (pBackReferenceAttributeProxy != null) ? pBackReferenceAttributeProxy.getAttributeSetType() : null;
1061 + if ( A_ToOne.TYPE.equals( zBackType ) ) {
1062 + addAttributeToManyRegular( pAttribute );
1063 + return;
1064 + }
1065 + if ( A_VariableBridgeToOneLeft.TYPE.equals( zBackType ) ) {
1066 + addAttributeToManyVariableBridgeLeft( pAttribute );
1067 + return;
1068 + }
1069 + if ( A_VariableToOne.TYPE.equals( zBackType ) ) {
1070 + addAttributeToManyVariable( pAttribute );
1071 + return;
1072 + }
1073 + if ( A_BridgeToOneLeft.TYPE.equals( zBackType ) || A_BridgeToOneRight.TYPE.equals( zBackType ) ) {
1074 + addAttributeToManyBridge( pAttribute );
1075 + return;
1076 + }
1077 + throw new Error( "Currently Unsupported To Many, Back Type: " + zBackType + " on " + pAttribute + " on " + mObjectName );
1078 + }
1079 +
1080 + private void addToMany( String pForm, AttributeProxy pAttribute, boolean pCascadeDeleteThem ) {
1081 + String zName = pAttribute.getName();
1082 + String zToMany = ClassName.simpleIfPackage( pAttribute.getToManyFullyQualifiedName(), mPackage + "." );
1083 + String zGenericType = "<" + mObjectName + "," + zToMany + ">";
1084 + String zAAtype = "AttributeAccessorSCDtoMany" + pForm + zGenericType;
1085 + addLine( "public static final " + zAAtype + " CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
1086 + addBlankLine();
1087 +
1088 + String zLLtype = "org.litesoft.orsup.lazyload.LazyLoadToMany" + pForm + zGenericType;
1089 + addLine( "protected " + zLLtype + " m" + zName + " = //" );
1090 + addLine( " new " + zLLtype + "( (" + mObjectName + ") this, CD_" + zName + " );" );
1091 + addBlankLine();
1092 +
1093 + addMethodPublic( "java.util.List<" + zToMany + ">", "get" + zName );
1094 + addLine( "return processLazyLoadAccess( m" + zName + " );" );
1095 + addMethodEnd();
1096 +
1097 + Mutability zMutability = pAttribute.getMutability();
1098 + if ( !Mutability.RO.equals( zMutability ) ) {
1099 + addMethodPublic( "void", "set" + zName, "java.util.List<" + zToMany + "> p" + zName );
1100 + addLine( "processLazyLoadMutation( m" + zName + ", p" + zName + " );" );
1101 + addMethodEnd();
1102 +
1103 + addMethodPublic( "void", "add" + zName, zToMany + " p" + zName );
1104 + addLine( "processLazyLoadMutationAdd( m" + zName + ", p" + zName + " );" );
1105 + addMethodEnd();
1106 +
1107 + addMethodPublic( "void", "remove" + zName, zToMany + " p" + zName );
1108 + addLine( "processLazyLoadMutationRemove( m" + zName + ", p" + zName + " );" );
1109 + addMethodEnd();
1110 + }
1111 +
1112 + makeClassPrivate();
1113 + makeClassStatic();
1114 + addClassDefinition( "AttributeAccessor_" + zName, zAAtype );
1115 +
1116 + addConstructorPublic( "AttributeAccessor_" + zName );
1117 +
1118 + String zOrderBy = ConstrainTo.significantOrNull( pAttribute.getPropertyManager().get_String( PMD_OrderByAttribute.NAME, null ) );
1119 + if ( zOrderBy != null ) {
1120 + zOrderBy = "\"" + zOrderBy + "\"";
1121 + }
1122 + if ( "Variable".equals( pForm ) ) {
1123 + addLine( "super( \"" + zName + "\", " + zToMany + ".class, \"" + pAttribute.getToManyBackReference() + "\", " + //
1124 + zOrderBy + ", " + //
1125 + pCascadeDeleteThem + ", " + pAttribute.isRequired() + ", " + //
1126 + "Mutability." + zMutability + " );" );
1127 + } else {
1128 + addLine( "super( \"" + zName + "\", \"ID\", " + zToMany + ".class, \"" + pAttribute.getToManyBackReference() + "\", " + //
1129 + zOrderBy + ", " + //
1130 + "Mutability." + zMutability + ", " + pAttribute.isRequired() + ", " + //
1131 + pCascadeDeleteThem + " );" );
1132 + }
1133 + addMethodEnd();
1134 +
1135 + addLine( "@Override" );
1136 + addMethodPublic( zLLtype, "getValueHolder", mObjectName + " pPO" );
1137 + addLine( "return pPO.m" + zName + ";" );
1138 + addMethodEnd();
1139 +
1140 + addLine( "@Override" );
1141 + addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
1142 + addLine( "return pPO.get" + zName + "();" );
1143 + addMethodEnd();
1144 +
1145 + addLine( "@Override" );
1146 + addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
1147 +
1148 + if ( Mutability.RO.equals( zMutability ) ) {
1149 + addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
1150 + } else {
1151 + addLine( "pPO.set" + zName + "( to_POs( pPO, " + zToMany + ".class, pValue ) );" );
1152 + }
1153 + addMethodEnd();
1154 +
1155 + addLine( "@Override" );
1156 + addMethodPublic( "void", "addValueOnPO", mObjectName + " pPO", "Object pValue" );
1157 +
1158 + if ( Mutability.RO.equals( zMutability ) ) {
1159 + addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
1160 + } else {
1161 + addLine( "pPO.add" + zName + "( to_PO( pPO, " + zToMany + ".class, pValue ) );" );
1162 + }
1163 + addMethodEnd();
1164 +
1165 + addLine( "@Override" );
1166 + addMethodPublic( "void", "removeValueOnPO", mObjectName + " pPO", "Object pValue" );
1167 +
1168 + if ( Mutability.RO.equals( zMutability ) ) {
1169 + addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
1170 + } else {
1171 + addLine( "pPO.remove" + zName + "( to_PO( pPO, " + zToMany + ".class, pValue ) );" );
1172 + }
1173 + addBlockEnd();
1174 + addClassEnd();
1175 + }
1176 +
1177 + private void addToManyRegular( AttributeProxy pAttribute, boolean pCascadeDeleteThem ) {
1178 + addToMany( "Regular", pAttribute, pCascadeDeleteThem );
1179 + }
1180 +
1181 + private void addToManyVariable( AttributeProxy pAttribute, boolean pCascadeDeleteThem ) {
1182 + addToMany( "Variable", pAttribute, pCascadeDeleteThem );
1183 + }
1184 +
1185 + private void addAttributeToManyVirtual( AttributeProxy pAttribute ) {
1186 + String zName = pAttribute.getName();
1187 + String zToMany = ClassName.simpleIfPackage( pAttribute.getToManyFullyQualifiedName(), mPackage + "." );
1188 + String zGenericType = "<" + mObjectName + "," + zToMany + ">";
1189 + String zAAtype = "AttributeAccessorSCDtoManyVirtual" + zGenericType;
1190 + addLine( "public static final " + zAAtype + " CD_" + zName + " = new AttributeAccessor_" + zName + "();" );
1191 + addBlankLine();
1192 +
1193 + addAbstractMethodPublic( "java.util.List<" + zToMany + ">", "get" + zName );
1194 + addBlankLine();
1195 +
1196 + addAbstractMethodProtected( "void", "LLclear" + zName );
1197 + addBlankLine();
1198 +
1199 + Mutability zMutability = pAttribute.getMutability();
1200 + if ( !Mutability.RO.equals( zMutability ) ) {
1201 + addAbstractMethodProtected( "void", "LLset" + zName, "java.util.List<" + zToMany + ">" + " p" + zName );
1202 + addBlankLine();
1203 +
1204 + addMethodPublic( "void", "set" + zName, "java.util.List<" + zToMany + ">" + " p" + zName );
1205 + addLine( "verifyMutability( CD_" + zName + ", get" + zName + "(), p" + zName + " );" );
1206 + addLine( "LLset" + zName + "( p" + zName + ");" );
1207 + addMethodEnd();
1208 +
1209 + addAbstractMethodProtected( "void", "LLadd" + zName, zToMany + " p" + zName );
1210 + addBlankLine();
1211 +
1212 + addMethodPublic( "void", "add" + zName, zToMany + " p" + zName );
1213 + addLine( "verifyMutability( CD_" + zName + ", null, p" + zName + " );" );
1214 + addLine( "LLadd" + zName + "( p" + zName + ");" );
1215 + addMethodEnd();
1216 +
1217 + addAbstractMethodProtected( "void", "LLremove" + zName, zToMany + " p" + zName );
1218 + addBlankLine();
1219 +
1220 + addMethodPublic( "void", "remove" + zName, zToMany + " p" + zName );
1221 + addLine( "verifyMutability( CD_" + zName + ", null, p" + zName + " );" );
1222 + addLine( "LLremove" + zName + "( p" + zName + ");" );
1223 + addMethodEnd();
1224 + }
1225 +
1226 + makeClassPrivate();
1227 + makeClassStatic();
1228 + addClassDefinition( "AttributeAccessor_" + zName, zAAtype );
1229 +
1230 + addConstructorPublic( "AttributeAccessor_" + zName );
1231 + addLine( "super( \"" + zName + "\", " + zToMany + ".class, " + (pAttribute.isRequired() ? "true" : "false") + ", Mutability." + zMutability + " );" );
1232 + addMethodEnd();
1233 +
1234 + addLine( "@Override" );
1235 + addMethodPublic( "Object", "getValueOnPO", mObjectName + " pPO" );
1236 + addLine( "return pPO.get" + zName + "();" );
1237 + addMethodEnd();
1238 +
1239 + addLine( "@Override" );
1240 + addMethodPublic( "void", "setValueOnPO", mObjectName + " pPO", "Object pValue" );
1241 +
1242 + if ( Mutability.RO.equals( zMutability ) ) {
1243 + addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
1244 + } else {
1245 + addLine( "pPO.set" + zName + "( to_POs( pPO, " + zToMany + ".class, pValue ) );" );
1246 + }
1247 + addMethodEnd();
1248 +
1249 + addLine( "@Override" );
1250 + addMethodPublic( "void", "addValueOnPO", mObjectName + " pPO", "Object pValue" );
1251 +
1252 + if ( Mutability.RO.equals( zMutability ) ) {
1253 + addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
1254 + } else {
1255 + addLine( "pPO.add" + zName + "( to_PO( pPO, " + zToMany + ".class, pValue ) );" );
1256 + }
1257 + addMethodEnd();
1258 +
1259 + addLine( "@Override" );
1260 + addMethodPublic( "void", "removeValueOnPO", mObjectName + " pPO", "Object pValue" );
1261 +
1262 + if ( Mutability.RO.equals( zMutability ) ) {
1263 + addLine( "throw new UnsupportedOperationException( \"'" + zName + "' is Read Only\" );" );
1264 + } else {
1265 + addLine( "pPO.remove" + zName + "( to_PO( pPO, " + zToMany + ".class, pValue ) );" );
1266 + }
1267 + addMethodEnd();
1268 +
1269 + addLine( "@Override" );
1270 + addMethodProtected( "void", "LL_clearVirtualValueOnPO", mObjectName + " pPO" );
1271 + addLine( "pPO.LLclear" + zName + "();" );
1272 + addBlockEnd();
1273 + addClassEnd();
1274 + }
1275 +
1276 + private void addAttributeToManyRegular( AttributeProxy pAttribute ) {
1277 + addToManyRegular( pAttribute, pAttribute.getToManyBackReferenceAttributeProxy().isRequired() ); // CascadeDeleteThem if Other End Required
1278 + }
1279 +
1280 + private void addAttributeToManyVariable( AttributeProxy pAttribute ) {
1281 + // A_VariableToOne.TYPE, pPersisted
1282 + addToManyVariable( pAttribute, pAttribute.getToManyBackReferenceAttributeProxy().isRequired() ); // CascadeDeleteThem if Other End Required
1283 + }
1284 +
1285 + private void addAttributeToManyBridge( AttributeProxy pAttribute ) {
1286 + addToManyRegular( pAttribute, true );
1287 + }
1288 +
1289 + private void addAttributeToManyVariableBridgeLeft( AttributeProxy pAttribute ) {
1290 + // A_VariableBridgeToOneLeft.TYPE, pPersisted - String (Var2One) PMD_Changeable & PMD_UniqueGroup & PMD_ColumnName implicitly Required!
1291 + addToManyVariable( pAttribute, true );
1292 + }
1293 + }