SimRecord.java 8.28 KB
Newer Older
TongZuu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
package com.csc.library.database;
import java.util.Iterator;

import com.csc.library.session.DbRecord;
import com.csc.library.session.InitialRecord;
import com.csc.library.session.RecordCmp;
import com.csc.library.session.RecordCmp0;
import com.csc.library.utilities.MyLog;
import com.csc.library.utilities.UProfile;
/**
 * @author developer11
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class SimRecord extends RecordCmp0 {
	public boolean simWorking = false;
	private MyHashMap hTable;
	public SimRecord(String a, String b) {
		super(a, b);
		hTable = new MyHashMap(true);
	}
	public SimRecord(String a, String b, boolean c) {
		super(a, b);
		hTable = new MyHashMap(true);
		this.simWorking = c;
	}
	
	public FieldManager getSimField(String table, String fieldName) {
		try {				
			MyHashMap hRecNo = (MyHashMap) this.hTable.get(table);
			MyHashMap hField = (MyHashMap) hRecNo.get("0");
			return (FieldManager) hField.get(fieldName);
		} catch (Exception e) {
			MyLog.error(this,"table : " + table + " field : " + fieldName);
			MyLog.error(this,  e);
			return null;
		}
	}
	public void clearSimField() {
		try {				
			MyHashMap hRecNo;
			for (Iterator IT = this.hTable.getKeyIterator(); IT.hasNext();) {
				String table = IT.next().toString();
				 hRecNo = (MyHashMap) this.hTable.get(table);
				MyHashMap hField = (MyHashMap) hRecNo.get("0");
				for (Iterator ITF = hField.getKeyIterator(); ITF.hasNext();) {
					String fieldName = ITF.next().toString();
					FieldManager fm = (FieldManager) hField.get(fieldName);
					fm.setDefault();
				}	
			}
		} catch (Exception e) {
			MyLog.error(this,  e);
		}
	}
	public FieldManager getSimField(String table, String key, String fieldName) {
		MyHashMap hRecNo = (MyHashMap) this.hTable.get(table);
		MyHashMap hField = (MyHashMap) hRecNo.get(key);
		return (FieldManager) hField.get(fieldName);
	}
	public MyHashMap getSimRecord(String table) {
		MyHashMap hRecNo = (MyHashMap) this.hTable.get(table);
		return (MyHashMap) hRecNo.get("0");
	}
	public MyHashMap getSimRecord(String table, String key) {
		MyHashMap hRecNo = (MyHashMap) this.hTable.get(table);
		return (MyHashMap) hRecNo.get(key);
	}

	protected DbRecord initRecord(String table) {
		DbRecord rec = new InitialRecord(this.userPro, this.param).getDbRecord(table);
		try {
			rec.setProperties(true);
		} catch (Exception ex) {
			MyLog.error(this, ex);
		}
		return rec;
	}
	public Iterator getFieldSimListKey(String table) {
		MyHashMap hRecNo = (MyHashMap) this.hTable.get(table);
		MyHashMap hField = (MyHashMap) hRecNo.get("0");
		return hField.keySet().iterator();
	}
	public Iterator getFieldSimListKey(String table, String key) {
		MyHashMap hRecNo = (MyHashMap) this.hTable.get(table);
		MyHashMap hField = (MyHashMap) hRecNo.get(key);
		return hField.keySet().iterator();
	}
	public Iterator getSimListKey(String table) {
		MyHashMap hRecNo = (MyHashMap) this.hTable.get(table);
		return hRecNo.keySet().iterator();
	}
	public Iterator getSimTableAll() {
		Iterator it = this.hTable.keySet().iterator();
		return this.hTable.keySet().iterator();
	}
	public FieldManager getField(String fieldName) {
		String tName, kName, fName, tmpStr;
		FieldManager fm = super.getField(fieldName);
		if (this.simWorking == true) {
			try {
				if (fm == null) {
					if (fieldName.indexOf("$") >= 0) {
						tName = fieldName.substring(0, fieldName.indexOf("$"));
						tmpStr = fieldName.substring(fieldName.indexOf("$") + 1, fieldName.length());
						if (tmpStr.indexOf("$") >= 0) {
							kName = tmpStr.substring(0, tmpStr.indexOf("$"));
							fName = tmpStr.substring(tmpStr.indexOf("$") + 1, tmpStr.length());
							fm = this.getSimField(tName, kName, fName);
						} else {
							fName = fieldName.substring(fieldName.indexOf("$") + 1, fieldName.length());
							fm = this.getSimField(tName, fName);
							//System.out.println("fieldName <"+fieldName+">fm---->"+fm.getName()+"<-----"+fm.getString());
						}
					} else if (fieldName.indexOf(".") >= 0) {
						tName = fieldName.substring(0, fieldName.indexOf("."));
						tmpStr = fieldName.substring(fieldName.indexOf(".") + 1, fieldName.length());
						if (tmpStr.indexOf(".") >= 0) {
							kName = tmpStr.substring(0, tmpStr.indexOf("."));
							fName = tmpStr.substring(tmpStr.indexOf(".") + 1, tmpStr.length());
							fm = this.getSimField(tName, kName, fName);
						} else {
							fName = fieldName.substring(fieldName.indexOf(".") + 1, fieldName.length());
							fm = this.getSimField(tName, fName);
							//System.out.println("fieldName <"+fieldName+">fm---->"+fm.getName()+"<-----"+fm.getString());
						}
					}
				}

					
			} catch (Exception e) {
				MyLog.error(this, e);
			}
		}
		return fm;
	}
	
//	public FieldManager getField(int index) {
//		String tName, kName, fName, tmpStr,fieldName;
//		FieldManager fm = super.getField(index);
//		fieldName=fm.getName();
//		if (this.simWorking == true) {
//			try {
//				if (fm == null) {
//					if (fieldName.indexOf("$") >= 0) {
//						tName = fieldName.substring(0, fieldName.indexOf("$"));
//						tmpStr = fieldName.substring(fieldName.indexOf("$") + 1, fieldName.length());
//						if (tmpStr.indexOf("$") >= 0) {
//							kName = tmpStr.substring(0, tmpStr.indexOf("$"));
//							fName = tmpStr.substring(tmpStr.indexOf("$") + 1, tmpStr.length());
//							fm = this.getSimField(tName, kName, fName);
//						} else {
//							fName = fieldName.substring(fieldName.indexOf("$") + 1, fieldName.length());
//							fm = this.getSimField(tName, fName);
//							//System.out.println("fieldName <"+fieldName+">fm---->"+fm.getName()+"<-----"+fm.getString());
//						}
//					} else if (fieldName.indexOf(".") >= 0) {
//						tName = fieldName.substring(0, fieldName.indexOf("."));
//						tmpStr = fieldName.substring(fieldName.indexOf(".") + 1, fieldName.length());
//						if (tmpStr.indexOf(".") >= 0) {
//							kName = tmpStr.substring(0, tmpStr.indexOf("."));
//							fName = tmpStr.substring(tmpStr.indexOf(".") + 1, tmpStr.length());
//							fm = this.getSimField(tName, kName, fName);
//						} else {
//							fName = fieldName.substring(fieldName.indexOf(".") + 1, fieldName.length());
//							fm = this.getSimField(tName, fName);
//							//System.out.println("fieldName <"+fieldName+">fm---->"+fm.getName()+"<-----"+fm.getString());
//						}
//					}
//				}
//
//					
//			} catch (Exception e) {
//				MyLog.error(this, e);
//			}
//		}
//		return fm;
//	}
	
	public void removeSimTable(String tableName) {
		String keyName, fieldName;
		Iterator iKey = this.getSimListKey(tableName);
		MyHashMap hRecNo = (MyHashMap) this.hTable.get(tableName);
		while (iKey.hasNext()) {
			keyName = iKey.next().toString();
			Iterator iField = this.getFieldSimListKey(tableName, keyName);
			MyHashMap hField = (MyHashMap) hRecNo.get(keyName);
			MyHashMap tmphField = (MyHashMap) hField.clone();
			while (iField.hasNext()) {
				fieldName = iField.next().toString();
				tmphField.remove(fieldName);
			}
			hField = tmphField;
			hRecNo.remove(keyName);
		}
		this.hTable.remove(tableName);
	}
	public void getFileSimList() {
		Iterator itable = this.getSimTableAll();
		while (itable.hasNext()) {
			String table = itable.next().toString();
			Iterator irec = this.getSimListKey(table);
			while (irec.hasNext()) {
				String rec = irec.next().toString();
				Iterator ifield = this.getFieldSimListKey(table, rec);
				while (ifield.hasNext()) {
					String field = ifield.next().toString();
				}
			}
		}
	}
	public boolean set(String fieldName, String data) {
		boolean st=super.set(fieldName, data);
		if(!st){
				try {
					FieldManager fm = this.getField(fieldName);
					if(fm!=null){
						fm.set(data);
						return true;
					}
				}catch(Exception ex){}
		}
		return st;
	}
	public MyHashMap getHTable() {
		return hTable;
	}
	public void setHTable(MyHashMap table) {
		hTable = table;
	}
	
	@Override
	public DbRecord clone(UProfile upf) {
		RecordCmp rc=(RecordCmp)super.clone(upf);
		rc.setHTable(new MyHashMap(true));
		return (DbRecord)rc;
	}
	
	
}