diff --git a/javav2/usecases/CreatingSpringRedshiftRest/Readme.md b/javav2/usecases/CreatingSpringRedshiftRest/Readme.md index 65c41bac600..5b56c653f3e 100644 --- a/javav2/usecases/CreatingSpringRedshiftRest/Readme.md +++ b/javav2/usecases/CreatingSpringRedshiftRest/Readme.md @@ -436,6 +436,7 @@ The following Java code represents the **WorkItemRepository** class. Notice that In addition, notice the use of [Class SqlParameter](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/redshiftdata/model/SqlParameter.html) when using SQL statements. For example, in the **getData** method, you build a list of **SqlParameter** objects used to get records from the database. ```java + package com.aws.rest; import org.springframework.stereotype.Component; @@ -484,14 +485,14 @@ public class WorkItemRepository { // Get all records from the Amazon Redshift table. if (arch.compareTo("") == 0) { - sqlStatement = "SELECT idwork, date, description, guide, status, username FROM work"; + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive FROM work"; ExecuteStatementResponse response = executeAll(sqlStatement); String id = response.id(); System.out.println("The identifier of the statement is "+id); checkStatement(id); return getResults(id); } else { - sqlStatement = "SELECT idwork, date, description, guide, status, username " + + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive " + "FROM work WHERE username = :username and archive = :arch ;"; parameters = List.of( @@ -608,8 +609,6 @@ public class WorkItemRepository { flipItemArchive(sqlStatement,parameters); } - - public String injectNewSubmission(WorkItem item) { try { String name = item.getName(); @@ -648,6 +647,7 @@ public class WorkItemRepository { } } + ``` ### WorkItem class @@ -668,11 +668,17 @@ public class WorkItem { private String date; private String description; private String status; + private boolean archived ; public static WorkItem from(List fields) { var item = new WorkItem(); - for (int i = 0; i <= 5; i++) { - String value = fields.get(i).stringValue(); + for (int i = 0; i <= 6; i++) { + String value=""; + boolean val = false; + value = fields.get(i).stringValue(); + if (i == 6) + val = fields.get(i).booleanValue(); + switch (i) { case 0: item.setId(value); @@ -692,11 +698,22 @@ public class WorkItem { case 5: item.setName(value); break; + case 6: + item.setArchived(val); + break; } } return item; } + public boolean getArchived() { + return this.archived; + } + + public void setArchived(boolean archived) { + this.archived = archived; + } + public void setId(String id) { this.id = id; } diff --git a/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItem.java b/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItem.java index 36d245ddbd2..ef914ba9338 100644 --- a/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItem.java +++ b/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItem.java @@ -16,11 +16,17 @@ public class WorkItem { private String date; private String description; private String status; + private boolean archived ; public static WorkItem from(List fields) { var item = new WorkItem(); - for (int i = 0; i <= 5; i++) { - String value = fields.get(i).stringValue(); + for (int i = 0; i <= 6; i++) { + String value=""; + boolean val = false; + value = fields.get(i).stringValue(); + if (i == 6) + val = fields.get(i).booleanValue(); + switch (i) { case 0: item.setId(value); @@ -40,11 +46,22 @@ public static WorkItem from(List fields) { case 5: item.setName(value); break; + case 6: + item.setArchived(val); + break; } } return item; } + public boolean getArchived() { + return this.archived; + } + + public void setArchived(boolean archived) { + this.archived = archived; + } + public void setId(String id) { this.id = id; } @@ -93,4 +110,4 @@ public void setGuide(String guide) { public String getGuide() { return this.guide; } -} \ No newline at end of file +} diff --git a/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItemRepository.java b/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItemRepository.java index 21618950691..a1be8c746fc 100644 --- a/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItemRepository.java +++ b/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItemRepository.java @@ -51,14 +51,14 @@ public List getData(String arch) { // Get all records from the Amazon Redshift table. if (arch.compareTo("") == 0) { - sqlStatement = "SELECT idwork, date, description, guide, status, username FROM work"; + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive FROM work"; ExecuteStatementResponse response = executeAll(sqlStatement); String id = response.id(); System.out.println("The identifier of the statement is "+id); checkStatement(id); return getResults(id); } else { - sqlStatement = "SELECT idwork, date, description, guide, status, username " + + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive " + "FROM work WHERE username = :username and archive = :arch ;"; parameters = List.of( diff --git a/javav2/usecases/Creating_Spring_RDS_ Rest/Readme.md b/javav2/usecases/Creating_Spring_RDS_ Rest/Readme.md index 966c6352d41..52fb3b5d7dc 100644 --- a/javav2/usecases/Creating_Spring_RDS_ Rest/Readme.md +++ b/javav2/usecases/Creating_Spring_RDS_ Rest/Readme.md @@ -555,7 +555,7 @@ public class WorkItemRepository implements CrudRepository { @Override public Optional findById(String s) { - String sqlStatement = "SELECT idwork, date, description, guide, status, username FROM work WHERE idwork = :id;"; + String sqlStatement = "SELECT idwork, date, description, guide, status, username, archive FROM work WHERE idwork = :id;"; List parameters = List.of(param("id", s)); var result = execute(sqlStatement, parameters) .records() @@ -586,7 +586,7 @@ public class WorkItemRepository implements CrudRepository { param("id", id), param("arch", archived) ); - execute(sqlStatement, parameters); + execute(sqlStatement, parameters); } catch (RdsDataException e) { e.printStackTrace(); } @@ -598,7 +598,7 @@ public class WorkItemRepository implements CrudRepository { String isArc; if (status.compareTo("true") == 0) { - sqlStatement = "SELECT idwork, date, description, guide, status, username " + + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive " + "FROM work WHERE archive = :arch ;"; isArc = "1"; List parameters = List.of( @@ -611,7 +611,7 @@ public class WorkItemRepository implements CrudRepository { .collect(Collectors.toUnmodifiableList()); } else if (status.compareTo("false") == 0) { - sqlStatement = "SELECT idwork, date, description, guide, status, username " + + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive " + "FROM work WHERE archive = :arch ;"; isArc = "0"; List parameters = List.of( @@ -624,7 +624,7 @@ public class WorkItemRepository implements CrudRepository { .collect(Collectors.toUnmodifiableList()); } else { - sqlStatement = "SELECT idwork, date, description, guide, status, username FROM work ;"; + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive FROM work ;"; List parameters = List.of( ); @@ -685,7 +685,6 @@ public class WorkItemRepository implements CrudRepository { } } - ``` @@ -707,11 +706,16 @@ public class WorkItem { private String date; private String description; private String status; + private boolean archived; public static WorkItem from(List fields) { var item = new WorkItem(); - for (int i = 0; i <= 5; i++) { + boolean arcVal = false; + for (int i = 0; i <= 6; i++) { String value = fields.get(i).stringValue(); + if (i == 6) + arcVal = fields.get(i).booleanValue(); + switch (i) { case 0: item.setId(value); @@ -731,11 +735,23 @@ public class WorkItem { case 5: item.setName(value); break; + + case 6: + item.setArchived(arcVal); + break; } } return item; } + public void setArchived(boolean archived) { + this.archived =archived; + } + + public boolean getArchived() { + return this.archived; + } + public void setId(String id) { this.id = id; } diff --git a/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItem.java b/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItem.java index 28b214fe8ae..af07a93a866 100644 --- a/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItem.java +++ b/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItem.java @@ -16,11 +16,17 @@ public class WorkItem { private String date; private String description; private String status; + private boolean archived; public static WorkItem from(List fields) { var item = new WorkItem(); - for (int i = 0; i <= 5; i++) { + boolean arcVal = false; + for (int i = 0; i <= 6; i++) { String value = fields.get(i).stringValue(); + + if (i == 6) + arcVal = fields.get(i).booleanValue(); + switch (i) { case 0: item.setId(value); @@ -40,11 +46,23 @@ public static WorkItem from(List fields) { case 5: item.setName(value); break; + + case 6: + item.setArchived(arcVal); + break; } } return item; } + public void setArchived(boolean archived) { + this.archived =archived; + } + + public boolean getArchived() { + return this.archived; + } + public void setId(String id) { this.id = id; } @@ -93,4 +111,4 @@ public void setGuide(String guide) { public String getGuide() { return this.guide; } -} \ No newline at end of file +} diff --git a/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItemRepository.java b/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItemRepository.java index 8ca1b3cde40..b719e8be44d 100644 --- a/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItemRepository.java +++ b/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItemRepository.java @@ -98,7 +98,7 @@ public Iterable saveAll(Iterable entities) { @Override public Optional findById(String s) { - String sqlStatement = "SELECT idwork, date, description, guide, status, username FROM work WHERE idwork = :id;"; + String sqlStatement = "SELECT idwork, date, description, guide, status, username, archive FROM work WHERE idwork = :id;"; List parameters = List.of(param("id", s)); var result = execute(sqlStatement, parameters) .records() @@ -129,7 +129,7 @@ public void flipItemArchive(String id) { param("id", id), param("arch", archived) ); - execute(sqlStatement, parameters); + execute(sqlStatement, parameters); } catch (RdsDataException e) { e.printStackTrace(); } @@ -141,7 +141,7 @@ public Iterable findAllWithStatus(String status) { String isArc; if (status.compareTo("true") == 0) { - sqlStatement = "SELECT idwork, date, description, guide, status, username " + + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive " + "FROM work WHERE archive = :arch ;"; isArc = "1"; List parameters = List.of( @@ -154,7 +154,7 @@ public Iterable findAllWithStatus(String status) { .collect(Collectors.toUnmodifiableList()); } else if (status.compareTo("false") == 0) { - sqlStatement = "SELECT idwork, date, description, guide, status, username " + + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive " + "FROM work WHERE archive = :arch ;"; isArc = "0"; List parameters = List.of( @@ -167,7 +167,7 @@ public Iterable findAllWithStatus(String status) { .collect(Collectors.toUnmodifiableList()); } else { - sqlStatement = "SELECT idwork, date, description, guide, status, username FROM work ;"; + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive FROM work ;"; List parameters = List.of( );