Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
package org.litesoft.boviews.podataproviders.support;

import org.litesoft.bo.attributes.*;
import org.litesoft.bo.change.*;
import org.litesoft.bo.views.*;
import org.litesoft.bo.views.communication.*;
import org.litesoft.bo.views.server.*;
import org.litesoft.commonfoundation.base.*;
import org.litesoft.commonfoundation.exceptions.*;
import org.litesoft.commonfoundation.iterators.*;
import org.litesoft.commonfoundation.typeutils.*;
import org.litesoft.core.simpletypes.*;
import org.litesoft.core.util.*;
import org.litesoft.orsup.base.*;
import org.litesoft.orsup.selection.*;
import org.litesoft.orsup.transact.*;

import org.litesoft.commonfoundation.typeutils.Objects;
import java.util.*;

public class PoServerVoDataProvider<T extends IViewObject> extends AbstractServerRequestRowOrRowsVoDataProvider<T>
{
    public static final WhereClauseFactory WCF = WhereClauseFactory.INSTANCE;

    private static final String VO_ID_ATTRIBUTE_NAME = "ID";

    protected MetaDataForPO mPOMetaData = null;
    protected AttributeAccessorSCD<PersistentObject<?>> mPrimaryKeyASCD;
    protected POrecordVersion mPOrecordVersion = POrecordVersion.INSTANCE;

    @SuppressWarnings({"UnusedDeclaration"})
    public PoServerVoDataProvider( VoMetaData<T> pVOMetaData, MetaDataForPO pPOMetaData )
    {
        super( pVOMetaData );
        mPOMetaData = pPOMetaData;
    }

    @SuppressWarnings({"UnusedDeclaration"})
    public PoServerVoDataProvider( VoMetaData<T> pVOMetaData, MetaDataStore pMetaDataStore )
    {
        super( pVOMetaData );
        String zType = Strings.noEmpty( mVOMetaData.getDerivedFromRegisteredObjectType() );
        if ( zType == null )
        {
            throw new PersistenceException( "ViewObject '" + pVOMetaData.getObjectName() + "' does not indicate Derived From!" );
        }
        if ( null == (mPOMetaData = pMetaDataStore.getMetaDataOptionallyByIdentifier( zType )) )
        {
            mPOMetaData = pMetaDataStore.getMetaDataRequired( zType );
        }
    }

    @Override
    protected void LLinitialize()
    {
        super.LLinitialize();

        AttributeAccessorSCD<PersistentObject<?>>[] zSCDs = mPOMetaData.getKeySet().getKeyAttributeAccessorSCDs();
        if ( zSCDs.length != 1 )
        {
            throw new PersistenceException( "POs w/ Multiple Primary Keys or no Primary Key are not supported" + this );
        }
        Class<?> zVoIDtype = mVOMetaData.getVoAttribute( VO_ID_ATTRIBUTE_NAME ).getType().getType();
        Class zPoIDtype = (mPrimaryKeyASCD = zSCDs[0]).getColumnType();
        if ( !zPoIDtype.equals( zVoIDtype ) )
        {
            throw new PersistenceException( "Mismatched column types VO: " + zVoIDtype + " != " + zPoIDtype + " :PO" + this );
        }
        String zRecordVersionAttributeName = mPOMetaData.getRecordVersionAttributeName();
        if ( Strings.isNotNullOrEmpty( zRecordVersionAttributeName ) )
        {
            mPOrecordVersion = new POrecordVersionImpl( zRecordVersionAttributeName );
        }
    }

    @SuppressWarnings({"UnusedDeclaration"})
    protected void assertMatchingVOsALL( Integer pMaxToReturn, SSMap[] pORed_ANDFilters )
    {
        if ( pMaxToReturn != null )
        {
            throw new IllegalStateException( "MaxToReturn not supported for: " + getVOMetaData().getViewObjectClass().getSimpleName() );
        }
        if ( (pORed_ANDFilters != null) && (pORed_ANDFilters.length != 0) )
        {
            throw new IllegalStateException( "Only auto filtering supported for: " + getVOMetaData().getViewObjectClass().getSimpleName() );
        }
    }

    public T createView( PersistentObject pPO, boolean pOnlyQueryAttributes )
    {
        return (pPO != null) ? LLcreateView( pPO, pOnlyQueryAttributes, false ) : null;
    }

    public T LLcreateView( PersistentObject pPO, boolean pOnlyQueryAttributes, boolean pExtraFlag )
    {
        T zVO = mVOMetaData.createViewObject( false, null );

        zVO.setRecordVersion( mPOrecordVersion.get( pPO ) );

        zVO.setAttributeValue( VO_ID_ATTRIBUTE_NAME, mPrimaryKeyASCD.getValueOnPO( pPO ) );

        updateView( zVO, pPO, pOnlyQueryAttributes, pExtraFlag );

        zVO.initialize();
        return zVO;
    }

    @SuppressWarnings({"UnusedParameters"})
    public void updateView( T pVO, PersistentObject pPO, boolean pOnlyQueryAttributes, boolean pExtraFlag )
    {
        String[] zAttributeNames = mVOMetaData.getAttributeNames();
        for ( String zAttributeName : zAttributeNames )
        {
            VoAttribute<T> zAttribute = mVOMetaData.getVoAttribute( zAttributeName );
            if ( zAttribute.isQueryViewAttribute() || !pOnlyQueryAttributes )
            {
                String zPath = zAttribute.getDerivedFromAttributePath();
                if ( Strings.isNotNullOrEmpty( zPath ) )
                {
                    Object zValueOnPO = getDottedAttributeValue( pPO, zPath );
                    pVO.setAttributeValue( zAttributeName, zValueOnPO );
                }
            }
        }
    }

    public void updatePO( PersistentObject pPO, T pMember )
    {
        String[] zAttributeNames = mVOMetaData.getAttributeNames();
        for ( String zAttributeName : zAttributeNames )
        {
            VoAttribute<T> zAttribute = mVOMetaData.getVoAttribute( zAttributeName );
            String zPath = zAttribute.getDerivedFromAttributePath();
            if ( Strings.isNotNullOrEmpty( zPath ) )
            {
                Mutability zMutability = zAttribute.getMutability();
                if ( Mutability.RW.equals( zMutability ) || (pPO.isNew() && Mutability.AddOnly.equals( zMutability )) )
                {
                    setDottedAttributeValue( pPO, zPath, pMember.getAttributeValue( zAttributeName ) );
                }
            }
        }
    }

    public PersistentObject getAndUpdatePO( Transaction pTransaction, T pMember )
    {
        PersistentObject zPO = getTransactionPO( pTransaction, pMember );
        updatePO( zPO, pMember );
        return zPO;
    }

    public PersistentObject getTransactionPO( Transaction pTransaction, T pMember )
    {
        return pMember.isNew() ? createNewPO( pTransaction, pMember ) : getUpdatableExistingPO( pTransaction, pMember );
    }

    public PersistentObject getUpdatableExistingPO( Transaction pTransaction, T pMember )
    {
        PersistentObject zPO = getExistingPO( pTransaction, pMember );
        if ( zPO == null )
        {
            throw new ConcurrentPOModificationException( "No Persisted data for '" + pMember + "', it may have been deleted" );
        }
        if ( !Objects.areNonArraysEqual( pMember.getRecordVersion(), mPOrecordVersion.get( zPO ) ) )
        {
            throw new ConcurrentPOModificationException( "Persisted data for '" + pMember + "' has been updated, please refresh and try again" );
        }
        return zPO;
    }

    public PersistentObject getExistingPO( Finder pFinder, T pMember )
    {
        return findPO( pFinder, pMember.getID() );
    }

    @SuppressWarnings({"UnusedParameters"})
    public PersistentObject createNewPO( Transaction pTransaction, T pMember )
    {
        return mPOMetaData.createNew( pTransaction );
    }

    @SuppressWarnings({"UnusedDeclaration"})
    public PersistentObject getPO( Object pDBValueForPrimaryKey )
    {
        return findPO( DataStoreLocator.get().getUnfilteredFinder(), pDBValueForPrimaryKey );
    }

    @SuppressWarnings({"UnnecessaryLocalVariable"})
    public PersistentObject findPO( Finder pFinder, Object pDBValueForPrimaryKey )
    {
        PersistentObjectUniqueKey zPOUK = new UniqueKeySingle( mPrimaryKeyASCD, pDBValueForPrimaryKey );
        PersistentObject zPO = pFinder.findOne( mPOMetaData.getPOregistrationName(), zPOUK );
        return zPO;
    }

    /**
     * Get a single VO based on an ObejctURL
     *
     * @param pObjectURL if null, null will be return
     *
     * @return single VO found (matches), or null if not found (or pObjectURL is null)
     *
     * @throws PersistenceException if there was an underlying exception!
     */
    @Override
    public T getVOby( ObjectURL pObjectURL )
            throws PersistenceException
    {
        if ( pObjectURL != null )
        {
            if ( !mVOMetaData.getObjectName().equals( pObjectURL.getObjectName() ) )
            {
                throw new PersistenceException( "Unacceptable ObjectName: " + pObjectURL.getObjectName() + this );
            }
            ObjectUniqueKey zObjectUniqueKey = pObjectURL.getObjectUniqueKey();
            if ( !zObjectUniqueKey.isForNewObject() )
            {
                return createVObyURLkey( zObjectUniqueKey );
            }
        }
        return null;
    }

    protected T createVObyURLkey( ObjectUniqueKey pObjectUniqueKey )
    {
        PersistentObject zPO = findPO( DataStoreLocator.get().getUnfilteredFinder(), pObjectUniqueKey.getParsedID() );

        return createView( zPO, false );
    }

    /**
     * Get all Matching VO(s) with the supplied URLs.
     *
     * @param pObjectURLs the URLs for the VOs to fetch.
     *
     * @return a SizedIterator, if the rows found are <= pMaxToReturn then the size indicated will match the rows returned by iterating, otherwise, the state of the iterator is unspecified.
     *
     * @throws PersistenceException if there was an underlying exception!
     */
    @Override
    public SizedIterator<T> getMatchingVOs( ObjectURL... pObjectURLs )
            throws PersistenceException
    {
        if ( pObjectURLs != null )
        {
            List<Object> zKeys = new ArrayList<Object>();
            for ( ObjectURL zURL : pObjectURLs )
            {
                if ( zURL != null )
                {
                    if ( !mVOMetaData.getObjectName().equals( zURL.getObjectName() ) )
                    {
                        throw new PersistenceException( "Unacceptable ObjectName: " + zURL.getObjectName() + this );
                    }
                    ObjectUniqueKey zObjectUniqueKey = zURL.getObjectUniqueKey();
                    if ( !zObjectUniqueKey.isForNewObject() )
                    {
                        zKeys.add( zObjectUniqueKey.getParsedID() );
                    }
                }
            }
            if ( !zKeys.isEmpty() )
            {
                POQueryIterator zPOs = findAllCursored( DataStoreLocator.get().getUnfilteredFinder(), augment_getMatchingVOs( WCF.isAnyFrom( mPrimaryKeyASCD, zKeys ) ), null );
                return new SizedIterator<T>( new PoToVoIterator<T>( false, zPOs ) );
            }
        }
        return new SizedIterator<T>( new PoToVoIterator<T>( false, Iterators.empty() ) );
    }

    /**
     * Get all Matching VO(s) by the supplied criteria (Not to exceed the pMaxToReturn).
     *
     * @param pMaxToReturn     if ! null, then if there are more then the pMaxToReturn that match, return none, but indicate how many would have been returned.
     * @param pORed_ANDFilters - OR the criteria of each map, where each map is the ANDing of the attribute values (Note: if No Maps are given then return ALL)
     *
     * @return a SizedIterator, if the rows found are <= pMaxToReturn then the size indicated will match the rows returned by iterating, otherwise, the state of the iterator is unspecified.
     *
     * @throws PersistenceException if there was an underlying exception!
     */
    @Override
    public SizedIterator<T> getMatchingVOs( Integer pMaxToReturn, SSMap... pORed_ANDFilters )
            throws PersistenceException
    {
        boolean zOnlyQueryAttributes = getMatchingVOsOnlyQueryAttributesFlag();
        UnfilteringFinder zFinder = DataStoreLocator.get().getUnfilteredFinder();

        WhereClause zWhereClause = createWhereClauseSupport( zFinder ).createWhereClause( pORed_ANDFilters );

        POQueryIterator zPOs = findAllCursored( zFinder, augment_getMatchingVOs( zWhereClause ), augment_getMatchingVOs( (OrderBy) null ) );

        if ( pMaxToReturn == null )
        {
            return new SizedIterator<T>( new PoToVoIterator<T>( zOnlyQueryAttributes, zPOs ) );
        }
        List<PersistentObject> zList = new ArrayList<PersistentObject>();
        for ( int max = pMaxToReturn; zPOs.hasNext(); zList.add( zPOs.next() ) )
        {
            if ( --max < 0 )
            {
                zPOs.dispose();
                return new SizedIterator<T>( zFinder.count( mPOMetaData.getPOregistrationName(), zWhereClause ) );
            }
        }
        zPOs.dispose();
        return new SizedIterator<T>( new PoToVoIterator<T>( zOnlyQueryAttributes, zList.iterator() ) );
    }

    protected WhereClauseSupport createWhereClauseSupport( UnfilteringFinder pFinder )
    {
        return new WhereClauseSupport( pFinder, mPOMetaData, mVOMetaData );
    }

    protected boolean getMatchingVOsOnlyQueryAttributesFlag()
    {
        return true;
    }

    protected OrderBy augment_getMatchingVOs( OrderBy pOrderBy )
    {
        return pOrderBy;
    }

    protected WhereClause augment_getMatchingVOs( WhereClause pWhereClause )
    {
        return pWhereClause;
    }

    protected POQueryIterator findAllCursored( UnfilteringFinder pFinder, WhereClause pWhereClause, OrderBy pOrderBy )
    {
        return pFinder.findAllCursored( mPOMetaData.getPOregistrationName(), pWhereClause, pOrderBy );
    }

    protected class PoToVoIterator<VO> extends Iterators.AbstractReadOnly<VO>
    {
        private boolean mOnlyQueryAttributes;
        private Iterator mIterator;

        public PoToVoIterator( boolean pOnlyQueryAttributes, Iterator pIterator )
        {
            mOnlyQueryAttributes = pOnlyQueryAttributes;
            mIterator = pIterator;
        }

        @SuppressWarnings({"unchecked"}) @Override
        public VO next()
        {
            return (VO) createView( (PersistentObject) mIterator.next(), mOnlyQueryAttributes );
        }

        @Override
        public boolean hasNext()
        {
            return mIterator.hasNext();
        }

        @Override
        public void dispose()
        {
            if ( mIterator instanceof Disposable )
            {
                ((Disposable) mIterator).dispose();
            }
        }
    }

    protected void setDottedAttributeValue( PersistentObject pPO, String pPath, Object pAttributeValue )
    {
        for ( int zDotAt; -1 != (zDotAt = pPath.indexOf( '.' )); pPath = pPath.substring( zDotAt + 1 ) )
        {
            String zAttributeName = pPath.substring( 0, zDotAt );

            pPO = getToOne( pPO, zAttributeName );
        }
        setAttributeValue( pPO, pPath, pAttributeValue );
    }

    protected PersistentObject getToOne( PersistentObject pPO, String pAttributeName )
    {
        Object zValue = getAttributeValue( pPO, pAttributeName );
        if ( zValue instanceof PersistentObject )
        {
            return (PersistentObject) zValue;
        }
        throw new PersistenceException( "Invalid ToOne Attribute '" + pAttributeName + "' requested on PO: " + pPO );
    }

    protected Object getDottedAttributeValue( PersistentObject pPO, String pPath )
    {
        for ( int zDotAt; -1 != (zDotAt = pPath.indexOf( '.' )); pPath = pPath.substring( zDotAt + 1 ) )
        {
            String zAttributeName = pPath.substring( 0, zDotAt );

            Object zValue = getAttributeValue( pPO, zAttributeName );
            if ( !(zValue instanceof PersistentObject) )
            {
                if ( zValue != null )
                {
                    LOGGER.error.log( "Invalid ToOne Attribute '", zAttributeName, "' requested on PO: " + pPO );
                }
                return null;
            }
            pPO = (PersistentObject) zValue;
        }
        return getAttributeValue( pPO, pPath );
    }

    @SuppressWarnings({"unchecked"})
    protected void setAttributeValue( PersistentObject pPO, String pAttributeName, Object pAttributeValue )
    {
        AttributeAccessorSCD zASCD = pPO.getMetaDataForPO().getAccessorSCDrequired( pAttributeName );
        Mutability zMutability = zASCD.getMutability();
        if ( Mutability.RW.equals( zMutability ) || (pPO.isNew() && Mutability.AddOnly.equals( zMutability )) )
        {
            if ( !pPO.isNew() || !zASCD.isRequired() || (pAttributeValue != null) )
            {
                zASCD.setValueOnPO( pPO, pAttributeValue );
            }
        }
    }

    @SuppressWarnings({"unchecked"})
    protected Object getAttributeValue( PersistentObject pPO, String pAttributeName )
    {
        AttributeAccessorSCD zASCD = pPO.getMetaDataForPO().getAccessorSCDoptional( pAttributeName );
        if ( zASCD != null )
        {
            return zASCD.getValueOnPO( pPO );
        }
        LOGGER.error.log( "Invalid Attribute '", pAttributeName, "' requested on PO: " + pPO );
        return null;
    }

    /**
     * ACIDly update the Backing Persistence Engine (DB?) with rows from the pTransactionSet.
     *
     * @param pTransactionSet  !null
     * @param pReturnOnSuccess the SCresult will contain a VO (of type T) (which may be null) entry for each VO originally in the pTransactionSet whose original ObjectURL matches the entry in this array (dups allowed).
     *
     * @return a Relatively complex object that is used to manage Caches.
     *
     * @throws PersistenceException if there was an underlying exception!
     */
    @Override
    public SCresult requestCommit( TransactionSet pTransactionSet, ObjectURL... pReturnOnSuccess )
            throws PersistenceException
    {
        SCresult rv = new SCresult();

        Map<ObjectURL, VoPoPair> zURLsToSaved = new HashMap<ObjectURL, VoPoPair>();

        Set<ViewObject> zMembers = ValidateTransactionSet( pTransactionSet );
        if ( !zMembers.isEmpty() )
        {
            Transaction zTransaction = DataStoreLocator.get().getUnfilteredFinder().createUnaugmentedTransaction();

            try
            {
                prepopulateTransaction( zTransaction, zMembers );
                for ( ViewObject<?> zMember : zMembers )
                {
                    if ( zMember instanceof Precommitable )
                    {
                        ((Precommitable) zMember).aboutToCommit();
                    }
                    PersistentObject zPO = getAndUpdatePO( zTransaction, zMember, //
                                                           mVOMetaData.getObjectName().equals( zMember.getObjectName() ) ? //
                                                           this : getNotUsDataProvider( zMember ) );
                    zURLsToSaved.put( zMember.getObjectURL(), new VoPoPair( zMember, zPO ) );
                }
                commit( zTransaction );
            }
            catch ( ConcurrentPOModificationException e )
            {
                return VOSC.result( e.getMessage() );
            }

            for ( ViewObject<?> zVO : zMembers )
            {
                committedVO( zVO, zURLsToSaved.get( zVO.getObjectURL() ) );
            }

            pTransactionSet.clear();
        }
        ArrayList<T> zRequestedBack = new ArrayList<T>();
        if ( pReturnOnSuccess != null )
        {
            for ( ObjectURL zObjectURL : pReturnOnSuccess )
            {
                zRequestedBack.add( createViewForCommitReturn( false, zURLsToSaved.get( zObjectURL ) ) );
            }
        }

        return rv.setSCresponse( new VOSCresponseRows( new ImmutableArrayList<T>( zRequestedBack ) ) );
    }

    protected void commit( Transaction pTransaction )
    {
        pTransaction.commit();
    }

    @SuppressWarnings({"unchecked"})
    private PersistentObject getAndUpdatePO( Transaction pTransaction, ViewObject<?> zMember, PoServerVoDataProvider pDataProvider )
    {
        return pDataProvider.getAndUpdatePO( pTransaction, zMember );
    }

    private void prepopulateTransaction( Transaction pTransaction, Collection<ViewObject> pMembers )
    {
        List<ViewObject> zNotUs = new ArrayList<ViewObject>();
        List<Object> zOurKeys = new ArrayList<Object>();

        for ( ViewObject zMember : pMembers )
        {
            if ( !zMember.isNew() )
            {
                if ( mVOMetaData.getObjectName().equals( zMember.getObjectName() ) )
                {
                    zOurKeys.add( zMember.getID() );
                }
                else
                {
                    zNotUs.add( zMember );
                }
            }
        }
        if ( !zOurKeys.isEmpty() )
        {
            pTransaction.findAll( mPOMetaData.getPOregistrationName(), WCF.isAnyFrom( mPrimaryKeyASCD, zOurKeys ) );
        }
        if ( !zNotUs.isEmpty() )
        {
            getNotUsDataProvider( zNotUs.get( 0 ) ).prepopulateTransaction( pTransaction, zNotUs );
        }
    }

    @SuppressWarnings({"unchecked", "UnusedDeclaration"})
    protected <VoType extends IViewObject> PoServerVoDataProvider<VoType> getNotUsDataProvider( Class<VoType> pViewObjectClass )
    {
        return (PoServerVoDataProvider<VoType>) getNotUsDataProvider( pViewObjectClass.getName() );
    }

    protected PoServerVoDataProvider getNotUsDataProvider( ViewObject pViewObject )
    {
        return getNotUsDataProvider( pViewObject.getClass().getName() );
    }

    private PoServerVoDataProvider getNotUsDataProvider( String pObjectName )
    {
        ServerVoDataProvider<IViewObject> zDataProvider = getServerVoDataProviderMap().get( pObjectName );
        if ( !(zDataProvider instanceof PoServerVoDataProvider) )
        {
            throw new PersistenceException( "TransactionSet contained a VO '" + pObjectName + "' not currently supported by a PoServerVoDataProvider" );
        }
        return (PoServerVoDataProvider) zDataProvider;
    }

    protected Set<ViewObject> ValidateTransactionSet( TransactionSet pTransactionSet )
    {
        Set<ViewObject> zMembers = pTransactionSet.getAllMembers();

        for ( ViewObject zMember : zMembers )
        {
            if ( validateMember( zMember ) )
            {
                return zMembers;
            }
        }
        throw new PersistenceException( "Base View: " + mVOMetaData.getObjectName() + " not in TransactionSet" );
    }

    protected boolean validateMember( ViewObject pMember )
    {
        return pMember.getObjectName().equals( mVOMetaData.getObjectName() );
    }

    protected T createViewForCommitReturn( boolean pOnlyQueryAttributes, VoPoPair pVoPoPair )
    {
        if ( pVoPoPair != null )
        {
            if ( validateMember( pVoPoPair.getVO() ) )
            {
                return createView( pVoPoPair.getPO(), pOnlyQueryAttributes );
            }
        }
        return null;
    }

    private void committedVO( ViewObject<?> pVO, VoPoPair pVoPoPair )
    {
        pVO.committed( getID( pVoPoPair ) );
    }

    private Object getID( VoPoPair pVoPoPair )
    {
        return (pVoPoPair != null) ? TypeConverter.to_Long( getAttributeValue( pVoPoPair.getPO(), VO_ID_ATTRIBUTE_NAME ) ) : null;
    }

    protected static class POrecordVersion
    {
        public static final POrecordVersion INSTANCE = new POrecordVersion();

        public Long get( PersistentObject pPO )
        {
            return null;
        }
    }

    private static class POrecordVersionImpl extends POrecordVersion
    {
        private String mRecordVersionAttributeName;

        private POrecordVersionImpl( String pRecordVersionAttributeName )
        {
            mRecordVersionAttributeName = pRecordVersionAttributeName;
        }

        @Override
        public Long get( PersistentObject pPO )
        {
            return TypeConverter.to_Long( pPO.getAttributeValue( mRecordVersionAttributeName ) );
        }
    }

    @Override
    public String toString()
    {
        return " (" + getClass().getSimpleName() + ": " + mVOMetaData.getObjectName() + " <-> " + mPOMetaData.getIdentifierName() + ")";
    }

    protected static class VoPoPair
    {
        private ViewObject<?> mVO;
        private PersistentObject mPO;

        public VoPoPair( ViewObject<?> pVO, PersistentObject pPO )
        {
            mVO = pVO;
            mPO = pPO;
        }

        public ViewObject<?> getVO()
        {
            return mVO;
        }

        public PersistentObject getPO()
        {
            return mPO;
        }
    }
}

Commits for litesoft/trunk/Java/GWT/Server/src/org/litesoft/boviews/podataproviders/support/PoServerVoDataProvider.java

Diff revisions: vs.
Revision Author Commited Message
947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

917 Diff Diff GeorgeS picture GeorgeS Sun 08 Dec, 2013 20:49:56 +0000

1.7 prep & VersionedStaticContentFilter upgrade to new “/ver” model!

804 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 12:48:51 +0000
802 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 04:04:47 +0000
801 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 03:59:02 +0000
486 Diff Diff GeorgeS picture GeorgeS Tue 06 Sep, 2011 03:00:59 +0000
398 GeorgeS picture GeorgeS Mon 15 Aug, 2011 19:57:47 +0000