public Configuration(String folder, String dbName, IStoreEngine db, Key[] keysList, bool massInsertMode) { try { this.folder = folder; this.dbName = dbName; this.db = db; //db = StoreEngineFactory.build(folder, dbName, "conf", dbEngine, massInsertMode); if (db.contains(Configuration.KEY_NAMES)) { var kfn = db.get(Configuration.KEY_NAMES); this.keyFieldNames = kfn as string[];//TODO: FIX JSON STORAGE OR IMPLEMENT ANOTHER for (int i = 0; i < this.keyFieldNames.Length; i++) { String keyFieldName = this.keyFieldNames[i]; this.keys[keyFieldName] = (Key)db.get("conf_" + keyFieldName); } if (db.contains(Configuration.KEY_MODE)) { this.isKeyed = (bool)db.get(Configuration.KEY_MODE); } if (db.contains(Configuration.PRIVATE_MODE)) { this.isPrivate = true; } } else { this.keyFieldNames = new String[keysList.Length]; for (int i = 0; i < keysList.Length; i++) { this.keyFieldNames[i] = keysList[i].keyFieldName; keys[keyFieldNames[i]] = keysList[i]; db.set("conf_" + this.keyFieldNames[i], keysList[i]); if (this.keyFieldNames[0] == Configuration.RECORD_LEVEL) { this.isKeyed = false; } else { this.isKeyed = true; } } db.set(Configuration.KEY_MODE, this.isKeyed); db.set(Configuration.KEY_NAMES, this.keyFieldNames); } } catch (Exception ex) { throw new StoreInitException("Store init error: " + ex.Message); } }
public Configuration(IStoreEngine db, Key[] keysList) { this.keyFieldNames = new String[keysList.Length]; for (int i = 0; i < keysList.Length; i++) { this.keyFieldNames[i] = keysList[i].keyFieldName; keys[keyFieldNames[i]] = keysList[i]; db.set("conf_" + this.keyFieldNames[i], keysList[i]); if (this.keyFieldNames[0] == Configuration.RECORD_LEVEL) { this.isKeyed = false; } else { this.isKeyed = true; } } db.set(Configuration.KEY_MODE, this.isKeyed); db.set(Configuration.KEY_NAMES, this.keyFieldNames); }
public void insert(Record rec) { if (this.getConfiguration().isPrivate) { Embeddable emb = (Embeddable)rec.get(Record.PRIVATE_STRUCTURE); data.set(rec.getId(), emb); setHashKeys(rec.getId(), emb, Configuration.RECORD_LEVEL); return; } bool isKeyed = this.getConfiguration().isKeyed; String[] keyFieldNames = this.getConfiguration().keyFieldNames; Dictionary <String, Embeddable[]> embMap = buildEmbeddableMap(rec); if (isKeyed) { for (int i = 0; i < keyFieldNames.Length; i++) { String keyFieldName = keyFieldNames[i]; Embeddable[] embs = embMap[keyFieldName]; for (int j = 0; j < embs.Length; j++) { Embeddable emb = embs[j]; setHashKeys(rec.getId() + Key.KEYFIELD + j, emb, keyFieldName); this.getDataMap(keyFieldName).set(rec.getId() + Key.KEYFIELD + j, emb); } } } else { data.set(rec.getId(), ((Embeddable[])embMap[Configuration.RECORD_LEVEL])[0]); setHashKeys(rec.getId(), ((Embeddable[])embMap[Configuration.RECORD_LEVEL])[0], Configuration.RECORD_LEVEL); } records.set(rec.getId(), rec); }
public void persistCache(String keyFieldName) { bool isKeyed = this.getConfiguration().isKeyed; IStoreEngine hashKeys = keys; if (isKeyed) { hashKeys = this.getKeyMap(keyFieldName); } Dictionary <String, Object> cache = getCacheMap(keyFieldName); foreach (string key in cache.Keys) { long tt = incId(); hashKeys.set(key + "_" + tt, cache[key]); } cache.Clear(); }
public void setHashKeys(String id, Embeddable emb, String keyFieldName) { bool isKeyed = this.getConfiguration().isKeyed; String[] keyFieldNames = this.getConfiguration().keyFieldNames; IStoreEngine hashKeys = keys; if (isKeyed) { hashKeys = this.getKeyMap(keyFieldName); } Dictionary <String, Object> cache = this.getCacheMap(keyFieldName); Key key = this.getConfiguration().getKey(keyFieldName); for (int j = 0; j < key.L; j++) { String hashKey = buildHashKey(j, emb, keyFieldName); if (cache.ContainsKey(hashKey)) { List <String> arr = (List <String>)cache[hashKey]; arr.Add(id); if (arr.Count >= CACHEENTRYLIMIT) { long tt = incId(); hashKeys.set(hashKey + "_" + tt, arr); cache.Remove(hashKey); } } else { List <String> arr = new List <String>(); arr.Add(id); cache[hashKey] = arr; } if (cache.Count >= CACHENOLIMIT) { persistCache(keyFieldName); } } }