Update data in new table - java

I have one problem. Two DB's(say DB1 & DB2) are talking to each other.
In DB1 particular row is updated, so I just want to detect the changes from the DB2 and update the new row in DB2.
Please let me know how to di this using JPA/Hibernate.

You can create Rest API for update the new rows! Create database triggers in DB1, in the body of triggers write HttpClient for calling the Rest API and update the particular row in DB2.

Related

How I can Export ddl of all objects like table, index etc in SYBASE IQ/ SYBASE ASE without using any tools?

I have created a sample program in which I want to get ddl of all objects like table, trigger etc using get_ddl method. When I tried following queries in oracle it worked.
SELECT DBMS_METADATA.GET_DDL('TABLE', TABLE_NAME) FROM USER_TABLES;
SELECT DBMS_METADATA.GET_DDL('TRIGGER', TRIGGER_NAME) FROM USER_TRIGGERS;
SELECT DBMS_METADATA.GET_DDL('VIEW', VIEW_NAME) FROM USER_VIEWS;
SELECT DBMS_METADATA.GET_DDL('FUNCTION', OBJECT_NAME) FROM USER_PROCEDURES WHERE OBJECT_TYPE = 'FUNCTION';
SELECT DBMS_METADATA.GET_DDL('PROCEDURE', OBJECT_NAME) FROM USER_PROCEDURES WHERE OBJECT_TYPE = 'PROCEDURE';
SELECT DBMS_METADATA.GET_DDL('INDEX', INDEX_NAME) FROM USER_INDEXES ;
But when I try to create same sample for sybase to get ddl or script of all objects it doesn't work.because get_ddl not supported in sybase database. Can anyone help me to know that whether sybase Iq 15 supports get_ddl methods or there are any other method/way or queries for creating ddl/script of all objects.
I want to post it on SAP forums but all sites are unavailable can anyone suggest me link for post my problem.
Thanks in Advance!!
The ddl for triggers, stored procedures, and views can be pulled from sys.syssource. Unfortunately IQ doesn't store ddl for other objects
For ase,
Use sybsystemprocs
Go
sp_helptext (object)
Go
For views, stored procedures, and triggers

How to create a trigger from hibernate

I have a database that uses triggers. I must not change this use of triggers, because another application works also on this database.
Now I make a java application (using hibernate) that migrates data into this database.
For this reason I drop the trigger before I start my app:
DROP TRIGGER MYSCHEMA.TR_USER;
and I create the trigger again, after my app finished working:
CREATE OR REPLACE
TRIGGER MYSCHEMA.TR_USER
BEFORE INSERT
ON MYSCHEMA.BDV_USER
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
BEGIN
SELECT MYSCHEMA.BDV_USER_SEQ.NEXTVAL INTO :new.ID FROM dual;
END;
Now I want to integrate the deletion and creation of the trigger in my hibernate app.
I succeed to delete the trigger inside the app with:
String tmpStr = "DROP TRIGGER MYSCHEMA.TR_USER";
Query executeQuery = getSession().createSQLQuery(tmpStr);
ival = executeQuery.executeUpdate();
But when I want to to the same with the script for deleting the trigger, I fail.
How can be done this?
Thanks!

How to achieve Multiple Consumer Application for Shared Database (Multitenancy)?

Below Snapshot is current application flow.
Current Flow
When user Logged in at these multiple deployments, then respective SMSAgent(java class) insert user info in database, SMSHelper is a java Scheduler which reads data from database in its local queue,send SMS and then update user status in database.
Issue with this flow
Now,In above scenario, Multiple SMS is getting send to Single User because database is common and both the notification helper takes contact details from database(which may be common) and send SMS to that user.
Existing Solution
Currently, solution to this problem is only available in oracle 11g where select query has for update skip locked support.
Expectation
How to achieve the same with all databases at application level and not at query level ?
First,you have to RESERVE the row by update and then do select.
Suppose u have 200 row,
so first you should do is RESERVE by some value which are unique by instance, also you could limit on no of rows updated in your query and then select the row which are reserved by your query
UPDATE TABLE_NAME SET SERVER_INSTACE_ID=UNIQUE_VAL AND ROWNUM <= RECORD_RESERVATION_LIMIT
SELECT * FROM TABLE_NAME WHERE SERVER_INSTANCE_ID=UNIQUE_VAL
Through this approach, you don't need to obtain lock on row or table.

update table by using custom sql in liferay

I just want to update my table using custom sql in liferay 6.1, I have table with primary key auto increment not null. So whenever I am trying to update It creates a new row and instead of updating data it generate a new row. Please help me to update data using custom sql and my database is mysql.
thanks
asif aftab

Change Table names in derby database using entitymanager

I am using an APACHE DERBY database, and basing my database interactions on EntityManager, and I don't want to use JDBC class to build a query to change my tables' names (i just need to put a prefix to each new user to the application, but have the same structure of tables), such as:
//em stands for EntityManager object
Query tableNamesQuery= em.createNamedQuery("RENAME TABLE SCHEMA.EMP_ACT TO EMPLOYEE_ACT");
em.executeUpdate();
// ... rest of the function's work
// The command works from the database command prompt but i don't know how to use it in a program
//Or as i know you can't change system tables data, but here's the code
Query tableNamesQuery= em.createNamedQuery("UPDATE SYS.SYSTABLES SET TABLENAME='NEW_TABLE_NAME' WHERE TABLETYPE='T'");
em.executeUpdate();
// ... rest of the function's work
My questions are :
This syntax is correct?
Will it work?
Is there any other alternative?
Should I just use the SYS.SYSTABLES and find all the tables that has 'T' as tabletype and alter their name their, will it change the access name ?
I think you're looking for the RENAME TABLE statement: http://db.apache.org/derby/docs/10.10/ref/rrefsqljrenametablestatement.html
Don't just issue update statements against the system catalogs, you will corrupt your database.

Categories