{@inheritDoc}

@see jp.co.future.uroborosql.SqlAgent#insert(Object)
498394
@SuppressWarnings("unchecked")
	@Override
	public int insert(final Object entity) {
		@SuppressWarnings("rawtypes")
		EntityHandler handler = this.getEntityHandler();
		if (!handler.getEntityType().isInstance(entity)) {
			throw new IllegalArgumentException("Entity type not supported");
		}

		try {
			Class<?> type = entity.getClass();
			TableMetadata metadata = handler.getMetadata(this.transactionManager, type);
			SqlContext context = handler.createInsertContext(this, metadata, type);
			context.setSqlKind(SqlKind.INSERT);

			// IDアノテーションが付与されたカラム情報を取得する
			MappingColumn[] idColumns = MappingUtils.getIdMappingColumns(type);

			setGeneratedKeyColumns(context, idColumns, metadata);

			handler.setInsertParams(context, entity);
			int count = handler.doInsert(this, context, entity);

			if (idColumns != null && idColumns.length > 0) {
				BigDecimal[] ids = context.getGeneratedKeyValues();
				int idx = 0;
				for (MappingColumn col : idColumns) {
					BigDecimal id = ids[idx++];
					setEntityIdValue(entity, id, col);
				}
			}

			return count;
		} catch (SQLException e) {
			throw new EntitySqlRuntimeException(SqlKind.INSERT, e);
		}
	}
1035227
public DataBinder put(Object object) throws Exception {
        for (Field field: Beans.getKnownInstanceFields(object.getClass())) {
            Object value = field.get(object);
            if (value != null) {
                put(field.getName(), value.toString());
            }
        }
        return this;
    }
1176027
@Transactional()
    public E add(E entity)
    {
        getSqlSession().insert(getMapId(ADD_MAP_ID), entity);
        return entity;
    }
575832
@SafeVarargs
	public final void addInsert(Map<String, Object>... maps) throws SQLException {
		if (insertNps != null) {
			addAction(insertNps, insertKeysToColumns, maps);
			noOfInserts++;
		} else {
			throw new RuntimeException("No insert for importer: " + tableName);
		}
	}
531723
@Override
	public <T extends DAO> T insert(DAO dao, boolean excludePrimaryKeys)  throws DatabaseException{
		ModelDef model = db.getModelMetaDataDefinition().getDefinition(dao.getModelName());
		if(excludePrimaryKeys){
			dao.add_IgnoreColumn( model.getPrimaryAttributes());
		}
		return insertRecord(dao, model, true);
	}
567713
public function insert() {
        $sql = new Sql();
        $queryFields = '';
        $queryValues = '';
        $manyToMany = null;
        $transaction = Database::instance()->db()->inTransaction();

        if (!$transaction) {
            Database::instance()->db()->beginTransaction();
        }

        /** @var $fieldsInsertOneToMany \Gcs\Framework\Core\Orm\Entity\Entity[] */
        $fieldsInsertOneToMany = [];
        /** @var $fieldsUpdateOneToMany \Gcs\Framework\Core\Orm\Entity\Entity[] */
        $fieldsUpdateOneToMany = [];

        /** @var $fieldsInsertOneToMany \Gcs\Framework\Core\Orm\Entity\Entity[] */
        $fieldsInsertManyToMany = [];
        /** @var $fieldsUpdateOneToMany \Gcs\Framework\Core\Orm\Entity\Entity[] */
        $fieldsUpdateManyToMany = [];

        /** @var $field \Gcs\Framework\Core\Orm\Entity\Field */
        foreach ($this->_fields as $field) {
            if ($field->primary == false) {
                if ($field->foreign != null) {
                    switch ($field->foreign->type()) {
                        case ForeignKey::ONE_TO_ONE :
                            if (gettype($field->value) != 'object') {
                                if ($field->foreign->belong() == ForeignKey::COMPOSITION) {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be an Entity');
                                }
                            }
                            if (!preg_match('#Orm\\\Entity\\\#isU', get_class($field->value))) {
                                throw new MissingEntityException('The foreign key "' . $field->name . '" in "' . $this->_name . '" must be an Entity object');
                            }

                            if ($field->value == null) {
                                throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" can\'t be null');
                            }
                            else {
                                $field->value->insert();
                                $queryFields .= $field->name . ', ';
                                $queryValues .= ':' . $field->name . ', ';
                                $sql->vars($field->name, $field->value->get($field->foreign->referenceField()));
                            }
                            break;

                        case ForeignKey::MANY_TO_ONE :
                            if (gettype($field->value) != 'object') {
                                if ($field->foreign->belong() == ForeignKey::COMPOSITION) {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be an Entity');
                                }
                            }
                            if (!preg_match('#Orm\\\Entity\\\#isU', get_class($field->value))) {
                                //throw new MissingEntityException('The foreign key "'.$field->name.'" in "'.$this->_name.'" must be an Entity object');
                            }

                            if ($field->value == null) {
                                if ($field->beNull == false) {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" can\'t be null');
                                }
                                else {
                                    $sql->vars($field->name, null);
                                    $queryFields .= $field->name . ', ';
                                    $queryValues .= ':' . $field->name . ', ';
                                }
                            }
                            else {
                                if ($field->value->get($field->value->primary()) == null) {
                                    $field->value->insert();
                                }

                                $sql->vars($field->name, $field->value->get($field->foreign->referenceField()));
                                $queryFields .= $field->name . ', ';
                                $queryValues .= ':' . $field->name . ', ';
                            }
                            break;

                        case ForeignKey::ONE_TO_MANY :
                            /** If we insert a new line and the are already sub-objects, we have to insert or update them */
                            if ($field->value != null) {
                                if (gettype($field->value) != 'object') {
                                    if ($field->foreign->belong() == ForeignKey::COMPOSITION) {
                                        throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be a Collection');
                                    }
                                }
                                if (get_class($field->value) != 'System\Collection\Collection') {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be a Collection');
                                }

                                /** @var $entity \Gcs\Framework\Core\Orm\Entity\Entity */
                                foreach ($field->value as $entity) {
                                    if ($entity != null) {
                                        /** the field is not in database yet, so after the insert of the Entity, we will do an insert for it */
                                        if ($entity->get($entity->primary()) == null) {
                                            array_push($fieldsInsertOneToMany, $entity);
                                        }
                                        /** the field is already in database, so after the insert of the Entity, we will do an update for it */
                                        else if ($entity->get($entity->primary()) != null) {
                                            array_push($fieldsUpdateOneToMany, $entity);
                                        }
                                    }
                                    else {
                                        if ($field->foreign->belong() == ForeignKey::COMPOSITION) {
                                            throw new MissingEntityException('The Collection field "' . $field->name . '" in "' . $this->_name . '" can\'t have a null item because the relation is a composition');
                                        }
                                    }
                                }
                            }
                            else if ($field->beNull == false) {
                                throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" can\'t be null');
                            }
                            break;

                        case ForeignKey::MANY_TO_MANY :
                            /** If we insert a new line and the are already sub-objects, we have to insert or update them */
                            if ($field->value != null) {
                                if (gettype($field->value) != 'object') {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be a Collection');
                                }
                                if (get_class($field->value) != 'System\Collection\Collection') {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be a Collection');
                                }

                                $manyToMany = $field;

                                /** @var $entity \Gcs\Framework\Core\Orm\Entity\Entity */
                                foreach ($field->value as $entity) {
                                    if ($entity != null) {
                                        /** the field is not in database yet, so after the insert of the Entity, we will do an insert for it */
                                        if ($entity->get($entity->primary()) == null) {
                                            array_push($fieldsInsertManyToMany, $entity);
                                        }
                                        else {
                                            array_push($fieldsUpdateManyToMany, $entity);
                                        }
                                    }
                                    else {
                                        throw new MissingEntityException('The Entity "' . get_class($entity) . '" in "' . $this->_name . '" can\'t be null');
                                    }
                                }
                            }
                            else if ($field->beNull == false) {
                                throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" can\'t be null');
                            }
                            break;
                    }
                }
                else {
                    if ($field->value == null && $field->beNull == false && $field->default == '') {
                        throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" can\'t be null');
                    }

                    if ($field->value == null) {
                        $field->value = $field->default;
                    }

                    if (gettype($field->value) != 'object') {
                        if (in_array($field->type, [Field::INCREMENT, Field::INT, Field::FLOAT])) {
                            $sql->vars($field->name, [$field->value, Sql::PARAM_INT]);
                        }
                        else if (in_array($field->type, [Field::CHAR, Field::TEXT, Field::STRING, Field::DATE, Field::DATETIME, Field::TIMESTAMP])) {
                            $sql->vars($field->name, [$field->value, Sql::PARAM_STR]);
                        }
                        else if (in_array($field->type, [Field::BOOL])) {
                            $sql->vars($field->name, [$field->value, Sql::PARAM_BOOL]);
                        }
                        else {
                            $sql->vars($field->name, $field->value);
                        }
                    }
                    elseif (in_array($field->type, [Field::DATETIME, Field::TIMESTAMP])) {
                        $sql->vars($field->name, [$field->value->format("Y-m-d H:i:s"), Sql::PARAM_STR]);
                    }
                    elseif (in_array($field->type, [Field::DATE])) {
                        $sql->vars($field->name, [$field->value->format("Y-m-d"), Sql::PARAM_STR]);
                    }
                    else if (in_array($field->type, [Field::FILE])) {
                        $sql->vars($field->name, $field->value->value());
                        $field->value->save();
                    }

                    $queryFields .= $field->name . ', ';
                    $queryValues .= ':' . $field->name . ', ';
                }
            }
        }

        /** Execution of the query */
        $queryFields = substr(trim($queryFields, ','), 0, strlen($queryFields) - 2);
        $queryValues = substr(trim($queryValues, ','), 0, strlen($queryValues) - 2);

        $query = 'INSERT INTO ' . $this->_name . '(' . $queryFields . ') VALUES(' . $queryValues . ')';

        $sql->query('insert_' . $this->_name . '_' . $this->_token, $query);
        $sql->fetch('insert_' . $this->_name . '_' . $this->_token, Sql::PARAM_FETCHINSERT);

        /** Update primary key */
        $this->_fields[$this->_primary]->value = Database::instance()->db()->lastInsertId();

        /** ######################################################################## */
        /** One to many and many to many need more queries after the principal query */

        /** @var $field \Gcs\Framework\Core\Orm\Entity\Field */
        foreach ($fieldsInsertOneToMany as $fields) {
            $relation = '';

            /** @var $relationFields \Gcs\Framework\Core\Orm\Entity\Field */
            foreach ($fields->fields() as $relationFields) {
                if ($relationFields->foreign != null) {
                    if ($relationFields->foreign->referenceEntity() == ucfirst(strtolower($this->_name))) {
                        $relation = $relationFields->foreign->field();
                    }
                }
            }

            $fields->set($relation, $this);
            $fields->insert();
        }

        foreach ($fieldsUpdateOneToMany as $fields) {
            $relation = '';

            /** @var $relationFields \Gcs\Framework\Core\Orm\Entity\Field */
            foreach ($fields->fields() as $relationFields) {
                if ($relationFields->foreign != null) {
                    if ($relationFields->foreign->referenceEntity() == ucfirst(strtolower($this->_name))) {
                        $relation = $relationFields->foreign->field();
                    }
                }
            }

            $fields->set($relation, $this);
            $fields->update();
        }

        if ($manyToMany != null) {
            $currentEntity = $manyToMany->foreign->entity();
            $currentField = $manyToMany->foreign->field();
            $referenceEntity = $manyToMany->foreign->referenceEntity();
            $referenceField = $manyToMany->foreign->referenceField();

            $current = strtolower($currentEntity . $currentField);
            $reference = strtolower($referenceEntity . $referenceField);
            $table = [$current, $reference];
            sort($table, SORT_STRING);
            $table = ucfirst($table[0] . $table[1]);

            $class = '\Orm\Entity\\' . $manyToMany->foreign->referenceEntity();
            /** @var $referencedEntity \Gcs\Framework\Core\Orm\Entity\Entity */
            $referencedEntity = new $class();

            $sql = new Sql();
            $sql->query('orm-delete-many', 'DELETE FROM ' . $table . ' WHERE ' . $this->name() . '_' . $manyToMany->foreign->referenceField() . ' = ' . $this->_fields[$this->_primary]->value);
            $sql->fetch('orm-delete-many');

            /** @var $fields \Gcs\Framework\Core\Orm\Entity\Entity */
            foreach ($fieldsInsertManyToMany as $fields) {
                $fields->set($manyToMany->foreign->field(), $this);
                $fields->insert();

                $sql->query('orm-insert-many', 'INSERT INTO ' . $table . '(' . $this->name() . '_' . $manyToMany->foreign->referenceField() . ', ' . $referencedEntity->name() . '_' . $manyToMany->foreign->field() . ') VALUES (\'' . $this->_fields[$this->_primary]->value . '\', \'' . $fields->get($manyToMany->foreign->field()) . '\')');
                $sql->fetch('orm-insert-many');
            }

            /** @var $fields \Gcs\Framework\Core\Orm\Entity\Entity */
            foreach ($fieldsUpdateManyToMany as $fields) {
                $sql->query('orm-update-many', 'INSERT INTO ' . $table . '(' . $this->name() . '_' . $manyToMany->foreign->referenceField() . ', ' . $referencedEntity->name() . '_' . $manyToMany->foreign->field() . ') VALUES (\'' . $this->_fields[$this->_primary]->value . '\', \'' . $fields->get($manyToMany->foreign->field()) . '\')');
                $sql->fetch('orm-update-many');
            }
        }

        if (!$transaction) {
            Database::instance()->db()->commit();
        }
    }
962347
protected int insertUser (final User user)
        throws UserExistsException, PersistenceException
    {
        executeUpdate(new Operation<Object>() {
            public Object invoke (Connection conn, DatabaseLiaison liaison)
                throws PersistenceException, SQLException
            {
                try {
                    _utable.insert(conn, user);
                    // update the userid now that it's known
                    user.userId = liaison.lastInsertedId(conn, null, _utable.getName(), "userId");
                    // nothing to return
                    return null;

                } catch (SQLException sqe) {
                    if (liaison.isDuplicateRowException(sqe)) {
                        throw new UserExistsException("error.user_exists");
                    } else {
                        throw sqe;
                    }
                }
            }
        });

        return user.userId;
    }
1093688
protected final void doInsert(Connection c) throws SQLException {
		PreparedStatement stmt = null;
		try {
			stmt = c.prepareStatement("insert into foo values (?, ?)  ");
			stmt.setInt(1, rand.nextInt(99999));
			stmt.setString(2, "This is a text");
			stmt.executeUpdate();
		} finally {
			if (stmt != null) {
				stmt.close();
			}
		}
	}
1289008
public void bindInsert(PreparedStatement stmt, ClassDescriptor cld, Object obj) throws java.sql.SQLException
    {
        ValueContainer[] values;
        cld.updateLockingValues(obj); // BRJ : provide useful defaults for locking fields

        if (cld.getInsertProcedure() != null)
        {
            this.bindProcedure(stmt, cld, obj, cld.getInsertProcedure());
        }
        else
        {
            values = getAllValues(cld, obj);
            for (int i = 0; i < values.length; i++)
            {
                setObjectForStatement(stmt, i + 1, values[i].getValue(), values[i].getJdbcType().getType());
            }
        }
    }
148813
public void insert(Entity entity) {
        if (entity.getId() == null) {
            String id = dbSqlSessionFactory.getIdGenerator().getNextId();
            entity.setId(id);
        }

        Class<? extends Entity> clazz = entity.getClass();
        if (!insertedObjects.containsKey(clazz)) {
            insertedObjects.put(clazz,
                                new LinkedHashMap<String, Entity>()); // order of insert is important, hence LinkedHashMap
        }

        insertedObjects.get(clazz).put(entity.getId(),
                                       entity);
        entityCache.put(entity,
                        false); // False -> entity is inserted, so always changed
        entity.setInserted(true);
    }
920188
private static void insertJsonColumn(CqlSession session) {

    JsonObject alice = Json.createObjectBuilder().add("name", "alice").add("age", 30).build();

    JsonObject bob = Json.createObjectBuilder().add("name", "bob").add("age", 35).build();

    // Build and execute a simple statement
    Statement stmt =
        insertInto("examples", "json_jsr353_column")
            .value("id", literal(1))
            // the JSON object will be converted into a String and persisted into the VARCHAR column
            // "json"
            .value("json", literal(alice, session.getContext().getCodecRegistry()))
            .build();
    session.execute(stmt);

    // The JSON object can be a bound value if the statement is prepared
    // (subsequent calls to the prepare() method will return cached statement)
    PreparedStatement pst =
        session.prepare(
            insertInto("examples", "json_jsr353_column")
                .value("id", bindMarker("id"))
                .value("json", bindMarker("json"))
                .build());
    session.execute(
        pst.bind()
            .setInt("id", 2)
            // note that the codec requires that the type passed to the set() method
            // be always JsonStructure, and not a subclass of it, such as JsonObject
            .set("json", bob, JsonStructure.class));
  }
489603
private Single<SingleInsertionResult> insert(String preparedSql, Object[] sqlParams) {
        return Single.fromCallable(() -> {
            PreparedStatement statement = connection0.prepareStatement(preparedSql, PreparedStatement.RETURN_GENERATED_KEYS);
            for (int i = 0; i < sqlParams.length; i++) {
                statement.setObject(i + 1, sqlParams[i]);
            }
            statement.execute();
            ResultSet rs = statement.getGeneratedKeys();
            Integer count = statement.getUpdateCount();
            Long id;
            if (rs.next()) {
                id = rs.getLong(1);
            } else {
                //no id is generated
                id = null;
            }
            rs.close();
            statement.close();
            return new SingleInsertionResult().setCount(count).setId(id).setPreparedSql(preparedSql);
        });
    }
1317633
function insert() {
    var insertValues = this.single.insert || [];
    var sql = 'insert into ' + this.tableName + ' ';

    if (Array.isArray(insertValues)) {
      if (insertValues.length === 0) {
        return '';
      }
    } else if (typeof insertValues === 'object' && isEmpty(insertValues)) {
      return sql + this._emptyInsertValue;
    }

    var insertData = this._prepInsert(insertValues);
    this.__insertValues = insertData.values;
    if (typeof insertData === 'string') {
      sql += insertData;
    } else {
      if (insertData.columns.length) {
        sql += '(' + this.formatter.columnize(insertData.columns);
        sql += ') values (';
        sql += this.formatter.parameterize(insertData.columns);
        sql += ')';
      } else if (insertValues.length === 1 && insertValues[0]) {
        sql += this._emptyInsertValue;
      } else {
        sql = '';
      }
    }
    var out = {
      sql: sql,
      bindings: insertData.values
    };
    if (out.sql !== '') {
      out.returning = this.single.returning;
    }
    return out;
  }
1304347
public int insert(Connection conn, Entity record) throws SQLException {
		checkConn(conn);
		if(CollectionUtil.isEmpty(record)){
			throw new SQLException("Empty entity provided!");
		}
		PreparedStatement ps = null;
		try {
			ps = dialect.psForInsert(conn, record);
			return ps.executeUpdate();
		} catch (SQLException e) {
			throw e;
		} finally {
			DbUtil.close(ps);
		}
	}
480644
public Long insertForGeneratedKey(Entity record) throws SQLException {
		Connection conn = null;
		try {
			conn = this.getConnection();
			return runner.insertForGeneratedKey(conn, record);
		} catch (SQLException e) {
			throw e;
		} finally {
			this.closeConnection(conn);
		}
	}
927085
public int[] insert(Collection<Entity> records) throws SQLException {
		Connection conn = null;
		try {
			conn = this.getConnection();
			return runner.insert(conn, records);
		} catch (SQLException e) {
			throw e;
		} finally {
			this.closeConnection(conn);
		}
	}
429401
public int insert(String sql, Object value) {
        Class<?> parameterType = value != null ? value.getClass() : null;
        String msId = msUtils.insertDynamic(sql, parameterType);
        return sqlSession.insert(msId, value);
    }