How to auto generate random employee id in postgresql and implement in servlet - servlets

How to auto generate random employee id in postgresql and implement in servlet.
I am not able to create the code to auto generate random employee id in postgresql and implement in servlet please help me with the code.

Related

How can i retrieve a qtableview from stored procedure in qt?

I created a stored procedure:
CREATE PROCEDURE dbo.TableView
AS
SELECT *
FROM table
GO
When i call this sp on frontend what code i need to write to retrieve a qtableview?
I think a good option would be to store your model on the SQL Database and then retrieve the informations as needed. A good way to do so would be to use a Database table (or a Database view) as the model for the Qtableview. You can refer to this QSqlRelationalTableModel Class from QT documentation.

How do I include a third party SQL table into a asp.net code first web application?

It would be nice to be able to access the third party table in the same ApplicationDbContext that is generated by code first. But ultimately I really want to be able to join on the table in a linq query that translates into a single sql query (dont want it to make two database calls because I am joining two database contexts)
The table is a zipcodes table purchased from a third party. It does not have a unique id as code first requires, so I would have to give it one i guess?
If you're not using Code First Migrations to manage the database, you could just create a model for the zip codes table. The EF model for the table and the table itself don't necessarily have to match, so you could create a class to represent a zip code table record, and set a key for the zip codes entity even if the database table itself doesn't have one. You would have to be sure that the chosen key is unique or you would get unexpected results.
If you're using Code First Migrations, the same thing applies, but you can also run the SQL script itself in a DbMigration or in the DbMigrationsConfiguration.Seed.

How to restrict DB user to view table data if he has SELECT permission

An Oracle DB user has SELECT permission on all the tables of a DB schema. Can i restrict the user to view the table data.The user should be able to select the table but should not be able to see the data.
This specific requirement is required for user who reviews DB design and generates ALTER script for DB using Oracle Data Modeler 3.3 where he can just see the table design and can compare it with ERD
Can i achieve it using FGAC or RLS?
You can achieve this by granting only references
GRANT references ON schema_a.table TO erd_user;
the erd_user can then use
DESC schema_a.table
to get a definition but not select any data.
This might be preferred to giving the SELECT CATALOGUE where they can see a lot more information that you might like.

Entity Framework hides n to n table

I have the following tables created using SQL Server management studio (I must not let EF create the DB because I need customized indexing along with something else).
Table A (AId)
Table B (BId)
Table AB(AId, BId)
There are foreign key constrains setup so A - B is a n-n relationship.
Now, when I import the model into EF, the relationship is displayed as * - * (which is correct), but Table AB is gone. This is not what I want! I want to have the ability to manually manage the relationship. How can I have EF show this table?
(the reason is the way EF manage relationship through strongly typed objects is counter performance - e.g. I want to manually create a B and link it to some As (I know the ID) without selecting those As and adding it in B's collection)
As Slauma stated it is possible to add a dummy field, but more importantly you can remove that dummy field and still have the link table.
Simple create the table AB, with an extra column called "Dummy" for example. Generate your model from this table. The table will now be included in the model.
Now got to the database and drop the "Dummy" column.
You can now either refresh the model from the database of simple delete the mapping for the "Dummy" column. You now have the link table in your EF model.
It's not possible to force EF to expose the link table as an entity when you create the model via database first - unless you change the schema in a way that EF does not consider the table as a pure many-to-many link table anymore, for example by adding a "dummy column" to the table. When you are using Code-First however, you can manually create an entity for the link table with two one-to-many relationships between A and AB and between B and AB.
I am not convinced by your argument why you want to do that...
I want to manually create a B and link it to some As (I know the ID)
without selecting those As and adding it in B's collection.
...because you don't need to load any entities from the database if you know the key values. You can use attached stub entities in order to create the relationships and write entries into the link table:
var newB = new B { As = new List<A>() };
foreach (var aId in someAIdCollection)
{
var existingA = new A { Id = aId };
context.As.Attach(existingA);
newB.As.Add(existingA);
}
context.Bs.Add(newB);
context.SaveChanges();
No database query is involved here and the resulting SQL commands are the same like inserting an AB link entity directly.

wso2 data services server - CRUD insert using a java generated GUID

I have an entity that requires a GUID for it's primary key. Ideally, I would like to use a java class to generate the GUID before adding the entity to the database, so that I can control exactly how the GUID is created.
Is it possible to delegate the key generation to a java class with WSO2 DSS? How?
you can try to generate the GUID within the SQL statement, using ORACLE (for example) functions. I guess you will success if the algorithm is not too complex. This way, your insert statement would look like:
Insert into table (c1, c2, ..) values (functions for ID, v2,...)
Although the best practice is to use a trigger before insert which call a database sequence to generate a new guid.
You can also try to make a xslt transformation where you implement the algorithm to generate de guid. You would just have to perform the transformation before calling to dss.
Hope it helps!

Resources