+ /**
+ * Sets value in properties instance.
+ *
+ * @param key Property key (part) to set
+ * @param value Property value to set
+ */
+ protected void setProperty (final String key, final String value) {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); //NOI18N
+
+ // Both should not be null
+ if (key == null) {
+ // key is null
+ throw new NullPointerException("key is null");
+ } else if (value == null) {
+ // value is null
+ throw new NullPointerException("value is null");
+ }
+
+ // Set it
+ properties.setProperty(String.format("org.mxchange.%s", key), value); //NOI18N
+
+ // Trace message
+ this.getLogger().trace("EXIT!"); //NOI18N
+ }
+
+ /**
+ * Some getter for properties names (without org.mxchange)
+ *
+ * @return An array with property names
+ */
+ protected String[] getPropertyNames () {
+ // Init array
+ String[] names = {
+ "database.backend.class", //NOI18N
+ "database.backend.storagepath", //NOI18N
+ "database.mysql.login", //NOI18N
+ "database.mysql.host", //NOI18N
+ "database.mysql.password", //NOI18N
+ "database.mysql.dbname", //NOI18N
+ };
+
+ // Return it
+ return names;
+ }
+
+ /**
+ * Some "setter" for a value in given Storeable instance and target class
+ *
+ * @param instance An instance of a Storeable class
+ * @param targetClass The target class (where the field resides)
+ * @param columnName Column name (= field name)
+ * @param value Value to set
+ * @throws java.lang.NoSuchMethodException If the setter is not found
+ * @throws java.lang.IllegalAccessException If the setter cannot be accessed
+ * @throws java.lang.reflect.InvocationTargetException Any other problem?
+ */
+ protected void setValueInStoreableFromColumn (final Storeable instance, final String targetClass, final String columnName, final Object value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ // Trace message
+ this.getLogger().trace("instance=" + instance + ",targetClass=" + targetClass + ",columnName=" + columnName + ",value=" + value + " - CALLED!");
+
+ // A '$' means not our field
+ if (columnName.startsWith("$")) {
+ // Don't handle these
+ throw new IllegalArgumentException("columnsName contains $");
+ }
+
+ // Determine if the given column is boolean
+ if (this.isBooleanField(instance, targetClass, columnName)) {
+ // Debug message
+ this.getLogger().debug("Column " + columnName + " represents a boolean field.");
+
+ // Yes, then call other method
+ this.setBooleanField(instance, targetClass, this.convertColumnNameToSetterMethod(columnName), columnName, (Boolean) value);
+ }
+
+ // Convert column name to field name
+ String methodName = this.convertColumnNameToSetterMethod(columnName);
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("methodName={0}", methodName));
+
+ // Get field
+ this.setField(instance, targetClass, methodName, columnName, value);
+
+ // Trace message
+ this.getLogger().trace("EXIT!");
+ }
+
+ /**
+ * Some "getter" for a value from given Storeable instance and target class
+ *
+ * @param instance An instance of a Storeable class
+ * @param targetClass The target class (where the field resides)
+ * @param columnName Column name (= field name)
+ * @return value Value to get
+ * @throws java.lang.NoSuchMethodException If the getter was not found
+ * @throws java.lang.IllegalAccessException If the getter cannot be accessed
+ * @throws java.lang.reflect.InvocationTargetException Some other problems?
+ */
+ protected Object getValueInStoreableFromColumn (final Storeable instance, final String targetClass, final String columnName) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},columnName={2} - CALLED!", instance, targetClass, columnName));
+
+ // A '$' means not our field
+ if (columnName.startsWith("$")) {
+ // Don't handle these
+ throw new IllegalArgumentException("columnsName contains $");
+ }
+
+ // Determine if the given column is boolean
+ if (this.isBooleanField(instance, targetClass, columnName)) {
+ // Debug message
+ this.getLogger().debug("Column " + columnName + " represents a boolean field.");
+
+ // Yes, then call other method
+ return this.getBooleanField(instance, targetClass, this.convertColumnNameToGetterMethod(columnName, true));
+ }
+
+ // Convert column name to field name
+ String methodName = this.convertColumnNameToGetterMethod(columnName, false);
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("methodName={0}", methodName));
+
+ // Get field
+ Object value = this.getField(instance, targetClass, methodName);
+
+ // Trace message
+ this.getLogger().trace("value=" + value + " - EXIT!");
+
+ // Return value
+ return value;
+ }
+
+ /**
+ * Some getter for type reflection of given column name
+ *
+ * @param instance The instance to check
+ * @param targetClass Target class to check
+ * @param columnName Column name
+ * @return Type reflection of value
+ */
+ private Class<?> getType (final FrameworkInterface instance, final String targetClass, final String columnName) {
+ // Trace message
+ this.getLogger().trace("instance=" + instance + ",targetClass=" + targetClass + ",columnName=" + columnName + " - CALLED!");
+
+ // Init field tye
+ Class<?> type = null;
+
+ // Get all attributes from given instance
+ Field[] fields = this.getClassFromTarget(instance, targetClass).getDeclaredFields();
+
+ // Debug message
+ this.getLogger().debug("fields()=" + fields.length);
+
+ // Search for proper field instance
+ for (final Field field : fields) {
+ // Debug message
+ this.getLogger().debug("field=" + field);
+
+ // Does it match?
+ if (field.getName().equals(columnName)) {
+ // Found it
+ type = field.getType();
+ break;
+ }
+ }
+
+ // type should not be null
+ if (type == null) {
+ // No null allowed
+ throw new NullPointerException("type is null");
+ }
+
+ // Trace message
+ this.getLogger().debug("type=" + type + " - EXIT!");
+
+ // Return it
+ return type;
+ }