Child Rows Getting removed in tree table after executing commit in ADF - oracle-adf

I have a tree table in jspx page, which is based on EO and VO without database. I have added parent and child records in tree table programmatically . After executing commit operation the child rows are getting removed from the GUI. Please help me prevent this.

Related

Is it possible to create a view where deleted rows in the original table are kept

I have a table COMPANY where companies are kept. I want to create a view of that table, let's name it COMPANY_CDC but with one caveat:
When an entry in the original table is deleted, I want to set a deleted flag on the view entry instead of deleting it.
EDIT Why soft deletes? The point is that im performing change data capture using JDBC, and JDBC is only able to capture soft deletes. Inserts / updates are no problem.
If this cannot be done by using a view, what would be an alternative solution?
You can insert deleted values in another table using trigger
, and with join of these two table you can create your view.

Refresh Detail Data Grid in WPF

I have a master and detail page. For Master table i have 4 text box displayed in detail layout and for detail table i have data grid. There is trigger on master table which insert some records in detail table. i want to refresh the detail data grid from database. How i can refresh detail data grid with database changes. Here is image. Data is inserted in upper form and there is trigger on upper form which insert data in detail table. I want to load data inserted by triggers in below grid. I m using Entity Framework and using context.SaveChanges(); to save data in database.
Thanks.
Usually Master details information displayed on same page; If there is your case, it is easy. when you are going to insert something in your master table, You can get updated records from detail tables based on PK. One downsize of this approach is, you need to be 100% sure how much trigger will take time.(I am not sure ADO.Net return status of ExecuteNonquery after insert row in specific table or completion of triggers).
In your case when you saveChanges(), make a request to get details against user. Hopefully it is the easiest way to achieve goal.
But if Master and details pages are separate, or information can be changed from other mean. Then you can use SqlDependency. Please Note that SqlDependency only works with SQL server. It monitor DB changes in specific table, and notify ADO.Net. You can handle SqlDependency.OnChange.

How to prevent a child record from being deleted

When delete a master record a cascade trigger will get fired and delete the records in the child tables.
And I cannot delete a record manually from the table as it got a foreign key relation with child table.
But how can I prevent the child record from being deleted manually from the table. Currently I am able to delete the child record manually and on page loads as the child record is missing and page load fails.
I'm a bit unclear as to why you'd want to have something like this done. You simply don't allow for the deletion of child records on the UI aside from your cascade delete - just don't give the user the option.
If you're worried about some random DBA going in to your database and writing:
delete from childTable where parentId = 5 -- or whatever
then i think you have more things to worry about... such as why people with production database write access are even thinking about manually writing and executing statements such as this on your prod database.
If you still really needed to do something like this. You could potentially write a before delete trigger on all of your child tables to ensure that the parentId doesn't exist in the parent table prior to delete. This would likely cause your cascade delete to fail (i would guess) so you would need to update your cascade delete functionality to disable the trigger before deletion, re-enabling the trigger after. But this would not prevent your "random dba" from just doing something similar by disabling the trigger, deleting a record, and re-enabling.
If you provide a little more information around the specific scenarios of why a child record would "manually" be deleted, might be able to offer more.
I'm not sure who or what would manually delete records from this table, but I would lean towards using DENY permissions with this requirement, and ensure all roles on that database have no delete permissions on that table.
Sample script:
USE [YOUR_DB]
GO
DENY DELETE ON [dbo].[YOUR_TABLE] TO [DOMAIN\user]
GO
Replace [dbo] with relevant schema name and replace [DOMAIN\user] with the relevant user.

How to make SQLDataSource insert into view instead of the underlying table?

We have replaced 20 tables with a consolidated table, that separates each set of data via a "set id" (all the records for table "A" have a set_id of 1, table "B" is 2, etc.).
We then built views on the table, and renamed each so they had the views had the same names as the original 20 tables, with a WHERE to add the set_id. Net result - inserts/updates/selects of the views still work
We did this so our web page, which uses a sqldatasource with "sql command builder", wouldn't have to change. We added an INSTEAD OF INSERT trigger on each view, so that when you insert into the view, it adds the set_id and inserts into the consolidated table. So far, so good.
It partially works: UPDATEs and DELETEs work, because they know the actual ID for the record.
However INSERTs don't - when the command actually executes, we see "exec sp_executesql insert into consolidatedtable" - rather than hitting the view, the data source control finds the underlying table, then inserts directly into it. If we try adding fields to the views, they then show up in the data source control, but the web page then shows a configurable field.
Is there a way to change things on the database side to force it to use the view? My only other option at this point is to replace the views with tables, add an AFTER INSERT, UPDATE, DELETE trigger so that the consolidated gets updated, and then a process to make sure they're in sync and there are no issues.
MANY thanks in advance.

SQL Server ON DELETE and inheritance

I have 3 tables: Notifications, NewItemNotifications and Items.
I've set an ON DELETE rule on the NewItemNotifications and Items table which deletes the NewItemNotification row when I delete some item.
The problem is that the parent row in the Notifications table is still exists, how can I handle this?
NewItemNotification is dependent table - it can never trigger deletion of parent record through database constraint. The only way is to write a database trigger on NewItemNotification to perform delete in Notification table after the dependent record is deleted.
The problem is that such trigger can cause issue if EF will try to delete NewItemNotification because it doesn't know about trigger existence. It first deleted NewItemNotification record which trigger deletion of Notification item without EF to know it. EF will then try to delete Notification record again but the record was already deleted. I think it will result in concurrency exception.
The best option in this case is not using cascade delete and handle delete yourselves.

Resources