Class InsertRequest
- java.lang.Object
-
- org.datanucleus.store.rdbms.request.Request
-
- org.datanucleus.store.rdbms.request.InsertRequest
-
public class InsertRequest extends Request
Class to provide a means of insertion of records to RDBMS. Extends basic request class implementing the execute method to do a JDBC insert operation. The SQL will be of the formINSERT INTO TBL_NAME (col1, col2, col3, ...) VALUES (?, ?, ?, ...)
When inserting an object with inheritance this will involve 1 InsertRequest for each table involved. So if we have a class B that extends class A and they both use "new-table" inheritance strategy, we will have 2 InsertRequests, one for table A, and one for table B.
When the InsertRequest starts to populate its statement and it has a PC field, this calls PersistableMapping.setObject(). This then checks if the other PC object is yet persistent and, if not, will persist it before processing this objects INSERT. This forms the key to "persistence-by-reachability".
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
InsertRequest.InsertMappingConsumer
Internal class to provide mapping consumption for an INSERT.
-
Field Summary
Fields Modifier and Type Field Description private boolean
batch
Whether to batch the INSERT SQL.private StatementMappingIndex
createTimestampStmtMapping
StatementExpressionIndex for create-timestamp.private StatementMappingIndex
createUserStmtMapping
StatementExpressionIndex for create-user.private StatementMappingIndex
discriminatorStmtMapping
StatementExpressionIndex for discriminator.private StatementMappingIndex[]
externalFKDiscrimStmtMappings
StatementExpressionIndex for external FK discriminators (shared FKs)private StatementMappingIndex[]
externalFKStmtMappings
StatementExpressionIndex for external FKsprivate StatementMappingIndex[]
externalOrderStmtMappings
StatementExpressionIndex for external indicesprivate boolean
hasIdentityColumn
Whether the class has an identity (auto-increment, serial etc) columnprivate static int
IDPARAMNUMBER
private int[]
insertFieldNumbers
Numbers of fields in the INSERT statement (excluding PK).private java.lang.String
insertStmt
SQL statement for the INSERT.private java.util.List<MappingCallbacks>
mappingCallbacks
callback mappings will have their postInsert method called after the updateprivate StatementMappingIndex
multitenancyStmtMapping
StatementExpressionIndex for multi-tenancy.private int[]
pkFieldNumbers
Numbers of Primary key fields.private java.util.List<JavaTypeMapping>
postSetMappings
private int[]
reachableFieldNumbers
Numbers of fields that are reachable yet have no datastore column in this table.private int[]
relationFieldNumbers
Numbers of fields that are relations that may be detached when persisting but not bidir so cant attach yet.private StatementMappingIndex[]
retrievedStmtMappings
StatementExpressionIndex for fields to be "retrieved"private StatementMappingIndex
softDeleteStmtMapping
StatementExpressionIndex for soft-delete.private StatementMappingIndex[]
stmtMappings
one StatementExpressionIndex for each fieldprivate StatementMappingIndex
updateTimestampStmtMapping
StatementExpressionIndex for update-timestamp.private StatementMappingIndex
updateUserStmtMapping
StatementExpressionIndex for update-user.private StatementMappingIndex
versionStmtMapping
StatementExpressionIndex for version
-
Constructor Summary
Constructors Constructor Description InsertRequest(DatastoreClass table, org.datanucleus.metadata.AbstractClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr)
Constructor, taking the table.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
execute(org.datanucleus.state.DNStateManager sm)
Method performing the insertion of the record from the datastore.private java.lang.Object
getInsertedIdentityValue(org.datanucleus.ExecutionContext ec, SQLController sqlControl, org.datanucleus.state.DNStateManager sm, org.datanucleus.store.connection.ManagedConnection mconn, java.sql.PreparedStatement ps)
Method to obtain the identity attributed by the datastore when using auto-increment/IDENTITY/SERIAL on a field.
-
-
-
Field Detail
-
IDPARAMNUMBER
private static final int IDPARAMNUMBER
- See Also:
- Constant Field Values
-
mappingCallbacks
private final java.util.List<MappingCallbacks> mappingCallbacks
callback mappings will have their postInsert method called after the update
-
postSetMappings
private final java.util.List<JavaTypeMapping> postSetMappings
-
insertFieldNumbers
private final int[] insertFieldNumbers
Numbers of fields in the INSERT statement (excluding PK).
-
pkFieldNumbers
private final int[] pkFieldNumbers
Numbers of Primary key fields.
-
reachableFieldNumbers
private final int[] reachableFieldNumbers
Numbers of fields that are reachable yet have no datastore column in this table. Used for reachability.
-
relationFieldNumbers
private final int[] relationFieldNumbers
Numbers of fields that are relations that may be detached when persisting but not bidir so cant attach yet.
-
insertStmt
private final java.lang.String insertStmt
SQL statement for the INSERT.
-
hasIdentityColumn
private boolean hasIdentityColumn
Whether the class has an identity (auto-increment, serial etc) column
-
stmtMappings
private StatementMappingIndex[] stmtMappings
one StatementExpressionIndex for each field
-
retrievedStmtMappings
private StatementMappingIndex[] retrievedStmtMappings
StatementExpressionIndex for fields to be "retrieved"
-
versionStmtMapping
private StatementMappingIndex versionStmtMapping
StatementExpressionIndex for version
-
discriminatorStmtMapping
private StatementMappingIndex discriminatorStmtMapping
StatementExpressionIndex for discriminator.
-
multitenancyStmtMapping
private StatementMappingIndex multitenancyStmtMapping
StatementExpressionIndex for multi-tenancy.
-
softDeleteStmtMapping
private StatementMappingIndex softDeleteStmtMapping
StatementExpressionIndex for soft-delete.
-
createUserStmtMapping
private StatementMappingIndex createUserStmtMapping
StatementExpressionIndex for create-user.
-
createTimestampStmtMapping
private StatementMappingIndex createTimestampStmtMapping
StatementExpressionIndex for create-timestamp.
-
updateUserStmtMapping
private StatementMappingIndex updateUserStmtMapping
StatementExpressionIndex for update-user.
-
updateTimestampStmtMapping
private StatementMappingIndex updateTimestampStmtMapping
StatementExpressionIndex for update-timestamp.
-
externalFKStmtMappings
private StatementMappingIndex[] externalFKStmtMappings
StatementExpressionIndex for external FKs
-
externalFKDiscrimStmtMappings
private StatementMappingIndex[] externalFKDiscrimStmtMappings
StatementExpressionIndex for external FK discriminators (shared FKs)
-
externalOrderStmtMappings
private StatementMappingIndex[] externalOrderStmtMappings
StatementExpressionIndex for external indices
-
batch
private boolean batch
Whether to batch the INSERT SQL.
-
-
Constructor Detail
-
InsertRequest
public InsertRequest(DatastoreClass table, org.datanucleus.metadata.AbstractClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr)
Constructor, taking the table. Uses the structure of the datastore table to build a basic query.- Parameters:
table
- The Class Table representing the datastore table to insert.cmd
- ClassMetaData for the object being persistedclr
- ClassLoader resolver
-
-
Method Detail
-
execute
public void execute(org.datanucleus.state.DNStateManager sm)
Method performing the insertion of the record from the datastore. Takes the constructed insert query and populates with the specific record information.
-
getInsertedIdentityValue
private java.lang.Object getInsertedIdentityValue(org.datanucleus.ExecutionContext ec, SQLController sqlControl, org.datanucleus.state.DNStateManager sm, org.datanucleus.store.connection.ManagedConnection mconn, java.sql.PreparedStatement ps) throws java.sql.SQLException
Method to obtain the identity attributed by the datastore when using auto-increment/IDENTITY/SERIAL on a field.- Parameters:
ec
- execution contextsqlControl
- SQLControllersm
- StateManager of the objectmconn
- The Connectionps
- PreparedStatement for the INSERT- Returns:
- The identity
- Throws:
java.sql.SQLException
- Thrown if an error occurs retrieving the identity
-
-