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

Change scope of unwanted Public APIs + Code Format #757

Merged
merged 5 commits into from
Jul 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mssql-jdbc_formatter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
Expand Down Expand Up @@ -146,7 +146,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="82"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="18"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/microsoft/sqlserver/jdbc/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,9 @@ private void setTypeDefinition(DTV dtv) {
* generic type info can be used as before.
*/
if (userProvidesScale) {
param.typeDefinition = con.isKatmaiOrLater()
? (SSType.DATETIME2.toString() + "(" + outScale
+ ")")
: (SSType.DATETIME.toString());
param.typeDefinition = con
.isKatmaiOrLater() ? (SSType.DATETIME2.toString() + "(" + outScale + ")")
: (SSType.DATETIME.toString());
} else {
param.typeDefinition = con.isKatmaiOrLater()
? (SSType.DATETIME2.toString() + "("
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3016,8 +3016,9 @@ else if (null != sourceBulkRecord && (null == destCryptoMeta)) {
}

/**
* Returns the temporal object from CSV
* This method is called against jdbc41, but it require jdbc42 to work therefore, we will throw exception.
* Returns the temporal object from CSV This method is called against jdbc41, but it require jdbc42 to work
* therefore, we will throw exception.
*
* @param valueStrUntrimmed
* valueStrUntrimmed
* @param srcJdbcType
Expand All @@ -3027,7 +3028,8 @@ else if (null != sourceBulkRecord && (null == destCryptoMeta)) {
* @param dateTimeFormatter
* dateTimeFormatter
* @return temporal object
* @throws SQLServerException if parsing error
* @throws SQLServerException
* if parsing error
*/
protected Object getTemporalObjectFromCSVWithFormatter(String valueStrUntrimmed, int srcJdbcType, int srcColOrdinal,
DateTimeFormatter dateTimeFormatter) throws SQLServerException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ final String getName() {
}

DriverPropertyInfo build(Properties connProperties) {
String propValue = name
.equals(SQLServerDriverStringProperty.PASSWORD.toString()) ? "" : connProperties.getProperty(name);
String propValue = name.equals(SQLServerDriverStringProperty.PASSWORD.toString()) ? "" : connProperties
.getProperty(name);

if (null == propValue)
propValue = defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ final int getErrorCode() {
* SQLServerExceptions are written to any open log files the user has specified.
*/
public final class SQLServerException extends java.sql.SQLException {
/**
* Always update serialVersionUID when prompted
*/
private static final long serialVersionUID = -2195310557661496761L;
static final String EXCEPTION_XOPEN_CONNECTION_CANT_ESTABLISH = "08001";
static final String EXCEPTION_XOPEN_CONNECTION_DOES_NOT_EXIST = "08003";
static final String EXCEPTION_XOPEN_CONNECTION_FAILURE = "08006"; // After connection was connected OK
Expand Down Expand Up @@ -142,26 +146,26 @@ static String getErrString(String errCode) {
* @param cause
* The exception that caused this exception
*/
public SQLServerException(String errText, SQLState sqlState, DriverError driverError, Throwable cause) {
SQLServerException(String errText, SQLState sqlState, DriverError driverError, Throwable cause) {
this(errText, sqlState.getSQLStateCode(), driverError.getErrorCode(), cause);
}

public SQLServerException(String errText, String errState, int errNum, Throwable cause) {
SQLServerException(String errText, String errState, int errNum, Throwable cause) {
super(errText, errState, errNum);
initCause(cause);
logException(null, errText, true);
ActivityCorrelator.setCurrentActivityIdSentFlag(); // set the activityid flag so that we don't send the current
// ActivityId later.
}

public SQLServerException(String errText, Throwable cause) {
SQLServerException(String errText, Throwable cause) {
super(errText);
initCause(cause);
logException(null, errText, true);
ActivityCorrelator.setCurrentActivityIdSentFlag();
}

public SQLServerException(Object obj, String errText, String errState, int errNum, boolean bStack) {
SQLServerException(Object obj, String errText, String errState, int errNum, boolean bStack) {
super(errText, errState, errNum);
logException(obj, errText, bStack);
ActivityCorrelator.setCurrentActivityIdSentFlag();
Expand All @@ -181,7 +185,7 @@ public SQLServerException(Object obj, String errText, String errState, int errNu
* @param bStack
* true to generate the stack trace
*/
public SQLServerException(Object obj, String errText, String errState, StreamError streamError, boolean bStack) {
SQLServerException(Object obj, String errText, String errState, StreamError streamError, boolean bStack) {
super(errText, errState, streamError.getErrorNumber());

// Log SQL error with info from StreamError.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ static final void throwBatchUpdateException(SQLServerException lastError,
throw new BatchUpdateException(lastError.getMessage(), lastError.getSQLState(), lastError.getErrorCode(),
updateCounts, new Throwable(lastError.getMessage()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2020,8 +2020,7 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL
} catch (SQLException e) {
// throw a BatchUpdateException with the given error message, and return null for the updateCounts.
throw new BatchUpdateException(e.getMessage(), null, 0, null);
}
catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
// If we fail with IllegalArgumentException, fall back to the original batch insert logic.
if (getStatementLogger().isLoggable(java.util.logging.Level.FINE)) {
getStatementLogger().fine("Parsing user's Batch Insert SQL Query failed: " + e.getMessage());
Expand Down Expand Up @@ -2174,8 +2173,7 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio
} catch (SQLException e) {
// throw a BatchUpdateException with the given error message, and return null for the updateCounts.
throw new BatchUpdateException(e.getMessage(), null, 0, null);
}
catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
// If we fail with IllegalArgumentException, fall back to the original batch insert logic.
if (getStatementLogger().isLoggable(java.util.logging.Level.FINE)) {
getStatementLogger().fine("Parsing user's Batch Insert SQL Query failed: " + e.getMessage());
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/microsoft/sqlserver/jdbc/SqlVariant.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ static sqlVariantProbBytes valueOf(int intValue) {
* Holds information regarding the basetype of a sql_variant data.
*
*/
public class SqlVariant {

class SqlVariant {
private int baseType;
private int precision;
private int scale;
Expand Down
38 changes: 16 additions & 22 deletions src/samples/adaptive/src/main/java/executeStoredProcedure.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/*
* Microsoft JDBC Driver for SQL Server
*
* Copyright(c) Microsoft Corporation All rights reserved.
*
* This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
* Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
* available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package adaptive.src.main.java;

Expand All @@ -20,6 +17,7 @@
import com.microsoft.sqlserver.jdbc.SQLServerCallableStatement;
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;


public class executeStoredProcedure {

public static void main(String[] args) {
Expand Down Expand Up @@ -66,7 +64,8 @@ public static void main(String[] args) {
for (int i = 0; i < 4000; i++)
buffer.append((char) ('A'));

PreparedStatement pstmt = con.prepareStatement("UPDATE Document_JDBC_Sample " + "SET DocumentSummary = ? WHERE (DocumentID = 1)");
PreparedStatement pstmt = con.prepareStatement(
"UPDATE Document_JDBC_Sample " + "SET DocumentSummary = ? WHERE (DocumentID = 1)");

pstmt.setString(1, buffer.toString());
pstmt.executeUpdate();
Expand Down Expand Up @@ -118,26 +117,19 @@ public static void main(String[] args) {
// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}
finally {
} finally {
if (rs != null)
try {
rs.close();
}
catch (Exception e) {
}
} catch (Exception e) {}
if (stmt != null)
try {
stmt.close();
}
catch (Exception e) {
}
} catch (Exception e) {}
if (con != null)
try {
con.close();
}
catch (Exception e) {
}
} catch (Exception e) {}
}
}

Expand All @@ -150,19 +142,21 @@ private static void createStoredProcedure(Connection con) throws SQLException {
+ "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + outputProcedure;
stmt.execute(sql);

sql = "CREATE PROCEDURE " + outputProcedure + " @p0 int, @p1 int OUTPUT, @p2 char(50) OUTPUT, " + "@p3 varchar(max) OUTPUT " + " AS"
+ " SELECT top 1 @p1=DocumentID, @p2=Title," + " @p3=DocumentSummary FROM Document_JDBC_Sample where DocumentID = @p0";
sql = "CREATE PROCEDURE " + outputProcedure + " @p0 int, @p1 int OUTPUT, @p2 char(50) OUTPUT, "
+ "@p3 varchar(max) OUTPUT " + " AS" + " SELECT top 1 @p1=DocumentID, @p2=Title,"
+ " @p3=DocumentSummary FROM Document_JDBC_Sample where DocumentID = @p0";

stmt.execute(sql);
}

private static void createTable(Connection con) throws SQLException {
Statement stmt = con.createStatement();

stmt.execute("if exists (select * from sys.objects where name = 'Document_JDBC_Sample')" + "drop table Document_JDBC_Sample");
stmt.execute("if exists (select * from sys.objects where name = 'Document_JDBC_Sample')"
+ "drop table Document_JDBC_Sample");

String sql = "CREATE TABLE Document_JDBC_Sample(" + "[DocumentID] [int] NOT NULL identity," + "[Title] [char](50) NOT NULL,"
+ "[DocumentSummary] [varchar](max) NULL)";
String sql = "CREATE TABLE Document_JDBC_Sample(" + "[DocumentID] [int] NOT NULL identity,"
+ "[Title] [char](50) NOT NULL," + "[DocumentSummary] [varchar](max) NULL)";

stmt.execute(sql);

Expand Down
37 changes: 15 additions & 22 deletions src/samples/adaptive/src/main/java/readLargeData.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/*
* Microsoft JDBC Driver for SQL Server
*
* Copyright(c) Microsoft Corporation All rights reserved.
*
* This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
* Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
* available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package adaptive.src.main.java;

Expand All @@ -19,6 +16,7 @@

import com.microsoft.sqlserver.jdbc.SQLServerStatement;


public class readLargeData {

public static void main(String[] args) {
Expand Down Expand Up @@ -48,8 +46,8 @@ public static void main(String[] args) {
password = br.readLine();

// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://" + serverName + ":" + portNumber + ";" + "databaseName=" + databaseName + ";username="
+ username + ";password=" + password + ";";
String connectionUrl = "jdbc:sqlserver://" + serverName + ":" + portNumber + ";" + "databaseName="
+ databaseName + ";username=" + username + ";password=" + password + ";";

// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Expand All @@ -62,7 +60,8 @@ public static void main(String[] args) {
for (int i = 0; i < 4000; i++)
buffer.append((char) ('A'));

PreparedStatement pstmt = con.prepareStatement("UPDATE Document_JDBC_Sample " + "SET DocumentSummary = ? WHERE (DocumentID = 1)");
PreparedStatement pstmt = con.prepareStatement(
"UPDATE Document_JDBC_Sample " + "SET DocumentSummary = ? WHERE (DocumentID = 1)");

pstmt.setString(1, buffer.toString());
pstmt.executeUpdate();
Expand Down Expand Up @@ -102,36 +101,30 @@ public static void main(String[] args) {
// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}
finally {
} finally {
if (rs != null)
try {
rs.close();
}
catch (Exception e) {
}
} catch (Exception e) {}
if (stmt != null)
try {
stmt.close();
}
catch (Exception e) {
}
} catch (Exception e) {}
if (con != null)
try {
con.close();
}
catch (Exception e) {
}
} catch (Exception e) {}
}
}

private static void createTable(Connection con) throws SQLException {
Statement stmt = con.createStatement();

stmt.execute("if exists (select * from sys.objects where name = 'Document_JDBC_Sample')" + "drop table Document_JDBC_Sample");
stmt.execute("if exists (select * from sys.objects where name = 'Document_JDBC_Sample')"
+ "drop table Document_JDBC_Sample");

String sql = "CREATE TABLE Document_JDBC_Sample (" + "[DocumentID] [int] NOT NULL identity," + "[Title] [char](50) NOT NULL,"
+ "[DocumentSummary] [varchar](max) NULL)";
String sql = "CREATE TABLE Document_JDBC_Sample (" + "[DocumentID] [int] NOT NULL identity,"
+ "[Title] [char](50) NOT NULL," + "[DocumentSummary] [varchar](max) NULL)";

stmt.execute(sql);

Expand Down
Loading