Skip to content

Commit e8b1f17

Browse files
author
Priyank Agarwal
authored
#60:Used error msg builder for error messages (#78)
* #60:Used error msg builder for error messages
1 parent 95d2fbf commit e8b1f17

22 files changed

+66
-58
lines changed

doc/changes/changes_3.2.0.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ Code name: Truncating tables
44

55
## Summary
66

7-
In this release we added support for truncating tables.
7+
In this release following changes are made:
8+
* Added support for truncating tables.
9+
* Used Error Message Builder for Error Messages.
810

911
## Features
1012

11-
* #67: Add Table#truncate()
13+
* #67: Add Table#truncate()
14+
* #60: Used Error Message Builder for Error Messages
15+
16+
## Dependency Updates
17+
18+
* Updated `com.exasol:error-reporting-java:0.2.2` to `0.4.0`

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
<dependency>
153153
<groupId>com.exasol</groupId>
154154
<artifactId>error-reporting-java</artifactId>
155-
<version>0.2.2</version>
155+
<version>0.4.0</version>
156156
</dependency>
157157
</dependencies>
158158
<build>

src/main/java/com/exasol/dbbuilder/dialects/AbstractImmediateDatabaseObjectWriter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected void writeToObject(final DatabaseObject object, final String sql, fina
3131
}
3232
preparedStatement.execute();
3333
} catch (final SQLException exception) {
34-
throw new DatabaseObjectException(object, "Failed to write to object: " + sql, exception);
34+
throw new DatabaseObjectException(object, ExaError.messageBuilder("E-TDBJ-13").message("Failed to write to object: {{sql}}", sql).toString(), exception);
3535
}
3636
}
3737

@@ -86,8 +86,7 @@ public void write(final Table table, final Stream<List<Object>> rows) {
8686
} catch (final SQLException exception) {
8787
throw new DatabaseObjectException(table,
8888
ExaError.messageBuilder("E-TDBJ-2")
89-
.message("Failed to create prepared statement {{statement}} for insert.")
90-
.parameter("statement", sql).toString(),
89+
.message("Failed to create prepared statement {{statement}} for insert.", sql).toString(),
9190
exception);
9291
}
9392
}
@@ -101,7 +100,7 @@ private void writeRow(final Table table, final String sql, final PreparedStateme
101100
preparedStatement.execute();
102101
} catch (final SQLException exception) {
103102
throw new DatabaseObjectException(table, ExaError.messageBuilder("E-TDBJ-1")
104-
.message("Failed to execute insert query: {{statement}}").parameter("statement", sql).toString(),
103+
.message("Failed to execute insert query: {{statement}}", sql).toString(),
105104
exception);
106105
}
107106
}
@@ -146,7 +145,7 @@ public void executeSqlFile(final Path... sqlFiles) {
146145
final String sql = Files.readString(sqlFile);
147146
statement.execute(sql);
148147
} catch (final IOException | SQLException exception) {
149-
throw new DatabaseObjectException("Unable to execute SQL from file: " + sqlFile, exception);
148+
throw new DatabaseObjectException(ExaError.messageBuilder("E-TDBJ-14").message("Unable to execute SQL from file: {{sqlFile}}", sqlFile).toString(), exception);
150149
}
151150
}
152151
}

src/main/java/com/exasol/dbbuilder/dialects/AbstractSchema.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.List;
55

66
import com.exasol.db.Identifier;
7+
import com.exasol.errorreporting.ExaError;
78

89
/**
910
* This class contains common logic for a database schema.
@@ -68,8 +69,9 @@ public Table createTable(final String name, final List<String> columnNames, fina
6869
this.tables.add(table);
6970
return table;
7071
} else {
71-
throw new IllegalArgumentException("Got " + columnNames.size() + " column names but " + columnTypes
72-
+ " column types. Please provide the same number of parameters for both when creating a table.");
72+
throw new IllegalArgumentException(ExaError.messageBuilder("E-TDBJ-18").message(
73+
"Got {{column names size}} column names but {{column types}} column types. Please provide the same number of parameters for both when creating a table.", columnNames.size(), columnTypes.size())
74+
.toString());
7375
}
7476
}
7577

src/main/java/com/exasol/dbbuilder/dialects/AbstractSchemaChild.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.exasol.dbbuilder.dialects;
22

33
import com.exasol.db.Identifier;
4+
import com.exasol.errorreporting.ExaError;
45

56
/**
67
* Base class for all database objects in the scope of a database schema.
@@ -71,8 +72,7 @@ protected void validate() {
7172
*/
7273
protected void requireNotNull(final Object object, final String name) {
7374
if (object == null) {
74-
throw new IllegalStateException(name + " is a required field. Please provide a value by calling " + name
75-
+ "() before build().");
75+
throw new IllegalStateException(ExaError.messageBuilder("E-TDBJ-15").message("{{name}} is a required field. Please provide a value by calling {{name|uq}}() before build().", name).toString());
7676
}
7777
}
7878
}

src/main/java/com/exasol/dbbuilder/dialects/Schema.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.List;
44

5+
import com.exasol.errorreporting.ExaError;
6+
57
/**
68
* Database schema.
79
*/
@@ -87,7 +89,6 @@ default boolean hasParent() {
8789

8890
@Override
8991
default DatabaseObject getParent() {
90-
throw new DatabaseObjectException(this,
91-
"Illegal attempt to access parent object of a SCHEMA which is a top-level object.");
92+
throw new DatabaseObjectException(this,ExaError.messageBuilder("E-TDBJ-16").message("Illegal attempt to access parent object of a SCHEMA which is a top-level object.").toString());
9293
}
9394
}

src/main/java/com/exasol/dbbuilder/dialects/Table.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,8 @@ public Table bulkInsert(final Stream<List<Object>> rows) {
9292
this.writer.write(this, rows.peek(row -> {
9393
if (row.size() != getColumnCount()) {
9494
throw new IllegalArgumentException(ExaError.messageBuilder("E-TDBJ-3").message(
95-
"Column count mismatch. Tried to insert row with {{actual}} values into table {{table name}} which has {{expected}} columns. If this is a bulk insert, multiple other rows might have already been written. Consider a rollback on the connection, to discard the changes.")
96-
.parameter("actual", row.size())//
97-
.parameter("table name", getFullyQualifiedName())//
98-
.parameter("expected", getColumnCount())//
99-
.toString());
95+
"Column count mismatch. Tried to insert row with {{actual}} values into table {{table name}} which has {{expected}} columns. If this is a bulk insert, multiple other rows might have already been written. Consider a rollback on the connection, to discard the changes.", row.size(), getFullyQualifiedName(), getColumnCount())
96+
.toString());
10097
}
10198
}));
10299
return this;

src/main/java/com/exasol/dbbuilder/dialects/User.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.Map;
44
import java.util.Set;
55

6+
import com.exasol.errorreporting.ExaError;
7+
68
/**
79
* Database user.
810
*/
@@ -66,7 +68,6 @@ default boolean hasParent() {
6668

6769
@Override
6870
default DatabaseObject getParent() {
69-
throw new DatabaseObjectException(this,
70-
"Illegal attempt to access parent object of a USER which is a top-level object.");
71+
throw new DatabaseObjectException(this,ExaError.messageBuilder("E-TDBJ-17").message("Illegal attempt to access parent object of a USER which is a top-level object.").toString());
7172
}
7273
}

src/main/java/com/exasol/dbbuilder/dialects/exasol/ConnectionDefinition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.exasol.dbbuilder.dialects.AbstractDatabaseObject;
55
import com.exasol.dbbuilder.dialects.DatabaseObject;
66
import com.exasol.dbbuilder.dialects.DatabaseObjectException;
7+
import com.exasol.errorreporting.ExaError;
78

89
/**
910
* Definition of a connection to another database or service.
@@ -92,8 +93,7 @@ public boolean hasParent() {
9293

9394
@Override
9495
public DatabaseObject getParent() {
95-
throw new DatabaseObjectException(this,
96-
"Illegal attempt to access parent object of a CONNECTION which is a top-level object.");
96+
throw new DatabaseObjectException(this, ExaError.messageBuilder("E-TDBJ-8").message("Illegal attempt to access parent object of a CONNECTION which is a top-level object.").toString());
9797
}
9898

9999
@Override

src/main/java/com/exasol/dbbuilder/dialects/exasol/ExasolImmediateDatabaseObjectWriter.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ public void write(final ConnectionDefinition definition) {
7878
} else {
7979
if (definition.hasPassword()) {
8080
throw new DatabaseObjectException(definition,
81-
"User name missing when trying to write connection definition "
82-
+ definition.getFullyQualifiedName()
83-
+ ". Please always provide user name and password together or not at all.");
81+
ExaError.messageBuilder("E-TDBJ-5").message("User name missing when trying to write connection definition {{definition name}}. Please always provide user name and password together or not at all.", definition.getFullyQualifiedName()).toString());
8482
} else {
8583
writeToObject(definition, "CREATE CONNECTION " + definition.getFullyQualifiedName() + " TO '"
8684
+ definition.getTarget() + "'");
@@ -271,7 +269,7 @@ public int execute(final Script script, final Object... parameterValues) {
271269
return statement.getUpdateCount();
272270
} catch (final SQLException exception) {
273271
throw new DatabaseObjectException(script, ExaError.messageBuilder("E-TDBJ-4")
274-
.message("Failed to execute script query {{query}}.").parameter("query", query).toString(),
272+
.message("Failed to execute script query {{query}}.", query).toString(),
275273
exception);
276274
}
277275
}
@@ -331,7 +329,7 @@ public List<List<Object>> executeQuery(final Script script, final Object... para
331329
return table;
332330
} catch (final SQLException exception) {
333331
throw new DatabaseObjectException(script,
334-
"Failed to execute script returning table" + script.getFullyQualifiedName(), exception);
332+
ExaError.messageBuilder("E-TDBJ-6").message("Failed to execute script returning table {{script name}}", script.getFullyQualifiedName()).toString(), exception);
335333
}
336334
}
337335
}

0 commit comments

Comments
 (0)