All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.snowflake.client.core.structs.SQLDataCreationHelper Maven / Gradle / Ivy

/*
 * Copyright (c) 2012-2024 Snowflake Computing Inc. All right reserved.
 */
package net.snowflake.client.core.structs;

import java.sql.SQLData;
import java.sql.SQLException;
import java.util.Optional;
import java.util.function.Supplier;
import net.snowflake.client.core.SnowflakeJdbcInternalApi;

@SnowflakeJdbcInternalApi
public class SQLDataCreationHelper {
  public static  T create(Class type) throws SQLException {
    Optional> typeFactory = SnowflakeObjectTypeFactories.get(type);
    return (T)
        typeFactory
            .map(Supplier::get)
            .orElseGet(() -> createUsingReflection((Class) type));
  }

  private static SQLData createUsingReflection(Class type) {
    try {
      return type.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
      throw new RuntimeException(e);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy