@Override public void close() { flush() ; closed = true ; metaFilename = null ; properties = null ; }
/** Check property is an expected value or set if missing */ public void checkOrSetMetadata(String key, String expected) { String x = getProperty(key) ; if ( x == null ) { setProperty(key, expected) ; return ; } if ( x.equals(expected) ) return ; inconsistent(key, x, expected) ; }
/** Clear all properties. */ public void clear() { _clear() ; }
/** Get property or the default value - also set the default value if not present */ public String getOrSetDefault(String key, String expected) { String x = getProperty(key) ; if ( x == null ) { setProperty(key, expected) ; x = expected ; } return x ; }
/** Clear all properties. */ private void _clear() { ensureInit() ; properties.clear() ; changedEvent() ; }
@Test public void meta2() { clear() ; MetaFile f = new MetaFile("META", testfile) ; f.setProperty("test.value1", "1") ; f.flush(); MetaFile f2 = new MetaFile("META", testfile) ; assertEquals("1", f2.getProperty("test.value1")) ; assertNull(f2.getProperty("test.value.other")) ; }
@Test public void meta1() { clear() ; MetaFile f = new MetaFile("META", testfile) ; assertFalse(new File(testfileMeta).exists()) ; f.setProperty("key", "value") ; f.flush() ; assertTrue(new File(f.getFilename()).exists()) ; }
public void addToMetaData(MetaFile mf) { mf.setProperty(ParamOrder, order) ; mf.setProperty(ParamKeyLength, recordFactory.keyLength()) ; mf.setProperty(ParamValueLength, recordFactory.valueLength()) ; mf.flush() ; }
/** Check property has the value given - throw exception if not. */ public void checkMetadata(String key, String expected) { String value = getProperty(key) ; if ( ! Objects.equals(value, value) ) inconsistent(key, value, expected) ; }
/** Get property as a string and split on ",". */ public String[] getPropertySplit(String key) { String str = getProperty(key) ; if ( str == null ) return null ; return str.split(",") ; }
private static void memInit(Location location, String name) { location.pathname = Names.memName ; if ( name != null ) { name = name.replace('\\', '/') ; location.pathname = location.pathname + '/' + name ; } else location.isMemUnique = true ; if ( !location.pathname.endsWith(pathSeparator) ) location.pathname = location.pathname + '/' ; location.isMem = true ; location.metafile = new MetaFile(Names.memName, Names.memName) ; location.lock = new LocationLock(location); }
/** Test for the presence of a property */ public boolean hasProperty(String key) { return _getProperty(key, null) != null ; }
/** Set property */ public void setProperty(String key, String value) { _setProperty(key, value) ; }
private String _getProperty(String key, String dft) { ensureInit() ; return properties.getProperty(key, dft) ; }
@Test public void meta2() { clear() ; MetaFile f = new MetaFile("META", testfile) ; f.setProperty("test.value1", "1") ; f.flush(); MetaFile f2 = new MetaFile("META", testfile) ; assertEquals("1", f2.getProperty("test.value1")) ; assertNull(f2.getProperty("test.value.other")) ; }
@Test public void meta1() { clear() ; MetaFile f = new MetaFile("META", testfile) ; assertFalse(new File(testfileMeta).exists()) ; f.setProperty("key", "value") ; f.flush() ; assertTrue(new File(f.getFilename()).exists()) ; }
/** Get the property value and parse as an integer or return default value. */ public int getPropertyAsInteger(String key, int defaultValue) { String x = getProperty(key) ; if ( x == null ) return defaultValue ; return Integer.parseInt(x) ; }
private void _setProperty(String key, String value) { ensureInit() ; properties.setProperty(key, value) ; changedEvent() ; }
private Location(String rootname) { super() ; if ( rootname.equals(Names.memName) ) { memInit(this, null) ; return ; } if ( rootname.startsWith(memNamePath) ) { String name = rootname.substring(memNamePath.length()) ; memInit(this, name) ; return ; } ensure(rootname) ; pathname = fixupName(rootname) ; // Metafilename for a directory. String metafileName = getPath(Names.directoryMetafile, Names.extMeta) ; metafile = new MetaFile("Location: " + rootname, metafileName) ; // Set up locking // Note that we don't check the lock in any way at this point, checking // and obtaining the lock is carried out by StoreConnection lock = new LocationLock(this); }
/** Get the property value or null. */ public String getProperty(String key) { return _getProperty(key, null) ; }