KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > cs > messages > MReadMultipleObjects


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.cs.messages;
22
23 import com.db4o.*;
24 import com.db4o.cs.*;
25
26 public final class MReadMultipleObjects extends MsgD {
27     
28     public final boolean processAtServer(YapServerThread serverThread) {
29         int size = readInt();
30         MsgD[] ret = new MsgD[size];
31         int length = (1 + size) * YapConst.INT_LENGTH;
32         synchronized (streamLock()) {
33             for (int i = 0; i < size; i++) {
34                 int id = this._payLoad.readInt();
35                 try {
36                     YapWriter bytes = stream().readWriterByID(transaction(),id);
37                     if(bytes != null){
38                         ret[i] = Msg.OBJECT_TO_CLIENT.getWriter(bytes);
39                         length += ret[i]._payLoad.getLength();
40                     }
41                 } catch (Exception JavaDoc e) {
42                     if(Debug.atHome){
43                         e.printStackTrace();
44                     }
45                 }
46             }
47         }
48         
49         MsgD multibytes = Msg.READ_MULTIPLE_OBJECTS.getWriterForLength(transaction(), length);
50         multibytes.writeInt(size);
51         for (int i = 0; i < size; i++) {
52             if(ret[i] == null){
53                 multibytes.writeInt(0);
54             }else{
55                 multibytes.writeInt(ret[i]._payLoad.getLength());
56                 multibytes._payLoad.append(ret[i]._payLoad._buffer);
57             }
58         }
59         serverThread.write(multibytes);
60         return true;
61     }
62 }
Popular Tags