Skip to content
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

Support MS SQL in Jdbc SQL connector [HZ-2694] #25071

Merged
merged 30 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1be42c7
add MSSQLAllTypesInsertJdbcSqlConnectorTest
Edizc Jul 25, 2023
d3be4ed
Add MSSQLGenericMapStoreTest
Edizc Aug 1, 2023
490204e
Add HazelcastMSSQlDialect and Update, SelectJdbcConnectorTest for Mic…
Edizc Aug 2, 2023
e5bb270
Unnecessary import and a comment corrected in HazelcastMSSQLDialect
Edizc Aug 2, 2023
7001339
Add the rest of the tests
Edizc Aug 4, 2023
7a43387
Add MSSQL's LEN function
Edizc Aug 7, 2023
c055b2d
Fixed Checkstyle Issues
Edizc Aug 7, 2023
2529e52
Make Length to LEN translation
TomaszGaweda Aug 7, 2023
149c3fe
Removed commented out tests and unused import
Edizc Aug 8, 2023
96419a8
Changed the upsert statement from IF to MERGE
Edizc Aug 9, 2023
a12e698
Merge branch 'hazelcast:master' into add-mssqlTests
Edizc Aug 9, 2023
764b40c
Updated MSSQLUpsertQueryBuilder and removed unnecessary code
Edizc Aug 9, 2023
ac78843
Merge branch 'add-mssqlTests' of github.com:Edizc/hazelcast into add-…
Edizc Aug 9, 2023
fa1b867
Add After annotation to close mocks
Edizc Aug 9, 2023
51c6ede
added GETTERS to serialization in readData and writeData
Edizc Aug 9, 2023
5277e6a
updated initializeGetters function
Edizc Aug 9, 2023
b6f8f6e
Add missing predicate tests
frant-hartm Aug 14, 2023
0c9fa89
Fix test for TIME data type
frant-hartm Aug 14, 2023
38f23f6
Cleanup bit/boolean support
frant-hartm Aug 16, 2023
b37d4ea
Fix CreateDataConnectionJdbcSqlConnectorTest
frant-hartm Aug 16, 2023
1dd1464
Cleanup duplication
frant-hartm Aug 16, 2023
c7add0a
Add BIT back - needed for MySQL boolean support
frant-hartm Aug 16, 2023
075e21b
Organized MSSQLUpsertQueryBuilder
Edizc Aug 16, 2023
50fc63d
Merge branch 'add-mssqlTests' of github.com:Edizc/hazelcast into add-…
Edizc Aug 16, 2023
46f4df2
add GettersProvider
Edizc Aug 16, 2023
19728c0
fixed GettersProvider
Edizc Aug 16, 2023
5294505
removed commented code in SelectProcessorSupplier
Edizc Aug 16, 2023
b954cec
Sorted the supported Sql dialect names
Edizc Aug 16, 2023
1a42b7f
Add BIT back (needed for MySQL boolean support)
frant-hartm Aug 16, 2023
9160aa7
Cleanup getters
frant-hartm Aug 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2023 Hazelcast Inc.
*
* Licensed under the Hazelcast Community License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://hazelcast.com/hazelcast-community-license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hazelcast.mapstore.mssql;

import com.hazelcast.mapstore.GenericMapStoreTest;
import com.hazelcast.nio.serialization.genericrecord.GenericRecord;
import com.hazelcast.test.annotation.NightlyTest;
import com.hazelcast.test.jdbc.MSSQLDatabaseProvider;
import com.hazelcast.test.jdbc.MySQLDatabaseProvider;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import java.util.Properties;

import static com.hazelcast.mapstore.GenericMapLoader.DATA_CONNECTION_REF_PROPERTY;
import static com.hazelcast.mapstore.GenericMapLoader.EXTERNAL_NAME_PROPERTY;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeFalse;

@Category(NightlyTest.class)
public class MSSQLGenericMapStoreTest extends GenericMapStoreTest {

@BeforeClass
public static void beforeClass() {
initialize(new MSSQLDatabaseProvider());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ private static QueryDataType resolveType(String columnTypeName) {
return QueryDataType.TIMESTAMP;

case "TIMESTAMP WITH TIME ZONE":
case "DATETIMEOFFSET":
return QueryDataType.TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static org.assertj.core.util.Lists.newArrayList;
import static java.util.Arrays.asList;

@RunWith(HazelcastParametrizedRunner.class)
Expand Down Expand Up @@ -108,12 +107,8 @@ public void insertRowWithAllTypes() throws Exception {
execute("INSERT INTO " + mappingName + " VALUES(0, " + sqlValue + ")");
execute("INSERT INTO " + mappingName + " VALUES(1, ?)", javaValue);

List<Class<?>> columnTypes = new ArrayList<>();
columnTypes.add(Integer.class);
columnTypes.add(jdbcValue.getClass());

assertJdbcRowsAnyOrder(tableName,
columnTypes,
newArrayList(Integer.class, jdbcValue.getClass()),
new Row(0, jdbcValue),
new Row(1, jdbcValue)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public static void beforeClass() {

@Before
public void setUp() throws Exception {
assumeThat(type).describedAs("TIMESTAMP WITH TIME ZONE not supported on MSSQL")
.isNotEqualTo("TIMESTAMP WITH TIME ZONE");


// MSSQL doesn't support BOOLEAN but BIT can be used instead and, uses FLOAT as 8-byte floating point type
frant-hartm marked this conversation as resolved.
Show resolved Hide resolved
// For Float in MSSQL see https://learn.microsoft.com/en-us/sql/t-sql/data-types/float-and-real-transact-sql?view=sql-server-ver16
// For BIT in MSSQL see https://learn.microsoft.com/en-us/sql/t-sql/data-types/bit-transact-sql?view=sql-server-ver16
// For TIMESTAMP in MSSQL see https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2005/ms182776(v=sql.90)?redirectedfrom=MSDN
// For DATETIMEOFFSET in MSSQL see https://learn.microsoft.com/en-us/sql/t-sql/data-types/datetimeoffset-transact-sql?view=sql-server-ver16
if (type.equals("BOOLEAN")) {
type = "BIT";
}
Expand All @@ -50,6 +50,9 @@ public void setUp() throws Exception {
if (type.equals("TIMESTAMP")) {
type = "DATETIME";
}
if (type.equals("TIMESTAMP WITH TIME ZONE")) {
type = "DATETIMEOFFSET";
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@ public void shutdown() {
container = null;
}
}

@Override
public String createSchemaQuery(String schemaName) {
return "IF NOT EXISTS (SELECT 0 FROM information_schema.schemata WHERE schema_name = '" + schemaName
+ "') BEGIN EXEC sp_executesql N'CREATE SCHEMA " + schemaName + "'; END";
frant-hartm marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ default String quote(String[] parts) {
.map(part -> '\"' + part.replaceAll("\"", "\"\"") + '\"')
.collect(joining("."));
};

default String createSchemaQuery(String schemaName) {
return "CREATE SCHEMA IF NOT EXISTS " + schemaName;
}
}