1 package com.daffodilwoods.daffodildb.server.datasystem.persistentsystem; 2 3 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 4 import com.daffodilwoods.database.general.*; 5 import com.daffodilwoods.database.resource.*; 6 import java.util.*; 7 import java.lang.ref.*; 8 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference; 9 10 11 17 public final class DatabaseUser implements _DatabaseUser{ 18 19 22 23 private HashMap usedClusters; 24 25 28 private PersistentDatabase persistentDatabase; 29 30 33 private long userCode; 34 35 private boolean isUnLocked; 36 37 40 private ArrayList tablesList; 41 42 DatabaseUser(PersistentDatabase persistentDatabase1,long userCode1) throws DException{ 43 persistentDatabase = persistentDatabase1; 44 usedClusters = new HashMap(15); 45 tablesList = new ArrayList(); 46 userCode = userCode1; 47 persistentDatabase.getUserLock().getLock(this); 48 } 49 50 DatabaseUser(PersistentDatabase persistentDatabase1,long userCode1,boolean flag) throws DException{ 51 } 52 53 DatabaseUser(PersistentDatabase persistentDatabase1,long userCode1,ArrayList tableNames) throws DException{ 54 persistentDatabase = persistentDatabase1; 55 usedClusters = new HashMap(15); 56 tablesList = new ArrayList(); 57 userCode = userCode1; 58 persistentDatabase.getUserLock().getLock(this,tableNames); 59 } 60 61 62 67 68 public final boolean writeToFile() throws DException { 69 persistentDatabase.writeAllClusterToFile(usedClusters); 70 releaseCluster(); 71 return true; 72 } 73 82 public final boolean writeToFileWithLock() throws DException { 83 persistentDatabase.writeAllClusterToFile(usedClusters); 84 usedClusters.clear(); 85 return true; 86 } 87 91 92 public final void addCluster(Object cluster){ 93 ClusterCharacteristics cc = ((Cluster)cluster).clusterCharacteristics; 94 if(!usedClusters.containsKey(cc)) 95 usedClusters.put(cc,new WeakReference(cluster)); 96 } 97 101 public void releaseCluster() throws DException{ 102 usedClusters.clear(); 103 if(!isUnLocked){ 104 persistentDatabase.getUserLock().unLock(this); 105 isUnLocked = true; 106 } 107 } 108 109 public boolean equals(Object object) { 110 return object == null ? false : userCode == ((DatabaseUser)object).userCode; 111 } 112 113 public String toString() { 114 return hashCode()+" --- "+userCode; 115 } 116 117 120 121 public void rollback() throws DException{ 122 throw new DException("PROBLEM IN COMMIT",null); 123 } 124 125 public ArrayList getTableNames() throws DException{ 126 return tablesList; 127 } 128 129 public void addTable(QualifiedIdentifier parm1) { 130 tablesList.add(parm1); 131 } 132 133 public final void removeCluster(Object clusterCC) throws DException{ 134 usedClusters.remove(clusterCC); 135 } 136 137 public int getSize() throws DException{ 138 return usedClusters.size(); 139 } 140 141 142 143 } 144 | Popular Tags |