Skip to content

Commit

Permalink
Update Row class and increase version in pom.xml
Browse files Browse the repository at this point in the history
Updated the Row.java class to enhance the readability of the code, primarily adjusting commenting style and method simplifications. Also, the MySQL API version has been incremented from 5.6 to 5.7 in pom.xml.
  • Loading branch information
Coho04 committed Feb 13, 2024
1 parent ae58d62 commit 0a6501d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>de.goldendeveloper</groupId>
<artifactId>MYSQL-Api</artifactId>
<version>5.6</version>
<version>5.7</version>
<packaging>jar</packaging>
<url>https://github.com/Golden-Developer/MYSQL-Api</url>

Expand Down
24 changes: 11 additions & 13 deletions src/main/java/de/goldendeveloper/mysql/entities/Row.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public class Row implements QueryHelper {

/**
* Represents a row in a database table.
*
* <p>
* The Row class contains methods to retrieve and modify data in the corresponding row of the table.
*
* @param table The Table object representing the table the row belongs to.
* @param table The Table object representing the table the row belongs to.
* @param column The Column object representing the column in the row.
* @param mysql The MYSQL object representing the connection to the database.
* @param item The value of the column in the row.
* @param mysql The MYSQL object representing the connection to the database.
* @param item The value of the column in the row.
*/
public Row(Table table, Column column, MYSQL mysql, String item) {
this.db = table.getDatabase();
Expand All @@ -51,13 +51,11 @@ public HashMap<String, SearchResult> getData() {
exportMap = executeQuery(query, rs -> {
HashMap<String, SearchResult> map = new HashMap<>();
ResultSetMetaData rsMetaData = rs.getMetaData();
if (rs.next()) {
for (int i = 1; i <= rsMetaData.getColumnCount(); i++) {
if (rs.getString(rsMetaData.getColumnName(i)) != null) {
map.put(rsMetaData.getColumnName(i), new SearchResult(rs.getString(rsMetaData.getColumnName(i))));
} else {
map.put(rsMetaData.getColumnName(i), null);
}
for (int i = 1; i <= rsMetaData.getColumnCount(); i++) {
if (rs.getString(rsMetaData.getColumnName(i)) != null) {
map.put(rsMetaData.getColumnName(i), new SearchResult(rs.getString(rsMetaData.getColumnName(i))));
} else {
map.put(rsMetaData.getColumnName(i), null);
}
}
return map;
Expand All @@ -79,7 +77,7 @@ public void setExportMap(HashMap<String, SearchResult> newMap) {
* Sets the value of a specific item in the column.
*
* @param column The Column object representing the column to set the value for.
* @param item The new value to set for the column.
* @param item The new value to set for the column.
*/
public void set(Column column, Object item) {
executeUpdate("UPDATE `" + this.getTable().getName() + "` SET `" + column.getName() + "` = '" + item.toString() + "' WHERE `" + this.column.getName() + "` = '" + this.item + "';", mysql);
Expand Down Expand Up @@ -134,7 +132,7 @@ public int getId() {
* Deletes the row from the database table associated with this object.
* The deletion is performed based on the value of the column in the row.
* The SQL query executed is as follows:
* DELETE FROM `tableName` WHERE `columnName` = 'columnValue';
* DELETE FROM `tableName` WHERE `columnName` = 'columnValue';
*
* @see Row#getTable() to retrieve the table associated with this row
* @see Row#column to retrieve the column associated with this row
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/goldendeveloper/mysql/entities/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ public boolean existsColumn(String name) {
*/
public boolean existsRow(Column column, String item) {
String query = "SELECT EXISTS(SELECT * FROM `" + this.getName() + "` WHERE `" + column.getName() + "` = '" + item + "')";
Boolean exists = executeQuery(query, rs -> rs.next() && rs.getBoolean(1), mysql);
Boolean exists = executeQuery(query, rs -> rs.getBoolean(1), mysql);
System.out.println("229: existsRow : " + exists );
return exists != null && exists;
}

Expand Down

0 comments on commit 0a6501d

Please sign in to comment.