Skip to content

Commit

Permalink
NEW: Queue managing with DB2 ODBC connections
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperl22 committed Sep 25, 2020
1 parent 5c6bef7 commit 8ee8a02
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 49 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
}
],
"require": {
"php": "^7.2.5",
"illuminate/database": "^7.0"
"php": "^7.2",
"illuminate/database": "^6.0"
},
"require-dev": {
},
"autoload": {
"psr-4": {
"Cooperl\\Database\\DB2\\": "src/"
"Cooperl\\DB2\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Cooperl\\Database\\DB2\\DB2ServiceProvider"
"Cooperl\\DB2\\DB2ServiceProvider"
]
}
}
Expand Down
24 changes: 19 additions & 5 deletions src/DB2ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?php

namespace Cooperl\Database\DB2;
namespace Cooperl\DB2;

use Illuminate\Foundation\Application as LaravelApplication;
use Laravel\Lumen\Application as LumenApplication;
use Cooperl\Database\DB2\Connectors\ODBCConnector;
use Cooperl\Database\DB2\Connectors\IBMConnector;
use Cooperl\Database\DB2\Connectors\ODBCZOSConnector;
use Cooperl\DB2\Database\DB2Connection;
use Cooperl\DB2\Database\Connectors\ODBCConnector;
use Cooperl\DB2\Database\Connectors\IBMConnector;
use Cooperl\DB2\Database\Connectors\ODBCZOSConnector;
use Cooperl\DB2\Queue\DB2Connector;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\ServiceProvider;

/**
* Class DB2ServiceProvider
*
* @package Cooperl\Database\DB2
* @package Cooperl\DB2\Database
*/
class DB2ServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -84,6 +87,17 @@ public function register()
return new DB2Connection($db2Connection, $config["database"], $config["prefix"], $config);
});
}

$this->app->extend(
'queue',
function (QueueManager $queueManager) {
$queueManager->addConnector('db2_odbc', function () {
return new DB2Connector($this->app['db']);
});

return $queueManager;
}
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

namespace Cooperl\Database\DB2\Connectors;
namespace Cooperl\DB2\Database\Connectors;

use Illuminate\Database\Connectors\Connector;
use Illuminate\Database\Connectors\ConnectorInterface;

/**
* Class IBMConnector
*
* @package Cooperl\Database\DB2\Connectors
* @package Cooperl\DB2\Database\Connectors
*/
class DB2Connector extends Connector implements ConnectorInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Cooperl\Database\DB2\Connectors;
namespace Cooperl\DB2\Database\Connectors;

/**
* Class IBMConnector
*
* @package Cooperl\Database\DB2\Connectors
* @package Cooperl\DB2\Database\Connectors
*/
class IBMConnector extends DB2Connector
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Cooperl\Database\DB2\Connectors;
namespace Cooperl\DB2\Database\Connectors;

/**
* Class ODBCConnector
*
* @package Cooperl\Database\DB2\Connectors
* @package Cooperl\DB2\Database\Connectors
*/
class ODBCConnector extends DB2Connector
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Cooperl\Database\DB2\Connectors;
namespace Cooperl\DB2\Database\Connectors;

/**
* Class ODBCZOSConnector
*
* @package Cooperl\Database\DB2\Connectors
* @package Cooperl\DB2\Database\Connectors
*/
class ODBCZOSConnector extends ODBCConnector
{
Expand Down
20 changes: 10 additions & 10 deletions src/DB2Connection.php → src/Database/DB2Connection.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php

namespace Cooperl\Database\DB2;
namespace Cooperl\DB2\Database;

use PDO;

use Illuminate\Database\Connection;

use Cooperl\Database\DB2\Schema\Builder;
use Cooperl\Database\DB2\Query\Processors\DB2Processor;
use Cooperl\Database\DB2\Query\Processors\DB2ZOSProcessor;
use Cooperl\Database\DB2\Query\Grammars\DB2Grammar as QueryGrammar;
use Cooperl\Database\DB2\Schema\Grammars\DB2Grammar as SchemaGrammar;
use Cooperl\Database\DB2\Schema\Grammars\DB2ExpressCGrammar;
use Cooperl\DB2\Database\Schema\Builder;
use Cooperl\DB2\Database\Query\Processors\DB2Processor;
use Cooperl\DB2\Database\Query\Processors\DB2ZOSProcessor;
use Cooperl\DB2\Database\Query\Grammars\DB2Grammar as QueryGrammar;
use Cooperl\DB2\Database\Schema\Grammars\DB2Grammar as SchemaGrammar;
use Cooperl\DB2\Database\Schema\Grammars\DB2ExpressCGrammar;

/**
* Class DB2Connection
*
* @package Cooperl\Database\DB2
* @package Cooperl\DB2\Database
*/
class DB2Connection extends Connection
{
Expand Down Expand Up @@ -86,7 +86,7 @@ public function executeCommand($command)
/**
* Get a schema builder instance for the connection.
*
* @return \Cooperl\Database\DB2\Schema\Builder
* @return \Cooperl\DB2\Database\Schema\Builder
*/
public function getSchemaBuilder()
{
Expand Down Expand Up @@ -133,7 +133,7 @@ protected function getDefaultSchemaGrammar()
/**
* Get the default post processor instance.
*
* @return \Cooperl\Database\DB2\Query\Processors\DB2Processor|\Cooperl\Database\DB2\Query\Processors\DB2ZOSProcessor
* @return \Cooperl\DB2\Database\Query\Processors\DB2Processor|\Cooperl\DB2\Database\Query\Processors\DB2ZOSProcessor
*/
protected function getDefaultPostProcessor()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

namespace Cooperl\Database\DB2\Query\Grammars;
namespace Cooperl\DB2\Database\Query\Grammars;

use Illuminate\Database\Query\Grammars\Grammar;
use Illuminate\Database\Query\Builder;

/**
* Class DB2Grammar
*
* @package Cooperl\Database\DB2\Query\Grammars
* @package Cooperl\DB2\Database\Query\Grammars
*/
class DB2Grammar extends Grammar
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

namespace Cooperl\Database\DB2\Query\Processors;
namespace Cooperl\DB2\Database\Query\Processors;

use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Processors\Processor;
use Cooperl\Database\DB2\Query\Grammars\DB2Grammar;
use Cooperl\DB2\Database\Query\Grammars\DB2Grammar;

/**
* Class DB2Processor
*
* @package Cooperl\Database\DB2\Query\Processors
* @package Cooperl\DB2\Database\Query\Processors
*/
class DB2Processor extends Processor
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

namespace Cooperl\Database\DB2\Query\Processors;
namespace Cooperl\DB2\Database\Query\Processors;

use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Processors\Processor;
use Cooperl\Database\DB2\Query\Grammars\DB2Grammar;
use Cooperl\DB2\Database\Query\Grammars\DB2Grammar;

/**
* Class DB2ZOSProcessor
*
* @package Cooperl\Database\DB2\Query\Processors
* @package Cooperl\DB2\Database\Query\Processors
*/
class DB2ZOSProcessor extends Processor
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

namespace Cooperl\Database\DB2\Schema;
namespace Cooperl\DB2\Database\Schema;

use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Grammars\Grammar;

/**
* Class Blueprint
*
* @package Cooperl\Database\DB2\Schema
* @package Cooperl\DB2\Database\Schema
*/
class Blueprint extends \Illuminate\Database\Schema\Blueprint
{
Expand Down
8 changes: 4 additions & 4 deletions src/Schema/Builder.php → src/Database/Schema/Builder.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

namespace Cooperl\Database\DB2\Schema;
namespace Cooperl\DB2\Database\Schema;

use Closure;
use Illuminate\Database\Schema\Blueprint;

/**
* Class Builder
*
* @package Cooperl\Database\DB2\Schema
* @package Cooperl\DB2\Database\Schema
*/
class Builder extends \Illuminate\Database\Schema\Builder
{
Expand Down Expand Up @@ -76,14 +76,14 @@ protected function build(Blueprint $blueprint)
* @param string $table
* @param \Closure $callback
*
* @return \Cooperl\Database\DB2\Schema\Blueprint
* @return \Cooperl\DB2\Database\Schema\Blueprint
*/
protected function createBlueprint($table, Closure $callback = null)
{
if (isset($this->resolver)) {
return call_user_func($this->resolver, $table, $callback);
}

return new \Cooperl\Database\DB2\Schema\Blueprint($table, $callback);
return new \Cooperl\DB2\Database\Schema\Blueprint($table, $callback);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<?php

namespace Cooperl\Database\DB2\Schema\Grammars;

use Illuminate\Database\Query\Expression;
use Illuminate\Support\Fluent;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Grammars\Grammar;
use Illuminate\Database\Schema\Blueprint;
namespace Cooperl\DB2\Database\Schema\Grammars;

class DB2ExpressCGrammar extends DB2Grammar
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Cooperl\Database\DB2\Schema\Grammars;
namespace Cooperl\DB2\Database\Schema\Grammars;

use Illuminate\Database\Query\Expression;
use Illuminate\Support\Fluent;
Expand Down
24 changes: 24 additions & 0 deletions src/Queue/DB2Connector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Cooperl\DB2\Queue;

use Illuminate\Queue\Connectors\DatabaseConnector;

class DB2Connector extends DatabaseConnector
{
/**
* Establish a queue connection.
*
* @param array $config
* @return \Illuminate\Contracts\Queue\Queue
*/
public function connect(array $config)
{
return new DB2Queue(
$this->connections->connection($config['connection'] ?? null),
$config['table'],
$config['queue'],
$config['retry_after'] ?? 60
);
}
}
18 changes: 18 additions & 0 deletions src/Queue/DB2Queue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Cooperl\DB2\Queue;

use Illuminate\Queue\DatabaseQueue;

class DB2Queue extends DatabaseQueue
{

/**
* {@inheritdoc}
*/
public function getLockForPopping()
{
return true;
}

}

0 comments on commit 8ee8a02

Please sign in to comment.