Skip to content

Commit

Permalink
added missing setter-methods in insert and update (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schubi1981 authored Apr 24, 2020
1 parent bc9fa30 commit 304f0c5
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ A Java-Library to build SQL-Statements
<dependency>
<groupId>de.jaggl.sqlbuilder</groupId>
<artifactId>sqlbuilder-core</artifactId>
<version>2.6.6</version>
<version>2.6.7</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>de.jaggl.sqlbuilder</groupId>
<artifactId>sqlbuilder-core</artifactId>
<version>2.6.6</version>
<version>2.6.7</version>

<packaging>jar</packaging>

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/de/jaggl/sqlbuilder/queries/Insert.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import static lombok.AccessLevel.PACKAGE;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.Map;

import de.jaggl.sqlbuilder.columns.Column;
import de.jaggl.sqlbuilder.columns.datetime.DateColumn;
import de.jaggl.sqlbuilder.columns.datetime.DateTimeColumn;
import de.jaggl.sqlbuilder.columns.number.NumberColumn;
import de.jaggl.sqlbuilder.columns.string.StringColumn;
import de.jaggl.sqlbuilder.dialect.Dialect;
Expand Down Expand Up @@ -82,6 +86,16 @@ public Insert set(Column column, Column otherColumn)
return addValue(column, new ValuableColumn(otherColumn));
}

public Insert set(DateColumn column, LocalDate value)
{
return addValue(column, new PlainValuable(value));
}

public Insert set(DateTimeColumn column, LocalDateTime value)
{
return addValue(column, new PlainValuable(value));
}

private Insert addValue(Column column, Valuable value)
{
values.put(column, value);
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/de/jaggl/sqlbuilder/queries/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import static de.jaggl.sqlbuilder.domain.ConditionType.WHERE_NOT;
import static lombok.AccessLevel.PACKAGE;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.Map;

import de.jaggl.sqlbuilder.columns.Column;
import de.jaggl.sqlbuilder.columns.datetime.DateColumn;
import de.jaggl.sqlbuilder.columns.datetime.DateTimeColumn;
import de.jaggl.sqlbuilder.columns.number.NumberColumn;
import de.jaggl.sqlbuilder.columns.string.StringColumn;
import de.jaggl.sqlbuilder.conditions.Condition;
Expand Down Expand Up @@ -78,6 +82,16 @@ public Update set(Column column, Column otherColumn)
return set(column, new ValuableColumn(otherColumn));
}

public Update set(DateColumn column, LocalDate value)
{
return set(column, new PlainValuable(value));
}

public Update set(DateTimeColumn column, LocalDateTime value)
{
return set(column, new PlainValuable(value));
}

public Update set(Column column, Valuable valuable)
{
values.put(column, valuable);
Expand Down
12 changes: 11 additions & 1 deletion src/test/java/de/jaggl/sqlbuilder/queries/InsertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
import static de.jaggl.sqlbuilder.utils.Indentation.enabled;
import static org.assertj.core.api.Assertions.assertThat;

import java.time.LocalDate;
import java.time.LocalDateTime;

import org.junit.jupiter.api.Test;

import de.jaggl.sqlbuilder.columns.datetime.DateColumn;
import de.jaggl.sqlbuilder.columns.datetime.DateTimeColumn;
import de.jaggl.sqlbuilder.columns.number.doubletype.DoubleColumn;
import de.jaggl.sqlbuilder.columns.number.integer.BigIntColumn;
import de.jaggl.sqlbuilder.columns.number.integer.IntColumn;
Expand All @@ -28,6 +32,8 @@ class InsertTest
public static final DoubleColumn SIZE = PERSONS.doubleColumn("size").build();
public static final IntColumn COUNT = PERSONS.intColumn("count").build();
public static final DateColumn BIRTHDAY = PERSONS.dateColumn("birthday").build();
public static final DateColumn DEATHDAY = PERSONS.dateColumn("deathday").build();
public static final DateTimeColumn LAST_UPDATE = PERSONS.dateTimeColumn("lastUpdate").build();
public static final BigIntColumn NUMBERS = PERSONS.bigIntColumn("numbers").build();

@Test
Expand All @@ -37,6 +43,8 @@ void testBuildInsert()
.set(NICKNAME, FORENAME)
.set(FORENAME, "Martin")
.set(BIRTHDAY, now())
.set(DEATHDAY, LocalDate.of(2020, 4, 24))
.set(LAST_UPDATE, LocalDateTime.of(2020, 4, 24, 13, 53))
.set(COUNT, Integer.valueOf(5))
.set(AGE, 38)
.set(SIZE, 175.89)
Expand All @@ -47,7 +55,7 @@ void testBuildInsert()
insert.println(SYBASE, enabled());

assertThat(insert.build())
.isEqualTo("INSERT INTO `persons` SET `persons`.`nickname` = `persons`.`forename`, `persons`.`forename` = 'Martin', `persons`.`birthday` = NOW(), `persons`.`count` = 5, `persons`.`age` = 38, `persons`.`size` = 175.89, `persons`.`numbers` = :numbers, `persons`.`lastname` = 'Schumacher'");
.isEqualTo("INSERT INTO `persons` SET `persons`.`nickname` = `persons`.`forename`, `persons`.`forename` = 'Martin', `persons`.`birthday` = NOW(), `persons`.`deathday` = '2020-04-24', `persons`.`lastUpdate` = '2020-04-24 13:53:00.000000', `persons`.`count` = 5, `persons`.`age` = 38, `persons`.`size` = 175.89, `persons`.`numbers` = :numbers, `persons`.`lastname` = 'Schumacher'");

assertThat(insert.build(enabled()))
.isEqualTo("INSERT INTO\n" //
Expand All @@ -56,6 +64,8 @@ void testBuildInsert()
+ " `persons`.`nickname` = `persons`.`forename`,\n" //
+ " `persons`.`forename` = 'Martin',\n" //
+ " `persons`.`birthday` = NOW(),\n" //
+ " `persons`.`deathday` = '2020-04-24',\n" //
+ " `persons`.`lastUpdate` = '2020-04-24 13:53:00.000000',\n" //
+ " `persons`.`count` = 5,\n" //
+ " `persons`.`age` = 38,\n" //
+ " `persons`.`size` = 175.89,\n" //
Expand Down
12 changes: 11 additions & 1 deletion src/test/java/de/jaggl/sqlbuilder/queries/UpdateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
import static de.jaggl.sqlbuilder.utils.Indentation.enabled;
import static org.assertj.core.api.Assertions.assertThat;

import java.time.LocalDate;
import java.time.LocalDateTime;

import org.junit.jupiter.api.Test;

import de.jaggl.sqlbuilder.columns.datetime.DateColumn;
import de.jaggl.sqlbuilder.columns.datetime.DateTimeColumn;
import de.jaggl.sqlbuilder.columns.number.doubletype.DoubleColumn;
import de.jaggl.sqlbuilder.columns.number.integer.IntColumn;
import de.jaggl.sqlbuilder.columns.string.VarCharColumn;
Expand All @@ -30,6 +34,8 @@ class UpdateTest
public static final DoubleColumn SIZE = PERSONS.doubleColumn("size").build();
public static final IntColumn COUNT = PERSONS.intColumn("count").build();
public static final DateColumn BIRTHDAY = PERSONS.dateColumn("birthday").build();
public static final DateColumn DEATHDAY = PERSONS.dateColumn("deathday").build();
public static final DateTimeColumn LAST_UPDATE = PERSONS.dateTimeColumn("lastUpdate").build();

@Test
void testBuildUpdate()
Expand All @@ -38,6 +44,8 @@ void testBuildUpdate()
.set(NICKNAME, FORENAME)
.set(LASTNAME, "Schumacher")
.set(BIRTHDAY, now())
.set(DEATHDAY, LocalDate.of(2020, 4, 24))
.set(LAST_UPDATE, LocalDateTime.of(2020, 4, 24, 13, 53))
.set(COUNT, Integer.valueOf(5))
.set(AGE, 38)
.set(SIZE, 175.89)
Expand All @@ -50,14 +58,16 @@ void testBuildUpdate()
update.println(SYBASE, enabled());

assertThat(update.build(MYSQL))
.isEqualTo("UPDATE `persons` SET `persons`.`nickname` = `persons`.`forename`, `persons`.`lastname` = 'Schumacher', `persons`.`birthday` = NOW(), `persons`.`count` = 5, `persons`.`age` = 38, `persons`.`size` = 175.89 WHERE (`persons`.`lastname` NOT LIKE 'Nils%' AND MIN(`persons`.`age`) >= 50 AND (`persons`.`lastname` = 'Schumacher' OR IsNull(COL, '') != ''))");
.isEqualTo("UPDATE `persons` SET `persons`.`nickname` = `persons`.`forename`, `persons`.`lastname` = 'Schumacher', `persons`.`birthday` = NOW(), `persons`.`deathday` = '2020-04-24', `persons`.`lastUpdate` = '2020-04-24 13:53:00.000000', `persons`.`count` = 5, `persons`.`age` = 38, `persons`.`size` = 175.89 WHERE (`persons`.`lastname` NOT LIKE 'Nils%' AND MIN(`persons`.`age`) >= 50 AND (`persons`.`lastname` = 'Schumacher' OR IsNull(COL, '') != ''))");

assertThat(update.build(MYSQL, enabled())).isEqualTo("UPDATE\n" //
+ " `persons`\n" //
+ "SET\n" //
+ " `persons`.`nickname` = `persons`.`forename`,\n" //
+ " `persons`.`lastname` = 'Schumacher',\n" //
+ " `persons`.`birthday` = NOW(),\n" //
+ " `persons`.`deathday` = '2020-04-24',\n" //
+ " `persons`.`lastUpdate` = '2020-04-24 13:53:00.000000',\n" //
+ " `persons`.`count` = 5,\n" //
+ " `persons`.`age` = 38,\n" //
+ " `persons`.`size` = 175.89\n" //
Expand Down

0 comments on commit 304f0c5

Please sign in to comment.