### Install Documentation Dependencies Source: https://github.com/domaframework/doma/blob/master/AGENTS.md Install the necessary Python packages for building the documentation within the activated virtual environment. This command reads dependencies from 'requirements.txt'. ```bash # Install dependencies in virtual environment pip install -r requirements.txt ``` -------------------------------- ### Install Sphinx Dependencies for Doma Docs Source: https://github.com/domaframework/doma/blob/master/CONTRIBUTING.md Navigate to the docs directory and install the required Python dependencies for Sphinx using pip. ```bash $ cd docs $ pip install -r requirements.txt ``` -------------------------------- ### Build Sample Project Source: https://github.com/domaframework/doma/blob/master/docs/getting-started.md Ensure successful project setup by building the sample project using Gradle. ```bash ./gradlew build ``` -------------------------------- ### Example Usage of SQL Processor Source: https://github.com/domaframework/doma/blob/master/docs/query/sql-processor.md Demonstrates how to use the SQL processor to modify a generated SQL statement and execute it. This example shows changing the SQL and executing it against a database connection. ```java void doSomething() { EmployeeDao dao = new EmployeeDaoImpl(config); dao.process(1, (config, preparedSql) -> { String sql = preparedSql.getRawSql(); String anotherSql = createAnotherSql(sql); DataSource dataSource = config.getDataSource(); Connection connection = dataSource.getConnection(); PreparedStatement statement = connection.prepareStatement(anotherSql); return statement.execute(); }); } ``` ```sql select * from employee where id = /*^ id */0 ``` -------------------------------- ### Generated SQL Template Example Source: https://github.com/domaframework/doma/blob/master/docs/codegen.md A basic example of an SQL template file generated by Doma. It uses Doma's template syntax for dynamic SQL generation. ```sql SELECT /*%expand*/* FROM users WHERE id = /* id */1 ``` -------------------------------- ### Delete SQL File Example Source: https://github.com/domaframework/doma/blob/master/docs/query/delete.md Example of a SQL file used with the @Delete(sqlFile = true) annotation. ```sql delete from employee where name = /* employee.name */'hoge' ``` -------------------------------- ### Basic SQL Template Example Source: https://github.com/domaframework/doma/blob/master/docs/sql.md An example of a simple SQL template with a bind variable. The expression `/* employeeId */99` is replaced by a bind variable `?` at runtime, and `99` is test data for direct SQL tool execution. ```sql select * from employee where employee_id = /* employeeId */99 ``` -------------------------------- ### Example of SQL file not found error Source: https://github.com/domaframework/doma/blob/master/docs/faq.md This message indicates that an SQL file cannot be found on the classpath during runtime. ```sh [DOMA4019] The file[META-INF/../select.sql] is not found from the classpath ``` -------------------------------- ### Limit and Offset (NativeSql) Source: https://github.com/domaframework/doma/blob/master/docs/criteria-api.md Implement pagination by specifying a limit and offset for the query results. This example fetches records starting from the 3rd row with a limit of 5, ordered by employee number. ```java Employee_ e = new Employee_(); List list = nativeSql.from(e).limit(5).offset(3).orderBy(c -> c.asc(e.employeeNo)).fetch(); ``` ```sql select t0_.EMPLOYEE_ID, t0_.EMPLOYEE_NO, t0_.EMPLOYEE_NAME, t0_.MANAGER_ID, t0_.HIREDATE, t0_.SALARY, t0_.DEPARTMENT_ID, t0_.ADDRESS_ID, t0_.VERSION from EMPLOYEE t0_ order by t0_.EMPLOYEE_NO asc offset 3 rows fetch first 5 rows only ``` -------------------------------- ### Calling Stored Procedures with @Procedure Annotation Source: https://github.com/domaframework/doma/blob/master/docs/query/procedure.md Demonstrates how to annotate DAO methods with the @Procedure annotation to execute stored procedures. The example shows a basic setup with an IN parameter and an INOUT parameter. ```APIDOC ## Calling Stored Procedures To call stored procedures, you must annotate DAO methods with the `@Procedure` annotation. ```java @Dao public interface EmployeeDao { @Procedure void execute(@In Integer id, @InOut Reference salary); // ... } ``` ### Return Type The method return type must be `void`. ### Procedure Name By default, the annotated method name is used as the procedure name. To specify a different name, set the `name` property of the `@Procedure` annotation: ```java @Procedure(name = "calculateSalary") void execute(@In Integer id, @InOut Reference salary); ``` ### Parameters The order of the stored procedure parameters must match the order of the DAO method parameters. All parameters must be annotated with one of the following annotations: `@In`, `@InOut`, `@Out`, `@ResultSet`. #### IN Parameter To indicate IN parameters, annotate corresponding DAO method parameters with the `@In` annotation. The type of the DAO method parameter must be one of the following: - [Basic classes](../basic.md) - [Domain classes](../domain.md) - `java.util.Optional` whose element type is either [Basic classes](../basic.md) or [Domain classes](../domain.md) - `java.util.OptionalInt` - `java.util.OptionalLong` - `java.util.OptionalDouble` **Example:** ```java @Procedure void execute(@In Integer id); // Invocation: void doSomething() { EmployeeDao dao = new EmployeeDaoImpl(); dao.execute(1); } ``` #### INOUT Parameter To indicate INOUT parameters, annotate corresponding DAO method parameters with the `@InOut` annotation. The type of the DAO method parameter must be `org.seasar.doma.jdbc.Reference` and its type parameter must be one of the following: - [Basic classes](../basic.md) - [Domain classes](../domain.md) - `java.util.Optional` whose element type is either [Basic classes](../basic.md) or [Domain classes](../domain.md) - `java.util.OptionalInt` - `java.util.OptionalLong` - `java.util.OptionalDouble` **Example:** ```java @Procedure void execute(@InOut Reference salary); // Invocation: void doSomething() { EmployeeDao dao = new EmployeeDaoImpl(); BigDecimal in = new BigDecimal(100); Reference ref = new Reference(in); dao.execute(ref); BigDecimal out = ref.get(); } ``` #### OUT Parameter To indicate OUT parameters, annotate corresponding DAO method parameters with the `@Out` annotation. The type of the DAO method parameter must be `org.seasar.doma.jdbc.Reference` and its type parameter must be one of the following: - [Basic classes](../basic.md) - [Domain classes](../domain.md) - `java.util.Optional` whose element type is either [Basic classes](../basic.md) or [Domain classes](../domain.md) - `java.util.OptionalInt` - `java.util.OptionalLong` - `java.util.OptionalDouble` **Example:** ```java @Procedure void execute(@Out Reference salary); // Invocation: void doSomething() { EmployeeDao dao = new EmployeeDaoImpl(); Reference ref = new Reference(); dao.execute(ref); BigDecimal out = ref.get(); } ``` #### Cursor or Result Set To indicate cursors or result sets, annotate corresponding DAO method parameters with the `@ResultSet` annotation. The DAO method parameter type must be `java.util.List` and its element type must be one of the following: - [Basic classes](../basic.md) - [Domain classes](../domain.md) - [Entity classes](../entity.md) - `java.util.Map` - `java.util.Optional` whose element type is either [Basic classes](../basic.md) or [Domain classes](../domain.md) - `java.util.OptionalInt` - `java.util.OptionalLong` - `java.util.OptionalDouble` **Example:** ```java @Procedure void execute(@ResultSet List employees); // Invocation: void doSomething() { EmployeeDao dao = new EmployeeDaoImpl(); List employees = new ArrayList(); dao.execute(employees); for (Employee e : employees) { // ... } } ``` ``` -------------------------------- ### Clone and Navigate Sample Project Source: https://github.com/domaframework/doma/blob/master/docs/getting-started.md Clone the Doma getting-started repository and navigate into the project directory. ```bash $ git clone https://github.com/domaframework/getting-started.git $ cd getting-started ``` -------------------------------- ### Get Tenant ID Property Type Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/EntityProcessorTest_Emp.txt Retrieves the property type designated as the tenant ID for the 'Emp' entity. Note: This example retrieves a property named 'null', which might indicate a placeholder or specific configuration. ```java @Override public org.seasar.doma.jdbc.entity.TenantIdPropertyType getTenantIdPropertyType() { return (org.seasar.doma.jdbc.entity.TenantIdPropertyType)__entityPropertyTypeMap.get("null"); } ``` -------------------------------- ### Instantiate Entityql Source: https://github.com/domaframework/doma/blob/master/docs/criteria-api.md Shows how to instantiate the Entityql class, which is the entry point for the Entityql DSL. ```java Entityql entityql = new Entityql(config); ``` -------------------------------- ### Multi-row Insert SQL Example Source: https://github.com/domaframework/doma/blob/master/docs/query/multi-row-insert.md Example of the SQL statement generated for a multi-row insert operation. ```sql insert into EMPLOYEE (EMPLOYEE_ID, EMPLOYEE_NO, EMPLOYEE_NAME, AGE, VERSION) values (?, ?, ?, ?, ?), (?, ?, ?, ?, ?) ``` -------------------------------- ### Serve Doma Documentation with Live Reload Source: https://github.com/domaframework/doma/blob/master/CONTRIBUTING.md Use sphinx-autobuild in the docs directory to start a development server with live reloading for documentation changes. ```bash $ cd docs $ sphinx-autobuild . _build/html ``` -------------------------------- ### Generated Entity Class Example Source: https://github.com/domaframework/doma/blob/master/docs/codegen.md An example of an entity class generated by Doma. It includes annotations for mapping to a database table and columns. ```java @Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) public Integer id; public String name; public String email; @Version public Integer version; @Column(name = "created_at") public Timestamp createdAt; } ``` -------------------------------- ### Build Doma Documentation HTML Files Source: https://github.com/domaframework/doma/blob/master/CONTRIBUTING.md Navigate to the docs directory and use 'make html' to build the static HTML documentation without auto-reload. ```bash $ cd docs $ make html ``` -------------------------------- ### Using SimpleConfig Instance Source: https://github.com/domaframework/doma/blob/master/docs/config.md Instantiate your DAO implementation with the config built by SimpleConfig. ```java EmployeeDao dao = new EmployeeDaoImpl(config); ``` -------------------------------- ### Prepare AutoFunction Query for List of Optional Strings Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/dao/DaoProcessorTest_AutoFunctionOptionalParameterDao.txt Shows the initial steps for setting up an AutoFunction query where the expected return type is a List of Optional Strings. This includes setting the method, config, and other query properties. ```java @Override public java.util.List> executeFunction3(java.util.List> arg1) { __support.entering("org.seasar.doma.internal.apt.processor.dao.AutoFunctionOptionalParameterDaoImpl", "executeFunction3", arg1); try { if (arg1 == null) { throw new org.seasar.doma.DomaNullPointerException("arg1"); } org.seasar.doma.jdbc.query.AutoFunctionQuery>> __query = __support.getQueryImplementors().createAutoFunctionQuery(__method2); __query.setMethod(__method2); __query.setConfig(__support.getConfig()); ``` -------------------------------- ### Subquery with IN Clause Source: https://github.com/domaframework/doma/blob/master/docs/query-dsl.md Use subqueries within the `where` clause, for example, with the `in` operator. The example demonstrates selecting employee IDs that are present in a subquery selecting manager IDs. ```java Employee_ e = new Employee_(); Employee_ e2 = new Employee_(); List list = queryDsl .from(e) .where(c -> c.in(e.employeeId, c.from(e2).select(e2.managerId))) .orderBy(c -> c.asc(e.employeeId)) .fetch(); ``` ```sql select t0_.EMPLOYEE_ID, t0_.EMPLOYEE_NO, t0_.EMPLOYEE_NAME, t0_.MANAGER_ID, t0_.HIREDATE, t0_.SALARY, t0_.DEPARTMENT_ID, t0_.ADDRESS_ID, t0_.VERSION from EMPLOYEE t0_ where t0_.EMPLOYEE_ID in (select t1_.MANAGER_ID from EMPLOYEE t1_) order by t0_.EMPLOYEE_ID asc ``` -------------------------------- ### Using Simple DbConfig Source: https://github.com/domaframework/doma/blob/master/docs/config.md Instantiate your DAO implementation with the singleton DbConfig instance. ```java EmployeeDao dao = new EmployeeDaoImpl(DbConfig.singleton()); ``` -------------------------------- ### Doma Entity Listener Example Source: https://context7.com/domaframework/doma/llms.txt Implement an EntityListener to execute logic before entity operations like INSERT. This example sets the tenant ID before an insert operation. ```java // Entity listener (fires before/after INSERT, UPDATE, DELETE) public class EmployeeEntityListener implements EntityListener { @Override public void preInsert(Employee e, PreInsertContext ctx) { e.setTenantId(TenantContext.current()); } } ``` -------------------------------- ### Building Config with SimpleConfig Source: https://github.com/domaframework/doma/blob/master/docs/config.md Easily build a Config instance using SimpleConfig, which infers the Dialect from the connection string and uses local transactions. This is primarily for sample or test code. ```java Config config = SimpleConfig.builder("jdbc:h2:mem:tutorial;DB_CLOSE_DELAY=-1", "sa", null) .naming(Naming.SNAKE_UPPER_CASE) .queryTimeout(10) .build(); ``` -------------------------------- ### ID Generation Table DDL Example Source: https://github.com/domaframework/doma/blob/master/docs/entity.md Example DDL for the ID generation table used with the TABLE strategy. The table structure should match the @TableGenerator annotation. ```sql CREATE TABLE ID_GENERATOR(PK VARCHAR(20) NOT NULL PRIMARY KEY, VALUE INTEGER NOT NULL); ``` -------------------------------- ### Instantiating and Using Generated DAO Implementation Source: https://github.com/domaframework/doma/blob/master/docs/dao.md Shows how to instantiate a generated DAO implementation class directly and use it to perform database operations. Assumes a Config instance is available. ```java void doSomething() { Config config = getConfig(); EmployeeDao employeeDao = new EmployeeDaoImpl(config); Employee employee = employeeDao.selectById(1); } ``` -------------------------------- ### Multiple Database Configurations Example Source: https://github.com/domaframework/doma/blob/master/docs/codegen.md Defines multiple named configurations within the `domaCodeGen` block to support different databases or environments. Each configuration can have its own connection details and package names. ```kotlin domaCodeGen { register("sales") { url.set("jdbc:postgresql://localhost:5432/sales") user.set("sales_user") password.set("sales_pass") entity { packageName.set("com.example.sales.entity") } dao { packageName.set("com.example.sales.dao") } } register("inventory") { url.set("jdbc:mysql://localhost:3306/inventory") user.set("inventory_user") password.set("inventory_pass") entity { packageName.set("com.example.inventory.entity") } dao { packageName.set("com.example.inventory.dao") } } } ``` -------------------------------- ### DAO Method with SQL File Mapping Source: https://github.com/domaframework/doma/blob/master/docs/sql.md Demonstrates how DAO methods are mapped to SQL templates defined in external files using `sqlFile = true`. ```java @Dao public interface EmployeeDao { @Select Employee selectById(Integer employeeId); @Delete(sqlFile = true) int deleteByName(Employee employee); } ``` -------------------------------- ### Generated DAO Interface Example Source: https://github.com/domaframework/doma/blob/master/docs/codegen.md An example of a Data Access Object (DAO) interface generated by Doma. It defines methods for common database operations like select, insert, update, and delete. ```java @Dao public interface UserDao { @Select User selectById(Integer id); @Insert Result insert(User entity); @Update Result update(User entity); @Delete Result delete(User entity); } ``` -------------------------------- ### Example Output of Native SQL peek Source: https://github.com/domaframework/doma/blob/master/docs/criteria-api.md This is the expected output when using the `peek` method with Native SQL, demonstrating the SQL statements at different stages of query building. ```sql select t0_.DEPARTMENT_ID, t0_.DEPARTMENT_NO, t0_.DEPARTMENT_NAME, t0_.LOCATION, t0_.VERSION from DEPARTMENT t0_ select t0_.DEPARTMENT_ID, t0_.DEPARTMENT_NO, t0_.DEPARTMENT_NAME, t0_.LOCATION, t0_.VERSION from DEPARTMENT t0_ where t0_.DEPARTMENT_NAME = ? select t0_.DEPARTMENT_ID, t0_.DEPARTMENT_NO, t0_.DEPARTMENT_NAME, t0_.LOCATION, t0_.VERSION from DEPARTMENT t0_ where t0_.DEPARTMENT_NAME = 'SALES' order by t0_.LOCATION asc select t0_.LOCATION from DEPARTMENT t0_ where t0_.DEPARTMENT_NAME = 'SALES' order by t0_.LOCATION asc ``` -------------------------------- ### Oracle SQL Script Example Source: https://github.com/domaframework/doma/blob/master/docs/query/script.md A comprehensive SQL script example valid for Oracle Database, including table creation, data insertion, and stored procedure definitions. It demonstrates the use of semicolons as statement delimiters and '/' as a block delimiter. ```sql /* * table creation statement */ create table EMPLOYEE ( ID numeric(5) primary key, -- identifier is not generated automatically NAME varchar2(20) -- first name only ); /* * insert statement */ insert into EMPLOYEE (ID, NAME) values (1, 'SMITH'); /* * procedure creation block */ create or replace procedure proc ( cur out sys_refcursor, employeeid in numeric ) as begin open cur for select * from employee where id > employeeid order by id; end proc_resultset; / /* * procedure creation block */ create or replace procedure proc2 ( cur out sys_refcursor, employeeid in numeric ) as begin open cur for select * from employee where id > employeeid order by id; end proc_resultset; / ``` -------------------------------- ### Configure Entity Generation (Basic) Source: https://github.com/domaframework/doma/blob/master/docs/codegen.md Configures basic entity generation, including package name, getters/setters, listeners, and database comments. Use this for standard entity setups. ```kotlin domaCodeGen { register("sales") { entity { packageName.set("com.example.sales.entity") useAccessor.set(true) // Generate getters/setters useListener.set(true) // Generate entity listeners showDbComment.set(true) // Include database comments prefix.set("Sales") // Add prefix to class names } } } ``` -------------------------------- ### Fetch Data with Query DSL Source: https://github.com/domaframework/doma/blob/master/docs/query-dsl.md Demonstrates fetching data using fetch, fetchOne, fetchOptional, and stream methods. fetch returns a list, fetchOne returns a single object or null, fetchOptional returns an Optional, and stream returns a Stream. ```java Employee_ e = new Employee_(); // The fetch method returns results as a list. List list = queryDsl.from(e).fetch(); // The fetchOne method returns a single result, possibly null. Employee employee = queryDsl.from(e).where(c -> c.eq(e.employeeId, 1)).fetchOne(); // The fetchOptional method returns a single result as an Optional object. Optional optional = queryDsl.from(e).where(c -> c.eq(e.employeeId, 1)).fetchOptional(); // The stream method returns results as a stream. Stream stream = queryDsl.from(e).stream(); ``` -------------------------------- ### Get Entity Class Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/EntityProcessorTest_Emp.txt Returns the Class object for the 'Emp' entity. ```java @Override public Class getEntityClass() { return org.seasar.doma.internal.apt.processor.entity.Emp.class; } ``` -------------------------------- ### Apply Doma Code Formatting with Gradle Source: https://github.com/domaframework/doma/blob/master/CONTRIBUTING.md Use the Gradle spotlessApply task to automatically format the code without building the project. ```bash $ ./gradlew spotlessApply ``` -------------------------------- ### Get Schema Name Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/EntityProcessorTest_AbstractEntity.txt Retrieves the schema name associated with the entity. ```java @Override public String getSchemaName() { return __schemaName; } ``` -------------------------------- ### Navigate to Docs Directory Source: https://github.com/domaframework/doma/blob/master/AGENTS.md Change the current directory to the 'docs' folder where documentation source files are located. This is a prerequisite for building documentation. ```bash # Go to docs directory cd docs ``` -------------------------------- ### Get Catalog Name Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/EntityProcessorTest_AbstractEntity.txt Retrieves the catalog name associated with the entity. ```java public String getCatalogName() { return __catalogName; } ``` -------------------------------- ### Using HikariCP with Doma Source: https://github.com/domaframework/doma/blob/master/docs/faq.md Example of configuring HikariCP as a JDBC connection pool for Doma. ```java import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import org.seasar.doma.jdbc.DataSource; public class DataSourceFactory { public static DataSource createDataSource() { HikariConfig config = new HikariConfig(); config.setDriverClassName("org.postgresql.Driver"); config.setJdbcUrl("jdbc:postgresql://localhost:5432/sample"); config.setUsername("postgres"); config.setPassword("password"); config.addDataSourceProperty("cachePrepStmts", true); config.addDataSourceProperty("prepStmtCacheSize", 256); config.addDataSourceProperty("prepStmtCacheSqlLimit", 2048); return () -> new HikariDataSource(config); } } ``` -------------------------------- ### Get Association Property Types Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/association/EntityProcessorTest_OptionalAssociation.txt Returns the list of association property types for the entity. ```java @Override public java.util.List getAssociationPropertyTypes() { return __associationPropertyTypes; } @Override ``` -------------------------------- ### Instantiate QueryDsl Source: https://github.com/domaframework/doma/blob/master/docs/query-dsl.md Demonstrates how to instantiate the QueryDsl class, which is the entry point for the Unified Criteria API. It requires a Doma Config object. ```java import org.seasar.doma.jdbc.criteria.QueryDsl; QueryDsl queryDsl = new QueryDsl(config); ``` -------------------------------- ### Get Singleton Instance Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/EntityProcessorTest_Emp.txt Provides access to the singleton instance of the internal entity helper class. ```java /** * @return the singleton */ public static _Emp getSingletonInternal() { return __singleton; } ``` -------------------------------- ### Get Version Property Type Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/EntityProcessorTest_Emp.txt Retrieves the property type designated as the version for the 'Emp' entity. ```java @Override public org.seasar.doma.jdbc.entity.VersionPropertyType getVersionPropertyType() { return (org.seasar.doma.jdbc.entity.VersionPropertyType)__entityPropertyTypeMap.get("version"); } ``` -------------------------------- ### Generate HTML Documentation with Auto-Reload Source: https://github.com/domaframework/doma/blob/master/AGENTS.md Build HTML documentation and enable auto-reloading for live preview during development. This command uses 'sphinx-autobuild' and starts a local server. ```bash source .venv/bin/activate && \ cd docs && \ sphinx-autobuild . _build/html && \ cd .. # Visit http://127.0.0.1:8000 ``` -------------------------------- ### Clone and Build Doma Project Source: https://github.com/domaframework/doma/blob/master/CONTRIBUTING.md Clone the Doma repository and build the project using Gradle. Ensure you have Git and JDK 21 installed. ```bash $ git clone https://github.com/domaframework/doma.git $ cd doma $ ./gradlew build ``` -------------------------------- ### Get All Entity Property Types Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/EntityProcessorTest_Emp.txt Retrieves a list of all entity property types for the 'Emp' entity. ```java @Override public java.util.List> getEntityPropertyTypes() { return __entityPropertyTypes; } ``` -------------------------------- ### Auto Function Query Initialization Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/dao/DaoProcessorTest_EnsureResultMappingDao.txt Shows the initial setup for calling a stored function that returns a list of entities. Includes method and configuration settings. ```java org.seasar.doma.jdbc.query.AutoFunctionQuery> __query = __support.getQueryImplementors().createAutoFunctionQuery(__method3); __query.setMethod(__method3); __query.setConfig(__support.getConfig()); __query.setCatalogName(""); __query.setSchemaName(""); __query.setFunctionName("function"); __query.setQuoteRequired(false); ``` -------------------------------- ### Get Entity Class Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/EntityProcessorTest_TenantIdEntity.txt Returns the Class object for TenantIdEntity. This is used by Doma for reflection and type checking. ```java @Override public Class getEntityClass() { return org.seasar.doma.internal.apt.processor.entity.TenantIdEntity.class; } ``` -------------------------------- ### Get Entity Class Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/EntityProcessorTest_ImmutableUser.txt Returns the Class object for the immutable entity. This is a standard method for entity metadata. ```java @Override public Class getEntityClass() { return org.seasar.doma.internal.apt.processor.entity.ImmutableUser.class; } ``` -------------------------------- ### Get Original Entity States Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/EntityProcessorTest_Emp.txt Retrieves the original state of an entity instance using a dedicated accessor. ```java @Override public org.seasar.doma.internal.apt.processor.entity.Emp getOriginalStates(org.seasar.doma.internal.apt.processor.entity.Emp __entity) { return __originalStatesAccessor.get(__entity); } ``` -------------------------------- ### Entity Creation and State Management Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/association/EntityProcessorTest_EntityAssociation.txt Demonstrates the creation of a new entity instance and methods for handling entity states, including retrieving original states and saving current states. These are essential for Doma's persistence operations. ```java @Override public org.seasar.doma.internal.apt.processor.entity.association.EntityAssociation newEntity(java.util.Map> __args) { org.seasar.doma.internal.apt.processor.entity.association.EntityAssociation entity = new org.seasar.doma.internal.apt.processor.entity.association.EntityAssociation(); return entity; } @Override public Class getEntityClass() { return org.seasar.doma.internal.apt.processor.entity.association.EntityAssociation.class; } @Override public org.seasar.doma.internal.apt.processor.entity.association.EntityAssociation getOriginalStates(org.seasar.doma.internal.apt.processor.entity.association.EntityAssociation __entity) { return null; } @Override public void saveCurrentStates(org.seasar.doma.internal.apt.processor.entity.association.EntityAssociation __entity) { } ``` -------------------------------- ### Doma Template Module Usage Source: https://github.com/domaframework/doma/blob/master/docs/sql.md Demonstrates how to use the doma-template module to obtain prepared SQL statements from SQL templates by adding arguments and executing the template. ```kotlin dependencies { implementation("org.seasar.doma:doma-template:{{ doma_version }}") } ``` ```java String sql = "select * from emp where name = /* name */'\' and salary = /* salary */0"; SqlStatement statement = new SqlTemplate(sql) .add("name", String.class, "abc") .add("salary", int.class, 1234) .execute(); String rawSql = statement.getRawSql(); // select * from emp where name = ? and salary = ? List arguments = statement.getArguments(); ``` -------------------------------- ### Get ID Property Types Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/EntityProcessorTest_Emp.txt Retrieves a list of property types that are designated as IDs for the 'Emp' entity. ```java @Override public java.util.List> getIdPropertyTypes() { return __idPropertyTypes; } ``` -------------------------------- ### Basic SelectCommand Execution in Doma Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/dao/DaoProcessorTest_SqlFileSelectBasicDao.txt Illustrates the creation and execution of a SelectCommand for retrieving a list of strings from a SQL file. This is typically part of an auto-generated DAO implementation. ```java org.seasar.doma.jdbc.command.SelectCommand> __command = __support.getCommandImplementors().createSelectCommand(__method1, __query, new org.seasar.doma.internal.jdbc.command.BasicResultListHandler(org.seasar.doma.internal.wrapper.WrapperSuppliers.ofString())); java.util.List __result = __command.execute(); __query.complete(); __support.exiting("org.seasar.doma.internal.apt.processor.dao.SqlFileSelectBasicDaoImpl", "selectByNameAndSalary", __result); return __result; } catch (java.lang.RuntimeException __e) { __support.throwing("org.seasar.doma.internal.apt.processor.dao.SqlFileSelectBasicDaoImpl", "selectByNameAndSalary", __e); throw __e; } } } ``` -------------------------------- ### Get Specific Entity Property Type by Name Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/EntityProcessorTest_Emp.txt Retrieves a specific entity property type by its name. ```java @Override public org.seasar.doma.jdbc.entity.EntityPropertyType getEntityPropertyType(String __name) { return __entityPropertyTypeMap.get(__name); } ``` -------------------------------- ### Get Version Property Type Source: https://github.com/domaframework/doma/blob/master/doma-processor/src/test/resources/org/seasar/doma/internal/apt/processor/entity/EntityProcessorTest_DomainPropertyEntity.txt Retrieves the version property type for the DomainPropertyEntity. Used for optimistic locking. ```java @Override public org.seasar.doma.jdbc.entity.VersionPropertyType getVersionPropertyType() { return (org.seasar.doma.jdbc.entity.VersionPropertyType)__entityPropertyTypeMap.get("ver"); } ``` -------------------------------- ### SQL for Entity Selection Source: https://github.com/domaframework/doma/blob/master/docs/query-dsl.md Illustrates the SQL generated for entity selection. The first example shows default entity selection, and the second shows selection of a joined entity using 'project'. ```sql select t0_.EMPLOYEE_ID, t0_.EMPLOYEE_NO, t0_.EMPLOYEE_NAME, t0_.MANAGER_ID, HIREDATE, t0_.SALARY, t0_.DEPARTMENT_ID, t0_.ADDRESS_ID, t0_.VERSION from EMPLOYEE t0_ inner join DEPARTMENT t1_ on (t0_.DEPARTMENT_ID = t1_.DEPARTMENT_ID) ``` ```sql select t1_.DEPARTMENT_ID, t1_.DEPARTMENT_NO, t1_.DEPARTMENT_NAME, t1_.LOCATION, t1_.VERSION from EMPLOYEE t0_ inner join DEPARTMENT t1_ on (t0_.DEPARTMENT_ID = t1_.DEPARTMENT_ID) ``` -------------------------------- ### Limit and Offset Expression Source: https://github.com/domaframework/doma/blob/master/docs/query-dsl.md Control the number of rows returned and the starting point using limit() and offset(). ```java Employee_ e = new Employee_(); List list = queryDsl .from(e) .limit(5) .offset(3) .orderBy(c -> c.asc(e.employeeNo)) .fetch(); ``` ```sql select t0_.EMPLOYEE_ID, t0_.EMPLOYEE_NO, t0_.EMPLOYEE_NAME, t0_.MANAGER_ID, t0_.HIREDATE, t0_.SALARY, t0_.DEPARTMENT_ID, t0_.ADDRESS_ID, t0_.VERSION from EMPLOYEE t0_ order by t0_.EMPLOYEE_NO asc offset 3 rows fetch first 5 rows only ```