Skip to content

Commit 98c29d4

Browse files
committed
insert folder structure/files
1 parent 991455a commit 98c29d4

File tree

16 files changed

+813
-0
lines changed

16 files changed

+813
-0
lines changed

05-Availability/fg/app/pom.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.sqldbsamples</groupId>
5+
<artifactId>SqlDbSample</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.0.0</version>
8+
<name>SqlDbSample</name>
9+
<url>http://maven.apache.org</url>
10+
<dependencies>
11+
<dependency>
12+
<groupId>junit</groupId>
13+
<artifactId>junit</artifactId>
14+
<version>3.8.1</version>
15+
<scope>test</scope>
16+
</dependency>
17+
<dependency>
18+
<groupId>com.microsoft.sqlserver</groupId>
19+
<artifactId>mssql-jdbc</artifactId>
20+
<version>6.1.0.jre8</version>
21+
</dependency>
22+
</dependencies>
23+
<properties>
24+
<maven.compiler.source>1.8</maven.compiler.source>
25+
<maven.compiler.target>1.8</maven.compiler.target>
26+
</properties>
27+
<build>
28+
<plugins>
29+
<plugin>
30+
<groupId>org.apache.maven.plugins</groupId>
31+
<artifactId>maven-jar-plugin</artifactId>
32+
<version>3.0.0</version>
33+
<configuration>
34+
<archive>
35+
<manifest>
36+
<mainClass>com.sqldbsamples.App</mainClass>
37+
</manifest>
38+
</archive>
39+
</configuration>
40+
</plugin>
41+
</plugins>
42+
</build>
43+
</project>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.sqldbsamples;
2+
3+
import java.sql.Connection;
4+
import java.sql.Statement;
5+
import java.sql.PreparedStatement;
6+
import java.sql.ResultSet;
7+
import java.sql.Timestamp;
8+
import java.sql.DriverManager;
9+
import java.util.Date;
10+
import java.util.concurrent.TimeUnit;
11+
12+
public class App {
13+
14+
// UPDATE WITH YOUR INFO
15+
private static final String FAILOVER_GROUP_NAME = "aw-server-fg-ID"; // add workshop ID
16+
// UPDATE WITH YOUR INFO
17+
private static final String DB_NAME = "AdventureWorksID"; // add workshop ID
18+
// UPDATE WITH YOUR INFO
19+
private static final String USER = "cloudadmin"; // add database user
20+
// UPDATE WITH YOUR INFO
21+
private static final String PASSWORD = "password"; // add database password
22+
// DO NOT MODIFY
23+
private static final String READ_WRITE_URL = String.format("jdbc:" +
24+
"sqlserver://%s.database.windows.net:1433;database=%s;user=%s;password=%s;encrypt=true;" +
25+
"hostNameInCertificate=*.database.windows.net;loginTimeout=30;",
26+
FAILOVER_GROUP_NAME, DB_NAME, USER, PASSWORD);
27+
private static final String READ_ONLY_URL = String.format("jdbc:" +
28+
"sqlserver://%s.secondary.database.windows.net:1433;database=%s;user=%s;password=%s;encrypt=true;" +
29+
"hostNameInCertificate=*.database.windows.net;loginTimeout=30;",
30+
FAILOVER_GROUP_NAME, DB_NAME, USER, PASSWORD);
31+
32+
public static void main(String[] args) {
33+
System.out.println("#######################################");
34+
System.out.println("## GEO DISTRIBUTED DATABASE TUTORIAL ##");
35+
System.out.println("#######################################");
36+
System.out.println("");
37+
38+
int highWaterMark = getHighWaterMarkId();
39+
40+
try {
41+
for(int i = 1; i < 1000; i++) {
42+
// loop will run for about 1 hour
43+
System.out.print(i + ": insert on primary " +
44+
(insertData((highWaterMark + i))?"successful":"failed"));
45+
TimeUnit.SECONDS.sleep(1);
46+
System.out.print(", read from secondary " +
47+
(selectData((highWaterMark + i))?"successful":"failed") + "\n");
48+
TimeUnit.SECONDS.sleep(3);
49+
}
50+
} catch(Exception e) {
51+
e.printStackTrace();
52+
}
53+
}
54+
55+
private static boolean insertData(int id) {
56+
// Insert data into the product table with a unique product name so we can find the product again
57+
String sql = "INSERT INTO SalesLT.Product " +
58+
"(Name, ProductNumber, Color, StandardCost, ListPrice, SellStartDate) VALUES (?,?,?,?,?,?);";
59+
60+
try (Connection connection = DriverManager.getConnection(READ_WRITE_URL);
61+
PreparedStatement pstmt = connection.prepareStatement(sql)) {
62+
pstmt.setString(1, "BrandNewProduct" + id);
63+
pstmt.setInt(2, 200989 + id + 10000);
64+
pstmt.setString(3, "Blue");
65+
pstmt.setDouble(4, 75.00);
66+
pstmt.setDouble(5, 89.99);
67+
pstmt.setTimestamp(6, new Timestamp(new Date().getTime()));
68+
return (1 == pstmt.executeUpdate());
69+
} catch (Exception e) {
70+
return false;
71+
}
72+
}
73+
74+
private static boolean selectData(int id) {
75+
// Query the data previously inserted into the primary database from the geo replicated database
76+
String sql = "SELECT Name, Color, ListPrice FROM SalesLT.Product WHERE Name = ?";
77+
78+
try (Connection connection = DriverManager.getConnection(READ_ONLY_URL);
79+
PreparedStatement pstmt = connection.prepareStatement(sql)) {
80+
pstmt.setString(1, "BrandNewProduct" + id);
81+
try (ResultSet resultSet = pstmt.executeQuery()) {
82+
return resultSet.next();
83+
}
84+
} catch (Exception e) {
85+
return false;
86+
}
87+
}
88+
89+
private static int getHighWaterMarkId() {
90+
// Query the high water mark id stored in the table to be able to make unique inserts
91+
String sql = "SELECT MAX(ProductId) FROM SalesLT.Product";
92+
int result = 1;
93+
try (Connection connection = DriverManager.getConnection(READ_WRITE_URL);
94+
Statement stmt = connection.createStatement();
95+
ResultSet resultSet = stmt.executeQuery(sql)) {
96+
if (resultSet.next()) {
97+
result = resultSet.getInt(1);
98+
}
99+
} catch (Exception e) {
100+
e.printStackTrace();
101+
}
102+
return result;
103+
}
104+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.sqldbsamples;
2+
3+
import junit.framework.Test;
4+
import junit.framework.TestCase;
5+
import junit.framework.TestSuite;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
extends TestCase
12+
{
13+
/**
14+
* Create the test case
15+
*
16+
* @param testName name of the test case
17+
*/
18+
public AppTest( String testName )
19+
{
20+
super( testName );
21+
}
22+
23+
/**
24+
* @return the suite of tests being tested
25+
*/
26+
public static Test suite()
27+
{
28+
return new TestSuite( AppTest.class );
29+
}
30+
31+
/**
32+
* Rigourous Test :-)
33+
*/
34+
public void testApp()
35+
{
36+
assertTrue( true );
37+
}
38+
}
Binary file not shown.
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#Created by Apache Maven 3.6.3
2+
#Thu Feb 06 20:52:45 UTC 2020
3+
version=1.0.0
4+
groupId=com.sqldbsamples
5+
artifactId=SqlDbSample
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com\sqldbsamples\App.class
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:\Users\antho\SqlDbSample\src\main\java\com\sqldbsamples\App.java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com\sqldbsamples\AppTest.class
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:\Users\vmuser\sqlworkshops\AzureSQLWorkshop\azuresqlworkshop\05-Availability\fg\app\src\test\java\com\sqldbsamples\AppTest.java
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<testsuite tests="1" failures="0" name="com.sqldbsamples.AppTest" time="0.002" errors="0" skipped="0">
3+
<properties>
4+
<property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
5+
<property name="sun.boot.library.path" value="C:\Program Files\Java\jdk1.8.0_241\jre\bin"/>
6+
<property name="java.vm.version" value="25.241-b07"/>
7+
<property name="java.vm.vendor" value="Oracle Corporation"/>
8+
<property name="maven.multiModuleProjectDirectory" value="C:\Users\vmuser\sqlworkshops\AzureSQLWorkshop\azuresqlworkshop\05-Availability\fg\app"/>
9+
<property name="java.vendor.url" value="http://java.oracle.com/"/>
10+
<property name="path.separator" value=";"/>
11+
<property name="guice.disable.misplaced.annotation.check" value="true"/>
12+
<property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/>
13+
<property name="file.encoding.pkg" value="sun.io"/>
14+
<property name="user.script" value=""/>
15+
<property name="user.country" value="US"/>
16+
<property name="sun.java.launcher" value="SUN_STANDARD"/>
17+
<property name="sun.os.patch.level" value=""/>
18+
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
19+
<property name="user.dir" value="C:\Users\vmuser\sqlworkshops\AzureSQLWorkshop\azuresqlworkshop\05-Availability\fg\app"/>
20+
<property name="java.runtime.version" value="1.8.0_241-b07"/>
21+
<property name="java.awt.graphicsenv" value="sun.awt.Win32GraphicsEnvironment"/>
22+
<property name="java.endorsed.dirs" value="C:\Program Files\Java\jdk1.8.0_241\jre\lib\endorsed"/>
23+
<property name="os.arch" value="amd64"/>
24+
<property name="java.io.tmpdir" value="C:\Users\vmuser\AppData\Local\Temp\"/>
25+
<property name="line.separator" value="
26+
"/>
27+
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
28+
<property name="user.variant" value=""/>
29+
<property name="os.name" value="Windows 10"/>
30+
<property name="classworlds.conf" value="C:\Program Files\apache-maven-3.6.3\bin\..\bin\m2.conf"/>
31+
<property name="sun.jnu.encoding" value="Cp1252"/>
32+
<property name="java.library.path" value="C:\Program Files\Java\jdk1.8.0_241\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program Files\Java\jdk1.8.0_241\bin;C:\Program Files\apache-maven-3.6.3\bin;C:\Program Files\Microsoft Corporation\RMLUtils;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Git\cmd;C:\Users\vmuser\AppData\Local\Microsoft\WindowsApps;;C:\Users\vmuser\AppData\Local\Programs\Azure Data Studio\bin;."/>
33+
<property name="maven.conf" value="C:\Program Files\apache-maven-3.6.3\bin\../conf"/>
34+
<property name="java.specification.name" value="Java Platform API Specification"/>
35+
<property name="java.class.version" value="52.0"/>
36+
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
37+
<property name="os.version" value="10.0"/>
38+
<property name="library.jansi.path" value="C:\Program Files\apache-maven-3.6.3\bin\..\lib\jansi-native"/>
39+
<property name="user.home" value="C:\Users\vmuser"/>
40+
<property name="user.timezone" value="UTC"/>
41+
<property name="java.awt.printerjob" value="sun.awt.windows.WPrinterJob"/>
42+
<property name="java.specification.version" value="1.8"/>
43+
<property name="file.encoding" value="Cp1252"/>
44+
<property name="user.name" value="vmuser"/>
45+
<property name="java.class.path" value="C:\Program Files\apache-maven-3.6.3\bin\..\boot\plexus-classworlds-2.6.0.jar"/>
46+
<property name="java.vm.specification.version" value="1.8"/>
47+
<property name="sun.arch.data.model" value="64"/>
48+
<property name="java.home" value="C:\Program Files\Java\jdk1.8.0_241\jre"/>
49+
<property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher package"/>
50+
<property name="java.specification.vendor" value="Oracle Corporation"/>
51+
<property name="user.language" value="en"/>
52+
<property name="awt.toolkit" value="sun.awt.windows.WToolkit"/>
53+
<property name="java.vm.info" value="mixed mode"/>
54+
<property name="java.version" value="1.8.0_241"/>
55+
<property name="java.ext.dirs" value="C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext;C:\windows\Sun\Java\lib\ext"/>
56+
<property name="sun.boot.class.path" value="C:\Program Files\Java\jdk1.8.0_241\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_241\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_241\jre\classes"/>
57+
<property name="sun.stderr.encoding" value="cp437"/>
58+
<property name="java.vendor" value="Oracle Corporation"/>
59+
<property name="maven.home" value="C:\Program Files\apache-maven-3.6.3\bin\.."/>
60+
<property name="file.separator" value="\"/>
61+
<property name="java.vendor.url.bug" value="http://bugreport.sun.com/bugreport/"/>
62+
<property name="sun.cpu.endian" value="little"/>
63+
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
64+
<property name="sun.stdout.encoding" value="cp437"/>
65+
<property name="sun.desktop" value="windows"/>
66+
<property name="sun.cpu.isalist" value="amd64"/>
67+
</properties>
68+
<testcase classname="com.sqldbsamples.AppTest" name="testApp" time="0.002"/>
69+
</testsuite>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-------------------------------------------------------------------------------
2+
Test set: com.sqldbsamples.AppTest
3+
-------------------------------------------------------------------------------
4+
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.033 sec
Binary file not shown.

0 commit comments

Comments
 (0)