Commit 7bfa9f07 authored by Asier Lostalé's avatar Asier Lostalé
Browse files

related to FR-44155: support for pg full text search

MR !10
parents 44ca69d6 b8186165
<?xml version='1.0' encoding='UTF-8'?>
<data>
<!--1--><TEST>
<!--1--> <TEST_ID><![CDATA[1]]></TEST_ID>
<!--1--></TEST>
<!--2--><TEST>
<!--2--> <TEST_ID><![CDATA[2]]></TEST_ID>
<!--2--> <SEARCH_VECTOR><![CDATA['2017900379769':5A 'libr':4A 'pos':3A 'ref':1A 'rsg5purs':6B 'us':2A]]></SEARCH_VECTOR>
<!--2--></TEST>
</data>
\ No newline at end of file
<?xml version="1.0"?>
<database name="TABLE TEST">
<table name="TEST" primaryKey="TEST_ID">
<column name="TEST_ID" primaryKey="true" required="true" type="VARCHAR" size="32" autoIncrement="false">
<default/>
<onCreateDefault/>
</column>
<column name="SEARCH_VECTOR" primaryKey="false" required="false" type="TSVECTOR" autoIncrement="false">
<default/>
<onCreateDefault/>
</column>
</table>
</database>
\ No newline at end of file
/*
************************************************************************************
* Copyright (C) 2015-2019 Openbravo S.L.U.
* Copyright (C) 2015-2020 Openbravo S.L.U.
* Licensed under the Apache Software License version 2.0
* 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
......@@ -57,6 +57,7 @@ import org.openbravo.dbsm.test.sqlscript.PgSystemPreScriptTest;
FunctionVolatility.class, //
Views.class, //
MaterializedViews.class, //
TSVectorColumn.class, //
AddDropConstraints.class, //
TypeChangeSuite.class, //
......
package org.openbravo.dbsm.test.model;
/*
************************************************************************************
* Copyright (C) 2020 Openbravo S.L.U.
* Licensed under the Apache Software License version 2.0
* 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.
************************************************************************************
*/
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.openbravo.dbsm.test.base.DbsmTest;
public class TSVectorColumn extends DbsmTest {
public TSVectorColumn(String rdbms, String driver, String url, String sid, String user,
String password, String name) throws FileNotFoundException, IOException {
super(rdbms, driver, url, sid, user, password, name);
}
/**
* Test sourcedata export of a table with a TSVector column to a file in /tmp folder
*/
@Test
public void testSourceDataFTS() throws SQLException, IOException {
resetDB();
String model = "fullTextSearch/BASE_MODEL.xml";
List<String> adTables = Arrays.asList("TEST");
updateDatabase(model, "data/datachanges/fullTextSearch", adTables);
exportDatabase("/tmp/exportDB");
assertExportIsConsistent(model);
}
}
......@@ -197,7 +197,7 @@ Defines a column in a table.
| DATE | TIME | TIMESTAMP | BINARY | VARBINARY | LONGVARBINARY
| NULL | OTHER | JAVA_OBJECT | DISTINCT | STRUCT | ARRAY
| BLOB | CLOB | REF | BOOLEANINT | BOOLEANCHAR
| DOUBLE) "VARCHAR"
| DOUBLE | TSVECTOR) "VARCHAR"
javaType (object | primitive) #IMPLIED
size CDATA #IMPLIED
default CDATA #IMPLIED
......
......@@ -128,6 +128,10 @@ public abstract class TypeMap {
* The string representation of the {@link java.sql.Types#NVARCHAR} constant.
*/
public static final String NVARCHAR = "NVARCHAR";
/**
* The string representation of the {@link java.sql.Types#NVARCHAR} constant.
*/
public static final String TSVECTOR = "TSVECTOR";
/** Maps type names to the corresponding {@link java.sql.Types} constants. */
private static HashMap _typeNameToTypeCode = new HashMap();
......@@ -169,6 +173,7 @@ public abstract class TypeMap {
registerJdbcType(Types.VARBINARY, VARBINARY, JdbcTypeCategoryEnum.BINARY);
registerJdbcType(Types.VARCHAR, VARCHAR, JdbcTypeCategoryEnum.TEXTUAL);
registerJdbcType(ExtTypes.NVARCHAR, NVARCHAR, JdbcTypeCategoryEnum.TEXTUAL);
registerJdbcType(ExtTypes.TSVECTOR, TSVECTOR, JdbcTypeCategoryEnum.SPECIAL);
// only available in JDK 1.4 and above:
if (Jdbc3Utils.supportsJava14JdbcTypes()) {
......
......@@ -2764,6 +2764,8 @@ public abstract class PlatformImplBase extends JdbcSupport implements Platform {
byte[] b = (byte[]) value;
InputStream isr = new ByteArrayInputStream(b);
statement.setBinaryStream(sqlIndex, isr, b.length);
} else if (typeCode == ExtTypes.TSVECTOR) {
statement.setNull(sqlIndex, Types.NULL, "tsvector");
} else {
statement.setObject(sqlIndex, value, typeCode);
}
......
......@@ -62,6 +62,7 @@ import org.apache.ddlutils.model.Unique;
import org.apache.ddlutils.model.ValueObject;
import org.apache.ddlutils.model.View;
import org.apache.ddlutils.platform.SqlBuilder;
import org.apache.ddlutils.util.ExtTypes;
import org.apache.ddlutils.util.Jdbc3Utils;
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.Pattern;
......@@ -159,6 +160,11 @@ public class OracleBuilder extends SqlBuilder {
public void writeColumnCommentStmt(Database database, Table table, Column column,
boolean keepComments) throws IOException {
String comment = "";
if (column.getTypeCode() == ExtTypes.TSVECTOR) {
comment += "--OBTG:TSVECTOR--";
}
if (column.getOnCreateDefault() != null && !column.getOnCreateDefault().equals("")) {
String oncreatedefaultp = column.getOnCreateDefault();
String oncreatedefault = "";
......
......@@ -318,6 +318,14 @@ public class OracleModelLoader extends ModelLoaderBase {
}
});
if (commentCol != null && !commentCol.equals("")) {
Pattern pat = Pattern.compile("--OBTG:TSVECTOR--");
Matcher match = pat.matcher(commentCol);
if (match.find()) {
t.getColumn(i).setTypeCode(ExtTypes.TSVECTOR);
// This setSize is necessary not to export the size to the xml of the TSVECTOR column and
// not to generate differences
t.getColumn(i).setSize(null);
}
List<String> commentLines = new ArrayList<>(Arrays.asList(commentCol.split("\\$")));
Pattern pat3 = Pattern.compile("--OBTG:ONCREATEDEFAULT:(.*?)--");
for (String comment : commentLines) {
......
......@@ -118,6 +118,9 @@ public class OraclePlatform extends PlatformImplBase {
info.addNativeTypeMapping(Types.VARBINARY, "RAW");
info.addNativeTypeMapping(Types.VARCHAR, "VARCHAR2");
info.addNativeTypeMapping(ExtTypes.NVARCHAR, "NVARCHAR2");
// This is to convert a TSVECTOR (as it is Postgres specific) column to text and lenght 1 is to
// avoid for it being used
info.addNativeTypeMapping(ExtTypes.TSVECTOR, "VARCHAR2(1)");
info.addNativeTypeMapping("BOOLEAN", "NUMBER(1)", "BIT");
info.addNativeTypeMapping("DATALINK", "BLOB", "BLOB");
......
......@@ -914,6 +914,8 @@ public class PostgreSqlModelLoader extends ModelLoaderBase {
return Types.CLOB;
} else if ("BYTEA".equalsIgnoreCase(nativeType)) {
return Types.BLOB;
} else if ("TSVECTOR".equalsIgnoreCase(nativeType)) {
return ExtTypes.TSVECTOR;
} else {
return Types.OTHER;
}
......
......@@ -272,6 +272,10 @@ public class PostgreSqlPlatform extends PlatformImplBase {
case Types.BLOB:
statement.setNull(sqlIndex, Types.BINARY);
break;
case ExtTypes.TSVECTOR:
// statement.setObject(sqlIndex, null);
statement.setNull(sqlIndex, Types.NULL, "tsvector");
break;
default:
statement.setNull(sqlIndex, typeCode);
break;
......
/*
************************************************************************************
* Copyright (C) 2001-2006 Openbravo S.L.U.
* Copyright (C) 2001-2020 Openbravo S.L.U.
* Licensed under the Apache Software License version 2.0
* 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
......@@ -25,4 +25,6 @@ public class ExtTypes {
public static final int NCHAR = -15;
public static final int NVARCHAR = -9;
public static final int TSVECTOR = 2222;
}
/*
************************************************************************************
* Copyright (C) 2013-2017 Openbravo S.L.U.
* Copyright (C) 2013-2020 Openbravo S.L.U.
* Licensed under the Apache Software License version 2.0
* 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
......@@ -330,7 +330,7 @@ public class ImportSampledata extends BaseDatabaseTask {
* Runnable class that will read data from a file and will write it in the database
*
*/
private static class ImportRunner implements Callable<Void> {
public static class ImportRunner implements Callable<Void> {
private final Logger log;
private final Platform platform;
private final Database db;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment