git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1150 f203690c-595d-4dc9-a70b-905162fa7fd2tags/jackcess-2.1.12
@@ -4,6 +4,11 @@ | |||
<author email="javajedi@users.sf.net">Tim McCune</author> | |||
</properties> | |||
<body> | |||
<release version="2.1.12" date="TBD"> | |||
<action dev="jahlborn" type="update"> | |||
Add some additional property keys and relevant enums for values. | |||
</action> | |||
</release> | |||
<release version="2.1.11" date="2018-03-04"> | |||
<action dev="jahlborn" type="fix" system="SourceForge2" issue="145"> | |||
Expose the "ddl" attribute on properties. Set the attribute |
@@ -47,6 +47,10 @@ public interface PropertyMap extends Iterable<PropertyMap.Property> | |||
public static final String ALLOW_MULTI_VALUE_PROP = "AllowMultipleValues"; | |||
public static final String ROW_SOURCE_TYPE_PROP = "RowSourceType"; | |||
public static final String ROW_SOURCE_PROP = "RowSource"; | |||
public static final String DISPLAY_CONTROL_PROP = "DisplayControl"; | |||
public static final String TEXT_FORMAT_PROP = "TextFormat"; | |||
public static final String IME_MODE_PROP = "IMEMode"; | |||
public static final String IME_SENTENCE_MODE_PROP = "IMESentenceMode"; | |||
public String getName(); | |||
@@ -113,7 +117,7 @@ public interface PropertyMap extends Iterable<PropertyMap.Property> | |||
* tolerated and ignored). | |||
*/ | |||
public void putAll(Iterable<? extends Property> props); | |||
/** | |||
* Removes the property with the given name | |||
* | |||
@@ -128,8 +132,8 @@ public interface PropertyMap extends Iterable<PropertyMap.Property> | |||
/** | |||
* Info about a property defined in a PropertyMap. | |||
*/ | |||
public interface Property | |||
*/ | |||
public interface Property | |||
{ | |||
public String getName(); | |||
@@ -153,4 +157,144 @@ public interface PropertyMap extends Iterable<PropertyMap.Property> | |||
*/ | |||
public void setValue(Object newValue); | |||
} | |||
/** | |||
* Interface for enums which can be used as property values. | |||
*/ | |||
public interface EnumValue | |||
{ | |||
/** | |||
* @return the property value which should be stored in the db | |||
*/ | |||
public Object getValue(); | |||
} | |||
/** | |||
* Enum value constants for the DisplayControl property | |||
*/ | |||
public enum DisplayControl implements EnumValue | |||
{ | |||
BOUND_OBJECT_FRAME(108), | |||
CHECK_BOX(106), | |||
COMBO_BOX(111), | |||
COMMAND_BUTTON(104), | |||
CUSTOM_CONTROL(119), | |||
EMPTY_CELL(127), | |||
IMAGE(103), | |||
LABEL(100), | |||
LINE(102), | |||
LIST_BOX(110), | |||
NAVIGATION_BUTTON(130), | |||
NAVIGATION_CONTROL(129), | |||
OBJECT_FRAME(114), | |||
OPTION_BUTTON(105), | |||
OPTION_GROUP(107), | |||
PAGE(124), | |||
PAGE_BREAK(118), | |||
RECTANGLE(101), | |||
SUB_FORM(112), | |||
TAB_CTL(123), | |||
TEXT_BOX(109), | |||
TOGGLE_BUTTON(122), | |||
WEB_BROWSER(128); | |||
private final Short _value; | |||
private DisplayControl(int value) { | |||
_value = (short)value; | |||
} | |||
public Short getValue() { | |||
return _value; | |||
} | |||
@Override | |||
public String toString() { | |||
return name() + "[" + _value + "]"; | |||
} | |||
} | |||
/** | |||
* Enum value constants for the TextFormat property | |||
*/ | |||
public enum TextFormat implements EnumValue | |||
{ | |||
HTMLRICHTEXT(1), | |||
PLAIN(0); | |||
private final Byte _value; | |||
private TextFormat(int value) { | |||
_value = (byte)value; | |||
} | |||
public Byte getValue() { | |||
return _value; | |||
} | |||
@Override | |||
public String toString() { | |||
return name() + "[" + _value + "]"; | |||
} | |||
} | |||
/** | |||
* Enum value constants for the IMEMode property | |||
*/ | |||
public enum IMEMode implements EnumValue | |||
{ | |||
NOCONTROL(0), | |||
ON(1), | |||
OFF(2), | |||
DISABLE(3), | |||
HIRAGANA(4), | |||
KATAKANA(5), | |||
KATAKANAHALF(6), | |||
ALPHAFULL(7), | |||
ALPHA(8), | |||
HANGULFULL(9), | |||
HANGUL(10); | |||
private final Byte _value; | |||
private IMEMode(int value) { | |||
_value = (byte)value; | |||
} | |||
public Byte getValue() { | |||
return _value; | |||
} | |||
@Override | |||
public String toString() { | |||
return name() + "[" + _value + "]"; | |||
} | |||
} | |||
/** | |||
* Enum value constants for the IMESentenceMode property | |||
*/ | |||
public enum IMESentenceMode implements EnumValue | |||
{ | |||
NORMAL(0), | |||
PLURAL(1), | |||
SPEAKING(2), | |||
NONE(3); | |||
private final Byte _value; | |||
private IMESentenceMode(int value) { | |||
_value = (byte)value; | |||
} | |||
public Byte getValue() { | |||
return _value; | |||
} | |||
@Override | |||
public String toString() { | |||
return name() + "[" + _value + "]"; | |||
} | |||
} | |||
} |
@@ -55,11 +55,15 @@ public class PropertyMapImpl implements PropertyMap | |||
DEFAULT_TYPES.put(DESCRIPTION_PROP, new PropDef(DataType.MEMO, false)); | |||
DEFAULT_TYPES.put(RESULT_TYPE_PROP, new PropDef(DataType.BYTE, true)); | |||
DEFAULT_TYPES.put(EXPRESSION_PROP, new PropDef(DataType.MEMO, true)); | |||
DEFAULT_TYPES.put(DISPLAY_CONTROL_PROP, new PropDef(DataType.INT, false)); | |||
DEFAULT_TYPES.put(TEXT_FORMAT_PROP, new PropDef(DataType.BYTE, false)); | |||
DEFAULT_TYPES.put(IME_MODE_PROP, new PropDef(DataType.BYTE, false)); | |||
DEFAULT_TYPES.put(IME_SENTENCE_MODE_PROP, new PropDef(DataType.BYTE, false)); | |||
} | |||
private final String _mapName; | |||
private final short _mapType; | |||
private final Map<String,Property> _props = | |||
private final Map<String,Property> _props = | |||
new LinkedHashMap<String,Property>(); | |||
private final PropertyMaps _owner; | |||
@@ -122,8 +126,8 @@ public class PropertyMapImpl implements PropertyMap | |||
for(Property prop : props) { | |||
put(prop); | |||
} | |||
} | |||
} | |||
public PropertyImpl put(Property prop) { | |||
return put(prop.getName(), prop.getType(), prop.getValue(), prop.isDdl()); | |||
} | |||
@@ -131,7 +135,7 @@ public class PropertyMapImpl implements PropertyMap | |||
/** | |||
* Puts a property into this map with the given information. | |||
*/ | |||
public PropertyImpl put(String name, DataType type, Object value, | |||
public PropertyImpl put(String name, DataType type, Object value, | |||
boolean isDdl) { | |||
PropertyImpl prop = (PropertyImpl)createProperty(name, type, value, isDdl); | |||
_props.put(DatabaseImpl.toLookupName(name), prop); | |||
@@ -153,7 +157,7 @@ public class PropertyMapImpl implements PropertyMap | |||
@Override | |||
public String toString() { | |||
return toString(this); | |||
} | |||
} | |||
public static String toString(PropertyMap map) { | |||
StringBuilder sb = new StringBuilder(); | |||
@@ -173,12 +177,17 @@ public class PropertyMapImpl implements PropertyMap | |||
public static Property createProperty(String name, DataType type, Object value) { | |||
return createProperty(name, type, value, false); | |||
} | |||
public static Property createProperty(String name, DataType type, | |||
public static Property createProperty(String name, DataType type, | |||
Object value, boolean isDdl) { | |||
// see if this is a builtin property that we already understand | |||
PropDef pd = DEFAULT_TYPES.get(name); | |||
if(value instanceof PropertyMap.EnumValue) { | |||
// convert custom enum to stored value | |||
value = ((PropertyMap.EnumValue)value).getValue(); | |||
} | |||
if(pd != null) { | |||
// update according to the default info | |||
type = ((type == null) ? pd._type : type); | |||
@@ -211,13 +220,13 @@ public class PropertyMapImpl implements PropertyMap | |||
" with value " + value); | |||
} | |||
} | |||
return new PropertyImpl(name, type, value, isDdl); | |||
} | |||
/** | |||
* Info about a property defined in a PropertyMap. | |||
*/ | |||
*/ | |||
static final class PropertyImpl implements PropertyMap.Property | |||
{ | |||
private final String _name; |
@@ -59,10 +59,10 @@ public class PropertiesTest extends TestCase | |||
assertTrue(colMap.isEmpty()); | |||
assertEquals(0, colMap.getSize()); | |||
assertFalse(colMap.iterator().hasNext()); | |||
assertFalse(maps.isEmpty()); | |||
assertEquals(2, maps.getSize()); | |||
assertSame(defMap, maps.get(PropertyMaps.DEFAULT_NAME)); | |||
assertEquals(PropertyMaps.DEFAULT_NAME, defMap.getName()); | |||
assertSame(colMap, maps.get("TESTCOL")); | |||
@@ -97,7 +97,7 @@ public class PropertiesTest extends TestCase | |||
} | |||
} | |||
assertEquals(Arrays.asList(defMap.get("foo"), defMap.get("baz"), | |||
assertEquals(Arrays.asList(defMap.get("foo"), defMap.get("baz"), | |||
colMap.get("buzz")), props); | |||
} | |||
@@ -106,16 +106,16 @@ public class PropertiesTest extends TestCase | |||
PropertyMaps maps = new PropertyMaps(10, null, null); | |||
PropertyMap defMap = maps.getDefault(); | |||
assertEquals(DataType.TEXT, | |||
assertEquals(DataType.TEXT, | |||
defMap.put(PropertyMap.FORMAT_PROP, null).getType()); | |||
assertEquals(DataType.BOOLEAN, | |||
assertEquals(DataType.BOOLEAN, | |||
defMap.put(PropertyMap.REQUIRED_PROP, null).getType()); | |||
assertEquals(DataType.TEXT, | |||
assertEquals(DataType.TEXT, | |||
defMap.put("strprop", "this is a string").getType()); | |||
assertEquals(DataType.BOOLEAN, | |||
assertEquals(DataType.BOOLEAN, | |||
defMap.put("boolprop", true).getType()); | |||
assertEquals(DataType.LONG, | |||
assertEquals(DataType.LONG, | |||
defMap.put("intprop", 37).getType()); | |||
} | |||
@@ -127,22 +127,22 @@ public class PropertiesTest extends TestCase | |||
Database db = open(testDb); | |||
TableImpl t = (TableImpl)db.getTable("Table1"); | |||
assertEquals(t.getTableDefPageNumber(), | |||
assertEquals(t.getTableDefPageNumber(), | |||
t.getPropertyMaps().getObjectId()); | |||
PropertyMap tProps = t.getProperties(); | |||
assertEquals(PropertyMaps.DEFAULT_NAME, tProps.getName()); | |||
int expectedNumProps = 3; | |||
if(db.getFileFormat() != Database.FileFormat.V1997) { | |||
assertEquals("{5A29A676-1145-4D1A-AE47-9F5415CDF2F1}", | |||
assertEquals("{5A29A676-1145-4D1A-AE47-9F5415CDF2F1}", | |||
tProps.getValue(PropertyMap.GUID_PROP)); | |||
if(nameMapBytes == null) { | |||
nameMapBytes = (byte[])tProps.getValue("NameMap"); | |||
} else { | |||
assertTrue(Arrays.equals(nameMapBytes, | |||
assertTrue(Arrays.equals(nameMapBytes, | |||
(byte[])tProps.getValue("NameMap"))); | |||
} | |||
expectedNumProps += 2; | |||
} | |||
} | |||
assertEquals(expectedNumProps, tProps.getSize()); | |||
assertEquals((byte)0, tProps.getValue("Orientation")); | |||
assertEquals(Boolean.FALSE, tProps.getValue("OrderByOn")); | |||
@@ -152,7 +152,7 @@ public class PropertiesTest extends TestCase | |||
assertEquals("A", colProps.getName()); | |||
expectedNumProps = 9; | |||
if(db.getFileFormat() != Database.FileFormat.V1997) { | |||
assertEquals("{E9EDD90C-CE55-4151-ABE1-A1ACE1007515}", | |||
assertEquals("{E9EDD90C-CE55-4151-ABE1-A1ACE1007515}", | |||
colProps.getValue(PropertyMap.GUID_PROP)); | |||
++expectedNumProps; | |||
} | |||
@@ -160,9 +160,9 @@ public class PropertiesTest extends TestCase | |||
assertEquals((short)-1, colProps.getValue("ColumnWidth")); | |||
assertEquals((short)0, colProps.getValue("ColumnOrder")); | |||
assertEquals(Boolean.FALSE, colProps.getValue("ColumnHidden")); | |||
assertEquals(Boolean.FALSE, | |||
assertEquals(Boolean.FALSE, | |||
colProps.getValue(PropertyMap.REQUIRED_PROP)); | |||
assertEquals(Boolean.FALSE, | |||
assertEquals(Boolean.FALSE, | |||
colProps.getValue(PropertyMap.ALLOW_ZERO_LEN_PROP)); | |||
assertEquals((short)109, colProps.getValue("DisplayControl")); | |||
assertEquals(Boolean.TRUE, colProps.getValue("UnicodeCompression")); | |||
@@ -251,12 +251,12 @@ public class PropertiesTest extends TestCase | |||
checkProperties(propMap, propMap2); | |||
} | |||
assertFalse(iter.hasNext()); | |||
assertFalse(iter2.hasNext()); | |||
db.close(); | |||
} | |||
} | |||
} | |||
public void testModifyProperties() throws Exception | |||
@@ -333,7 +333,7 @@ public class PropertiesTest extends TestCase | |||
assertTrue((Boolean)cProps.getValue(PropertyMap.REQUIRED_PROP)); | |||
assertEquals("42", fProps.getValue(PropertyMap.DEFAULT_VALUE_PROP)); | |||
assertNull(dProps.getValue("DisplayControl")); | |||
assertNull(dProps.getValue("DisplayControl")); | |||
cProps.put(PropertyMap.REQUIRED_PROP, DataType.BOOLEAN, false); | |||
fProps.get(PropertyMap.DEFAULT_VALUE_PROP).setValue("0"); | |||
@@ -355,7 +355,7 @@ public class PropertiesTest extends TestCase | |||
// weirdo format, no properties | |||
continue; | |||
} | |||
File file = TestUtil.createTempFile(false); | |||
Database db = new DatabaseBuilder(file) | |||
.setFileFormat(ff) | |||
@@ -380,16 +380,16 @@ public class PropertiesTest extends TestCase | |||
db.close(); | |||
db = new DatabaseBuilder(file).open(); | |||
assertEquals("123", db.getUserDefinedProperties().getValue("testing")); | |||
t = db.getTable("Test"); | |||
assertEquals(Boolean.TRUE, | |||
assertEquals(Boolean.TRUE, | |||
t.getProperties().getValue("awesome_table")); | |||
Column c = t.getColumn("id"); | |||
assertEquals(Boolean.TRUE, | |||
assertEquals(Boolean.TRUE, | |||
c.getProperties().getValue(PropertyMap.REQUIRED_PROP)); | |||
assertEquals("{" + u1.toString().toUpperCase() + "}", | |||
c.getProperties().getValue(PropertyMap.GUID_PROP)); | |||
@@ -397,13 +397,26 @@ public class PropertiesTest extends TestCase | |||
c = t.getColumn("data"); | |||
assertEquals(Boolean.FALSE, | |||
c.getProperties().getValue(PropertyMap.ALLOW_ZERO_LEN_PROP)); | |||
assertEquals("{" + u2.toString().toUpperCase() + "}", | |||
assertEquals("{" + u2.toString().toUpperCase() + "}", | |||
c.getProperties().getValue(PropertyMap.GUID_PROP)); | |||
} | |||
} | |||
private static void checkProperties(PropertyMap propMap1, | |||
public void testEnumValues() throws Exception | |||
{ | |||
PropertyMaps maps = new PropertyMaps(10, null, null); | |||
PropertyMapImpl colMap = maps.get("testcol"); | |||
colMap.put(PropertyMap.DISPLAY_CONTROL_PROP, | |||
PropertyMap.DisplayControl.TEXT_BOX); | |||
assertEquals(PropertyMap.DisplayControl.TEXT_BOX.getValue(), | |||
colMap.getValue(PropertyMap.DISPLAY_CONTROL_PROP)); | |||
} | |||
private static void checkProperties(PropertyMap propMap1, | |||
PropertyMap propMap2) | |||
{ | |||
assertEquals(propMap1.getSize(), propMap2.getSize()); |