mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
commit
958c657f50
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2014, Timo Westkämper
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mysema.query.sql.types;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
* SQLXMLType maps SQLXML to SQLXML on the JDBC level
|
||||
*
|
||||
* @author tiwe
|
||||
*
|
||||
*/
|
||||
public class SQLXMLType extends AbstractType<SQLXML> {
|
||||
|
||||
public SQLXMLType() {
|
||||
super(Types.SQLXML);
|
||||
}
|
||||
|
||||
public SQLXMLType(int type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLXML getValue(ResultSet rs, int startIndex) throws SQLException {
|
||||
return rs.getSQLXML(startIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<SQLXML> getReturnedClass() {
|
||||
return SQLXML.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(PreparedStatement st, int startIndex, SQLXML value)
|
||||
throws SQLException {
|
||||
st.setSQLXML(startIndex, value);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2014, Timo Westkämper
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mysema.query.sql.types;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
* SQLXMLType maps String to SQLXML on the JDBC level
|
||||
*
|
||||
* @author tiwe
|
||||
*
|
||||
*/
|
||||
public class XMLAsStringType extends AbstractType<String> {
|
||||
|
||||
public XMLAsStringType() {
|
||||
super(Types.SQLXML);
|
||||
}
|
||||
|
||||
public XMLAsStringType(int type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(ResultSet rs, int startIndex) throws SQLException {
|
||||
SQLXML value = rs.getSQLXML(startIndex);
|
||||
return value != null ? value.getString() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<String> getReturnedClass() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(PreparedStatement st, int startIndex, String value)
|
||||
throws SQLException {
|
||||
SQLXML xml = st.getConnection().createSQLXML();
|
||||
xml.setString(value);
|
||||
st.setSQLXML(startIndex, xml);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -13,12 +13,11 @@
|
||||
*/
|
||||
package com.mysema.query;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.sql.Connection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import com.mysema.query.dml.DMLClause;
|
||||
import com.mysema.query.sql.*;
|
||||
import com.mysema.query.sql.dml.SQLDeleteClause;
|
||||
import com.mysema.query.sql.dml.SQLInsertClause;
|
||||
@ -26,16 +25,13 @@ import com.mysema.query.sql.dml.SQLMergeClause;
|
||||
import com.mysema.query.sql.dml.SQLUpdateClause;
|
||||
import com.mysema.query.sql.mysql.MySQLReplaceClause;
|
||||
import com.mysema.query.sql.teradata.TeradataQuery;
|
||||
|
||||
import com.mysema.query.sql.types.XMLAsStringType;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.MethodRule;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mysema.query.dml.DMLClause;
|
||||
|
||||
public abstract class AbstractBaseTest {
|
||||
|
||||
protected static final Logger logger = LoggerFactory.getLogger(AbstractBaseTest.class);
|
||||
@ -81,6 +77,13 @@ public abstract class AbstractBaseTest {
|
||||
@Nullable
|
||||
protected String expectedQuery;
|
||||
|
||||
public AbstractBaseTest() {
|
||||
// TODO enable registration of (jdbc type, java type) -> usertype mappings
|
||||
if (target == Target.POSTGRES || target == Target.ORACLE) {
|
||||
configuration.register("XML_TEST", "COL", new XMLAsStringType());
|
||||
}
|
||||
}
|
||||
|
||||
@Rule
|
||||
public static MethodRule skipForQuotedRule = new SkipForQuotedRule();
|
||||
|
||||
|
||||
@ -286,6 +286,11 @@ public final class Connections {
|
||||
stmt.execute("drop table if exists DATE_TEST");
|
||||
stmt.execute(CREATE_TABLE_TIMETEST);
|
||||
stmt.execute(CREATE_TABLE_DATETEST);
|
||||
|
||||
// xml
|
||||
stmt.execute("drop table if exists XML_TEST");
|
||||
stmt.execute("create table XML_TEST(COL varchar(128))");
|
||||
|
||||
cubridInited = true;
|
||||
}
|
||||
|
||||
@ -341,6 +346,11 @@ public final class Connections {
|
||||
|
||||
dropTable(templates, "DATE_TEST");
|
||||
stmt.execute(CREATE_TABLE_DATETEST);
|
||||
|
||||
// xml
|
||||
dropTable(templates, "XML_TEST");
|
||||
stmt.execute("create table XML_TEST(COL varchar(128))");
|
||||
|
||||
derbyInited = true;
|
||||
}
|
||||
|
||||
@ -450,6 +460,11 @@ public final class Connections {
|
||||
dropTable(templates, "DATE_TEST");
|
||||
stmt.execute(CREATE_TABLE_TIMETEST);
|
||||
stmt.execute(CREATE_TABLE_DATETEST);
|
||||
|
||||
// xml
|
||||
dropTable(templates, "XML_TEST");
|
||||
stmt.execute("create table XML_TEST(COL varchar(128))");
|
||||
|
||||
firebirdInited = true;
|
||||
}
|
||||
|
||||
@ -517,6 +532,11 @@ public final class Connections {
|
||||
stmt.execute("drop table DATE_TEST if exists");
|
||||
stmt.execute(CREATE_TABLE_TIMETEST);
|
||||
stmt.execute(CREATE_TABLE_DATETEST);
|
||||
|
||||
// xml
|
||||
dropTable(templates, "XML_TEST");
|
||||
stmt.execute("create table XML_TEST(COL varchar(128))");
|
||||
|
||||
h2Inited = true;
|
||||
}
|
||||
|
||||
@ -578,6 +598,11 @@ public final class Connections {
|
||||
stmt.execute("drop table DATE_TEST if exists");
|
||||
stmt.execute(CREATE_TABLE_TIMETEST);
|
||||
stmt.execute(CREATE_TABLE_DATETEST);
|
||||
|
||||
// xml
|
||||
dropTable(templates, "XML_TEST");
|
||||
stmt.execute("create table XML_TEST(COL varchar(128))");
|
||||
|
||||
hsqlInited = true;
|
||||
}
|
||||
|
||||
@ -643,6 +668,11 @@ public final class Connections {
|
||||
stmt.execute("drop table if exists DATE_TEST");
|
||||
stmt.execute(CREATE_TABLE_TIMETEST);
|
||||
stmt.execute(CREATE_TABLE_DATETEST);
|
||||
|
||||
// xml
|
||||
stmt.execute("drop table if exists XML_TEST");
|
||||
stmt.execute("create table XML_TEST(COL varchar(128))");
|
||||
|
||||
mysqlInited = true;
|
||||
}
|
||||
|
||||
@ -716,6 +746,11 @@ public final class Connections {
|
||||
// date_test and time_test
|
||||
dropTable(templates, "DATE_TEST");
|
||||
stmt.execute("create table date_test(date_test date)");
|
||||
|
||||
// xml
|
||||
dropTable(templates, "XML_TEST");
|
||||
stmt.execute("create table XML_TEST(COL XMLTYPE)");
|
||||
|
||||
oracleInited = true;
|
||||
}
|
||||
|
||||
@ -803,6 +838,11 @@ public final class Connections {
|
||||
dropTable(templates, "DATE_TEST");
|
||||
stmt.execute(quote(CREATE_TABLE_TIMETEST, "TIME_TEST"));
|
||||
stmt.execute(quote(CREATE_TABLE_DATETEST, "DATE_TEST"));
|
||||
|
||||
// xml
|
||||
dropTable(templates, "XML_TEST");
|
||||
stmt.execute("create table \"XML_TEST\"(\"COL\" XML)");
|
||||
|
||||
postgresInited = true;
|
||||
}
|
||||
|
||||
@ -865,6 +905,11 @@ public final class Connections {
|
||||
stmt.execute("drop table if exists DATE_TEST");
|
||||
stmt.execute(CREATE_TABLE_TIMETEST);
|
||||
stmt.execute(CREATE_TABLE_DATETEST);
|
||||
|
||||
// xml
|
||||
stmt.execute("drop table if exists XML_TEST");
|
||||
stmt.execute("create table XML_TEST(COL varchar(128))");
|
||||
|
||||
sqliteInited = true;
|
||||
}
|
||||
|
||||
@ -916,6 +961,11 @@ public final class Connections {
|
||||
dropTable(templates, "DATE_TEST");
|
||||
stmt.execute(CREATE_TABLE_TIMETEST);
|
||||
stmt.execute(CREATE_TABLE_DATETEST);
|
||||
|
||||
// xml
|
||||
dropTable(templates, "XML_TEST");
|
||||
stmt.execute("create table XML_TEST(COL XML)");
|
||||
|
||||
sqlServerInited = true;
|
||||
}
|
||||
|
||||
@ -982,6 +1032,11 @@ public final class Connections {
|
||||
dropTable(templates, "DATE_TEST");
|
||||
stmt.execute(CREATE_TABLE_TIMETEST);
|
||||
stmt.execute(CREATE_TABLE_DATETEST);
|
||||
|
||||
// xml
|
||||
dropTable(templates, "XML_TEST");
|
||||
stmt.execute("create table XML_TEST(COL varchar(128))");
|
||||
|
||||
teradataInited = true;
|
||||
}
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ public class InsertBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws SQLException{
|
||||
public void setUp() throws SQLException {
|
||||
reset();
|
||||
}
|
||||
|
||||
@ -430,4 +430,13 @@ public class InsertBase extends AbstractBaseTest {
|
||||
assertEquals(uuid, query().from(uuids).singleResult(uuids.field));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void XML() {
|
||||
delete(QXmlTest.xmlTest).execute();
|
||||
QXmlTest xmlTest = QXmlTest.xmlTest;
|
||||
String contents = "<html><head></head><body></body></html>";
|
||||
insert(xmlTest).set(xmlTest.col, contents).execute();
|
||||
assertEquals(contents, query().from(xmlTest).singleResult(xmlTest.col));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,51 @@
|
||||
package com.mysema.query.sql.domain;
|
||||
|
||||
import javax.annotation.Generated;
|
||||
import java.sql.Types;
|
||||
|
||||
import com.mysema.query.sql.ColumnMetadata;
|
||||
import com.mysema.query.sql.spatial.RelationalPathSpatial;
|
||||
import com.mysema.query.types.Path;
|
||||
import com.mysema.query.types.PathMetadata;
|
||||
import com.mysema.query.types.path.StringPath;
|
||||
import static com.mysema.query.types.PathMetadataFactory.forVariable;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* QXmlTest is a Querydsl query type for QXmlTest
|
||||
*/
|
||||
@Generated("com.mysema.query.sql.codegen.MetaDataSerializer")
|
||||
public class QXmlTest extends RelationalPathSpatial<QXmlTest> {
|
||||
|
||||
private static final long serialVersionUID = 574759316;
|
||||
|
||||
public static final QXmlTest xmlTest = new QXmlTest("XML_TEST");
|
||||
|
||||
public final StringPath col = createString("COL");
|
||||
|
||||
public QXmlTest(String variable) {
|
||||
super(QXmlTest.class, forVariable(variable), "PUBLIC", "XML_TEST");
|
||||
addMetadata();
|
||||
}
|
||||
|
||||
public QXmlTest(String variable, String schema, String table) {
|
||||
super(QXmlTest.class, forVariable(variable), schema, table);
|
||||
addMetadata();
|
||||
}
|
||||
|
||||
public QXmlTest(Path<? extends QXmlTest> path) {
|
||||
super(path.getType(), path.getMetadata(), "PUBLIC", "XML_TEST");
|
||||
addMetadata();
|
||||
}
|
||||
|
||||
public QXmlTest(PathMetadata<?> metadata) {
|
||||
super(QXmlTest.class, metadata, "PUBLIC", "XML_TEST");
|
||||
addMetadata();
|
||||
}
|
||||
|
||||
public void addMetadata() {
|
||||
addMetadata(col, ColumnMetadata.named("COL").withIndex(1).ofType(Types.SQLXML).withSize(2147483647));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user