Merge /pub/main
[educational.data.git] / Dr.NO / src / drno / server / database / persistence / StateNew.java
blob5cedb549f5971fa2c4bf1c2ae1b7d86cc3fdd979
1 /*
2 * Created on 2005-04-02 This file is created 2005-04-02 and
3 * descripes StateNew
4 */
5 package drno.server.database.persistence;
7 import drno.exception.ConsistanceException;
8 import drno.exception.ObjectLockException;
9 import drno.exception.UnkErrException;
10 import drno.server.database.persistence.repository.MapperFacade;
11 import drno.support.Logger;
13 /**
14 * Represents the situation when an object is new and still
15 * not committed to the database.
16 * <p>
17 * When its new, the only meaningfull operation will be to
18 * commit the object to the database by using the commit
19 * operation. all other operations are ignored.
21 * @author tobibobi
23 final class StateNew extends AbstractState {
24 /** singleton instance */
25 public final static AbstractState instance = new StateNew();
27 /**
28 * Singleton constructor.
29 * <p>
30 * private forces use of instance.
32 private StateNew() {
35 boolean canUnload()
37 // the object is actually not placed in any cache
38 // yet.
39 return false;
42 /**
43 * persists the object and changes state to
44 * StateOldClean
46 * @throws UnkErrException
49 void commit(LockObject lock, PersistentObject obj) throws ObjectLockException,
50 ConsistanceException,
51 UnkErrException
53 try {
54 obj.verify();
55 MapperFacade.instance().insert(obj);
56 obj.setState(StateOldClean.instance);
58 catch (Exception e) {
59 Logger.log(e);
63 LockObject delete(LockObject lock, PersistentObject obj)
65 obj.setState(StateDeleted.instance);
66 return lock;