Best method to accomplish auto id generation

31 views
Skip to first unread message

Vineeth Mohan

unread,
Oct 24, 2012, 2:13:30 PM10/24/12
to cleo-ty...@googlegroups.com
Hi ,

Instead of providing a unique id for each and every element to be indexed , i am letting the server to figure out the unique id.
What would be the easiest and safest way to accomplish this ?

Thanks
           Vineeth

vineethmohan

unread,
Oct 25, 2012, 2:36:31 AM10/25/12
to cleo-ty...@googlegroups.com

Following is the method i have employed to accomplish this.

Id for the element would be created by the server and a map will keep track of the size of each typeahead instance.
On restart following code is executed to find the largest ID and this value is stored to the above map.
    public int getLargest(ArrayStoreElement<E> store) {
        int largest=0;
        int start = store.getIndexStart();
        int end = start + store.length();
        for(int i = start; i < end; i++) {
            E element = store.getElement(i);
            if(element != null && ((ElementDTO) element).isSearchable()) {
                if(largest < i){
                        largest=i;
                }
            }
        }
        return largest;
    }

Is there a better way to generate ID.

Thanks
           Vineeth
Reply all
Reply to author
Forward
0 new messages