Create a INSERT ... ON DUPLICATE KEY UPDATE clause

@param entity table to insert to
@param clause clause
@return insert clause
480030
public SQLInsertClause insertOnDuplicateKeyUpdate(RelationalPath<?> entity, String clause) {
        SQLInsertClause insert = insert(entity);
        insert.addFlag(Position.END, " on duplicate key update " + clause);
        return insert;
    }
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);
	}
536037
public boolean createOrReplaceEntity(Entity entity) {
        String entityName = entity.getName();
        checkEntityIsEmpty(entityName);
        QueryPart<Entity> queryPart = new Query<Entity>("entities")
                .path(entityName, true);
        return httpClientManager.updateMetaData(queryPart, put(entity));
    }
387385
protected List<String> createInsertQuery(EntityMetadata entityMetadata, Object entity,
        Cassandra.Client cassandra_client, List<RelationHolder> rlHolders, Object ttlColumns) {
        List<String> insert_Queries = new ArrayList<String>();
        CQLTranslator translator = new CQLTranslator();
        HashMap<TranslationType, Map<String, StringBuilder>> translation = translator.prepareColumnOrColumnValues(
            entity, entityMetadata, TranslationType.ALL, externalProperties, kunderaMetadata);

        Map<String, StringBuilder> columnNamesMap = translation.get(TranslationType.COLUMN);
        Map<String, StringBuilder> columnValuesMap = translation.get(TranslationType.VALUE);

        for (String tableName : columnNamesMap.keySet()) {
            String insert_Query = translator.INSERT_QUERY;

            insert_Query = StringUtils.replace(insert_Query, CQLTranslator.COLUMN_FAMILY,
                translator.ensureCase(new StringBuilder(), tableName, false).toString());
            String columnNames = columnNamesMap.get(tableName).toString();
            String columnValues = columnValuesMap.get(tableName).toString();

            StringBuilder columnNameBuilder = new StringBuilder(columnNames);
            StringBuilder columnValueBuilder = new StringBuilder(columnValues);

            for (RelationHolder rl : rlHolders) {
                columnValueBuilder =
                    onRelationColumns(columnNames, columnValues, columnNameBuilder, columnValueBuilder, rl);

                columnNameBuilder.append(",");
                columnValueBuilder.append(",");
                translator.appendColumnName(columnNameBuilder, rl.getRelationName());
                translator.appendValue(columnValueBuilder, rl.getRelationValue().getClass(), rl.getRelationValue(),
                    true, false);

            }

            insert_Query =
                StringUtils.replace(insert_Query, CQLTranslator.COLUMN_VALUES, columnValueBuilder.toString());
            insert_Query = StringUtils.replace(insert_Query, CQLTranslator.COLUMNS, columnNameBuilder.toString());

            if (log.isDebugEnabled()) {
                log.debug("Returning cql query {}.", insert_Query);
            }

            if (ttlColumns != null && ttlColumns instanceof Integer) {
                int ttl = ((Integer) ttlColumns).intValue();
                if (ttl != 0) {
                    insert_Query = insert_Query + " USING TTL " + ttl;
                }
            }
            insert_Queries.add(insert_Query);
        }
        return insert_Queries;
    }
1109711
@SuppressWarnings("unchecked")
	@Override
	public <E> int bulkInsert(final Class<E> entityType, final Stream<E> entities,
			final InsertsCondition<? super E> condition) {
		@SuppressWarnings("rawtypes")
		EntityHandler handler = this.getEntityHandler();
		if (!handler.getEntityType().isAssignableFrom(entityType)) {
			throw new IllegalArgumentException("Entity type not supported");
		}

		try {
			TableMetadata metadata = handler.getMetadata(this.transactionManager, entityType);
			SqlContext context = handler.createBulkInsertContext(this, metadata, entityType);
			context.setSqlKind(SqlKind.BULK_INSERT);

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

			setGeneratedKeyColumns(context, idColumns, metadata);

			int frameCount = 0;
			int count = 0;
			List<E> entityList = new ArrayList<>();
			for (Iterator<E> iterator = entities.iterator(); iterator.hasNext();) {
				E entity = iterator.next();

				if (!entityType.isInstance(entity)) {
					throw new IllegalArgumentException("Entity types do not match");
				}

				entityList.add(entity);

				handler.setBulkInsertParams(context, entity, frameCount);
				frameCount++;

				if (condition.test(context, frameCount, entity)) {
					count += doBulkInsert(context, entityType, handler, metadata, idColumns, entityList);
					frameCount = 0;
					entityList.clear();

					// 新しいSqlContextを作成する前にgeneratedKeyColumnsを退避しておく
					String[] generatedKeyColumns = context.getGeneratedKeyColumns();
					context = handler.createBulkInsertContext(this, metadata, entityType);
					context.setSqlKind(SqlKind.BULK_INSERT);
					// 実行結果から生成されたIDを取得できるようにPreparedStatementにIDカラムを渡す
					context.setGeneratedKeyColumns(generatedKeyColumns);
				}
			}
			return count + (frameCount > 0 ? doBulkInsert(context, entityType, handler, metadata, idColumns, entityList)
					: 0);

		} catch (SQLException e) {
			throw new EntitySqlRuntimeException(SqlKind.BULK_INSERT, e);
		}
	}
1321577
private Key insert(Entity entity) throws DatastoreException {
    CommitRequest req = CommitRequest.newBuilder()
	.addMutations(Mutation.newBuilder()
	    .setInsert(entity))
        .setMode(CommitRequest.Mode.NON_TRANSACTIONAL)
	.build();
    return datastore.commit(req).getMutationResults(0).getKey();
  }
454506
private Instance insertNewProp(final String _key,
                                 final String _value)
    {
        Instance ret = null;
        try {
            final Insert insert = new Insert(DBPropertiesUpdate.TYPE_PROPERTIES);
            insert.add("BundleID", this.bundleInstance);
            insert.add("Key", _key);
            insert.add("Default", _value);
            insert.executeWithoutAccessCheck();
            ret = insert.getInstance();
            insert.close();

        } catch (final EFapsException e) {
            DBPropertiesUpdate.LOG.error("InsertNew(String, String)", e);
        }
        return ret;
    }
976716
public function insert(Record $record, Entity $entity)
    {
        (new InsertRecord($record, $entity, $this))->execute();

        return $this;
    }
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);
        });
    }
559141
private Instance insertNewBundle()
    {
        Instance ret = null;
        try {
            final Insert insert = new Insert(DBPropertiesUpdate.TYPE_PROPERTIES_BUNDLE);
            insert.add("Name", this.bundlename);
            insert.add("UUID", this.bundeluuid);
            insert.add("Sequence", this.bundlesequence);
            insert.add("CacheOnStart", this.cacheOnStart);
            insert.executeWithoutAccessCheck();
            ret = insert.getInstance();
            insert.close();
        } catch (final EFapsException e) {
            DBPropertiesUpdate.LOG.error("insertNewBundle()", e);
        }
        return ret;
    }
110943
public static TaskEntity createAndInsert(VariableScope execution) {
    TaskEntity task = create();

    if (execution instanceof ExecutionEntity) {
      ExecutionEntity executionEntity = (ExecutionEntity) execution;
      task.setExecution(executionEntity);
      task.skipCustomListeners = executionEntity.isSkipCustomListeners();
      task.insert(executionEntity);
      return task;

    }
    else if (execution instanceof CaseExecutionEntity) {
      task.setCaseExecution((DelegateCaseExecution) execution);
    }

    task.insert(null);
    return task;
  }
1101924
public void insert(Object object) {
        EntityManager entityManager = null;
        try {
            entityManager = entityManagers.poll();
            entityManager.getTransaction().begin();
            try {

                entityManager.persist(object);
                entityManager.getTransaction().commit();
            } catch (Exception e) {
                e.printStackTrace();
                entityManager.getTransaction().rollback();
            }
        } finally {
            if(entityManager != null)
                entityManagers.add(entityManager);
        }
    }
721458
public function insert($entity)
    {
        $persistor = new DoctrinePersistor(
            $this->connection,
            $this->table,
            $this->entityRegistry->getEntityBuilder(),
            $this->entityRegistry
        );
        $persistor->insert($entity);
    }
635343
public static String insertColumns(Class<?> entityClass, boolean skipId, boolean notNull, boolean notEmpty) {
        StringBuilder sql = new StringBuilder();
        sql.append("<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">");
        //获取全部列
        Set<EntityColumn> columnSet = EntityHelper.getColumns(entityClass);
        //当某个列有主键策略时，不需要考虑他的属性是否为空，因为如果为空，一定会根据主键策略给他生成一个值
        for (EntityColumn column : columnSet) {
            if (!column.isInsertable()) {
                continue;
            }
            if (skipId && column.isId()) {
                continue;
            }
            if (notNull) {
                sql.append(SqlHelper.getIfNotNull(column, column.getColumn() + ",", notEmpty));
            } else {
                sql.append(column.getColumn() + ",");
            }
        }
        sql.append("</trim>");
        return sql.toString();
    }
1020922
public List<Object> insertForGeneratedKeys(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);
			ps.executeUpdate();
			return StatementUtil.getGeneratedKeys(ps);
		} catch (SQLException e) {
			throw e;
		} finally {
			DbUtil.close(ps);
		}
	}
727359
public List<Object> addForGeneratedKeys(Entity entity) throws SQLException {
		return db.insertForGeneratedKeys(fixEntity(entity));
	}
29532
public List<Object> insertForGeneratedKeys(Entity record) throws SQLException {
		Connection conn = null;
		try {
			conn = this.getConnection();
			return runner.insertForGeneratedKeys(conn, record);
		} catch (SQLException e) {
			throw e;
		} finally {
			this.closeConnection(conn);
		}
	}