01: // Space4J(TM) - Object Persistence in RAM
02: // Copyright (C) 2003 Sergio Oliveira Junior
03: // This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
04:
05: package org.space4j.commands;
06:
07: import org.space4j.*;
08:
09: import java.util.*;
10:
11: public class IncrementSeqCmd extends Command {
12:
13: private Object target;
14:
15: public IncrementSeqCmd(Object target) {
16: this .target = target;
17: }
18:
19: public int execute(Space space) throws CommandException {
20: Object obj = space.getObject(target);
21: if (obj == null)
22: throw new CommandException("Sequence " + target.toString()
23: + " does not exists!");
24: if (!(obj instanceof Integer))
25: throw new CommandException(target.toString()
26: + " is not a sequence!");
27: Integer seq = (Integer) obj;
28: int id = seq.intValue() + 1;
29: space.putObject(target, new Integer(id));
30: return id;
31: }
32:
33: }
|