nz.co.gregs.dbvolution.annotations.DBAutoIncrement Maven / Gradle / Ivy
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package nz.co.gregs.dbvolution.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import nz.co.gregs.dbvolution.datatypes.DBInteger;
import nz.co.gregs.dbvolution.datatypes.DBNumber;
/**
*
* Used to indicate that this field is an auto-incrementing column in the
* database.
*
*
* DBAutoIncrement allows you to insert rows without specifying the primary key,
* have the PK generated automatically, and have the row inserted updated with
* the new PK value:
*
*
* MyRow row = new MyRow();
* row.name.setValue("example");
* database.insert(row);
* row.pkColumn.getValue(); // now contains the primary key created by the
* database.
*
*
*
* It also allows DBvolution to create the correct data types to automatically
* populate primary keys.
*
*
* Example of use:
*
*
* public class MyRow extends DBRow{
*
* @DBColumn("primary_key_col")
* @DBPrimaryKey
* @DBAutoIncrement
* public DBInteger pkColumn = new DBInteger();
*
* @DBColumn
* public DBInteger name = new DBInteger();
* }
*
*
*
* DBAutoIncrement has no effect unless the field is also a DBColumn and a
* DBPrimaryKey. It should also be a DBNumber or DBinteger as shown above.
*
*
* DBAutoIncrement is generated automatically by DBTableClassGenerator.
*
* Support DBvolution at
* Patreon
*
* @author Gregory Graham
* @see DBColumn
* @see DBPrimaryKey
* @see DBInteger
* @see DBNumber
*/
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface DBAutoIncrement {
// String value() default "";
}