return this.executePreparedStatement(statement, null);
}
- public MSqlStatementResults executePreparedStatement(String statement, LinkedList<String> parameters) throws MStatementSqlException {
+ public MSqlStatementResults executePreparedStatement(String statement, LinkedList<Object> parameters) throws MStatementSqlException {
if ((null == statement) || ("".equals(statement))) {
throw new IllegalArgumentException("Invalid 'statement': null or empty.");
}
// prepare the statement
preparedStatement = this.getConnectionReference().prepareStatement(statement, PreparedStatement.RETURN_GENERATED_KEYS);
for (int p = 0; p < parameters.size(); p++) {
- preparedStatement.setString(p + 1, parameters.get(p));
+ preparedStatement.setObject(p + 1, parameters.get(p));
}
// execute the statement and parse the results
preparedStatement.execute();
protected PreparedStatement preparedStatement = null;
protected ResultSet resultSet = null;
- protected LinkedList<LinkedHashMap<String, String>> records = new LinkedList<LinkedHashMap<String, String>>();
+ protected LinkedList<LinkedHashMap<String, Object>> records = new LinkedList<LinkedHashMap<String, Object>>();
- protected LinkedHashSet<String> generatedKeys = new LinkedHashSet<String>();
+ protected LinkedHashSet<Object> generatedKeys = new LinkedHashSet<Object>();
/* */
if (null != this.getResultSetReference()) {
while (this.getResultSetReference().next()) {
ResultSetMetaData resultSetMetaData = this.getResultSetReference().getMetaData();
- LinkedHashMap<String, String> record = new LinkedHashMap<String, String>();
+ LinkedHashMap<String, Object> record = new LinkedHashMap<String, Object>();
for (int f = 0; f < resultSetMetaData.getColumnCount(); f++) {
String field = resultSetMetaData.getColumnLabel(f + 1);
- record.put(field, this.getResultSetReference().getString(field));
+ record.put(field, this.getResultSetReference().getObject(field));
}
this.getRecordsReference().add(record);
}
try {
ResultSet generatedKeysResultSet = this.getPreparedStatementReference().getGeneratedKeys();
while (generatedKeysResultSet.next()) {
- this.getGeneratedKeysReference().add(generatedKeysResultSet.getString(1));
+ this.getGeneratedKeysReference().add(generatedKeysResultSet.getObject(1));
}
generatedKeysResultSet.close();
}
/* Records */
- protected LinkedList<LinkedHashMap<String, String>> getRecordsReference() {
+ protected LinkedList<LinkedHashMap<String, Object>> getRecordsReference() {
return this.records;
}
- public LinkedList<LinkedHashMap<String, String>> getRecords() {
- LinkedList<LinkedHashMap<String, String>> tmpRecords = new LinkedList<LinkedHashMap<String, String>>();
- for (LinkedHashMap<String, String> record: this.getRecordsReference()) {
- LinkedHashMap<String, String> tmpRecord = new LinkedHashMap<String, String>();
+ public LinkedList<LinkedHashMap<String, Object>> getRecords() {
+ LinkedList<LinkedHashMap<String, Object>> tmpRecords = new LinkedList<LinkedHashMap<String, Object>>();
+ for (LinkedHashMap<String, Object> record: this.getRecordsReference()) {
+ LinkedHashMap<String, Object> tmpRecord = new LinkedHashMap<String, Object>();
for (String key: record.keySet()) {
tmpRecord.put(key, record.get(key));
}
return tmpRecords;
}
- public LinkedList<String> getRecordsByField(String field) {
+ public LinkedList<Object> getRecordsByField(String field) {
if ((null == field) || ("".equals(field))) {
throw new IllegalArgumentException("Invalid 'field': null or empty.");
}
//
- LinkedList<String> recordsByField = new LinkedList<String>();
- for (LinkedHashMap<String, String> record: this.getRecordsReference()) {
- String r = record.get(field);
+ LinkedList<Object> recordsByField = new LinkedList<Object>();
+ for (LinkedHashMap<String, Object> record: this.getRecordsReference()) {
+ Object r = record.get(field);
if (null == r) {
throw new IllegalArgumentException(String.format("Invalid 'field': %s.", field));
}
/* Generated keys */
- protected LinkedHashSet<String> getGeneratedKeysReference() {
+ protected LinkedHashSet<Object> getGeneratedKeysReference() {
return this.generatedKeys;
}
- public LinkedHashSet<String> getGeneratedKeys() {
- LinkedHashSet<String> tmpGeneratedKeys = new LinkedHashSet<String>();
+ public LinkedHashSet<Object> getGeneratedKeys() {
+ LinkedHashSet<Object> tmpGeneratedKeys = new LinkedHashSet<Object>();
Iterator i = this.getGeneratedKeysReference().iterator();
while (i.hasNext()) {
- tmpGeneratedKeys.add((String)i.next());
+ tmpGeneratedKeys.add(i.next());
}
return tmpGeneratedKeys;
}
/* Statements */
- protected MSqlStatementResults insertRecord(LinkedHashMap<String, String> map) throws MStatementSqlException {
+ protected MSqlStatementResults insertRecord(LinkedHashMap<String, Object> map) throws MStatementSqlException {
if (null == map) {
throw new IllegalArgumentException("Invalid 'map': null.");
}
//
- LinkedList<String> p = new LinkedList<String>();
+ LinkedList<Object> p = new LinkedList<Object>();
StringBuilder fields = new StringBuilder("");
StringBuilder s = new StringBuilder("");
for (String field: map.keySet()) {
p);
}
- protected MSqlStatementResults updateRecord(LinkedHashMap<String, String> map, String id) throws MStatementSqlException {
+ protected MSqlStatementResults updateRecord(LinkedHashMap<String, Object> map, Object id) throws MStatementSqlException {
if (null == map) {
throw new IllegalArgumentException("Invalid 'map': null.");
}
- if ((null == id) || ("".equals(id))) {
- throw new IllegalArgumentException("Invalid 'id': null or empty.");
+ if (null == id) {
+ throw new IllegalArgumentException("Invalid 'id': null.");
}
//
- LinkedList<String> p = new LinkedList<String>();
+ LinkedList<Object> p = new LinkedList<Object>();
StringBuilder s = new StringBuilder("");
for (String field: map.keySet()) {
s.append("\"" + this.getTable() + "\".\"" + field + "\" = ?, ");
p);
}
- public MSqlStatementResults setRecord(LinkedHashMap<String, String> map, String id) throws MStatementSqlException {
+ public MSqlStatementResults setRecord(LinkedHashMap<String, Object> map, Object id) throws MStatementSqlException {
if (null == id) {
return this.insertRecord(map);
}
}
}
- public MSqlStatementResults getRecord(String id) throws MStatementSqlException {
- if ((null == id) || ("".equals(id))) {
- throw new IllegalArgumentException("Invalid 'id': null or empty.");
+ public MSqlStatementResults getRecord(Object id) throws MStatementSqlException {
+ if (null == id) {
+ throw new IllegalArgumentException("Invalid 'id': null.");
}
//
- LinkedList<String> p = new LinkedList<String>();
+ LinkedList<Object> p = new LinkedList<Object>();
p.add(id);
return this.getConnectionReference().executePreparedStatement(" SELECT *"
+ " FROM \"" + this.getTable() + "\""
p);
}
- public MSqlStatementResults deleteRecord(String id) throws MStatementSqlException {
- if ((null == id) || ("".equals(id))) {
- throw new IllegalArgumentException("Invalid 'id': null or empty.");
+ public MSqlStatementResults deleteRecord(Object id) throws MStatementSqlException {
+ if (null == id) {
+ throw new IllegalArgumentException("Invalid 'id': null.");
}
//
- LinkedList<String> p = new LinkedList<String>();
+ LinkedList<Object> p = new LinkedList<Object>();
p.add(id);
return this.getConnectionReference().executePreparedStatement(" DELETE FROM \"" + this.getTable() + "\""
+ " WHERE (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)",