Skip to content

Commit

Permalink
SNOW-1746282: Fix warnings (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pbulawa authored Oct 17, 2024
1 parent 52a326e commit f94a517
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class SnowflakeDialect extends Dialect {
private final TableType tableType;

/**
* Minimal version suppporting HTAP is 3.13.31
* https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc-2023#version-3-13-31-may-25-2023
* Minimal version suppporting HTAP is <a
* href="https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc-2023#version-3-13-31-may-25-2023">3.13.31</a>
*/
private final Version MINIMAL_DRIVER_VERSION = Version.from("3.13.31");

Expand Down Expand Up @@ -124,10 +124,7 @@ private static void logDialectProperties(Map<String, Object> configurationValues
if (log.isTraceEnabled()) {
configurationValues.entrySet().stream()
.filter(e -> e.getKey().startsWith(CONFIGURATION_PROPERTY_PREFIX))
.forEach(
e -> {
log.trace("Dialect property {} has value {}", e.getKey(), e.getValue());
});
.forEach(e -> log.trace("Dialect property {} has value {}", e.getKey(), e.getValue()));
}
}

Expand Down Expand Up @@ -170,19 +167,15 @@ public String getAddForeignKeyConstraintString(
// Base dialect by default does not add name of primary table when referencesPrimaryKey is true
// Unistore allows creating foreign keys after creation but it should be disabled

final StringBuilder res = new StringBuilder();

res.append(" add constraint ")
.append(quote(constraintName))
.append(" foreign key (")
.append(String.join(", ", foreignKey))
.append(") references ")
.append(referencedTable)
.append(" (")
.append(String.join(", ", primaryKey))
.append(')');

return res.toString();
return " add constraint "
+ quote(constraintName)
+ " foreign key ("
+ String.join(", ", foreignKey)
+ ") references "
+ referencedTable
+ " ("
+ String.join(", ", primaryKey)
+ ')';
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import java.util.stream.Stream;

class Version implements Comparable<Version> {
private int major;
private int minor;
private int patch;
private final int major;
private final int minor;
private final int patch;

static Version from(String rawVersion) {
List<Integer> versionParts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class DroppingTablesBaseTest {
protected static SessionFactory sessionFactory;

protected static String hbm2ddlMode = "create";
private static String driverConnectionString =
private static final String driverConnectionString =
"jdbc:snowflake://"
+ System.getenv("SNOWFLAKE_TEST_ACCOUNT")
+ ".snowflakecomputing.com/?"
Expand All @@ -35,8 +35,8 @@ public abstract class DroppingTablesBaseTest {
+ System.getenv("SNOWFLAKE_TEST_SCHEMA")
+ "&warehouse="
+ System.getenv("SNOWFLAKE_TEST_WAREHOUSE");
private static String userName = System.getenv("SNOWFLAKE_TEST_USER");
private static String password = System.getenv("SNOWFLAKE_TEST_PASSWORD");
private static final String userName = System.getenv("SNOWFLAKE_TEST_USER");
private static final String password = System.getenv("SNOWFLAKE_TEST_PASSWORD");

protected static SessionFactory initSessionFactory() {
System.setProperty("net.snowflake.jdbc.loggerImpl", "net.snowflake.client.log.SLF4JLogger");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ public void shouldRunCrudOperationsOnSimplePerson() {
});

sessionFactory.inTransaction(
session -> {
assertEquals(
new SimplePerson(5L, "Bob", "Kowalski"), session.get(SimplePerson.class, 5L));
});
session ->
assertEquals(
new SimplePerson(5L, "Bob", "Kowalski"), session.get(SimplePerson.class, 5L)));

sessionFactory.inTransaction(
session -> {
Expand Down Expand Up @@ -133,10 +132,7 @@ public void shouldSelectWithLimit() {
public void shouldSelectCaseInsensitive() {
SimplePersonAutoId person1 =
new SimplePersonAutoId(null, UUID.randomUUID().toString().toUpperCase(), "Doe");
sessionFactory.inTransaction(
session -> {
session.persist(person1);
});
sessionFactory.inTransaction(session -> session.persist(person1));

sessionFactory.inSession(
session -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void shouldCreateVersion(String rawVersion) {
@ValueSource(strings = {"3.13.xx", "3.15", "3.15.1.23", "bla", " "})
@ParameterizedTest
void shouldFailOnVersionCreation(String rawVersion) {
assertThrows(VersionParsingException.class, () -> Version.from("rawVersion"));
assertThrows(VersionParsingException.class, () -> Version.from(rawVersion));
}

@CsvSource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ public void shouldSaveComplexHierarchy() {
sessionFactory.inTransaction(
session -> {
Employee employee =
(Employee)
session
.createQuery("from Employee where id = :id")
.setParameter("id", employee1.getId())
.getSingleResultOrNull();
session
.createSelectionQuery("from Employee where id = :id", Employee.class)
.setParameter("id", employee1.getId())
.getSingleResultOrNull();
assertEquals(3, employee.getCompany().getProjects().size());
});

Expand All @@ -96,49 +95,54 @@ public void shouldSaveComplexHierarchy() {
session -> {
assertNotNull(
session
.createQuery("from ProjectEmployeeV1 where projectEmployeeKey = ?1")
.createSelectionQuery(
"from ProjectEmployeeV1 where projectEmployeeKey = ?1",
ProjectEmployeeV1.class)
.setParameter(1, new ProjectEmployeeKey(project1.getId(), employee1.getId()))
.getSingleResultOrNull());
assertNotNull(
session
.createQuery("from ProjectEmployeeV2 where employee.id = ?1 and project.id = ?2")
.createSelectionQuery(
"from ProjectEmployeeV2 where employee.id = ?1 and project.id = ?2",
ProjectEmployeeV2.class)
.setParameter(1, employee1.getId())
.setParameter(2, project1.getId())
.getSingleResultOrNull());
assertNotNull(
session
.createQuery("from ProjectEmployeeV3 where id = ?1")
.createSelectionQuery(
"from ProjectEmployeeV3 where id = ?1", ProjectEmployeeV3.class)
.setParameter(1, new ProjectEmployeeKeyJoin(project1, employee1))
.getSingleResultOrNull());
});

sessionFactory.inTransaction(
session -> {
String projectName1 =
(String)
session
.createQuery(
"SELECT pev.project.name from ProjectEmployeeV1 pev inner join pev.employee.address a where a.addressLine = ?1")
.setParameter(1, employee1.getAddress().getAddressLine())
.getSingleResultOrNull();
session
.createSelectionQuery(
"SELECT pev.project.name from ProjectEmployeeV1 pev inner join pev.employee.address a where a.addressLine = ?1",
String.class)
.setParameter(1, employee1.getAddress().getAddressLine())
.getSingleResultOrNull();
assertEquals(project1.getName(), projectName1);

String projectName2 =
(String)
session
.createQuery(
"SELECT pev.project.name from ProjectEmployeeV2 pev inner join pev.employee.address a where a.addressLine = ?1")
.setParameter(1, employee1.getAddress().getAddressLine())
.getSingleResultOrNull();
session
.createSelectionQuery(
"SELECT pev.project.name from ProjectEmployeeV2 pev inner join pev.employee.address a where a.addressLine = ?1",
String.class)
.setParameter(1, employee1.getAddress().getAddressLine())
.getSingleResultOrNull();
assertEquals(project1.getName(), projectName2);

String projectName3 =
(String)
session
.createQuery(
"SELECT pev.project.name from ProjectEmployeeV3 pev inner join pev.employee.address a where a.addressLine = ?1")
.setParameter(1, employee1.getAddress().getAddressLine())
.getSingleResultOrNull();
session
.createSelectionQuery(
"SELECT pev.project.name from ProjectEmployeeV3 pev inner join pev.employee.address a where a.addressLine = ?1",
String.class)
.setParameter(1, employee1.getAddress().getAddressLine())
.getSingleResultOrNull();
assertEquals(project1.getName(), projectName3);
});
}
Expand All @@ -165,18 +169,21 @@ public void shouldUpdateMultipleHierarchiesInOneTransaction() {
try (Session session = sessionFactory.openSession()) {
assertNotNull(
session
.createQuery("from ProjectEmployeeV1 where projectEmployeeKey = ?1")
.createSelectionQuery(
"from ProjectEmployeeV1 where projectEmployeeKey = ?1", ProjectEmployeeV1.class)
.setParameter(1, new ProjectEmployeeKey(project.getId(), employee.getId()))
.getSingleResultOrNull());
assertNotNull(
session
.createQuery("from ProjectEmployeeV2 where employee.id = ?1 and project.id = ?2")
.createSelectionQuery(
"from ProjectEmployeeV2 where employee.id = ?1 and project.id = ?2",
ProjectEmployeeV2.class)
.setParameter(1, employee.getId())
.setParameter(2, project.getId())
.getSingleResultOrNull());
assertNotNull(
session
.createQuery("from ProjectEmployeeV3 where id = ?1")
.createSelectionQuery("from ProjectEmployeeV3 where id = ?1", ProjectEmployeeV3.class)
.setParameter(1, new ProjectEmployeeKeyJoin(project, employee))
.getSingleResultOrNull());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Employee {
private String firstName;
private String lastName;

@OneToOne(cascade = CascadeType.PERSIST, optional = true)
@OneToOne(cascade = CascadeType.PERSIST)
private Address address;

@ManyToOne
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class Project2 {

private String name;

@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(
cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
@JoinTable(
name = "project_employee",
joinColumns = @JoinColumn(name = "project_id", referencedColumnName = "id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.UUID;

@Embeddable
class ProjectEmployeeKey implements Serializable {
public class ProjectEmployeeKey implements Serializable {

@Column(name = "project_id", nullable = false)
UUID projectId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ public void shouldDeleteCascade() {
Address address = new Address(addressLine);
Person person = new Person(personFirstName, "Doe", address);

sessionFactory.inTransaction(
session -> {
session.persist(person);
});
sessionFactory.inTransaction(session -> session.persist(person));

sessionFactory.inSession(
session -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void shouldCreateSimplePersonWithHiLoSequenceId() {
new SimplePersonHiLoSequenceId(null, "Alice", "Doe"));
}

private <ID> void testSimplePersonAdding(AbstractSimplePerson<ID>... people) {
@SafeVarargs
private final <ID> void testSimplePersonAdding(AbstractSimplePerson<ID>... people) {
AbstractSimplePerson<ID> person1 = people[0];
AbstractSimplePerson<ID> person2 = people[1];
sessionFactory.inTransaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import net.snowflake.hibernate.dialect.DroppingTablesBaseTest;
import net.snowflake.hibernate.dialect.TestTags;
Expand All @@ -15,7 +15,8 @@ public class KeywordsTest extends DroppingTablesBaseTest {
// This class does not use Hybrid table specific features - there is no need to test this class
// also with standard tables

private static final List<Class<?>> mappedClasses = Arrays.asList(KeywordEntity.class);
private static final List<Class<?>> mappedClasses =
Collections.singletonList(KeywordEntity.class);

@BeforeAll
public static void setupClass() {
Expand All @@ -28,8 +29,6 @@ public void shouldAddTableWithKeywordNameAndColumns() {
KeywordEntity entity = new KeywordEntity();
sessionFactory.inTransaction(session -> session.persist(entity));
sessionFactory.inTransaction(
session -> {
assertNotNull(session.get(KeywordEntity.class, entity.getId()));
});
session -> assertNotNull(session.get(KeywordEntity.class, entity.getId())));
}
}
Loading

0 comments on commit f94a517

Please sign in to comment.