Skip to content

Latest commit

 

History

History
202 lines (193 loc) · 5.07 KB

File metadata and controls

202 lines (193 loc) · 5.07 KB

Mongo Documents

Describes live templates which are good to use in creating data classes which describes MongoDB collections.

Very specific templates, may be not useful in general, bu still goo for creating a data class to represent MongoDB collection.

Wrapped - marked as that are wrapped examples to keep proper readability of the whole table.

| shows the final place of the cursor.

TemplateDescription and Enter pointsExample of the result
doce Creates three standard annotations for MongoDB document class.
@Document
@Canonical
@EqualsAndHashCode( excludes = [|] )
ciopt Creates an optimistic concurrency compound index annotation. Wrapped: the result will be in a line.
@CompoundIndex( name = 'optimistic_concurrency_idx', 
                def = "{ '_id': 1, 'version': 1 }" )
ci Creates a compound index annotation.
Enter points:
  1. Index name
  2. First indexed field name
  3. Second indexed field name
Wrapped: the result will be in a line.
@CompoundIndex( name = 'index_name', 
                def = "{ 'first-field': 1, 'second-field': 1| }", 
                unique = true )
fnames Creates a nested immutable class to describe document field names.
/**
 * Contains mongo field name constants, which are publicly accessible.
 */
@Immutable
static final class FieldNames {
    public static final String MIME_TYPE = 'mime-type'
    public static final String ID = '_id'
    public static final String VERSION = 'version'
    |
}
name Creates a field name variable.
Creates an underlined capitalized name of the variable based on the value.
Enter points:
  1. Value of the field name variable
public static final String FIELD_NAME = 'field-name'
|
ids Creates a document id field of type String.
/**
 * Mongo generated id of the document.
 */
@Id
@Field( FieldNames.ID )
String id|
idu Creates a document id field of type UUID.
/**
 * Mongo generated id of the document.
 */
@Id
@Field( FieldNames.ID )
UUID id|
ver Creates a document version field declaration.
/**
 * A version field used to implement optimistic locking on entities.
 */
@Version
@Field( FieldNames.VERSION )
Long version|
df Creates a general document field. Suggests a field type.
Enter points:
  1. Type
  2. Name of the field
  3. Value for @Field
  4. Groovydoc comment
/**
 * Groovydoc comment.
 */
@Field( FieldNames.VALUE )
Type filedName|
dfs Creates a String document field.
Enter points:
  1. Name of the field
  2. Value for @Field
  3. Groovydoc comment
/**
 * Groovydoc comment.
 */
@Field( FieldNames.VALUE )
String fieldName|
dfl Creates a long document field.
Enter points:
  1. Name of the field
  2. Value for @Field
  3. Groovydoc comment
/**
 * Groovydoc comment.
 */
@Field( FieldNames.VALUE )
long fieldName|

Surroundings

Describes the surround live templates for mongo documents. Surround live templates can be invoked by short cut Ctr+Alt+J.

| shows the place of the cursor.

Compound indexes

CIS

To surround the annotation @CompoundIndex by the annotation @CompoundIndexes, put a cursor at the line of the former and press Ctr+Alt+J and choose CIS template. Then you can use ci live template to add another @CompoundIndex.

Before

@CompoundIndex( name = 'index_name', def = "{ 'first-field': 1, 'second-field': 1 }", unique = true )|

After

@CompoundIndexes( [@CompoundIndex( name = 'index_name', def = "{ 'first-field': 1, 'second-field': 1 }", unique = true ),
        |] )