Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
7ac6d891
Commit
7ac6d891
authored
Jun 13, 2012
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Sharding] Add SQL Azure examples
parent
94414675
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
298 additions
and
0 deletions
+298
-0
README.md
examples/sharding/README.md
+26
-0
bootstrap.php
examples/sharding/bootstrap.php
+26
-0
composer.json
examples/sharding/composer.json
+6
-0
create_schema.php
examples/sharding/create_schema.php
+51
-0
insert_data.php
examples/sharding/insert_data.php
+132
-0
insert_data_aftersplit.php
examples/sharding/insert_data_aftersplit.php
+27
-0
query_filtering_off.php
examples/sharding/query_filtering_off.php
+8
-0
query_filtering_on.php
examples/sharding/query_filtering_on.php
+9
-0
split_federation.php
examples/sharding/split_federation.php
+5
-0
view_federation_members.php
examples/sharding/view_federation_members.php
+8
-0
No files found.
examples/sharding/README.md
0 → 100644
View file @
7ac6d891
# Sharding with SQLAzure Example
This example demonstrates Sharding with SQL Azure Federations.
## Requirements
1.
Windows Azure Account
2.
SQL Azure Database
3.
Composer for dependencies
## Install
composer install
Change "examples/sharding/bootstrap.php" to contain Database connection.
## Order to execute Scripts
1.
create_schema.php
2.
view_federation_members.php
3.
insert_data.php
4.
split_federation.php
5.
insert_data_after_split.php
6.
query_filtering_off.php
7.
query_filtering_on.php
examples/sharding/bootstrap.php
0 → 100644
View file @
7ac6d891
<?php
// bootstrap.php
use
Doctrine\DBAL\DriverManager
;
use
Doctrine\Shards\DBAL\SQLAzure\SQLAzureShardManager
;
require_once
"vendor/composer/autoload.php"
;
$config
=
array
(
'dbname'
=>
'SalesDB'
,
'host'
=>
'tcp:dbname.windows.net'
,
'user'
=>
'user@dbname'
,
'password'
=>
'XXX'
,
'sharding'
=>
array
(
'federationName'
=>
'Orders_Federation'
,
'distributionKey'
=>
'CustId'
,
'distributionType'
=>
'integer'
,
)
);
if
(
$config
[
'host'
]
==
"tcp:dbname.windows.net"
)
{
die
(
"You have to change the configuration to your Azure account.
\n
"
);
}
$conn
=
DriverManager
::
getConnection
(
$config
);
$shardManager
=
new
SQLAzureShardManager
(
$conn
);
examples/sharding/composer.json
0 → 100644
View file @
7ac6d891
{
"require"
:
{
"doctrine/dbal"
:
"*"
,
"doctrine/shards"
:
"0.3"
}
}
examples/sharding/create_schema.php
0 → 100644
View file @
7ac6d891
<?php
// create_schema.php
use
Doctrine\DBAL\Schema\Schema
;
use
Doctrine\Shards\DBAL\SQLAzure\SQLAzureSchemaSynchronizer
;
require_once
'bootstrap.php'
;
$schema
=
new
Schema
();
$products
=
$schema
->
createTable
(
'Products'
);
$products
->
addColumn
(
'ProductID'
,
'integer'
);
$products
->
addColumn
(
'SupplierID'
,
'integer'
);
$products
->
addColumn
(
'ProductName'
,
'string'
);
$products
->
addColumn
(
'Price'
,
'decimal'
,
array
(
'scale'
=>
2
,
'precision'
=>
12
));
$products
->
setPrimaryKey
(
array
(
'ProductID'
));
$products
->
addOption
(
'azure.federated'
,
true
);
$customers
=
$schema
->
createTable
(
'Customers'
);
$customers
->
addColumn
(
'CustomerID'
,
'integer'
);
$customers
->
addColumn
(
'CompanyName'
,
'string'
);
$customers
->
addColumn
(
'FirstName'
,
'string'
);
$customers
->
addColumn
(
'LastName'
,
'string'
);
$customers
->
setPrimaryKey
(
array
(
'CustomerID'
));
$customers
->
addOption
(
'azure.federated'
,
true
);
$customers
->
addOption
(
'azure.federatedOnColumnName'
,
'CustomerID'
);
$orders
=
$schema
->
createTable
(
'Orders'
);
$orders
->
addColumn
(
'CustomerID'
,
'integer'
);
$orders
->
addColumn
(
'OrderID'
,
'integer'
);
$orders
->
addColumn
(
'OrderDate'
,
'datetime'
);
$orders
->
setPrimaryKey
(
array
(
'CustomerID'
,
'OrderID'
));
$orders
->
addOption
(
'azure.federated'
,
true
);
$orders
->
addOption
(
'azure.federatedOnColumnName'
,
'CustomerID'
);
$orderItems
=
$schema
->
createTable
(
'OrderItems'
);
$orderItems
->
addColumn
(
'CustomerID'
,
'integer'
);
$orderItems
->
addColumn
(
'OrderID'
,
'integer'
);
$orderItems
->
addColumn
(
'ProductID'
,
'integer'
);
$orderItems
->
addColumn
(
'Quantity'
,
'integer'
);
$orderItems
->
setPrimaryKey
(
array
(
'CustomerID'
,
'OrderID'
,
'ProductID'
));
$orderItems
->
addOption
(
'azure.federated'
,
true
);
$orderItems
->
addOption
(
'azure.federatedOnColumnName'
,
'CustomerID'
);
// Create the Schema + Federation:
$synchronizer
=
new
SQLAzureSchemaSynchronizer
(
$conn
,
$shardManager
);
// Or jut look at the SQL:
echo
implode
(
"
\n
"
,
$synchronizer
->
getCreateSchema
(
$schema
));
$synchronizer
->
createSchema
(
$schema
);
examples/sharding/insert_data.php
0 → 100644
View file @
7ac6d891
<?php
// insert_data.php
require_once
"bootstrap.php"
;
$shardManager
->
selectShard
(
0
);
$conn
->
insert
(
"Products"
,
array
(
"ProductID"
=>
386
,
"SupplierID"
=>
1001
,
"ProductName"
=>
'Titanium Extension Bracket Left Hand'
,
"Price"
=>
5.25
,
));
$conn
->
insert
(
"Products"
,
array
(
"ProductID"
=>
387
,
"SupplierID"
=>
1001
,
"ProductName"
=>
'Titanium Extension Bracket Right Hand'
,
"Price"
=>
5.25
,
));
$conn
->
insert
(
"Products"
,
array
(
"ProductID"
=>
388
,
"SupplierID"
=>
1001
,
"ProductName"
=>
'Fusion Generator Module 5 kV'
,
"Price"
=>
10.50
,
));
$conn
->
insert
(
"Products"
,
array
(
"ProductID"
=>
389
,
"SupplierID"
=>
1001
,
"ProductName"
=>
'Bypass Filter 400 MHz Low Pass'
,
"Price"
=>
10.50
,
));
$conn
->
insert
(
"Customers"
,
array
(
'CustomerID'
=>
10
,
'CompanyName'
=>
'Van Nuys'
,
'FirstName'
=>
'Catherine'
,
'LastName'
=>
'Abel'
,
));
$conn
->
insert
(
"Customers"
,
array
(
'CustomerID'
=>
20
,
'CompanyName'
=>
'Abercrombie'
,
'FirstName'
=>
'Kim'
,
'LastName'
=>
'Branch'
,
));
$conn
->
insert
(
"Customers"
,
array
(
'CustomerID'
=>
30
,
'CompanyName'
=>
'Contoso'
,
'FirstName'
=>
'Frances'
,
'LastName'
=>
'Adams'
,
));
$conn
->
insert
(
"Customers"
,
array
(
'CustomerID'
=>
40
,
'CompanyName'
=>
'A. Datum Corporation'
,
'FirstName'
=>
'Mark'
,
'LastName'
=>
'Harrington'
,
));
$conn
->
insert
(
"Customers"
,
array
(
'CustomerID'
=>
50
,
'CompanyName'
=>
'Adventure Works'
,
'FirstName'
=>
'Keith'
,
'LastName'
=>
'Harris'
,
));
$conn
->
insert
(
"Customers"
,
array
(
'CustomerID'
=>
60
,
'CompanyName'
=>
'Alpine Ski House'
,
'FirstName'
=>
'Wilson'
,
'LastName'
=>
'Pais'
,
));
$conn
->
insert
(
"Customers"
,
array
(
'CustomerID'
=>
70
,
'CompanyName'
=>
'Baldwin Museum of Science'
,
'FirstName'
=>
'Roger'
,
'LastName'
=>
'Harui'
,
));
$conn
->
insert
(
"Customers"
,
array
(
'CustomerID'
=>
80
,
'CompanyName'
=>
'Blue Yonder Airlines'
,
'FirstName'
=>
'Pilar'
,
'LastName'
=>
'Pinilla'
,
));
$conn
->
insert
(
"Customers"
,
array
(
'CustomerID'
=>
90
,
'CompanyName'
=>
'City Power & Light'
,
'FirstName'
=>
'Kari'
,
'LastName'
=>
'Hensien'
,
));
$conn
->
insert
(
"Customers"
,
array
(
'CustomerID'
=>
100
,
'CompanyName'
=>
'Coho Winery'
,
'FirstName'
=>
'Peter'
,
'LastName'
=>
'Brehm'
,
));
$conn
->
executeUpdate
(
"
DECLARE @orderId INT
DECLARE @customerId INT
SET @orderId = 10
SELECT @customerId = CustomerId FROM Customers WHERE LastName = 'Hensien' and FirstName = 'Kari'
INSERT INTO Orders (CustomerId, OrderId, OrderDate)
VALUES (@customerId, @orderId, GetDate())
INSERT INTO OrderItems (CustomerID, OrderID, ProductID, Quantity)
VALUES (@customerId, @orderId, 388, 4)
SET @orderId = 20
SELECT @customerId = CustomerId FROM Customers WHERE LastName = 'Harui' and FirstName = 'Roger'
INSERT INTO Orders (CustomerId, OrderId, OrderDate)
VALUES (@customerId, @orderId, GetDate())
INSERT INTO OrderItems (CustomerID, OrderID, ProductID, Quantity)
VALUES (@customerId, @orderId, 389, 2)
SET @orderId = 30
SELECT @customerId = CustomerId FROM Customers WHERE LastName = 'Brehm' and FirstName = 'Peter'
INSERT INTO Orders (CustomerId, OrderId, OrderDate)
VALUES (@customerId, @orderId, GetDate())
INSERT INTO OrderItems (CustomerID, OrderID, ProductID, Quantity)
VALUES (@customerId, @orderId, 387, 3)
SET @orderId = 40
SELECT @customerId = CustomerId FROM Customers WHERE LastName = 'Pais' and FirstName = 'Wilson'
INSERT INTO Orders (CustomerId, OrderId, OrderDate)
VALUES (@customerId, @orderId, GetDate())
INSERT INTO OrderItems (CustomerID, OrderID, ProductID, Quantity)
VALUES (@customerId, @orderId, 388, 1)"
);
examples/sharding/insert_data_aftersplit.php
0 → 100644
View file @
7ac6d891
<?php
// insert_data_aftersplit.php
require_once
'bootstrap.php'
;
$newCustomerId
=
55
;
$shardManager
->
selectShard
(
$newCustomerId
);
$conn
->
insert
(
"Customers"
,
array
(
"CustomerID"
=>
$newCustomerId
,
"CompanyName"
=>
"Microsoft"
,
"FirstName"
=>
"Brian"
,
"LastName"
=>
"Swan"
,
));
$conn
->
insert
(
"Orders"
,
array
(
"CustomerID"
=>
55
,
"OrderID"
=>
37
,
"OrderDate"
=>
date
(
'Y-m-d H:i:s'
),
));
$conn
->
insert
(
"OrderItems"
,
array
(
"CustomerID"
=>
55
,
"OrderID"
=>
37
,
"ProductID"
=>
387
,
"Quantity"
=>
1
,
));
examples/sharding/query_filtering_off.php
0 → 100644
View file @
7ac6d891
<?php
// query_filtering_off.php
require_once
"bootstrap.php"
;
$shardManager
->
selectShard
(
0
);
$data
=
$conn
->
fetchAll
(
'SELECT * FROM Customers'
);
print_r
(
$data
);
examples/sharding/query_filtering_on.php
0 → 100644
View file @
7ac6d891
<?php
// query_filtering_on.php
require_once
"bootstrap.php"
;
$shardManager
->
setFilteringEnabled
(
true
);
$shardManager
->
selectShard
(
55
);
$data
=
$conn
->
fetchAll
(
'SELECT * FROM Customers'
);
print_r
(
$data
);
examples/sharding/split_federation.php
0 → 100644
View file @
7ac6d891
<?php
// split_federation.php
require_once
'bootstrap.php'
;
$shardManager
->
splitFederation
(
60
);
examples/sharding/view_federation_members.php
0 → 100644
View file @
7ac6d891
<?php
// view_federation_members.php
require_once
"bootstrap.php"
;
$shards
=
$shardManager
->
getShards
();
foreach
(
$shards
as
$shard
)
{
print_r
(
$shard
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment