DataGrip 2024.1 Help

Generate code

DataGrip provides multiple ways to generate common code constructs and recurring elements, which helps you increase productivity. These can be either file templates used when creating a new file, custom or predefined live templates that are applied differently based on the context, various wrappers, or automatic pairing of characters.

Go to Code | Generate Alt+Insert to open the popup menu with available constructs that you can generate.

Generate a database entity

You can generate the following database entities: function, procedure, index, rule, trigger, view, materialized view, schema, database, role, user, sequence, enum, domain, composite type, foreign table, aggregate, operator, collation, foreign data wrapper, access method, extension table.

  1. Click Code | Generate or press Alt+Insert.

  2. Select the entity that you want to generate and press Enter.

Generate Java entity classes for tables and views

To store point objects in the database by using JPA, you must define an entity class. A JPA entity class is a Java class that is annotated as having the ability to represent objects in the database (a POJO (Plain Old Java Object) class).

You can select the necessary tables and views and generate corresponding JAVA files.

  1. Right-click a database object for which you want to generate a Java entity class and navigate to Tools | Scripted Extensions | Generate POJOs.groovy.

  2. In the file browser, specify the directory where you want to store JAVA class files

Generate Java entity classes for tables and views

Example of a generated Java entity class:

package com.sample; public class Actor { private long actorId; private String firstName; private String lastName; private java.sql.Timestamp lastUpdate; public long getActorId() { return actorId; } public void setActorId(long actorId) { this.actorId = actorId; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public java.sql.Timestamp getLastUpdate() { return lastUpdate; } public void setLastUpdate(java.sql.Timestamp lastUpdate) { this.lastUpdate = lastUpdate; } }
Last modified: 26 April 2024