11/**
22 The MIT License (MIT)
33
4- Copyright (c) 2010-2021 head systems, ltd
4+ Copyright (c) 2010-2025 head systems, ltd
55
66 Permission is hereby granted, free of charge, to any person obtaining a copy of
77 this software and associated documentation files (the "Software"), to deal in
@@ -61,21 +61,14 @@ public IndexFrame() {
6161 this .terminate = true ;
6262 }
6363
64- public IndexFrame (int file , long pointer , int size , FrameData bd , Table t , Class c , List <FrameData > uframes ) throws Exception {
64+ public IndexFrame (int file , long pointer , int size , FrameData bd , Table t , Class c , List <FrameData > uframes , boolean dcinit ) throws Exception {
6565 super (null , file , pointer , size , bd , t , c );
6666 this .terminate = false ;
6767
6868 Map <Integer , UndoChunk > ucs = new HashMap <>();
6969 for (FrameData uframe : uframes ) {
7070 final DataFrame uf = uframe .getDataFrame ();
71- for (Chunk udc : uf .getChunks ()) {
72- UndoChunk uc = (UndoChunk ) udc .getEntity ();
73- final long frameId = file + pointer ;
74- final long frameId_ = uc .getFile () + uc .getFrame ();
75- if (frameId == frameId_ ) {
76- ucs .put (uc .getPtr (), uc );
77- }
78- }
71+ uf .data .getUCs (ucs , file , pointer );
7972 }
8073
8174 int ptr = FRAME_HEADER_SIZE ;
@@ -86,7 +79,7 @@ public IndexFrame(int file, long pointer, int size, FrameData bd, Table t, Class
8679 if ((h .getPtr ()>0 )&&(h .getLen ()>0 )) {
8780 final DataChunk dc = new DataChunk (bs .substring (ptr , ptr +INDEX_HEADER_SIZE +h .getLen ()), this .getFile (), this .getPointer (), INDEX_HEADER_SIZE , this .getDataObject (), this .getEntityClass ());
8881 if (this .getType ()==INDEX_FRAME_LEAF ) {
89- if (INITIALIZE_DURING_CONSTRUCT == 1 ) {
82+ if (dcinit ) {
9083 final IndexChunk ib = (IndexChunk ) dc .getEntity ();
9184 }
9285 }
@@ -139,7 +132,7 @@ public IndexFrame(byte[] b, int file, long pointer, Map<Long, Long> imap, Map<Lo
139132 }
140133
141134 @ Override
142- public synchronized void rollbackTransaction (Transaction tran , ArrayList <FrameData > ubs , Session s ) throws Exception {
135+ public synchronized void rollbackTransaction (Transaction tran , List <FrameData > ubs , Session s ) throws Exception {
143136 data .check ();
144137 final LLT llt = LLT .getLLT ();
145138 llt .add (this );
@@ -394,6 +387,46 @@ public synchronized List<DataChunk> getObjectsByKey(ValueSet key, Session s) thr
394387 return r ;
395388 }
396389
390+ //return unique element by ptr - for non-unique indexes
391+ public synchronized List <DataChunk > getObjectsByKey (ValueSet key , long frameptr , int ptr , Session s ) throws InternalException {
392+ final List <DataChunk > r = new ArrayList <>();
393+ final long tr = s .getTransaction ().getTransId ();
394+ final long mtran = s .getTransaction ().getMTran ();
395+ for (Chunk ie : this .data .getChunks ()) {
396+ if (((DataChunk )ie ).getDcs ().equals (key )) {
397+ if (((DataChunk )ie ).getHeader ().getState () == Header .RECORD_NORMAL_STATE ) {
398+ if (((DataChunk ) ie ).getUndoChunk () != null && ((DataChunk ) ie ).getHeader ().getTran ().getCid () == 0 ) { //updated chunk in live transaction
399+ if (((DataChunk ) ie ).getHeader ().getFramePtr () == frameptr && ((DataChunk ) ie ).getHeader ().getFramePtrRowId ().getRowPointer () == ptr ) {
400+ r .add ((DataChunk ) ie );
401+ }
402+ } else {
403+ if (((DataChunk ) ie ).getHeader ().getTran () == null || s .isStream ()) {
404+ if (((DataChunk ) ie ).getHeader ().getFramePtr () == frameptr && ((DataChunk ) ie ).getHeader ().getFramePtrRowId ().getRowPointer () == ptr ) {
405+ r .add ((DataChunk ) ie );
406+ }
407+ } else {
408+ if ((tr == ((DataChunk ) ie ).getHeader ().getTran ().getTransId ()) || (((DataChunk ) ie ).getHeader ().getTran ().getCid () > 0 && ((DataChunk ) ie ).getHeader ().getTran ().getCid () <= mtran )) {
409+ if (((DataChunk ) ie ).getHeader ().getFramePtr () == frameptr && ((DataChunk ) ie ).getHeader ().getFramePtrRowId ().getRowPointer () == ptr ) {
410+ r .add ((DataChunk ) ie );
411+ }
412+ }
413+ }
414+ }
415+ }
416+ if (((DataChunk )ie ).getHeader ().getState () == Header .RECORD_DELETED_STATE ) {
417+ if (((DataChunk )ie ).getHeader ().getTran ()!=null ) {
418+ if ((tr != ((DataChunk )ie ).getHeader ().getTran ().getTransId ()) && (((DataChunk )ie ).getHeader ().getTran ().getCid () == 0 || ((DataChunk )ie ).getHeader ().getTran ().getCid () > mtran )) {
419+ if (((DataChunk ) ie ).getHeader ().getFramePtr () == frameptr && ((DataChunk ) ie ).getHeader ().getFramePtrRowId ().getRowPointer () == ptr ) {
420+ r .add ((DataChunk ) ie );
421+ }
422+ }
423+ }
424+ }
425+ }
426+ }
427+ return r ;
428+ }
429+
397430 public synchronized int removeObjects (ValueSet key , Object o ) throws InternalException {
398431 int len = 0 ;
399432 ArrayList <Integer > d = new ArrayList <Integer >();
0 commit comments