Search This Blog

Thursday, September 10, 2020

Binding Y/N to Angular Checkbox

By default, Angular and Material checkboxes bind to boolean properties.


export class MyComponent {

    isActive:boolean = true

}

<input type="checkbox" [(ngModel)]="isActive"/>

 

<mat-checkbox [(ngModel)]="isActive">Check me</mat-checkbox>



But what if you have a string indicating a boolean state, especially if we are using databases not supported boolean. For example, we often use “Y”, “N” as boolean indicators in the database. Let’s explore a few ways of doing this.


Using Checked and Change Event Binding

We can separately bind the checked property and the change event for the checkbox.



export class MyComponent {

    strValue: String = "Y"

}


<input type="checkbox"

  [checked]="strValue === 'Y'" 

  (change)="strValue = $event.target.checked ? 'Y' : 'N'"/>


Using Property Accessor

Another approach is to define a new property in the component that simply maps the String or number values to boolean using property accessors.



export class MyComponent {

    isActive: number = 1

 

  get isActiveBool() {

    return this.isActive == 1

  }

 

  set isActiveBool(newValue:boolean) {

    this.isActive = newValue ? 1 : 0

  }

}

This will define a new property called isActiveBool which is just the isActive property converted to a boolean. Now you can bind this new property to a checkbox.


<input type="checkbox" [(ngModel)]="isActiveBool"/>

 

<mat-checkbox [(ngModel)]="isActiveBool">Check me</mat-checkbox>


I find this second approach cleaner. It also gives you a chance to do more complex mapping from any data type to boolean.

Wednesday, September 9, 2020

How to Manually Cleanup Oracle Advanced Queuing Tables

When the queue table is locked and not able to proceed, then the simplest way to rectify is to drop the queue table forcefully and create again using below sql.

BEGIN

 DBMS_AQADM.DROP_QUEUE_TABLE (

   queue_table         => 'queue_table',

   force               => TRUE,   auto_commit         => TRUE

 );

End;

/

Typical scenarios when a queue table/queue cannot be dropped

i) Cannot create or drop queue table DBMS_AQADM.CREATE_QUEUE_TABLE results in an

ORA-24001 cannot create QUEUE_TABLE, string already exists

Cause: The queue table already exists in the queueing system.

Action: Drop the table first using the DROP_QUEUE_TABLE() command or specify another table.

while DBMS_AQADM.DROP_QUEUE_TABLE results in an

ORA-24002 QUEUE_TABLE string does not exist

Cause: QUEUE_TABLE does not exist.

Action: Query on the user view USER_QUEUE_TABLES to find out existing queue tables.

ii) Cannot create or drop queue DBMS_AQADM.CREATE_QUEUE results in an

ORA-24006 cannot create QUEUE, string already exists

Cause: The queue requested to be created already exists.

Action: Specify another queue name. Query USER_QUEUES for all the

existing queues in the users's schema.

while executing DBMS_AQADM.DROP_QUEUE results in an

ORA-24010 QUEUE string does not exist

Cause: The specified queue does not exist.

Action: Specify a valid queue. Query USER_QUEUES for all the valid queues.