-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add xmltype in postgres #1112
Open
mauravan
wants to merge
4
commits into
eclipse-vertx:master
Choose a base branch
from
mauravan:datatype-xml-pg
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+149
−4
Open
add xmltype in postgres #1112
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
vertx-pg-client/src/test/java/io/vertx/pgclient/data/XMLCodecTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package io.vertx.pgclient.data; | ||
|
||
import io.vertx.ext.unit.TestContext; | ||
import io.vertx.pgclient.PgConnection; | ||
import io.vertx.pgclient.PgException; | ||
import io.vertx.sqlclient.*; | ||
import org.junit.Test; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class XMLCodecTest extends DataTypeTestBase { | ||
|
||
@Test | ||
public void testBinaryEncodePgSQLXMLAsVarcharOrXML(TestContext ctx) { | ||
String asVarchar = "<message><to><be><validated></validated></be></to></message>"; | ||
String asXML = "<message><to><be><validated><again></again></validated></be></to></message>"; | ||
|
||
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { | ||
conn.preparedQuery("SELECT ($1::xml)::VARCHAR, ($2::xml)").execute(Tuple.of(asVarchar, asXML), | ||
ctx.asyncAssertSuccess(rows -> { | ||
ctx.assertEquals(1, rows.size()); | ||
Row row = rows.iterator().next(); | ||
String v1 = row.getString(0); | ||
String v2 = (String)row.getValue(1); | ||
ctx.assertEquals("<message><to><be><validated></validated></be></to></message>", v1); | ||
ctx.assertEquals(asXML, v2); | ||
}) | ||
); | ||
})); | ||
} | ||
|
||
@Test | ||
public void testBinaryEncodePgSQLXMLMalformed(TestContext ctx) { | ||
String malformedXml = "<message><to><be><validated><malformed>>></validated></be></to></message>"; | ||
|
||
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { | ||
conn.preparedQuery("SELECT ($1::xml)").execute(Tuple.of(malformedXml), | ||
ctx.asyncAssertFailure(err -> { | ||
assertThat(((PgException) err).getCode(), is(equalTo("2200N"))); | ||
}) | ||
); | ||
})); | ||
} | ||
|
||
@Test | ||
public void testTextDecodePgSQLXML(TestContext ctx) { | ||
testDecodePgSQLXML(ctx, SqlClient::query); | ||
} | ||
|
||
@Test | ||
public void testBinaryDecodePgSQLXML(TestContext ctx) { | ||
testDecodePgSQLXML(ctx, SqlClient::preparedQuery); | ||
} | ||
|
||
private void testDecodePgSQLXML(TestContext ctx, BiFunction<SqlClient, String, Query<RowSet<Row>>> a) { | ||
String first = "<message><to><be><validated></validated></be></to></message>"; | ||
|
||
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { | ||
a.apply(conn, "SELECT '<message><to><be><validated></validated></be></to></message>'::xml") | ||
.execute(ctx.asyncAssertSuccess(rows -> { | ||
ctx.assertEquals(1, rows.size()); | ||
Row row = rows.iterator().next(); | ||
String v1 = (String) row.getValue(0); | ||
ctx.assertEquals(first, v1); | ||
})); | ||
})); | ||
} | ||
|
||
@Test | ||
public void testBinaryDecodePgSQLXMLArray(TestContext ctx) throws Exception { | ||
String first = "<message><to><be><validated></validated></be></to></message>"; | ||
String second = "<message><to><be><validated><again></again></validated></be></to></message>"; | ||
|
||
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { | ||
conn.preparedQuery("SELECT ARRAY['<message><to><be><validated></validated></be></to></message>'::xml,'<message><to><be><validated><again></again></validated></be></to></message>'::xml]") | ||
.execute(ctx.asyncAssertSuccess(rows -> { | ||
ctx.assertEquals(1, rows.size()); | ||
Row row = rows.iterator().next(); | ||
String[] array = (String[]) row.getValue(0); | ||
String v1 = array[0]; | ||
String v2 = array[1]; | ||
ctx.assertEquals(first, v1); | ||
ctx.assertEquals(second, v2); | ||
})); | ||
})); | ||
} | ||
|
||
@Test | ||
public void testBinaryEncodePgSQLXMLArray(TestContext ctx) { | ||
String first = "<message><to><be><validated></validated></be></to></message>"; | ||
String second = "<message><to><be><validated><again></again></validated></be></to></message>"; | ||
|
||
|
||
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { | ||
conn.preparedQuery("SELECT ($1::xml[])::VARCHAR[]").execute(Tuple.of( | ||
new String[]{ | ||
"<message><to><be><validated></validated></be></to></message>", | ||
"<message><to><be><validated><again></again></validated></be></to></message>"} | ||
), | ||
ctx.asyncAssertSuccess(rows -> { | ||
ctx.assertEquals(1, rows.size()); | ||
Row row = rows.iterator().next(); | ||
String[] array = row.getArrayOfStrings(0); | ||
String v1 = array[0]; | ||
String v2 = array[1]; | ||
ctx.assertEquals(first, v1); | ||
ctx.assertEquals(second, v2); | ||
})); | ||
})); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this commented ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand it, there can only be one mapping per class to a Type. This is the Problem i was talking about in the other comments which we need to solve here - so either there will be a need for a wrapper class or someone can come up with a better solution for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are totally right, this is because we cannot specify which database type to use in a tuple for a given java type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there will be something like a new Class like
PgXMLType
which just holds a String. Would you agree to that?