TT#81154 subscriber_profile DAO

Change-Id: Ib14ec6ac92bcd295bb0f793677799f2d13cc141c
changes/71/39971/1
Rene Krenn 5 years ago
parent 8e4de26084
commit 6f3ed53106

@ -0,0 +1,114 @@
package NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_subscriber_profiles;
use strict;
## no critic
use NGCP::BulkProcessor::ConnectorPool qw(
get_provisioning_db
);
use NGCP::BulkProcessor::SqlProcessor qw(
checktableinfo
copy_row
);
use NGCP::BulkProcessor::SqlRecord qw();
require Exporter;
our @ISA = qw(Exporter NGCP::BulkProcessor::SqlRecord);
our @EXPORT_OK = qw(
gettablename
check_table
findby_setid_name
);
my $tablename = 'voip_subscriber_profiles';
my $get_db = \&get_provisioning_db;
my $expected_fieldnames = [
'id',
'set_id',
'name',
'description',
'set_default',
];
my $indexes = {};
sub new {
my $class = shift;
my $self = NGCP::BulkProcessor::SqlRecord->new($class,$get_db,
$tablename,$expected_fieldnames,$indexes);
copy_row($self,shift,$expected_fieldnames);
return $self;
}
sub findby_setid_name {
my ($set_id,$name,$load_recursive) = @_;
check_table();
my $db = &$get_db();
my $table = $db->tableidentifier($tablename);
my $stmt = 'SELECT * FROM ' . $table;
#' WHERE h.name = ? AND g.name = ?';
my @params = ();
my @terms = ();
if (defined $set_id) {
push(@terms,'set_id = ?');
push(@params,$set_id);
}
if (defined $name) {
push(@terms,'name = ?');
push(@params,$name);
}
$stmt .= ' WHERE ' . join(' AND ',@terms) if (scalar @terms) > 0;
my $rows = $db->db_get_all_arrayref($stmt,@params);
return buildrecords_fromrows($rows,$load_recursive);
}
sub buildrecords_fromrows {
my ($rows,$load_recursive) = @_;
my @records = ();
my $record;
if (defined $rows and ref $rows eq 'ARRAY') {
foreach my $row (@$rows) {
$record = __PACKAGE__->new($row);
# transformations go here ...
push @records,$record;
}
}
return \@records;
}
sub gettablename {
return $tablename;
}
sub check_table {
return checktableinfo($get_db,
__PACKAGE__,$tablename,
$expected_fieldnames,
$indexes);
}
1;
Loading…
Cancel
Save