import java.util.Properties;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
-import java.util.logging.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mxchange.jcore.application.Application;
Boolean value = (Boolean) method.invoke(instance);
// Trace message
- this.getLogger().trace("value=" + value + " - EXIT!");
+ this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
// Return value
return value;
method.invoke(instance, value);
// Trace message
- this.getLogger().trace("EXIT!");
+ this.getLogger().trace("EXIT!"); //NOI18N
}
/**
Method method = this.getMethodFromName(instance, targetClass, methodName);
// Debug message
- this.getLogger().debug("method=" + method + ",instance=" + instance);
+ this.getLogger().debug(MessageFormat.format("method={0},instance={1}", method, instance)); //NOI18N
// Get value from field
Object value = method.invoke(instance);
// Trace messahe
- this.getLogger().trace("value=" + value + " - EXIT!");
+ this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
// Return value
return value;
Class<?> type = this.getType(instance, targetClass, columnName);
// Debug message
- this.getLogger().debug("type=" + type);
+ this.getLogger().debug(MessageFormat.format("type={0}", type)); //NOI18N
// Init object
Object object = value;
// Hard-coded "cast" again ... :-(
// @TODO Can't we get rid of this???
switch (type.getSimpleName()) {
- case "Long": // Long object
+ case "Long": // Long object //NOI18N
object = Long.parseLong((String) value);
break;
- case "Float": // Float object
+ case "Float": // Float object //NOI18N
object = Float.parseFloat((String) value);
break;
- case "Boolean": // Boolean object
+ case "Boolean": // Boolean object //NOI18N
object = Boolean.parseBoolean((String) value);
break;
- case "String": // String object
+ case "String": // String object //NOI18N
break;
default: // Unsupported type
- throw new IllegalArgumentException("value " + value + " has unsupported type " + type.getSimpleName());
+ throw new IllegalArgumentException(MessageFormat.format("value {0} has unsupported type {1}", value, type.getSimpleName())); //NOI18N
}
// Debug message
- this.getLogger().debug("object[" + object.getClass().getSimpleName() + "]=" + object);
+ this.getLogger().debug(MessageFormat.format("object[{0}]={1}", object.getClass().getSimpleName(), object)); //NOI18N
// Get method to call
Method method = this.getMethodFromName(instance, targetClass, methodName, type);
// Debug message
- this.getLogger().debug("method=" + method + ",instance=" + instance + ",value[" + value.getClass().getSimpleName() + "]=" + value);
+ this.getLogger().debug(MessageFormat.format("method={0},instance={1},value[{2}]={3}", method, instance, value.getClass().getSimpleName(), value)); //NOI18N
// Get value from field
method.invoke(instance, object);
// Trace messahe
- this.getLogger().trace("EXIT!");
+ this.getLogger().trace("EXIT!"); //NOI18N
}
/**
*/
protected void initBundle () {
// Trace message
- this.getLogger().trace("CALLED!");
+ this.getLogger().trace("CALLED!"); //NOI18N
// Is the bundle set?
if (bundle instanceof ResourceBundle) {
bundle = ResourceBundle.getBundle(FrameworkInterface.I18N_BUNDLE_FILE); // NOI18N
// Trace message
- this.getLogger().trace("EXIT!");
+ this.getLogger().trace("EXIT!"); //NOI18N
}
/**
// Both should not be null
if (key == null) {
// key is null
- throw new NullPointerException("key is null");
+ throw new NullPointerException("key is null"); //NOI18N
} else if (value == null) {
// value is null
- throw new NullPointerException("value is null");
+ throw new NullPointerException("value is null"); //NOI18N
}
// Set it
*/
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!");
+ this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},columnName={2},value={3} - CALLED!", instance, targetClass, columnName, value)); //NOI18N
// A '$' means not our field
- if (columnName.startsWith("$")) {
+ if (columnName.startsWith("$")) { //NOI18N
// Don't handle these
- throw new IllegalArgumentException("columnsName contains $");
+ throw new IllegalArgumentException("columnsName contains $"); //NOI18N
}
// Determine if the given column is boolean
if (this.isBooleanField(instance, targetClass, columnName)) {
// Debug message
- this.getLogger().debug("Column " + columnName + " represents a boolean field.");
+ this.getLogger().debug(MessageFormat.format("Column {0} represents a boolean field.", columnName)); //NOI18N
// Yes, then call other method
this.setBooleanField(instance, targetClass, this.convertColumnNameToSetterMethod(columnName), columnName, (Boolean) value);
String methodName = this.convertColumnNameToSetterMethod(columnName);
// Debug message
- this.getLogger().debug(MessageFormat.format("methodName={0}", methodName));
+ this.getLogger().debug(MessageFormat.format("methodName={0}", methodName)); //NOI18N
// Get field
this.setField(instance, targetClass, methodName, columnName, value);
// Trace message
- this.getLogger().trace("EXIT!");
+ this.getLogger().trace("EXIT!"); //NOI18N
}
/**
*/
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));
+ this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},columnName={2} - CALLED!", instance, targetClass, columnName)); //NOI18N
// A '$' means not our field
- if (columnName.startsWith("$")) {
+ if (columnName.startsWith("$")) { //NOI18N
// Don't handle these
- throw new IllegalArgumentException("columnsName contains $");
+ throw new IllegalArgumentException("columnsName contains $"); //NOI18N
}
// Determine if the given column is boolean
if (this.isBooleanField(instance, targetClass, columnName)) {
// Debug message
- this.getLogger().debug("Column " + columnName + " represents a boolean field.");
+ this.getLogger().debug(MessageFormat.format("Column {0} represents a boolean field.", columnName)); //NOI18N
// Yes, then call other method
return this.getBooleanField(instance, targetClass, this.convertColumnNameToGetterMethod(columnName, true));
String methodName = this.convertColumnNameToGetterMethod(columnName, false);
// Debug message
- this.getLogger().debug(MessageFormat.format("methodName={0}", methodName));
+ this.getLogger().debug(MessageFormat.format("methodName={0}", methodName)); //NOI18N
// Get field
Object value = this.getField(instance, targetClass, methodName);
// Trace message
- this.getLogger().trace("value=" + value + " - EXIT!");
+ this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
// Return value
return 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!");
+ this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},columnName={2} - CALLED!", instance, targetClass, columnName)); //NOI18N
// Init field tye
Class<?> type = null;
Field[] fields = this.getClassFromTarget(instance, targetClass).getDeclaredFields();
// Debug message
- this.getLogger().debug("fields()=" + fields.length);
+ this.getLogger().debug("fields()=" + fields.length); //NOI18N
// Search for proper field instance
for (final Field field : fields) {
// Debug message
- this.getLogger().debug("field=" + field);
+ this.getLogger().debug("field=" + field); //NOI18N
// Does it match?
if (field.getName().equals(columnName)) {
// type should not be null
if (type == null) {
// No null allowed
- throw new NullPointerException("type is null");
+ throw new NullPointerException("type is null"); //NOI18N
}
// Trace message
- this.getLogger().debug("type=" + type + " - EXIT!");
+ this.getLogger().debug(MessageFormat.format("type={0} - EXIT!", type)); //NOI18N
// Return it
return type;
*/
@Override
public final void setFamilyName (final String familyName) {
- /* NOISY-DEBUG: */ this.getLogger().trace(MessageFormat.format("familyName={0} - CALLED!", familyName));
+ /* NOISY-DEBUG: */ this.getLogger().trace(MessageFormat.format("familyName={0} - CALLED!", familyName)); //NOI18N
this.familyName = familyName;
}
@Override
public Object getValueFromColumn (final String columnName) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
// Trace message
- this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName));
+ this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName)); //NOI18N
// A '$' means not our field
- if (columnName.startsWith("$")) {
+ if (columnName.startsWith("$")) { //NOI18N
// Don't handle these
- throw new IllegalArgumentException("columnsName contains $");
+ throw new IllegalArgumentException("columnsName contains $"); //NOI18N
}
// Determine if the given column is boolean
- if (this.isBooleanField(this, "BaseContact", columnName)) {
+ if (this.isBooleanField(this, "BaseContact", columnName)) { //NOI18N
// Debug message
- this.getLogger().debug("Column " + columnName + " represents a boolean field.");
+ this.getLogger().debug(MessageFormat.format("Column {0} represents a boolean field.", columnName)); //NOI18N
// Yes, then call other method
- return this.getBooleanField(this, "BaseContact", this.convertColumnNameToGetterMethod(columnName, true));
+ return this.getBooleanField(this, "BaseContact", this.convertColumnNameToGetterMethod(columnName, true)); //NOI18N
}
// Convert column name to field name
String methodName = this.convertColumnNameToGetterMethod(columnName, false);
// Debug message
- this.getLogger().debug(MessageFormat.format("field={0}", methodName));
+ this.getLogger().debug(MessageFormat.format("field={0}", methodName)); //NOI18N
// Get field
- Object value = this.getField(this, "BaseContact", methodName);
+ Object value = this.getField(this, "BaseContact", methodName); //NOI18N
// Trace message
- this.getLogger().trace("value=" + value + " - EXIT!");
+ this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
// Return it
return value;
@Override
public int hashCode () {
// Validate gender instance
- assert (this.getGender() instanceof Gender) : "gender is not set.";
+ assert (this.getGender() instanceof Gender) : "gender is not set."; //NOI18N
int hash = 7;
hash = 79 * hash + Objects.hashCode(this.getFamilyName());
@Override
public boolean isFieldValueEqual (final String columnName, final boolean bool) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
// Trace message
- this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool));
+ this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool)); //NOI18N
// Convert column name to field name
String methodName = this.convertColumnNameToGetterMethod(columnName, true);
// Debug message
- this.getLogger().debug(MessageFormat.format("field={0}", methodName));
+ this.getLogger().debug(MessageFormat.format("field={0}", methodName)); //NOI18N
// Init class instance
- boolean value = this.getBooleanField(this, "BaseContact", methodName);
+ boolean value = this.getBooleanField(this, "BaseContact", methodName); //NOI18N
// Debug message
- this.getLogger().debug(MessageFormat.format("value={0}", value));
+ this.getLogger().debug(MessageFormat.format("value={0}", value)); //NOI18N
// Compare it
boolean isFound = (bool == value);
// Trace message
- this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound));
+ this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound)); //NOI18N
// Return result
return isFound;
*/
@Override
public Iterator<Map.Entry<Field, Object>> iterator () throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- return this.fieldIterator(this, "BaseContact");
+ return this.fieldIterator(this, "BaseContact"); //NOI18N
}
/**
// The client must be set
if (client == null) {
// Not set
- throw new NullPointerException("client is null");
+ throw new NullPointerException("client is null"); //NOI18N
}
// Display name "box"
@Override
public void setValueFromColumn (final String columnName, final Object value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Trace message
- this.getLogger().trace(MessageFormat.format("columnName={0},value={1} - CALLED!", columnName, value));
+ this.getLogger().trace(MessageFormat.format("columnName={0},value={1} - CALLED!", columnName, value)); //NOI18N
// Call super method
- this.setValueInStoreableFromColumn(this, "BaseContact", columnName, value);
+ this.setValueInStoreableFromColumn(this, "BaseContact", columnName, value); //NOI18N
// Trace message
- this.getLogger().trace("EXIT!");
+ this.getLogger().trace("EXIT!"); //NOI18N
}
}
this.criteria.put(key, value);
}
+ @Override
+ public void addCriteria (final String key, final Number value) {
+ this.criteria.put(key, value);
+ }
+
@Override
public Set<Map.Entry<String, Object>> entrySet () {
return this.criteria.entrySet();
}
+ /**
+ * Setter for Logical instance
+ *
+ * @param logcial the Logical instance to set
+ */
+ public final void setLogcial (final Logical logcial) {
+ this.logcial = logcial;
+ }
+
@Override
public Iterable<Object> values () {
// Call map's method
protected final Logical getLogical () {
return this.logcial;
}
-
- /**
- * Setter for Logical instance
- *
- * @param logcial the Logical instance to set
- */
- public final void setLogcial (final Logical logcial) {
- this.logcial = logcial;
- }
-
- @Override
- public void addCriteria (final String key, final Number value) {
- this.criteria.put(key, value);
- }
}
*/
package org.mxchange.jcore.criteria.searchable;
-import org.mxchange.jcore.criteria.logical.Logical;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.HashMap;
@Override
public boolean matches (final Storeable storeable) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
// Trace message
- this.getLogger().trace(MessageFormat.format("storeable={0} - CALLED!", storeable));
+ this.getLogger().trace(MessageFormat.format("storeable={0} - CALLED!", storeable)); //NOI18N
// Must not be null
if (storeable == null) {
// Abort here
- throw new NullPointerException("storeable is null");
+ throw new NullPointerException("storeable is null"); //NOI18N
}
// Debug message
- this.getLogger().debug("this.entrySet().size()=" + this.entrySet().size());
+ this.getLogger().debug("this.entrySet().size()=" + this.entrySet().size()); //NOI18N //NOI18N
// No matches found?
if (this.entrySet().isEmpty()) {
// Debug message
- this.getLogger().debug("No criteria set, returning true ...");
+ this.getLogger().debug("No criteria set, returning true ..."); //NOI18N
// Then there is nothing to match!
return true;
// Check all conditions
for (final Map.Entry<String, Object> criteria : this.entrySet()) {
// Debug message
- this.getLogger().debug(MessageFormat.format("criteria: key={0},value[{1}]={2}", criteria.getKey(), criteria.getValue().getClass().getSimpleName(), criteria.getValue()));
+ this.getLogger().debug(MessageFormat.format("criteria: key={0},value[{1}]={2}", criteria.getKey(), criteria.getValue().getClass().getSimpleName(), criteria.getValue())); //NOI18N
// Get value from column name
Object value = storeable.getValueFromColumn(criteria.getKey());
// Debug message
- this.getLogger().debug("value[" + value.getClass().getSimpleName() + "]=" + value);
+ this.getLogger().debug(MessageFormat.format("value[{0}]={1}", value.getClass().getSimpleName(), value)); //NOI18N
// Is both same?
if (value.equals(criteria.getValue())) {
// Debug message
- this.getLogger().debug("value=" + value + " - MATCHES!");
+ this.getLogger().debug(MessageFormat.format("value={0} - MATCHES!", value)); //NOI18N
// Matching criteria found
criteraMatches.put(criteria.getKey(), true);
matches = (criteraMatches.size() == 1);
} else if (this.getLogical() == null) {
// Logical instance is null
- throw new NullPointerException("logical is not set, but more than one column shall be matched.");
+ throw new NullPointerException("logical is not set, but more than one column shall be matched."); //NOI18N
} else {
// Now for the final test
matches = this.getLogical().matches(this.entrySet(), criteraMatches);
}
// Trace message
- this.getLogger().trace(MessageFormat.format("matches={0} - EXIT!", matches));
+ this.getLogger().trace(MessageFormat.format("matches={0} - EXIT!", matches)); //NOI18N
// Return result
return matches;
@Override
public Result<? extends Storeable> doInsertDataSet (final Map<String, Object> dataset) throws IOException {
// Trace message
- this.getLogger().trace(MessageFormat.format("dataset={0} - CALLED!", dataset));
+ this.getLogger().trace(MessageFormat.format("dataset={0} - CALLED!", dataset)); //NOI18N
// dataset should not be null and not empty
if (dataset == null) {
// It is null, so abort here
- throw new NullPointerException("dataset is null");
+ throw new NullPointerException("dataset is null"); //NOI18N
} else if (dataset.isEmpty()) {
// It is empty, also abort here
- throw new IllegalArgumentException("dataset is empty");
+ throw new IllegalArgumentException("dataset is empty"); //NOI18N
}
// Debug message
- this.getLogger().debug(MessageFormat.format("Need to parse {0} values ...", dataset.size()));
+ this.getLogger().debug(MessageFormat.format("Need to parse {0} values ...", dataset.size())); //NOI18N
// Get iterator from it
Iterator<Map.Entry<String, Object>> iterator = dataset.entrySet().iterator();
StringBuilder output = new StringBuilder(dataset.size() * 20);
// Add index column
- output.append(String.format("key=%s,value=\"%s\";", this.getFrontend().getIdName(), this.getTotalRows() + 1));
+ output.append(String.format("key=%s,value=\"%s\";", this.getFrontend().getIdName(), this.getTotalRows() + 1)); //NOI18N
// "Walk" over all entries
while (iterator.hasNext()) {
String str = (String) value;
// Does it contain a " ?
- if (str.contains("\"")) {
+ if (str.contains("\"")) { //NOI18N
// Don't accept here
- throw new IllegalArgumentException("value " + value + " with double-quote not supported yet.");
+ throw new IllegalArgumentException(MessageFormat.format("value {0} with double-quote not supported yet.", value)); //NOI18N
}
}
// Generate key=value pair
- String pair = String.format("key=%s,value=\"%s\";", entry.getKey(), String.valueOf(value));
+ String pair = String.format("key=%s,value=\"%s\";", entry.getKey(), String.valueOf(value)); //NOI18N
// Debug message
- this.getLogger().debug("pair=" + pair);
+ this.getLogger().debug(MessageFormat.format("pair={0}", pair)); //NOI18N
// Append to output
output.append(pair);
Result<? extends Storeable> result = new DatabaseResult();
// Trace message
- this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result));
+ this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result)); //NOI18N
// Return it
return result;
@Override
public Result<? extends Storeable> doSelectByCriteria (final SearchableCriteria critera) throws IOException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Trace message
- this.getLogger().trace(MessageFormat.format("criteria={0} - CALLED!", critera));
+ this.getLogger().trace(MessageFormat.format("criteria={0} - CALLED!", critera)); //NOI18N
// Init result instance
Result<Storeable> result = new DatabaseResult();
String line = this.readLine();
// Debug message
- this.getLogger().debug(MessageFormat.format("line={0}", line));
+ this.getLogger().debug(MessageFormat.format("line={0}", line)); //NOI18N
// Parse it to a Map<String, Object>
Map<String, String> map = this.getMapFromLine(line);
Storeable storeable = this.getFrontend().toStoreable(map);
// Debug message
- this.getLogger().debug(MessageFormat.format("storeable={0}", storeable));
+ this.getLogger().debug(MessageFormat.format("storeable={0}", storeable)); //NOI18N
// Now matches the found instance
if (critera.matches(storeable)) {
*/
private void writeData (final StringBuilder output) throws IOException {
// Trace message
- this.getLogger().trace("output=" + output + " - CALLED!");
+ this.getLogger().trace(MessageFormat.format("output={0} - CALLED!", output)); //NOI18N
// No null or empty strings
if (output == null) {
// Is null
- throw new NullPointerException("output is null");
+ throw new NullPointerException("output is null"); //NOI18N
} else if (output.length() == 0) {
// Is empty
- throw new IllegalArgumentException("output is empty");
+ throw new IllegalArgumentException("output is empty"); //NOI18N
}
// Encode it to BASE64
String rawOutput = Base64.encodeBase64String(output.toString().getBytes());
// Debug message
- this.getLogger().debug("rawOutput=" + rawOutput);
+ this.getLogger().debug(MessageFormat.format("rawOutput={0}", rawOutput)); //NOI18N
// Write each line separately
- this.getStorageFile().writeBytes(rawOutput + "\n");
+ this.getStorageFile().writeBytes(String.format("%s\n", rawOutput)); //NOI18N
// Trace message
- this.getLogger().trace("EXIT!");
+ this.getLogger().trace("EXIT!"); //NOI18N
}
/**
*/
private Map<String, String> getMapFromLine (final String line) throws CorruptedDatabaseFileException, BadTokenException {
// Trace message
- this.getLogger().debug("line=" + line + " - CALLED!");
+ this.getLogger().debug(MessageFormat.format("line={0} - CALLED!", line)); //NOI18N
// "line" must not be null or empty
if (line == null) {
// Is null
- throw new NullPointerException("line is null");
+ throw new NullPointerException("line is null"); //NOI18N
} else if (line.isEmpty()) {
// Is empty
- throw new IllegalArgumentException("line is empty, maybe isEndOfFile() was not called?");
- } else if (!line.endsWith(";")) {
+ throw new IllegalArgumentException("line is empty, maybe isEndOfFile() was not called?"); //NOI18N
+ } else if (!line.endsWith(";")) { //NOI18N
// Bad line found
- throw new CorruptedDatabaseFileException(this.fileName, "No semicolon at end of line");
- } else if (!line.contains("key=")) {
+ throw new CorruptedDatabaseFileException(this.fileName, "No semicolon at end of line"); //NOI18N
+ } else if (!line.contains("key=")) { //NOI18N
// Bad line found
- throw new CorruptedDatabaseFileException(this.fileName, "No \"key=bla\" found.");
- } else if (!line.contains("value=")) {
+ throw new CorruptedDatabaseFileException(this.fileName, "No \"key=bla\" found."); //NOI18N
+ } else if (!line.contains("value=")) { //NOI18N
// Bad line found
- throw new CorruptedDatabaseFileException(this.fileName, "No \"value=bla\" found.");
+ throw new CorruptedDatabaseFileException(this.fileName, "No \"value=bla\" found."); //NOI18N
}
- Pattern pattern = Pattern.compile("(key=([a-z0-9_]{1,}),value=\"([^\"]*)\";){1,}");
+ Pattern pattern = Pattern.compile("(key=([a-z0-9_]{1,}),value=\"([^\"]*)\";){1,}"); //NOI18N
Matcher matcher = pattern.matcher(line);
// Debug message
- this.getLogger().debug("matches=" + matcher.matches());
+ this.getLogger().debug(MessageFormat.format("matches={0}", matcher.matches())); //NOI18N
// Matches?
if (!matcher.matches()) {
// Corrupted file found
- throw new CorruptedDatabaseFileException(this.fileName, "line " + line + " doesn't match regular expression.");
+ throw new CorruptedDatabaseFileException(this.fileName, MessageFormat.format("line {0} doesn't match regular expression.", line)); //NOI18N
}
// Instance map
Map<String, String> map = new HashMap<>(line.length() / 40);
- pattern = Pattern.compile("(key=([a-z0-9_]{1,}),value=\"([^\"]*)\";)");
+ pattern = Pattern.compile("(key=([a-z0-9_]{1,}),value=\"([^\"]*)\";)"); //NOI18N
matcher = pattern.matcher(line);
// Init group count
String value = matcher.group(3);
// key must noch be empty
- assert((key != null) && (!key.isEmpty())) : "key=" + key + " is not valid";
+ assert((key != null) && (!key.isEmpty())) : MessageFormat.format("key={0} is not valid", key); //NOI18N
// Get start and end
int start = matcher.start();
int end = matcher.end();
// Debug message
- this.getLogger().debug("init=" + init + ",start=" + start + ",end=" + end + ",match=" + match + ",key=" + key + ",value=" + value);
+ this.getLogger().debug(MessageFormat.format("init={0},start={1},end={2},match={3},key={4},value={5}", init, start, end, match, key, value)); //NOI18N
// Add key/value to map
map.put(key, value);
}
// Trace message
- this.getLogger().trace("map()=" + map.size() + " - EXIT!");
+ this.getLogger().trace(MessageFormat.format("map()={0} - EXIT!", map.size())); //NOI18N
// Return finished map
return map;
@Override
public final Long getTotalRows () throws IOException {
// Trace message
- this.getLogger().trace("CALLED!");
+ this.getLogger().trace("CALLED!"); //NOI18N
// Init count
Long count = 0L;
// Get next line
String line = this.readLine();
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("line={0}", line)); //NOI18N
+
// Count one up
count++;
}
// Trace message
- this.getLogger().trace("count=" + count + " - EXIT!");
+ this.getLogger().trace(MessageFormat.format("count={0} - EXIT!", count)); //NOI18N
// Return it
return count;
*/
public DatabaseFile (final String fqfn) throws FileNotFoundException {
// Init it here
- this.file = new RandomAccessFile(fqfn, "rw");
+ this.file = new RandomAccessFile(fqfn, "rw"); //NOI18N
}
@Override
this.getLogger().debug("Connection is up, preparing some statements ..."); //NOI18N
// Set prepared statement
- this.totalRows = connection.prepareStatement(String.format("SELECT COUNT(`%s`) AS `cnt` FROM `%s` LIMIT 1", this.getFrontend().getIdName(), this.getTableName()));
+ this.totalRows = connection.prepareStatement(String.format("SELECT COUNT(`%s`) AS `cnt` FROM `%s` LIMIT 1", this.getFrontend().getIdName(), this.getTableName())); //NOI18N
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
@Override
public Result<? extends Storeable> doInsertDataSet (final Map<String, Object> dataset) throws SQLException {
// Trace message
- this.getLogger().trace(MessageFormat.format("dataset={0} - CALLED!", dataset));
+ this.getLogger().trace(MessageFormat.format("dataset={0} - CALLED!", dataset)); //NOI18N
// dataset should not be null and not empty
if (dataset == null) {
// It is null, so abort here
- throw new NullPointerException("dataset is null");
+ throw new NullPointerException("dataset is null"); //NOI18N
} else if (dataset.isEmpty()) {
// It is empty, also abort here
- throw new IllegalArgumentException("dataset is empty");
+ throw new IllegalArgumentException("dataset is empty"); //NOI18N
}
// Debug message
- this.getLogger().debug(MessageFormat.format("Need to parse {0} values ...", dataset.size()));
+ this.getLogger().debug(MessageFormat.format("Need to parse {0} values ...", dataset.size())); //NOI18N
// Init values
Set<Object> values = new LinkedHashSet<>(dataset.size());
// Start with INSERT INTO
- StringBuilder query = new StringBuilder(String.format("INSERT INTO `%s` (", this.getTableName()));
- StringBuilder valueQuery = new StringBuilder("(");
+ StringBuilder query = new StringBuilder(String.format("INSERT INTO `%s` (", this.getTableName())); //NOI18N
+ StringBuilder valueQuery = new StringBuilder("("); //NOI18N
// Get iterator from it
Iterator<Map.Entry<String, Object>> iterator = dataset.entrySet().iterator();
Map.Entry<String, Object> entry = iterator.next();
// Add key as database column to query
- query.append(String.format("`%s`,", entry.getKey()));
+ query.append(String.format("`%s`,", entry.getKey())); //NOI18N
// Get value
Object value = entry.getValue();
// Debug message
- this.getLogger().debug(MessageFormat.format("value={0} - BEFORE!", value));
+ this.getLogger().debug(MessageFormat.format("value={0} - BEFORE!", value)); //NOI18N
// Handle possible empty->null convertion
value = this.getFrontend().emptyStringToNull(entry.getKey(), value);
// Debug message
- this.getLogger().debug(MessageFormat.format("value={0} - AFTER!", value));
+ this.getLogger().debug(MessageFormat.format("value={0} - AFTER!", value)); //NOI18N
// Is the value null?
if (value == null) {
// Add null
- valueQuery.append("NULL,");
+ valueQuery.append("NULL,"); //NOI18N
} else {
// Add value
- valueQuery.append("?,");
+ valueQuery.append("?,"); //NOI18N
values.add(value);
}
}
// Now put all together
- query.replace(query.length() - 1, query.length(), ") VALUES ");
+ query.replace(query.length() - 1, query.length(), ") VALUES "); //NOI18N
query.append(valueQuery.substring(0, valueQuery.length() - 1));
- query.append(")");
+ query.append(")"); //NOI18N
// Full statement is complete here, better log it
- this.getLogger().debug(MessageFormat.format("query={0} is complete.", query));
+ this.getLogger().debug(MessageFormat.format("query={0} is complete.", query)); //NOI18N
// Prepare statement instance
PreparedStatement statement = this.getPreparedStatement(query, values);
int status = statement.executeUpdate();
// Debug message
- this.getLogger().debug(MessageFormat.format("status={0}", status));
+ this.getLogger().debug(MessageFormat.format("status={0}", status)); //NOI18N
// The result set needs to be transformed into Result, so initialize a result instance here
Result<? extends Storeable> result = new DatabaseResult(status, statement);
// Trace message
- this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result));
+ this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result)); //NOI18N
// Return it
return result;
@Override
public Result<? extends Storeable> doSelectByCriteria (final SearchableCriteria critera) throws SQLException {
// Trace message
- this.getLogger().trace(MessageFormat.format("criteria={0} - CALLED!", critera));
+ this.getLogger().trace(MessageFormat.format("criteria={0} - CALLED!", critera)); //NOI18N
// Start SELECT query
- StringBuilder query = new StringBuilder(String.format("SELECT * FROM `%s`", this.getTableName()));
+ StringBuilder query = new StringBuilder(String.format("SELECT * FROM `%s`", this.getTableName())); //NOI18N
// Get entry set
Set<Map.Entry<String, Object>> set = critera.entrySet();
// Debug message
- this.getLogger().debug(MessageFormat.format("set.isEmpty()={0}", set.isEmpty()));
+ this.getLogger().debug(MessageFormat.format("set.isEmpty()={0}", set.isEmpty())); //NOI18N
// Init values
Set<Object> values = new LinkedHashSet<>(set.size());
// Are there conditions?
if (!set.isEmpty()) {
// Continue with WHERE
- query.append(" WHERE ");
+ query.append(" WHERE "); //NOI18N
// No more than 1 value currently
if (set.size() > 1) {
// Not supported yet
- throw new IllegalArgumentException("More than one criteria is not supported yet.");
+ throw new IllegalArgumentException("More than one criteria is not supported yet."); //NOI18N
}
// Get iterator
Map.Entry<String, Object> entry = iterator.next();
// Add key as column name
- query.append(String.format("`%s`", entry.getKey()));
+ query.append(String.format("`%s`", entry.getKey())); //NOI18N
// Get value
Object value = entry.getValue();
// Debug message
- this.getLogger().debug(MessageFormat.format("value={0}", value));
+ this.getLogger().debug(MessageFormat.format("value={0}", value)); //NOI18N
// Add value
- query.append("=?");
+ query.append("=?"); //NOI18N
values.add(value);
}
}
// Is skip set?
if (critera.getSkip() > 0) {
// Limit with skip
- query.append(String.format(" LIMIT %d,%d", critera.getSkip(), critera.getLimit()));
+ query.append(String.format(" LIMIT %d,%d", critera.getSkip(), critera.getLimit())); //NOI18N
} else {
// Only limit
- query.append(String.format(" LIMIT %d", critera.getLimit()));
+ query.append(String.format(" LIMIT %d", critera.getLimit())); //NOI18N
}
}
// Full statement is complete here, better log it
- this.getLogger().debug(MessageFormat.format("query={0} is complete.", query));
+ this.getLogger().debug(MessageFormat.format("query={0} is complete.", query)); //NOI18N
// Get a prepared instance
PreparedStatement statement = this.getPreparedStatement(query, values);
Result<? extends Storeable> result = this.getFrontend().getResultFromSet(resultSet);
// Trace message
- this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result));
+ this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result)); //NOI18N
// Return it
return result;
@Override
public Long getTotalRows () throws IOException, SQLException {
// Trace message
- this.getLogger().trace("CALLED!");
+ this.getLogger().trace("CALLED!"); //NOI18N
// Execute query
ResultSet set = this.totalRows.executeQuery();
set.beforeFirst();
// Get long
- Long count = set.getLong("cnt");
+ Long count = set.getLong("cnt"); //NOI18N
// Trace message
- this.getLogger().trace("count=" + count + " - EXIT!");
+ this.getLogger().trace(MessageFormat.format("count={0} - EXIT!", count)); //NOI18N
// Return it
return count;
*/
private PreparedStatement getPreparedStatement (final StringBuilder query, final Set<Object> values) throws SQLException {
// Trace message
- this.getLogger().trace("query=" + query + ",values=" + values + " - CALLED!");
+ this.getLogger().trace(MessageFormat.format("query={0},values={1} - CALLED!", query, values)); //NOI18N
// Init prepared statement
PreparedStatement statement = connection.prepareStatement(query.toString());
// Debug message
- this.getLogger().debug(MessageFormat.format("statement={0}", statement));
+ this.getLogger().debug(MessageFormat.format("statement={0}", statement)); //NOI18N
// Get iterator on values
Iterator<Object> valueIterator = values.iterator();
Object value = valueIterator.next();
//Debug message
- this.getLogger().debug(MessageFormat.format("index={1} has value={0}", value, index));
+ this.getLogger().debug(MessageFormat.format("index={1} has value={0}", value, index)); //NOI18N
// Detect type again
if (value instanceof Boolean) {
// Debug log
- this.getLogger().debug(MessageFormat.format("Setting boolean value={0} for index={1}", value, index));
+ this.getLogger().debug(MessageFormat.format("Setting boolean value={0} for index={1}", value, index)); //NOI18N
// Found boolean
statement.setBoolean(index, (boolean) value);
} else if (value instanceof String) {
// Debug message
- this.getLogger().debug(MessageFormat.format("Setting string value={0} for index={1}", value, index));
+ this.getLogger().debug(MessageFormat.format("Setting string value={0} for index={1}", value, index)); //NOI18N
// Found string
statement.setString(index, (String) value);
} else if (value instanceof Integer) {
// Debug message
- this.getLogger().debug(MessageFormat.format("Setting integer value={0} for index={1}", value, index));
+ this.getLogger().debug(MessageFormat.format("Setting integer value={0} for index={1}", value, index)); //NOI18N
// Found ineteger
statement.setInt(index, (int) value);
} else if (value instanceof Long) {
// Debug message
- this.getLogger().debug(MessageFormat.format("Setting long value={0} for index={1}", value, index));
+ this.getLogger().debug(MessageFormat.format("Setting long value={0} for index={1}", value, index)); //NOI18N
// Found ineteger
statement.setLong(index, (long) value);
} else if (value instanceof Float) {
// Debug message
- this.getLogger().debug(MessageFormat.format("Setting float value={0} for index={1}", value, index));
+ this.getLogger().debug(MessageFormat.format("Setting float value={0} for index={1}", value, index)); //NOI18N
// Found ineteger
statement.setFloat(index, (float) value);
} else if (value == null) {
// Debug message
- this.getLogger().warn(MessageFormat.format("Null value in index={0} is not supported (yet)", index));
+ this.getLogger().warn(MessageFormat.format("Null value in index={0} is not supported (yet)", index)); //NOI18N
} else {
// Not parseable type
- throw new SQLException(MessageFormat.format("Cannot handle value({0})={1} for index={2} in table {3}", value.getClass().getSimpleName(), value, index, this.getTableName()));
+ throw new SQLException(MessageFormat.format("Cannot handle value({0})={1} for index={2} in table {3}", value.getClass().getSimpleName(), value, index, this.getTableName())); //NOI18N
}
// Increment index
}
// Trace message
- this.getLogger().trace(MessageFormat.format("statement={0} - EXIT!", statement));
+ this.getLogger().trace(MessageFormat.format("statement={0} - EXIT!", statement)); //NOI18N
// Return it
return statement;
*/
protected void addToDataSet (final String key, final String value) {
// Trace message
- this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value));
+ this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); //NOI18N
// Is key null?
if (key == null) {
// Key is null
- throw new NullPointerException("key is null");
+ throw new NullPointerException("key is null"); //NOI18N
}
// Add it to map
this.dataset.put(key, value);
// Trace message
- this.getLogger().trace("EXIT!");
+ this.getLogger().trace("EXIT!"); //NOI18N
}
/**
*/
protected void addToDataSet (final String key, final Number value) {
// Trace message
- this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value));
+ this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); //NOI18N
// Is key/value null?
if (key == null) {
// Key is null
- throw new NullPointerException("key is null");
+ throw new NullPointerException("key is null"); //NOI18N
} else if (value == null) {
// Key is null
- throw new NullPointerException("value is null");
+ throw new NullPointerException("value is null"); //NOI18N
}
// Add it to map
this.dataset.put(key, value);
// Trace message
- this.getLogger().trace("EXIT!");
+ this.getLogger().trace("EXIT!"); //NOI18N
}
/**
*/
protected void addToDataSet (final String key, final Boolean value) {
// Trace message
- this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value));
+ this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); //NOI18N
// Is key/value null?
if (key == null) {
// Key is null
- throw new NullPointerException("key is null");
+ throw new NullPointerException("key is null"); //NOI18N
} else if (value == null) {
// Key is null
- throw new NullPointerException("value is null");
+ throw new NullPointerException("value is null"); //NOI18N
}
// Add it to map
this.dataset.put(key, value);
// Trace message
- this.getLogger().trace("EXIT!");
+ this.getLogger().trace("EXIT!"); //NOI18N
}
/**
*/
protected void clearDataSet () {
// Trace message
- this.getLogger().trace("CALLED!");
+ this.getLogger().trace("CALLED!"); //NOI18N
// Clear dataset
this.dataset.clear();
// Trace message
- this.getLogger().trace("EXIT!");
+ this.getLogger().trace("EXIT!"); //NOI18N
}
/**
*/
protected Result<? extends Storeable> doInsertDataSet () throws SQLException, IOException {
// Trace message
- this.getLogger().trace("CALLED!");
+ this.getLogger().trace("CALLED!"); //NOI18N
// Is the dataset instance empty?
if (this.dataset.isEmpty()) {
// Cannot insert an empty dataset
- throw new IllegalStateException("The dataset instance is empty.");
+ throw new IllegalStateException("The dataset instance is empty."); //NOI18N
}
// Call backend method
Result<? extends Storeable> result = this.getBackend().doInsertDataSet(this.dataset);
// Trace message
- this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result));
+ this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result)); //NOI18N
// Return it
return result;
*/
public DatabaseResult () {
// Trace message
- this.getLogger().trace("CALLED!");
+ this.getLogger().trace("CALLED!"); //NOI18N
// Init set here
this.result = new TreeSet<>();
this();
// Trace message
- this.getLogger().trace(MessageFormat.format("status={0},statement={1} - CALLED!", status, statement));
+ this.getLogger().trace(MessageFormat.format("status={0},statement={1} - CALLED!", status, statement)); //NOI18N
// Set warnings
this.setWarnings(statement.getWarnings());