1 2 12 package com.versant.core.common; 13 14 import com.versant.core.jdo.PCStateMan; 15 import com.versant.core.metadata.*; 16 import com.versant.core.jdo.DetachStateContainer; 17 import com.versant.core.jdo.VersantPersistenceManagerImp; 18 import com.versant.core.jdo.*; 19 import com.versant.core.server.OIDGraph; 20 import com.versant.core.server.PersistGraph; 21 import com.versant.core.util.IntArray; 22 import com.versant.core.util.OIDObjectOutput; 23 import com.versant.core.util.OIDObjectInput; 24 25 import javax.jdo.spi.PersistenceCapable; 26 import java.util.*; 27 import java.lang.reflect.Array ; 28 import java.io.IOException ; 29 30 31 32 72 public abstract class State 73 { 74 75 81 public abstract boolean isHollow(); 82 83 88 public abstract State newInstance(); 89 90 97 public abstract int getClassIndex(); 98 99 104 public abstract ClassMetaData getClassMetaData(ModelMetaData jmd); 105 106 111 public abstract boolean isDirty(); 112 113 119 public abstract boolean isDirty(int fieldNo); 120 121 124 public void validateForCache() { 125 126 } 127 128 133 public abstract void makeDirtyAbs(int fieldNo); 134 135 138 public abstract void clearDirtyFields(); 139 140 146 public abstract void updateFrom(State state); 147 148 154 public abstract void updateNonFilled(State state); 155 156 159 public abstract void clearNonAutoSetFields(); 160 161 public abstract void retrieve(VersantPersistenceManagerImp sm); 162 163 168 public abstract void clearNonFilled(State state); 169 170 173 public abstract void clearCollectionFields(); 174 175 179 public abstract void clearSCOFields(); 180 181 184 public abstract void clearTransactionNonPersistentFields(); 185 186 200 public abstract boolean fillToStoreState(State stateToStore, 201 PersistenceContext sm, 202 VersantStateManager pcStateMan); 203 204 210 public abstract void fillForRead(State dest, 211 VersantPersistenceManagerImp sm); 212 213 218 public abstract State getCopy(); 219 220 227 public abstract void copyFieldsForOptimisticLocking(State state, 228 VersantPersistenceManagerImp sm); 229 230 234 public abstract void copyOptimisticLockingField(State state); 235 236 241 public abstract int replaceSCOFields(PersistenceCapable owner, 242 VersantPersistenceManagerImp sm, 243 int[] absFieldNos); 244 245 246 247 248 252 public abstract void unmanageSCOFields(); 253 254 256 public abstract void addRefs(VersantPersistenceManagerImp sm, PCStateMan pcStateMan); 257 258 261 public abstract void clear(); 262 263 266 public abstract void clearFilledFlags(); 267 268 271 public abstract void makeClean(); 272 273 278 public abstract void setClassMetaData(ClassMetaData cmd); 279 280 283 public abstract ClassMetaData getClassMetaData(); 284 285 289 public abstract boolean containsField(int stateFieldNo); 290 291 295 public abstract boolean containsFieldAbs(int absFieldNo); 296 297 300 public abstract boolean containFields(int[] stateFieldNos); 301 302 305 public abstract boolean containFieldsAbs(int[] absFieldNos); 306 307 310 public abstract boolean isEmpty(); 311 312 316 public abstract boolean containsFetchGroup(FetchGroup fetchGroup); 317 318 322 public abstract int getFieldNos(int[] buf); 323 324 331 public abstract int getPass1FieldNos(int[] buf); 332 333 337 public abstract int getPass1FieldRefFieldNosWithNewOids( 338 int[] stateFieldNoBuf); 339 340 347 public abstract int getPass2FieldNos(int[] buf); 348 349 355 public abstract boolean containsPass1Fields(); 356 357 363 public abstract boolean containsPass2Fields(); 364 365 376 public abstract int compareToPass1(State state); 377 378 383 public abstract boolean hasSameFields(State state); 384 385 388 public abstract boolean isNull(int stateFieldNo); 389 390 395 public abstract boolean containsApplicationIdentityFields(); 396 397 403 public abstract boolean containsValidAppIdFields(); 404 405 409 public abstract void clearApplicationIdentityFields(); 410 411 415 public abstract void copyFields(OID oid); 416 417 423 public abstract boolean replaceNewObjectOIDs(int[] fieldNos, 424 int fieldNosLength); 425 426 433 public abstract void findDirectEdges(OIDGraph graph, 434 IntArray edges); 435 436 442 public abstract void updateAutoSetFieldsCreated(Date now); 443 444 451 public abstract void updateAutoSetFieldsModified(Date now, State oldState); 452 453 458 public abstract void copyKeyFields(OID oid); 459 460 464 public abstract boolean checkKeyFields(OID oid); 465 466 473 public abstract void copyKeyFieldsUpdate(OID oid); 474 475 478 public abstract boolean getBooleanField(int stateFieldNo); 479 480 public abstract boolean getBooleanFieldAbs(int absFieldNo); 481 482 485 public abstract char getCharField(int stateFieldNo); 486 487 public abstract char getCharFieldAbs(int absFieldNo); 488 489 492 public abstract byte getByteField(int stateFieldNo); 493 494 public abstract byte getByteFieldAbs(int absFieldNo); 495 496 499 public abstract short getShortField(int stateFieldNo); 500 501 public abstract short getShortFieldAbs(int absFieldNo); 502 503 506 public abstract int getIntField(int stateFieldNo); 507 508 public abstract int getIntFieldAbs(int absFieldNo); 509 510 513 public abstract long getLongField(int stateFieldNo); 514 515 public abstract long getLongFieldAbs(int absFieldNo); 516 517 520 public abstract long getLongFieldInternal(int stateFieldNo); 521 522 525 public abstract float getFloatField(int stateFieldNo); 526 527 public abstract float getFloatFieldAbs(int absFieldNo); 528 529 532 public abstract double getDoubleField(int stateFieldNo); 533 534 public abstract double getDoubleFieldAbs(int absFieldNo); 535 536 539 public abstract String getStringField(int stateFieldNo); 540 541 public abstract String getStringFieldAbs(int absFieldNo); 542 543 546 public abstract Object getObjectField(int stateFieldNo, 547 PersistenceCapable owningPC, PersistenceContext pm, 548 OID oid); 549 550 public abstract Object getObjectFieldAbs(int absFieldNo, 551 PersistenceCapable owningPC, PersistenceContext pm, 552 OID oid); 553 554 557 public abstract void setBooleanField(int stateFieldNo, boolean newValue); 558 559 public abstract void setBooleanFieldAbs(int absFieldNo, boolean newValue); 560 561 564 public abstract void setCharField(int stateFieldNo, char newValue); 565 566 public abstract void setCharFieldAbs(int absFieldNo, char newValue); 567 568 571 public abstract void setByteField(int stateFieldNo, byte newValue); 572 573 public abstract void setByteFieldAbs(int absFieldNo, byte newValue); 574 575 578 public abstract void setShortField(int stateFieldNo, short newValue); 579 580 public abstract void setShortFieldAbs(int absFieldNo, short newValue); 581 582 585 public abstract void setIntField(int stateFieldNo, int newValue); 586 587 public abstract void setIntFieldAbs(int absFieldNo, int newValue); 588 589 592 public abstract void setLongField(int stateFieldNo, long newValue); 593 594 public abstract void setLongFieldAbs(int absFieldNo, long newValue); 595 596 599 public abstract void setFloatField(int stateFieldNo, float newValue); 600 601 public abstract void setFloatFieldAbs(int absFieldNo, float newValue); 602 603 606 public abstract void setDoubleField(int stateFieldNo, double newValue); 607 608 public abstract void setDoubleFieldAbs(int absFieldNo, double newValue); 609 610 613 public abstract void setStringField(int stateFieldNo, String newValue); 614 615 public abstract void setStringFieldAbs(int absFieldNo, String newValue); 616 617 620 public abstract void setObjectField(int stateFieldNo, Object newValue); 621 622 public abstract void setObjectFieldAbs(int absFieldNo, Object newValue); 623 624 public abstract void setObjectFieldUnresolved(int field, Object newValue); 625 626 public abstract void setObjectFieldUnresolvedAbs(int field, 627 Object newValue); 628 629 631 634 public abstract Object getInternalObjectField(int field); 635 636 public abstract Object getInternalObjectFieldAbs(int field); 637 638 641 public abstract void setInternalBooleanField(int field, boolean newValue); 642 643 public abstract void setInternalBooleanFieldAbs(int field, 644 boolean newValue); 645 646 649 public abstract void setInternalCharField(int field, char newValue); 650 651 public abstract void setInternalCharFieldAbs(int field, char newValue); 652 653 656 public abstract void setInternalByteField(int field, byte newValue); 657 658 public abstract void setInternalByteFieldAbs(int field, byte newValue); 659 660 663 public abstract void setInternalShortField(int field, short newValue); 664 665 public abstract void setInternalShortFieldAbs(int field, short newValue); 666 667 670 public abstract void setInternalIntField(int field, int newValue); 671 672 public abstract void setInternalIntFieldAbs(int field, int newValue); 673 674 677 public abstract void setInternalLongField(int field, long newValue); 678 679 public abstract void setInternalLongFieldAbs(int field, long newValue); 680 681 684 public abstract void setInternalFloatField(int field, float newValue); 685 686 public abstract void setInternalFloatFieldAbs(int field, float newValue); 687 688 691 public abstract void setInternalDoubleField(int field, double newValue); 692 693 public abstract void setInternalDoubleFieldAbs(int field, double newValue); 694 695 698 public abstract void setInternalStringField(int field, String newValue); 699 700 public abstract void setInternalStringFieldAbs(int field, String newValue); 701 702 705 public abstract void setInternalObjectField(int field, Object newValue); 706 707 public abstract void setInternalObjectFieldAbs(int field, Object newValue); 708 709 713 public abstract String getVersion(); 714 715 718 public void addFetchGroupStatesToDCS(FetchGroup fg, DetachStateContainer dcs, 719 VersantPersistenceManagerImp pm, OID oid, ClassMetaData cmd) { 720 FetchGroupField[] fields = fg.fields; 724 boolean defaultFG = fg == cmd.fetchGroups[0]; 725 int length = fields.length; 726 for (int fieldNo = 0; fieldNo < length; fieldNo++) { 727 FetchGroupField field = fields[fieldNo]; 728 FieldMetaData fmd = field.fmd; 729 if (fmd.fake) continue; 730 if (defaultFG && !fmd.isJDODefaultFetchGroup()) continue; 731 FetchGroup nextFetchGroup = field.nextFetchGroup; 732 FetchGroup nextKeyFetchGroup = field.nextKeyFetchGroup; 733 if (nextFetchGroup == null && nextKeyFetchGroup == null) continue; 734 int category = fmd.category; 735 int stateFieldNo; 736 Object o; 737 switch (category) { 738 case MDStatics.CATEGORY_COLLECTION: 739 o = getInternalObjectField(stateFieldNo = fmd.stateFieldNo); 740 if (o != null) { 741 if (isResolvedForClient(stateFieldNo)) { 742 for (Iterator i = ((Collection)o).iterator(); 744 i.hasNext();) { 745 addPCToDCS(dcs, (PersistenceCapable)i.next(), 746 nextFetchGroup, pm); 747 } 748 } else { 749 Object [] a = (Object [])o; 750 int c = a.length; 751 for (int i = 0; i < c; i++) { 752 Object object = a[i]; 753 if (object == null) break; 754 addOIDToDCS(dcs, (OID)object, nextFetchGroup, 755 pm); 756 } 757 } 758 } 759 break; 760 case MDStatics.CATEGORY_ARRAY: 761 if (fmd.elementTypeMetaData != null) { 762 o = getInternalObjectField( 763 stateFieldNo = fmd.stateFieldNo); 764 if (o != null) { 765 if (isResolvedForClient(stateFieldNo)) { 766 Object [] a = (Object [])o; 767 int c = a.length; 768 for (int i = 0; i < c; i++) { 769 Object object = a[i]; 770 if (object != null) { 771 addPCToDCS(dcs, (PersistenceCapable)object, 772 nextFetchGroup, pm); 773 } 774 } 775 } else { 776 Object [] a = (Object [])o; 777 int c = a.length; 778 for (int i = 0; i < c; i++) { 779 Object object = a[i]; 780 if (object != null) { 781 addOIDToDCS(dcs, (OID)object, nextFetchGroup, 782 pm); 783 } 784 } 785 } 786 } 787 } 788 break; 789 case MDStatics.CATEGORY_MAP: 790 o = getInternalObjectField(stateFieldNo = fmd.stateFieldNo); 791 if (o != null) { 792 if (isResolvedForClient(stateFieldNo)) { 793 for (Iterator i = ((Map)o).entrySet().iterator(); 795 i.hasNext();) { 796 Map.Entry e = (Map.Entry)i.next(); 797 if (nextKeyFetchGroup != null) { 798 addPCToDCS(dcs, (PersistenceCapable)e.getKey(), 799 nextKeyFetchGroup, pm); 800 } 801 if (nextFetchGroup != null) { 802 addPCToDCS(dcs, (PersistenceCapable)e.getValue(), 803 nextFetchGroup, pm); 804 } 805 } 806 } else { 807 MapEntries e = (MapEntries)o; 808 if (nextKeyFetchGroup != null) { 809 Object [] a = e.keys; 810 int c = a.length; 811 for (int i = 0; i < c; i++) { 812 OID nextOid = (OID)a[i]; 813 if (nextOid == null) break; 814 addOIDToDCS(dcs, nextOid, 815 nextKeyFetchGroup, pm); 816 } 817 } 818 if (nextFetchGroup != null) { 819 Object [] a = e.values; 820 int c = a.length; 821 for (int i = 0; i < c; i++) { 822 OID nextOid = (OID)a[i]; 823 if (nextOid == null) break; 824 addOIDToDCS(dcs, nextOid, nextFetchGroup, 825 pm); 826 } 827 } 828 } 829 } 830 break; 831 case MDStatics.CATEGORY_REF: 832 case MDStatics.CATEGORY_POLYREF: 833 o = getInternalObjectField(stateFieldNo = fmd.stateFieldNo); 834 if (o != null) { 835 if (isResolvedForClient(stateFieldNo)) { 836 addPCToDCS(dcs, (PersistenceCapable)o, 837 nextFetchGroup, pm); 838 } else { 839 OID nextOid = (OID)o; 840 if (nextOid != null) { 841 addOIDToDCS(dcs, nextOid, nextFetchGroup, pm); 842 } 843 } 844 } 845 break; 846 } 847 } 848 } 849 850 854 private void addOIDToDCS(DetachStateContainer dcs, OID oid, 855 FetchGroup nextFetchGroup, VersantPersistenceManagerImp pm) { 856 State ns = pm.getCache().getStateByOID(oid); 857 dcs.add(oid, ns, nextFetchGroup); 858 } 860 861 865 private void addPCToDCS(DetachStateContainer dcs, PersistenceCapable pc, 866 FetchGroup nextFetchGroup, VersantPersistenceManagerImp pm) { 867 PCStateMan internalSM = pm.getInternalSM(pc); 868 dcs.add(internalSM.oid, internalSM.state, nextFetchGroup); 869 } 871 872 public Object resolveArrayOIDs(Object [] oids, 873 PersistenceContext sm, Class type) { 874 Object [] vals = (Object [])Array.newInstance(type, oids.length); 875 for (int i = 0; i < vals.length; i++) { 876 if (oids[i] != null) { 877 vals[i] = sm.getObjectById(oids[i], false); 878 } 879 } 880 return vals; 881 } 882 883 public Object resolveArrayValues(Object vals[], 884 PersistenceContext pm) { 885 OID oids[] = new OID[vals.length]; 886 for (int i = 0; i < oids.length; i++) { 887 if (vals[i] != null) { 888 oids[i] = pm.getInternalOID((PersistenceCapable)vals[i]); 889 } 890 } 891 892 return oids; 893 } 894 895 898 public abstract boolean isResolvedForClient(int stateFieldNo); 899 900 904 public abstract Object getOptimisticLockingValue(); 905 906 909 public abstract void setFilled(int stateFieldNo); 910 911 918 public abstract void addOneToManyInverseFieldsForL2Evict( 919 VersantPersistenceManagerImp pm); 920 921 922 923 926 public boolean isCacheble() { 927 return true; 928 } 929 930 935 protected void findDirectEdges(OIDGraph graph, ClassMetaData cmd, 936 int fieldNo, State state, IntArray edges) { 937 OID oid = (OID)state.getInternalObjectField(fieldNo); 938 if (oid == null) return; 939 int index = graph.indexOf(oid); 940 if (index >= 0) edges.add(index); 941 } 942 943 946 public abstract boolean isFieldNullorZero(int stateFieldNo); 947 948 951 public abstract void writeExternal(OIDObjectOutput os) throws IOException ; 952 953 956 public abstract void readExternal(OIDObjectInput is) 957 throws IOException , ClassNotFoundException ; 958 959 } 960 | Popular Tags |