text:
package postgres

import (
	"bytes"
	"context"
	"reflect"
	"testing"

	"github.com/thrasher-corp/sqlboiler/boil"
	"github.com/thrasher-corp/sqlboiler/queries"
	"github.com/thrasher-corp/sqlboiler/randomize"
	"github.com/thrasher-corp/sqlboiler/strmangle"
)

var (
	// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
	// so force a package dependency in case they don't.
	_ = queries.Equal
)

func testDatahistoryjobs(t *testing.T) {
	t.Parallel()

	query := Datahistoryjobs()

	if query.Query == nil {
		t.Error("expected a query, got nothing")
	}
}

func testDatahistoryjobsDelete(t *testing.T) {
	t.Parallel()

	seed := randomize.NewSeed()
	var err error
	o := &Datahistoryjob{}
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	if rowsAff, err := o.Delete(ctx, tx); err != nil {
		t.Error(err)
	} else if rowsAff != 1 {
		t.Error("should only have deleted one row, but affected:", rowsAff)
	}

	count, err := Datahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Error(err)
	}

	if count != 0 {
		t.Error("want zero records, got:", count)
	}
}

func testDatahistoryjobsQueryDeleteAll(t *testing.T) {
	t.Parallel()

	seed := randomize.NewSeed()
	var err error
	o := &Datahistoryjob{}
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	if rowsAff, err := Datahistoryjobs().DeleteAll(ctx, tx); err != nil {
		t.Error(err)
	} else if rowsAff != 1 {
		t.Error("should only have deleted one row, but affected:", rowsAff)
	}

	count, err := Datahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Error(err)
	}

	if count != 0 {
		t.Error("want zero records, got:", count)
	}
}

func testDatahistoryjobsSliceDeleteAll(t *testing.T) {
	t.Parallel()

	seed := randomize.NewSeed()
	var err error
	o := &Datahistoryjob{}
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	slice := DatahistoryjobSlice{o}

	if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
		t.Error(err)
	} else if rowsAff != 1 {
		t.Error("should only have deleted one row, but affected:", rowsAff)
	}

	count, err := Datahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Error(err)
	}

	if count != 0 {
		t.Error("want zero records, got:", count)
	}
}

func testDatahistoryjobsExists(t *testing.T) {
	t.Parallel()

	seed := randomize.NewSeed()
	var err error
	o := &Datahistoryjob{}
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	e, err := DatahistoryjobExists(ctx, tx, o.ID)
	if err != nil {
		t.Errorf("Unable to check if Datahistoryjob exists: %s", err)
	}
	if !e {
		t.Errorf("Expected DatahistoryjobExists to return true, but got false.")
	}
}

func testDatahistoryjobsFind(t *testing.T) {
	t.Parallel()

	seed := randomize.NewSeed()
	var err error
	o := &Datahistoryjob{}
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	datahistoryjobFound, err := FindDatahistoryjob(ctx, tx, o.ID)
	if err != nil {
		t.Error(err)
	}

	if datahistoryjobFound == nil {
		t.Error("want a record, got nil")
	}
}

func testDatahistoryjobsBind(t *testing.T) {
	t.Parallel()

	seed := randomize.NewSeed()
	var err error
	o := &Datahistoryjob{}
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	if err = Datahistoryjobs().Bind(ctx, tx, o); err != nil {
		t.Error(err)
	}
}

func testDatahistoryjobsOne(t *testing.T) {
	t.Parallel()

	seed := randomize.NewSeed()
	var err error
	o := &Datahistoryjob{}
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	if x, err := Datahistoryjobs().One(ctx, tx); err != nil {
		t.Error(err)
	} else if x == nil {
		t.Error("expected to get a non nil record")
	}
}

func testDatahistoryjobsAll(t *testing.T) {
	t.Parallel()

	seed := randomize.NewSeed()
	var err error
	datahistoryjobOne := &Datahistoryjob{}
	datahistoryjobTwo := &Datahistoryjob{}
	if err = randomize.Struct(seed, datahistoryjobOne, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}
	if err = randomize.Struct(seed, datahistoryjobTwo, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = datahistoryjobOne.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}
	if err = datahistoryjobTwo.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	slice, err := Datahistoryjobs().All(ctx, tx)
	if err != nil {
		t.Error(err)
	}

	if len(slice) != 2 {
		t.Error("want 2 records, got:", len(slice))
	}
}

func testDatahistoryjobsCount(t *testing.T) {
	t.Parallel()

	var err error
	seed := randomize.NewSeed()
	datahistoryjobOne := &Datahistoryjob{}
	datahistoryjobTwo := &Datahistoryjob{}
	if err = randomize.Struct(seed, datahistoryjobOne, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}
	if err = randomize.Struct(seed, datahistoryjobTwo, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = datahistoryjobOne.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}
	if err = datahistoryjobTwo.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	count, err := Datahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Error(err)
	}

	if count != 2 {
		t.Error("want 2 records, got:", count)
	}
}

func datahistoryjobBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
	*o = Datahistoryjob{}
	return nil
}

func datahistoryjobAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
	*o = Datahistoryjob{}
	return nil
}

func datahistoryjobAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
	*o = Datahistoryjob{}
	return nil
}

func datahistoryjobBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
	*o = Datahistoryjob{}
	return nil
}

func datahistoryjobAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
	*o = Datahistoryjob{}
	return nil
}

func datahistoryjobBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
	*o = Datahistoryjob{}
	return nil
}

func datahistoryjobAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
	*o = Datahistoryjob{}
	return nil
}

func datahistoryjobBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
	*o = Datahistoryjob{}
	return nil
}

func datahistoryjobAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
	*o = Datahistoryjob{}
	return nil
}

func testDatahistoryjobsHooks(t *testing.T) {
	t.Parallel()

	var err error

	ctx := context.Background()
	empty := &Datahistoryjob{}
	o := &Datahistoryjob{}

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, false); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob object: %s", err)
	}

	AddDatahistoryjobHook(boil.BeforeInsertHook, datahistoryjobBeforeInsertHook)
	if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
		t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
	}
	if !reflect.DeepEqual(o, empty) {
		t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
	}
	datahistoryjobBeforeInsertHooks = []DatahistoryjobHook{}

	AddDatahistoryjobHook(boil.AfterInsertHook, datahistoryjobAfterInsertHook)
	if err = o.doAfterInsertHooks(ctx, nil); err != nil {
		t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
	}
	if !reflect.DeepEqual(o, empty) {
		t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
	}
	datahistoryjobAfterInsertHooks = []DatahistoryjobHook{}

	AddDatahistoryjobHook(boil.AfterSelectHook, datahistoryjobAfterSelectHook)
	if err = o.doAfterSelectHooks(ctx, nil); err != nil {
		t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
	}
	if !reflect.DeepEqual(o, empty) {
		t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
	}
	datahistoryjobAfterSelectHooks = []DatahistoryjobHook{}

	AddDatahistoryjobHook(boil.BeforeUpdateHook, datahistoryjobBeforeUpdateHook)
	if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
		t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
	}
	if !reflect.DeepEqual(o, empty) {
		t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
	}
	datahistoryjobBeforeUpdateHooks = []DatahistoryjobHook{}

	AddDatahistoryjobHook(boil.AfterUpdateHook, datahistoryjobAfterUpdateHook)
	if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
		t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
	}
	if !reflect.DeepEqual(o, empty) {
		t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
	}
	datahistoryjobAfterUpdateHooks = []DatahistoryjobHook{}

	AddDatahistoryjobHook(boil.BeforeDeleteHook, datahistoryjobBeforeDeleteHook)
	if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
		t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
	}
	if !reflect.DeepEqual(o, empty) {
		t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
	}
	datahistoryjobBeforeDeleteHooks = []DatahistoryjobHook{}

	AddDatahistoryjobHook(boil.AfterDeleteHook, datahistoryjobAfterDeleteHook)
	if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
		t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
	}
	if !reflect.DeepEqual(o, empty) {
		t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
	}
	datahistoryjobAfterDeleteHooks = []DatahistoryjobHook{}

	AddDatahistoryjobHook(boil.BeforeUpsertHook, datahistoryjobBeforeUpsertHook)
	if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
		t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
	}
	if !reflect.DeepEqual(o, empty) {
		t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
	}
	datahistoryjobBeforeUpsertHooks = []DatahistoryjobHook{}

	AddDatahistoryjobHook(boil.AfterUpsertHook, datahistoryjobAfterUpsertHook)
	if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
		t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
	}
	if !reflect.DeepEqual(o, empty) {
		t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
	}
	datahistoryjobAfterUpsertHooks = []DatahistoryjobHook{}
}

func testDatahistoryjobsInsert(t *testing.T) {
	t.Parallel()

	seed := randomize.NewSeed()
	var err error
	o := &Datahistoryjob{}
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	count, err := Datahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Error(err)
	}

	if count != 1 {
		t.Error("want one record, got:", count)
	}
}

func testDatahistoryjobsInsertWhitelist(t *testing.T) {
	t.Parallel()

	seed := randomize.NewSeed()
	var err error
	o := &Datahistoryjob{}
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Insert(ctx, tx, boil.Whitelist(datahistoryjobColumnsWithoutDefault...)); err != nil {
		t.Error(err)
	}

	count, err := Datahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Error(err)
	}

	if count != 1 {
		t.Error("want one record, got:", count)
	}
}

func testDatahistoryjobToManySourceJobCandles(t *testing.T) {
	var err error
	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c Candle

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	if err = randomize.Struct(seed, &b, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
		t.Fatal(err)
	}

	queries.Assign(&b.SourceJobID, a.ID)
	queries.Assign(&c.SourceJobID, a.ID)
	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	check, err := a.SourceJobCandles().All(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}

	bFound, cFound := false, false
	for _, v := range check {
		if queries.Equal(v.SourceJobID, b.SourceJobID) {
			bFound = true
		}
		if queries.Equal(v.SourceJobID, c.SourceJobID) {
			cFound = true
		}
	}

	if !bFound {
		t.Error("expected to find b")
	}
	if !cFound {
		t.Error("expected to find c")
	}

	slice := DatahistoryjobSlice{&a}
	if err = a.L.LoadSourceJobCandles(ctx, tx, false, (*[]*Datahistoryjob)(&slice), nil); err != nil {
		t.Fatal(err)
	}
	if got := len(a.R.SourceJobCandles); got != 2 {
		t.Error("number of eager loaded records wrong, got:", got)
	}

	a.R.SourceJobCandles = nil
	if err = a.L.LoadSourceJobCandles(ctx, tx, true, &a, nil); err != nil {
		t.Fatal(err)
	}
	if got := len(a.R.SourceJobCandles); got != 2 {
		t.Error("number of eager loaded records wrong, got:", got)
	}

	if t.Failed() {
		t.Logf("%#v", check)
	}
}

func testDatahistoryjobToManyValidationJobCandles(t *testing.T) {
	var err error
	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c Candle

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	if err = randomize.Struct(seed, &b, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
		t.Fatal(err)
	}

	queries.Assign(&b.ValidationJobID, a.ID)
	queries.Assign(&c.ValidationJobID, a.ID)
	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	check, err := a.ValidationJobCandles().All(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}

	bFound, cFound := false, false
	for _, v := range check {
		if queries.Equal(v.ValidationJobID, b.ValidationJobID) {
			bFound = true
		}
		if queries.Equal(v.ValidationJobID, c.ValidationJobID) {
			cFound = true
		}
	}

	if !bFound {
		t.Error("expected to find b")
	}
	if !cFound {
		t.Error("expected to find c")
	}

	slice := DatahistoryjobSlice{&a}
	if err = a.L.LoadValidationJobCandles(ctx, tx, false, (*[]*Datahistoryjob)(&slice), nil); err != nil {
		t.Fatal(err)
	}
	if got := len(a.R.ValidationJobCandles); got != 2 {
		t.Error("number of eager loaded records wrong, got:", got)
	}

	a.R.ValidationJobCandles = nil
	if err = a.L.LoadValidationJobCandles(ctx, tx, true, &a, nil); err != nil {
		t.Fatal(err)
	}
	if got := len(a.R.ValidationJobCandles); got != 2 {
		t.Error("number of eager loaded records wrong, got:", got)
	}

	if t.Failed() {
		t.Logf("%#v", check)
	}
}

func testDatahistoryjobToManyPrerequisiteJobDatahistoryjobs(t *testing.T) {
	var err error
	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c Datahistoryjob

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	if err = randomize.Struct(seed, &b, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
		t.Fatal(err)
	}

	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	_, err = tx.Exec("insert into \"datahistoryjobrelations\" (\"job_id\", \"prerequisite_job_id\") values ($1, $2)", a.ID, b.ID)
	if err != nil {
		t.Fatal(err)
	}
	_, err = tx.Exec("insert into \"datahistoryjobrelations\" (\"job_id\", \"prerequisite_job_id\") values ($1, $2)", a.ID, c.ID)
	if err != nil {
		t.Fatal(err)
	}

	check, err := a.PrerequisiteJobDatahistoryjobs().All(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}

	bFound, cFound := false, false
	for _, v := range check {
		if v.ID == b.ID {
			bFound = true
		}
		if v.ID == c.ID {
			cFound = true
		}
	}

	if !bFound {
		t.Error("expected to find b")
	}
	if !cFound {
		t.Error("expected to find c")
	}

	slice := DatahistoryjobSlice{&a}
	if err = a.L.LoadPrerequisiteJobDatahistoryjobs(ctx, tx, false, (*[]*Datahistoryjob)(&slice), nil); err != nil {
		t.Fatal(err)
	}
	if got := len(a.R.PrerequisiteJobDatahistoryjobs); got != 2 {
		t.Error("number of eager loaded records wrong, got:", got)
	}

	a.R.PrerequisiteJobDatahistoryjobs = nil
	if err = a.L.LoadPrerequisiteJobDatahistoryjobs(ctx, tx, true, &a, nil); err != nil {
		t.Fatal(err)
	}
	if got := len(a.R.PrerequisiteJobDatahistoryjobs); got != 2 {
		t.Error("number of eager loaded records wrong, got:", got)
	}

	if t.Failed() {
		t.Logf("%#v", check)
	}
}

func testDatahistoryjobToManyJobDatahistoryjobs(t *testing.T) {
	var err error
	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c Datahistoryjob

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	if err = randomize.Struct(seed, &b, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
		t.Fatal(err)
	}

	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	_, err = tx.Exec("insert into \"datahistoryjobrelations\" (\"prerequisite_job_id\", \"job_id\") values ($1, $2)", a.ID, b.ID)
	if err != nil {
		t.Fatal(err)
	}
	_, err = tx.Exec("insert into \"datahistoryjobrelations\" (\"prerequisite_job_id\", \"job_id\") values ($1, $2)", a.ID, c.ID)
	if err != nil {
		t.Fatal(err)
	}

	check, err := a.JobDatahistoryjobs().All(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}

	bFound, cFound := false, false
	for _, v := range check {
		if v.ID == b.ID {
			bFound = true
		}
		if v.ID == c.ID {
			cFound = true
		}
	}

	if !bFound {
		t.Error("expected to find b")
	}
	if !cFound {
		t.Error("expected to find c")
	}

	slice := DatahistoryjobSlice{&a}
	if err = a.L.LoadJobDatahistoryjobs(ctx, tx, false, (*[]*Datahistoryjob)(&slice), nil); err != nil {
		t.Fatal(err)
	}
	if got := len(a.R.JobDatahistoryjobs); got != 2 {
		t.Error("number of eager loaded records wrong, got:", got)
	}

	a.R.JobDatahistoryjobs = nil
	if err = a.L.LoadJobDatahistoryjobs(ctx, tx, true, &a, nil); err != nil {
		t.Fatal(err)
	}
	if got := len(a.R.JobDatahistoryjobs); got != 2 {
		t.Error("number of eager loaded records wrong, got:", got)
	}

	if t.Failed() {
		t.Logf("%#v", check)
	}
}

func testDatahistoryjobToManyJobDatahistoryjobresults(t *testing.T) {
	var err error
	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c Datahistoryjobresult

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	if err = randomize.Struct(seed, &b, datahistoryjobresultDBTypes, false, datahistoryjobresultColumnsWithDefault...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, datahistoryjobresultDBTypes, false, datahistoryjobresultColumnsWithDefault...); err != nil {
		t.Fatal(err)
	}

	b.JobID = a.ID
	c.JobID = a.ID

	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	check, err := a.JobDatahistoryjobresults().All(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}

	bFound, cFound := false, false
	for _, v := range check {
		if v.JobID == b.JobID {
			bFound = true
		}
		if v.JobID == c.JobID {
			cFound = true
		}
	}

	if !bFound {
		t.Error("expected to find b")
	}
	if !cFound {
		t.Error("expected to find c")
	}

	slice := DatahistoryjobSlice{&a}
	if err = a.L.LoadJobDatahistoryjobresults(ctx, tx, false, (*[]*Datahistoryjob)(&slice), nil); err != nil {
		t.Fatal(err)
	}
	if got := len(a.R.JobDatahistoryjobresults); got != 2 {
		t.Error("number of eager loaded records wrong, got:", got)
	}

	a.R.JobDatahistoryjobresults = nil
	if err = a.L.LoadJobDatahistoryjobresults(ctx, tx, true, &a, nil); err != nil {
		t.Fatal(err)
	}
	if got := len(a.R.JobDatahistoryjobresults); got != 2 {
		t.Error("number of eager loaded records wrong, got:", got)
	}

	if t.Failed() {
		t.Logf("%#v", check)
	}
}

func testDatahistoryjobToManyAddOpSourceJobCandles(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c, d, e Candle

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Candle{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	foreignersSplitByInsertion := [][]*Candle{
		{&b, &c},
		{&d, &e},
	}

	for i, x := range foreignersSplitByInsertion {
		err = a.AddSourceJobCandles(ctx, tx, i != 0, x...)
		if err != nil {
			t.Fatal(err)
		}

		first := x[0]
		second := x[1]

		if !queries.Equal(a.ID, first.SourceJobID) {
			t.Error("foreign key was wrong value", a.ID, first.SourceJobID)
		}
		if !queries.Equal(a.ID, second.SourceJobID) {
			t.Error("foreign key was wrong value", a.ID, second.SourceJobID)
		}

		if first.R.SourceJob != &a {
			t.Error("relationship was not added properly to the foreign slice")
		}
		if second.R.SourceJob != &a {
			t.Error("relationship was not added properly to the foreign slice")
		}

		if a.R.SourceJobCandles[i*2] != first {
			t.Error("relationship struct slice not set to correct value")
		}
		if a.R.SourceJobCandles[i*2+1] != second {
			t.Error("relationship struct slice not set to correct value")
		}

		count, err := a.SourceJobCandles().Count(ctx, tx)
		if err != nil {
			t.Fatal(err)
		}
		if want := int64((i + 1) * 2); count != want {
			t.Error("want", want, "got", count)
		}
	}
}

func testDatahistoryjobToManySetOpSourceJobCandles(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c, d, e Candle

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Candle{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err = a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	err = a.SetSourceJobCandles(ctx, tx, false, &b, &c)
	if err != nil {
		t.Fatal(err)
	}

	count, err := a.SourceJobCandles().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	err = a.SetSourceJobCandles(ctx, tx, true, &d, &e)
	if err != nil {
		t.Fatal(err)
	}

	count, err = a.SourceJobCandles().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	if !queries.IsValuerNil(b.SourceJobID) {
		t.Error("want b's foreign key value to be nil")
	}
	if !queries.IsValuerNil(c.SourceJobID) {
		t.Error("want c's foreign key value to be nil")
	}
	if !queries.Equal(a.ID, d.SourceJobID) {
		t.Error("foreign key was wrong value", a.ID, d.SourceJobID)
	}
	if !queries.Equal(a.ID, e.SourceJobID) {
		t.Error("foreign key was wrong value", a.ID, e.SourceJobID)
	}

	if b.R.SourceJob != nil {
		t.Error("relationship was not removed properly from the foreign struct")
	}
	if c.R.SourceJob != nil {
		t.Error("relationship was not removed properly from the foreign struct")
	}
	if d.R.SourceJob != &a {
		t.Error("relationship was not added properly to the foreign struct")
	}
	if e.R.SourceJob != &a {
		t.Error("relationship was not added properly to the foreign struct")
	}

	if a.R.SourceJobCandles[0] != &d {
		t.Error("relationship struct slice not set to correct value")
	}
	if a.R.SourceJobCandles[1] != &e {
		t.Error("relationship struct slice not set to correct value")
	}
}

func testDatahistoryjobToManyRemoveOpSourceJobCandles(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c, d, e Candle

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Candle{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	err = a.AddSourceJobCandles(ctx, tx, true, foreigners...)
	if err != nil {
		t.Fatal(err)
	}

	count, err := a.SourceJobCandles().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 4 {
		t.Error("count was wrong:", count)
	}

	err = a.RemoveSourceJobCandles(ctx, tx, foreigners[:2]...)
	if err != nil {
		t.Fatal(err)
	}

	count, err = a.SourceJobCandles().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	if !queries.IsValuerNil(b.SourceJobID) {
		t.Error("want b's foreign key value to be nil")
	}
	if !queries.IsValuerNil(c.SourceJobID) {
		t.Error("want c's foreign key value to be nil")
	}

	if b.R.SourceJob != nil {
		t.Error("relationship was not removed properly from the foreign struct")
	}
	if c.R.SourceJob != nil {
		t.Error("relationship was not removed properly from the foreign struct")
	}
	if d.R.SourceJob != &a {
		t.Error("relationship to a should have been preserved")
	}
	if e.R.SourceJob != &a {
		t.Error("relationship to a should have been preserved")
	}

	if len(a.R.SourceJobCandles) != 2 {
		t.Error("should have preserved two relationships")
	}

	// Removal doesn't do a stable deletion for performance so we have to flip the order
	if a.R.SourceJobCandles[1] != &d {
		t.Error("relationship to d should have been preserved")
	}
	if a.R.SourceJobCandles[0] != &e {
		t.Error("relationship to e should have been preserved")
	}
}

func testDatahistoryjobToManyAddOpValidationJobCandles(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c, d, e Candle

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Candle{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	foreignersSplitByInsertion := [][]*Candle{
		{&b, &c},
		{&d, &e},
	}

	for i, x := range foreignersSplitByInsertion {
		err = a.AddValidationJobCandles(ctx, tx, i != 0, x...)
		if err != nil {
			t.Fatal(err)
		}

		first := x[0]
		second := x[1]

		if !queries.Equal(a.ID, first.ValidationJobID) {
			t.Error("foreign key was wrong value", a.ID, first.ValidationJobID)
		}
		if !queries.Equal(a.ID, second.ValidationJobID) {
			t.Error("foreign key was wrong value", a.ID, second.ValidationJobID)
		}

		if first.R.ValidationJob != &a {
			t.Error("relationship was not added properly to the foreign slice")
		}
		if second.R.ValidationJob != &a {
			t.Error("relationship was not added properly to the foreign slice")
		}

		if a.R.ValidationJobCandles[i*2] != first {
			t.Error("relationship struct slice not set to correct value")
		}
		if a.R.ValidationJobCandles[i*2+1] != second {
			t.Error("relationship struct slice not set to correct value")
		}

		count, err := a.ValidationJobCandles().Count(ctx, tx)
		if err != nil {
			t.Fatal(err)
		}
		if want := int64((i + 1) * 2); count != want {
			t.Error("want", want, "got", count)
		}
	}
}

func testDatahistoryjobToManySetOpValidationJobCandles(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c, d, e Candle

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Candle{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err = a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	err = a.SetValidationJobCandles(ctx, tx, false, &b, &c)
	if err != nil {
		t.Fatal(err)
	}

	count, err := a.ValidationJobCandles().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	err = a.SetValidationJobCandles(ctx, tx, true, &d, &e)
	if err != nil {
		t.Fatal(err)
	}

	count, err = a.ValidationJobCandles().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	if !queries.IsValuerNil(b.ValidationJobID) {
		t.Error("want b's foreign key value to be nil")
	}
	if !queries.IsValuerNil(c.ValidationJobID) {
		t.Error("want c's foreign key value to be nil")
	}
	if !queries.Equal(a.ID, d.ValidationJobID) {
		t.Error("foreign key was wrong value", a.ID, d.ValidationJobID)
	}
	if !queries.Equal(a.ID, e.ValidationJobID) {
		t.Error("foreign key was wrong value", a.ID, e.ValidationJobID)
	}

	if b.R.ValidationJob != nil {
		t.Error("relationship was not removed properly from the foreign struct")
	}
	if c.R.ValidationJob != nil {
		t.Error("relationship was not removed properly from the foreign struct")
	}
	if d.R.ValidationJob != &a {
		t.Error("relationship was not added properly to the foreign struct")
	}
	if e.R.ValidationJob != &a {
		t.Error("relationship was not added properly to the foreign struct")
	}

	if a.R.ValidationJobCandles[0] != &d {
		t.Error("relationship struct slice not set to correct value")
	}
	if a.R.ValidationJobCandles[1] != &e {
		t.Error("relationship struct slice not set to correct value")
	}
}

func testDatahistoryjobToManyRemoveOpValidationJobCandles(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c, d, e Candle

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Candle{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	err = a.AddValidationJobCandles(ctx, tx, true, foreigners...)
	if err != nil {
		t.Fatal(err)
	}

	count, err := a.ValidationJobCandles().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 4 {
		t.Error("count was wrong:", count)
	}

	err = a.RemoveValidationJobCandles(ctx, tx, foreigners[:2]...)
	if err != nil {
		t.Fatal(err)
	}

	count, err = a.ValidationJobCandles().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	if !queries.IsValuerNil(b.ValidationJobID) {
		t.Error("want b's foreign key value to be nil")
	}
	if !queries.IsValuerNil(c.ValidationJobID) {
		t.Error("want c's foreign key value to be nil")
	}

	if b.R.ValidationJob != nil {
		t.Error("relationship was not removed properly from the foreign struct")
	}
	if c.R.ValidationJob != nil {
		t.Error("relationship was not removed properly from the foreign struct")
	}
	if d.R.ValidationJob != &a {
		t.Error("relationship to a should have been preserved")
	}
	if e.R.ValidationJob != &a {
		t.Error("relationship to a should have been preserved")
	}

	if len(a.R.ValidationJobCandles) != 2 {
		t.Error("should have preserved two relationships")
	}

	// Removal doesn't do a stable deletion for performance so we have to flip the order
	if a.R.ValidationJobCandles[1] != &d {
		t.Error("relationship to d should have been preserved")
	}
	if a.R.ValidationJobCandles[0] != &e {
		t.Error("relationship to e should have been preserved")
	}
}

func testDatahistoryjobToManyAddOpPrerequisiteJobDatahistoryjobs(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c, d, e Datahistoryjob

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Datahistoryjob{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	foreignersSplitByInsertion := [][]*Datahistoryjob{
		{&b, &c},
		{&d, &e},
	}

	for i, x := range foreignersSplitByInsertion {
		err = a.AddPrerequisiteJobDatahistoryjobs(ctx, tx, i != 0, x...)
		if err != nil {
			t.Fatal(err)
		}

		first := x[0]
		second := x[1]

		if first.R.JobDatahistoryjobs[0] != &a {
			t.Error("relationship was not added properly to the slice")
		}
		if second.R.JobDatahistoryjobs[0] != &a {
			t.Error("relationship was not added properly to the slice")
		}

		if a.R.PrerequisiteJobDatahistoryjobs[i*2] != first {
			t.Error("relationship struct slice not set to correct value")
		}
		if a.R.PrerequisiteJobDatahistoryjobs[i*2+1] != second {
			t.Error("relationship struct slice not set to correct value")
		}

		count, err := a.PrerequisiteJobDatahistoryjobs().Count(ctx, tx)
		if err != nil {
			t.Fatal(err)
		}
		if want := int64((i + 1) * 2); count != want {
			t.Error("want", want, "got", count)
		}
	}
}

func testDatahistoryjobToManySetOpPrerequisiteJobDatahistoryjobs(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c, d, e Datahistoryjob

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Datahistoryjob{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err = a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	err = a.SetPrerequisiteJobDatahistoryjobs(ctx, tx, false, &b, &c)
	if err != nil {
		t.Fatal(err)
	}

	count, err := a.PrerequisiteJobDatahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	err = a.SetPrerequisiteJobDatahistoryjobs(ctx, tx, true, &d, &e)
	if err != nil {
		t.Fatal(err)
	}

	count, err = a.PrerequisiteJobDatahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	// The following checks cannot be implemented since we have no handle
	// to these when we call Set(). Leaving them here as wishful thinking
	// and to let people know there's dragons.
	//
	// if len(b.R.JobDatahistoryjobs) != 0 {
	// 	t.Error("relationship was not removed properly from the slice")
	// }
	// if len(c.R.JobDatahistoryjobs) != 0 {
	// 	t.Error("relationship was not removed properly from the slice")
	// }
	if d.R.JobDatahistoryjobs[0] != &a {
		t.Error("relationship was not added properly to the slice")
	}
	if e.R.JobDatahistoryjobs[0] != &a {
		t.Error("relationship was not added properly to the slice")
	}

	if a.R.PrerequisiteJobDatahistoryjobs[0] != &d {
		t.Error("relationship struct slice not set to correct value")
	}
	if a.R.PrerequisiteJobDatahistoryjobs[1] != &e {
		t.Error("relationship struct slice not set to correct value")
	}
}

func testDatahistoryjobToManyRemoveOpPrerequisiteJobDatahistoryjobs(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c, d, e Datahistoryjob

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Datahistoryjob{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	err = a.AddPrerequisiteJobDatahistoryjobs(ctx, tx, true, foreigners...)
	if err != nil {
		t.Fatal(err)
	}

	count, err := a.PrerequisiteJobDatahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 4 {
		t.Error("count was wrong:", count)
	}

	err = a.RemovePrerequisiteJobDatahistoryjobs(ctx, tx, foreigners[:2]...)
	if err != nil {
		t.Fatal(err)
	}

	count, err = a.PrerequisiteJobDatahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	if len(b.R.JobDatahistoryjobs) != 0 {
		t.Error("relationship was not removed properly from the slice")
	}
	if len(c.R.JobDatahistoryjobs) != 0 {
		t.Error("relationship was not removed properly from the slice")
	}
	if d.R.JobDatahistoryjobs[0] != &a {
		t.Error("relationship was not added properly to the foreign struct")
	}
	if e.R.JobDatahistoryjobs[0] != &a {
		t.Error("relationship was not added properly to the foreign struct")
	}

	if len(a.R.PrerequisiteJobDatahistoryjobs) != 2 {
		t.Error("should have preserved two relationships")
	}

	// Removal doesn't do a stable deletion for performance so we have to flip the order
	if a.R.PrerequisiteJobDatahistoryjobs[1] != &d {
		t.Error("relationship to d should have been preserved")
	}
	if a.R.PrerequisiteJobDatahistoryjobs[0] != &e {
		t.Error("relationship to e should have been preserved")
	}
}

func testDatahistoryjobToManyAddOpJobDatahistoryjobs(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c, d, e Datahistoryjob

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Datahistoryjob{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	foreignersSplitByInsertion := [][]*Datahistoryjob{
		{&b, &c},
		{&d, &e},
	}

	for i, x := range foreignersSplitByInsertion {
		err = a.AddJobDatahistoryjobs(ctx, tx, i != 0, x...)
		if err != nil {
			t.Fatal(err)
		}

		first := x[0]
		second := x[1]

		if first.R.PrerequisiteJobDatahistoryjobs[0] != &a {
			t.Error("relationship was not added properly to the slice")
		}
		if second.R.PrerequisiteJobDatahistoryjobs[0] != &a {
			t.Error("relationship was not added properly to the slice")
		}

		if a.R.JobDatahistoryjobs[i*2] != first {
			t.Error("relationship struct slice not set to correct value")
		}
		if a.R.JobDatahistoryjobs[i*2+1] != second {
			t.Error("relationship struct slice not set to correct value")
		}

		count, err := a.JobDatahistoryjobs().Count(ctx, tx)
		if err != nil {
			t.Fatal(err)
		}
		if want := int64((i + 1) * 2); count != want {
			t.Error("want", want, "got", count)
		}
	}
}

func testDatahistoryjobToManySetOpJobDatahistoryjobs(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c, d, e Datahistoryjob

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Datahistoryjob{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err = a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	err = a.SetJobDatahistoryjobs(ctx, tx, false, &b, &c)
	if err != nil {
		t.Fatal(err)
	}

	count, err := a.JobDatahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	err = a.SetJobDatahistoryjobs(ctx, tx, true, &d, &e)
	if err != nil {
		t.Fatal(err)
	}

	count, err = a.JobDatahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	// The following checks cannot be implemented since we have no handle
	// to these when we call Set(). Leaving them here as wishful thinking
	// and to let people know there's dragons.
	//
	// if len(b.R.PrerequisiteJobDatahistoryjobs) != 0 {
	// 	t.Error("relationship was not removed properly from the slice")
	// }
	// if len(c.R.PrerequisiteJobDatahistoryjobs) != 0 {
	// 	t.Error("relationship was not removed properly from the slice")
	// }
	if d.R.PrerequisiteJobDatahistoryjobs[0] != &a {
		t.Error("relationship was not added properly to the slice")
	}
	if e.R.PrerequisiteJobDatahistoryjobs[0] != &a {
		t.Error("relationship was not added properly to the slice")
	}

	if a.R.JobDatahistoryjobs[0] != &d {
		t.Error("relationship struct slice not set to correct value")
	}
	if a.R.JobDatahistoryjobs[1] != &e {
		t.Error("relationship struct slice not set to correct value")
	}
}

func testDatahistoryjobToManyRemoveOpJobDatahistoryjobs(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c, d, e Datahistoryjob

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Datahistoryjob{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	err = a.AddJobDatahistoryjobs(ctx, tx, true, foreigners...)
	if err != nil {
		t.Fatal(err)
	}

	count, err := a.JobDatahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 4 {
		t.Error("count was wrong:", count)
	}

	err = a.RemoveJobDatahistoryjobs(ctx, tx, foreigners[:2]...)
	if err != nil {
		t.Fatal(err)
	}

	count, err = a.JobDatahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	if len(b.R.PrerequisiteJobDatahistoryjobs) != 0 {
		t.Error("relationship was not removed properly from the slice")
	}
	if len(c.R.PrerequisiteJobDatahistoryjobs) != 0 {
		t.Error("relationship was not removed properly from the slice")
	}
	if d.R.PrerequisiteJobDatahistoryjobs[0] != &a {
		t.Error("relationship was not added properly to the foreign struct")
	}
	if e.R.PrerequisiteJobDatahistoryjobs[0] != &a {
		t.Error("relationship was not added properly to the foreign struct")
	}

	if len(a.R.JobDatahistoryjobs) != 2 {
		t.Error("should have preserved two relationships")
	}

	// Removal doesn't do a stable deletion for performance so we have to flip the order
	if a.R.JobDatahistoryjobs[1] != &d {
		t.Error("relationship to d should have been preserved")
	}
	if a.R.JobDatahistoryjobs[0] != &e {
		t.Error("relationship to e should have been preserved")
	}
}

func testDatahistoryjobToManyAddOpJobDatahistoryjobresults(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c, d, e Datahistoryjobresult

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Datahistoryjobresult{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, datahistoryjobresultDBTypes, false, strmangle.SetComplement(datahistoryjobresultPrimaryKeyColumns, datahistoryjobresultColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	foreignersSplitByInsertion := [][]*Datahistoryjobresult{
		{&b, &c},
		{&d, &e},
	}

	for i, x := range foreignersSplitByInsertion {
		err = a.AddJobDatahistoryjobresults(ctx, tx, i != 0, x...)
		if err != nil {
			t.Fatal(err)
		}

		first := x[0]
		second := x[1]

		if a.ID != first.JobID {
			t.Error("foreign key was wrong value", a.ID, first.JobID)
		}
		if a.ID != second.JobID {
			t.Error("foreign key was wrong value", a.ID, second.JobID)
		}

		if first.R.Job != &a {
			t.Error("relationship was not added properly to the foreign slice")
		}
		if second.R.Job != &a {
			t.Error("relationship was not added properly to the foreign slice")
		}

		if a.R.JobDatahistoryjobresults[i*2] != first {
			t.Error("relationship struct slice not set to correct value")
		}
		if a.R.JobDatahistoryjobresults[i*2+1] != second {
			t.Error("relationship struct slice not set to correct value")
		}

		count, err := a.JobDatahistoryjobresults().Count(ctx, tx)
		if err != nil {
			t.Fatal(err)
		}
		if want := int64((i + 1) * 2); count != want {
			t.Error("want", want, "got", count)
		}
	}
}
func testDatahistoryjobToOneExchangeUsingExchangeName(t *testing.T) {
	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var local Datahistoryjob
	var foreign Exchange

	seed := randomize.NewSeed()
	if err := randomize.Struct(seed, &local, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}
	if err := randomize.Struct(seed, &foreign, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Exchange struct: %s", err)
	}

	if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	local.ExchangeNameID = foreign.ID
	if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	check, err := local.ExchangeName().One(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}

	if check.ID != foreign.ID {
		t.Errorf("want: %v, got %v", foreign.ID, check.ID)
	}

	slice := DatahistoryjobSlice{&local}
	if err = local.L.LoadExchangeName(ctx, tx, false, (*[]*Datahistoryjob)(&slice), nil); err != nil {
		t.Fatal(err)
	}
	if local.R.ExchangeName == nil {
		t.Error("struct should have been eager loaded")
	}

	local.R.ExchangeName = nil
	if err = local.L.LoadExchangeName(ctx, tx, true, &local, nil); err != nil {
		t.Fatal(err)
	}
	if local.R.ExchangeName == nil {
		t.Error("struct should have been eager loaded")
	}
}

func testDatahistoryjobToOneExchangeUsingSecondaryExchange(t *testing.T) {
	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var local Datahistoryjob
	var foreign Exchange

	seed := randomize.NewSeed()
	if err := randomize.Struct(seed, &local, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}
	if err := randomize.Struct(seed, &foreign, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Exchange struct: %s", err)
	}

	if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	queries.Assign(&local.SecondaryExchangeID, foreign.ID)
	if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	check, err := local.SecondaryExchange().One(ctx, tx)
	if err != nil {
		t.Fatal(err)
	}

	if !queries.Equal(check.ID, foreign.ID) {
		t.Errorf("want: %v, got %v", foreign.ID, check.ID)
	}

	slice := DatahistoryjobSlice{&local}
	if err = local.L.LoadSecondaryExchange(ctx, tx, false, (*[]*Datahistoryjob)(&slice), nil); err != nil {
		t.Fatal(err)
	}
	if local.R.SecondaryExchange == nil {
		t.Error("struct should have been eager loaded")
	}

	local.R.SecondaryExchange = nil
	if err = local.L.LoadSecondaryExchange(ctx, tx, true, &local, nil); err != nil {
		t.Fatal(err)
	}
	if local.R.SecondaryExchange == nil {
		t.Error("struct should have been eager loaded")
	}
}

func testDatahistoryjobToOneSetOpExchangeUsingExchangeName(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c Exchange

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*Exchange{&b, &c} {
		err = a.SetExchangeName(ctx, tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.ExchangeName != x {
			t.Error("relationship struct not set to correct value")
		}

		if x.R.ExchangeNameDatahistoryjobs[0] != &a {
			t.Error("failed to append to foreign relationship struct")
		}
		if a.ExchangeNameID != x.ID {
			t.Error("foreign key was wrong value", a.ExchangeNameID)
		}

		zero := reflect.Zero(reflect.TypeOf(a.ExchangeNameID))
		reflect.Indirect(reflect.ValueOf(&a.ExchangeNameID)).Set(zero)

		if err = a.Reload(ctx, tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.ExchangeNameID != x.ID {
			t.Error("foreign key was wrong value", a.ExchangeNameID, x.ID)
		}
	}
}
func testDatahistoryjobToOneSetOpExchangeUsingSecondaryExchange(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b, c Exchange

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*Exchange{&b, &c} {
		err = a.SetSecondaryExchange(ctx, tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.SecondaryExchange != x {
			t.Error("relationship struct not set to correct value")
		}

		if x.R.SecondaryExchangeDatahistoryjobs[0] != &a {
			t.Error("failed to append to foreign relationship struct")
		}
		if !queries.Equal(a.SecondaryExchangeID, x.ID) {
			t.Error("foreign key was wrong value", a.SecondaryExchangeID)
		}

		zero := reflect.Zero(reflect.TypeOf(a.SecondaryExchangeID))
		reflect.Indirect(reflect.ValueOf(&a.SecondaryExchangeID)).Set(zero)

		if err = a.Reload(ctx, tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if !queries.Equal(a.SecondaryExchangeID, x.ID) {
			t.Error("foreign key was wrong value", a.SecondaryExchangeID, x.ID)
		}
	}
}

func testDatahistoryjobToOneRemoveOpExchangeUsingSecondaryExchange(t *testing.T) {
	var err error

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()

	var a Datahistoryjob
	var b Exchange

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err = a.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Fatal(err)
	}

	if err = a.SetSecondaryExchange(ctx, tx, true, &b); err != nil {
		t.Fatal(err)
	}

	if err = a.RemoveSecondaryExchange(ctx, tx, &b); err != nil {
		t.Error("failed to remove relationship")
	}

	count, err := a.SecondaryExchange().Count(ctx, tx)
	if err != nil {
		t.Error(err)
	}
	if count != 0 {
		t.Error("want no relationships remaining")
	}

	if a.R.SecondaryExchange != nil {
		t.Error("R struct entry should be nil")
	}

	if !queries.IsValuerNil(a.SecondaryExchangeID) {
		t.Error("foreign key value should be nil")
	}

	if len(b.R.SecondaryExchangeDatahistoryjobs) != 0 {
		t.Error("failed to remove a from b's relationships")
	}
}

func testDatahistoryjobsReload(t *testing.T) {
	t.Parallel()

	seed := randomize.NewSeed()
	var err error
	o := &Datahistoryjob{}
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	if err = o.Reload(ctx, tx); err != nil {
		t.Error(err)
	}
}

func testDatahistoryjobsReloadAll(t *testing.T) {
	t.Parallel()

	seed := randomize.NewSeed()
	var err error
	o := &Datahistoryjob{}
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	slice := DatahistoryjobSlice{o}

	if err = slice.ReloadAll(ctx, tx); err != nil {
		t.Error(err)
	}
}

func testDatahistoryjobsSelect(t *testing.T) {
	t.Parallel()

	seed := randomize.NewSeed()
	var err error
	o := &Datahistoryjob{}
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	slice, err := Datahistoryjobs().All(ctx, tx)
	if err != nil {
		t.Error(err)
	}

	if len(slice) != 1 {
		t.Error("want one record, got:", len(slice))
	}
}

var (
	datahistoryjobDBTypes = map[string]string{`ID`: `uuid`, `Nickname`: `character varying`, `ExchangeNameID`: `uuid`, `Asset`: `character varying`, `Base`: `character varying`, `Quote`: `character varying`, `StartTime`: `timestamp with time zone`, `EndTime`: `timestamp with time zone`, `DataType`: `double precision`, `Interval`: `double precision`, `RequestSize`: `double precision`, `MaxRetries`: `double precision`, `BatchCount`: `double precision`, `Status`: `double precision`, `Created`: `timestamp with time zone`, `ConversionInterval`: `double precision`, `OverwriteData`: `boolean`, `DecimalPlaceComparison`: `integer`, `SecondaryExchangeID`: `uuid`, `IssueTolerancePercentage`: `double precision`, `ReplaceOnIssue`: `boolean`}
	_                     = bytes.MinRead
)

func testDatahistoryjobsUpdate(t *testing.T) {
	t.Parallel()

	if 0 == len(datahistoryjobPrimaryKeyColumns) {
		t.Skip("Skipping table with no primary key columns")
	}
	if len(datahistoryjobAllColumns) == len(datahistoryjobPrimaryKeyColumns) {
		t.Skip("Skipping table with only primary key columns")
	}

	seed := randomize.NewSeed()
	var err error
	o := &Datahistoryjob{}
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	count, err := Datahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Error(err)
	}

	if count != 1 {
		t.Error("want one record, got:", count)
	}

	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobPrimaryKeyColumns...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	} else if rowsAff != 1 {
		t.Error("should only affect one row but affected", rowsAff)
	}
}

func testDatahistoryjobsSliceUpdateAll(t *testing.T) {
	t.Parallel()

	if len(datahistoryjobAllColumns) == len(datahistoryjobPrimaryKeyColumns) {
		t.Skip("Skipping table with only primary key columns")
	}

	seed := randomize.NewSeed()
	var err error
	o := &Datahistoryjob{}
	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
		t.Error(err)
	}

	count, err := Datahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Error(err)
	}

	if count != 1 {
		t.Error("want one record, got:", count)
	}

	if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobPrimaryKeyColumns...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	// Remove Primary keys and unique columns from what we plan to update
	var fields []string
	if strmangle.StringSliceMatch(datahistoryjobAllColumns, datahistoryjobPrimaryKeyColumns) {
		fields = datahistoryjobAllColumns
	} else {
		fields = strmangle.SetComplement(
			datahistoryjobAllColumns,
			datahistoryjobPrimaryKeyColumns,
		)
	}

	value := reflect.Indirect(reflect.ValueOf(o))
	typ := reflect.TypeOf(o).Elem()
	n := typ.NumField()

	updateMap := M{}
	for _, col := range fields {
		for i := 0; i < n; i++ {
			f := typ.Field(i)
			if f.Tag.Get("boil") == col {
				updateMap[col] = value.Field(i).Interface()
			}
		}
	}

	slice := DatahistoryjobSlice{o}
	if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
		t.Error(err)
	} else if rowsAff != 1 {
		t.Error("wanted one record updated but got", rowsAff)
	}
}

func testDatahistoryjobsUpsert(t *testing.T) {
	t.Parallel()

	if len(datahistoryjobAllColumns) == len(datahistoryjobPrimaryKeyColumns) {
		t.Skip("Skipping table with only primary key columns")
	}

	seed := randomize.NewSeed()
	var err error
	// Attempt the INSERT side of an UPSERT
	o := Datahistoryjob{}
	if err = randomize.Struct(seed, &o, datahistoryjobDBTypes, true); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	ctx := context.Background()
	tx := MustTx(boil.BeginTx(ctx, nil))
	defer func() { _ = tx.Rollback() }()
	if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil {
		t.Errorf("Unable to upsert Datahistoryjob: %s", err)
	}

	count, err := Datahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Error(err)
	}
	if count != 1 {
		t.Error("want one record, got:", count)
	}

	// Attempt the UPDATE side of an UPSERT
	if err = randomize.Struct(seed, &o, datahistoryjobDBTypes, false, datahistoryjobPrimaryKeyColumns...); err != nil {
		t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
	}

	if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
		t.Errorf("Unable to upsert Datahistoryjob: %s", err)
	}

	count, err = Datahistoryjobs().Count(ctx, tx)
	if err != nil {
		t.Error(err)
	}
	if count != 1 {
		t.Error("want one record, got:", count)
	}
}


text:
<!doctype html>

        <meta charset="utf-8">
        <title>ReactJS Bootcamp</title>
        <meta name="description" content="A framework for easily creating beautiful presentations using HTML">
        <meta name="author" content="Westin & Stephen">
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
        <link rel="stylesheet" href="../__lib/css/reveal.css">
        <link rel="stylesheet" href="../__lib/css/theme/sky.css" id="theme">

        <link rel="stylesheet" href="../__lib/lib/css/zenburn.css">

Welcome to Day 5 of ReactJS Bootcamp

Agenda

Introduction to Flux

Actions, Dispatchers, Stores

Overall Result of Flux Architecture

Flux

                            Flux is really just a fancy term for pub/sub architecture,
                            i.e. data always flows one way through the application and
                            it is picked up along the way by various subscribers (stores)
                            who are listening to it.

                        Flux eschews MVC in favor of unidirectional data flow.
                        What this means is that data enters through a single place (your actions)
                        and then flow outward through their state manager (the store)
                        and finally onto the view. The view can then restart the flow by calling
                        other actions in response to user input.

Why Flux

State is messy

Unidirectional data makes for easy debugging

Composable components favor reuse

Stores as a single domain also simplifies debugging

Dispatcher

*SINGLE* messaging hub in the application

Registry of callbacks

Has no logic

Dispatcher recieves actions and fires corresponding callback

Can manage dependencies between stores

Stores

Contain the domain logic

More than just a model

All stores get the callback from the dispatcher and handle in a case statement

Changes made through dispatcher -> Store's case statement on action type -> Data update -> Fire change event

Views can query the store but they are treated as immutable from view's perspective

Actions

Views can start the communication intents via actions

Actions are sent through the dispatcher and sent out to the stores

We have had luck with past tense but it doesn't matter as long as you are consistent

Try to keep actions generic where possible

redpajama_set_name: RedPajamaGithub


text:
<?php

namespace Sylius\Bundle\CoreBundle\Provider;

use Sylius\Bundle\SettingsBundle\Model\Settings;
use Sylius\Component\Core\Provider\ZoneProviderInterface;

/**
 * @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
 */
class DefaultTaxZoneProvider implements ZoneProviderInterface
{
    /**
     * @var Settings
     */
    private $settings;

    /**
     * @param Settings $settings
     */
    public function __construct(Settings $settings)
    {
        $this->settings = $settings;
    }

    /**
     * {@inheritdoc}
     */
    public function getZone()
    {
        if ($this->settings->has('default_tax_zone')) {
            return $this->settings->get('default_tax_zone');
        }

        return null;
    }
}


text:
package org.finra.herd.dao.impl;

import java.util.List;
import java.util.Properties;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.apache.oozie.client.OozieClient;
import org.apache.oozie.client.OozieClientException;
import org.apache.oozie.client.WorkflowJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import org.finra.herd.core.helper.ConfigurationHelper;
import org.finra.herd.dao.OozieDao;
import org.finra.herd.dao.OozieOperations;
import org.finra.herd.dao.helper.EmrHelper;
import org.finra.herd.model.ObjectNotFoundException;
import org.finra.herd.model.api.xml.Parameter;
import org.finra.herd.model.dto.ConfigurationValue;

/**
 * The Oozie DAO implementation.
 */
@Repository
public class OozieDaoImpl implements OozieDao
{
    // TODO: Migrate these statuses to "HERD_PREP" and "HERD_FAILED". This is a breaking change since the statuses are returned from the REST tier
    // so this may be difficult.
    /*
     * The status that will be returned, when herd wrapper workflow has not yet started to run the client workflow.
     */
    public static final String OOZIE_WORKFLOW_JOB_STATUS_DM_PREP = "DM_PREP";
    public static final String OOZIE_WORKFLOW_JOB_STATUS_DM_FAILED = "DM_FAILED";

    public static final String OOZIE_ERROR_CODE_JOB_DOES_NOT_EXIST = "E0604";
    public static final String HERD_OOZIE_WRAPPER_WORKFLOW_NAME = "herd_wrapper_workflow";
    public static final String ACTION_NAME_CLIENT_WORKFLOW = "client_workflow";

    private static final String MAP_REDUCE_QUEUE_NAME_VARIABLE = "queueName";
    private static final String MAP_REDUCE_QUEUE_NAME_VALUE = "default";

    private static final String MASTER_IP_VARIABLE = "masterIp";

    private static final String OOZIE_USE_SYSTEM_LIBPATH_VARIABLE = "oozie.use.system.libpath";
    private static final String OOZIE_USE_SYSTEM_LIBPATH_VALUE = "true";

    private static final String NAMENODE_VARIABLE = "nameNode";
    private static final String NAMENODE_VALUE = "hdfs://${masterIp}:9000";

    private static final String JOB_TRACKER_VARIABLE = "jobTracker";
    private static final String JOB_TRACKER_VALUE = "${masterIp}:9022";

    private static final String USER_NAME_VARIABLE = "user.name";
    private static final String USER_NAME_VALUE = "hadoop";

    private static final String OOZIE_WF_APPLICATION_PATH_VARIABLE = "oozie.wf.application.path";
    private static final String OOZIE_WF_APPLICATION_PATH_VALUE = "${nameNode}/user/hadoop/datamgmt/oozie_wrapper/";

    private static final String S3_HDFS_COPY_SCRIPT_VARIABLE = "s3_hdfs_copy_script";

    private static final String TEMP_FOLDER_SUFFIX_VARIABLE = "temp_folder_suffix";

    private static final String CLIENT_WORKFLOW_HDFS_LOCATION_VARIABLE = "client_workflow_hdfs_location";
    private static final String CLIENT_WORKFLOW_HDFS_LOCATION_VALUE = "/user/hadoop/datamgmt/${temp_folder_suffix}/";

    private static final String CLIENT_WORKFLOW_S3_LOCATION_VARIABLE = "client_workflow_s3_location";

    @Autowired
    private ConfigurationHelper configurationHelper;

    @Autowired
    private OozieOperations oozieOperations;

    @Autowired
    private EmrHelper emrHelper;

    /**
     * {@inheritDoc}
     */
    @Override
    public String runOozieWorkflow(String masterIpAddress, String workflowLocation, List<Parameter> parameters) throws Exception
    {
        OozieClient oozieClient = getOozieClient(masterIpAddress);

        Properties conf = new Properties();

        // Add client properties.
        if (!CollectionUtils.isEmpty(parameters))
        {
            for (Parameter parameter : parameters)
            {
                conf.put(parameter.getName(), parameter.getValue());
            }
        }

        conf.put(MAP_REDUCE_QUEUE_NAME_VARIABLE, MAP_REDUCE_QUEUE_NAME_VALUE);
        conf.put(MASTER_IP_VARIABLE, masterIpAddress);
        conf.put(OOZIE_USE_SYSTEM_LIBPATH_VARIABLE, OOZIE_USE_SYSTEM_LIBPATH_VALUE);
        conf.put(NAMENODE_VARIABLE, NAMENODE_VALUE);
        conf.put(JOB_TRACKER_VARIABLE, JOB_TRACKER_VALUE);
        conf.put(USER_NAME_VARIABLE, USER_NAME_VALUE);

        // Properties needed for the herd wrapper workflow.
        conf.put(OOZIE_WF_APPLICATION_PATH_VARIABLE, OOZIE_WF_APPLICATION_PATH_VALUE);
        conf.put(S3_HDFS_COPY_SCRIPT_VARIABLE, emrHelper.getS3HdfsCopyScriptName());
        conf.put(TEMP_FOLDER_SUFFIX_VARIABLE, UUID.randomUUID().toString());
        conf.put(CLIENT_WORKFLOW_HDFS_LOCATION_VARIABLE, CLIENT_WORKFLOW_HDFS_LOCATION_VALUE);
        conf.put(CLIENT_WORKFLOW_S3_LOCATION_VARIABLE, workflowLocation);

        return oozieOperations.runOozieWorkflow(oozieClient, conf);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public WorkflowJob getEmrOozieWorkflow(String masterIpAddress, String emrOozieWorkflowId) throws OozieClientException
    {
        OozieClient oozieClient = getOozieClient(masterIpAddress);

        WorkflowJob workflowJob;
        try
        {
            workflowJob = oozieOperations.getJobInfo(oozieClient, emrOozieWorkflowId);
        }
        catch (OozieClientException oozieClientException)
        {
            /*
             * We will do our best effort to handle exceptions with known error codes.
             */
            if (OOZIE_ERROR_CODE_JOB_DOES_NOT_EXIST.equals(oozieClientException.getErrorCode()))
            {
                throw new ObjectNotFoundException("The oozie workflow with job ID '" + emrOozieWorkflowId + "' does not exist.", oozieClientException);
            }

            // If unhandlable, throw the exception as-is
            throw oozieClientException;
        }

        return workflowJob;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<WorkflowJob> getRunningEmrOozieJobsByName(String masterIpAddress, String appName, int start, int len) throws OozieClientException
    {
        OozieClient oozieClient = getOozieClient(masterIpAddress);

        String filter = "status=" + WorkflowJob.Status.RUNNING.toString();

        if (StringUtils.isNotEmpty(appName))
        {
            filter += ";name=" + appName;
        }

        return oozieOperations.getJobsInfo(oozieClient, filter, start, len);
    }

    /**
     * Builds the Oozie client for the given master IP address.
     *
     * @param masterIpAddress the IP address of oozie master server.
     *
     * @return the OozieClient.
     */
    private OozieClient getOozieClient(String masterIpAddress)
    {
        ConfigurationValue configurationValue = ConfigurationValue.EMR_OOZIE_URL_TEMPLATE;
        String oozieUrlTemplate = configurationHelper.getProperty(configurationValue);
        String oozieUrl = String.format(oozieUrlTemplate, masterIpAddress);
        return new OozieClient(oozieUrl);
    }
}


text:
Hi there, mighty web developer! You have found the repo of yet another jQuery plugin. This one is for shits and giggles, but maybe you can use it for something cool. Basically it checks if any of the specified elements are touching. If so, it executes a callback. You can also do something when the elements stop touching.

As always, I'll go by Linus' words:
> Talk is cheap. Show me the code

## When an element touches another..
.. they will make love tonight. Err. No. But the code is simple! Check thi

```js
jQuery(function() {
    jQuery("#element").touches(".collider", function() {
        // Do stuff.
    });
});
```

## When elements stop touching
```js
jQuery(function() {
    jQuery("#element").touches(".collider", null, function() {
        // Do something.
    })
});
```
Notice something? Yes, you don't need to pass a function for the touch event. You can just pass null and the function will not get executed. Quite handy to have.

## All together now
Here's what the complete API looks like. Simple, clean, functional.
Another cool fact: You can check this stuff on groups of elements, too. So, if you have 20 .collider elements it'll check against all of them. :)

```js
jQuery(function() {
    jQuery("#element").touches(".collider", function() {
        // Do something.
    }, function() {
        // Do something else.
    })
});
```

## Final words
If you want to make any contributions, feel free to send a pull request. If you find any bugs you can report them or maybe fix them yourself. For other stuff you can reach me on [Twitter.](http://twitter.com/F0lis)


text:
namespace chatterino {

void crossPlatformCopy(const QString &text)
{
    auto clipboard = QApplication::clipboard();

    clipboard->setText(text);

    if (clipboard->supportsSelection())
    {
        clipboard->setText(text, QClipboard::Selection);
    }
}

QString getClipboardText()
{
    return QApplication::clipboard()->text();
}

}  // namespace chatterino


text:
<?php
namespace Codecloud\ShopifyApiClient\Endpoint;

class Page extends Endpoint
{

}


text:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <import resource="properties.xml"/>

    <bean id="browser" class="com.algocrafts.browsers.Browsers" factory-method="valueOf">
        <constructor-arg value="${browser}"/>
    </bean>

    <bean id="entryUrl" class="com.algocrafts.clickables.Url">
        <constructor-arg ref="browser"/>
        <constructor-arg value="${entry.url}"/>
    </bean>

    <bean id="daughertyUrl" class="com.algocrafts.clickables.Url">
        <constructor-arg ref="browser"/>
        <constructor-arg value="${daugherty.url}"/>
    </bean>

    <bean id="homePage" class="com.orgsync.OrgSyncHomePage">
        <constructor-arg ref="browser"/>
        <constructor-arg ref="entryUrl"/>
        <constructor-arg ref="allMenuLocator"/>
    </bean>

    <bean id="daughertyHomePage" class="com.daugherty.DaughertyHomePage">
        <constructor-arg ref="browser"/>
        <constructor-arg ref="daughertyUrl"/>
        <constructor-arg ref="daughterMenuLocator"/>
    </bean>

    <bean id="daughterMenuLocator" class="com.daugherty.AllMenuLocatorForDaugherty"/>

    <bean id="firefox" class="com.algocrafts.browsers.FirefoxDriverSupplierOnWindows"/>

    <bean id="allMenuLocator" class="com.orgsync.AllMenuLocatorForOrgSync"/>

    <bean id="jQueryUrl" class="com.algocrafts.clickables.Url">
        <constructor-arg ref="browser"/>
        <constructor-arg value="${entry.url.jquery}"/>
    </bean>

    <bean id="jQueryHomePage" class="com.jquery.JQueryHomePage">
        <constructor-arg ref="browser"/>
        <constructor-arg ref="jQueryUrl"/>
        <constructor-arg ref="jQueryMenuLocator"/>
    </bean>

    <bean id="jQueryMenuLocator" class="com.jquery.menu.AllMenuLocatorForJQuery"/>

    <bean id="jQueryDatePickerPage" class="com.jquery.datepicker.JQueryDatePickerPage">
        <constructor-arg ref="browser"/>
    </bean>

    <bean id="googleUrl" class="com.algocrafts.clickables.Url">
        <constructor-arg ref="browser"/>
        <constructor-arg value="${google.com}"/>
    </bean>

    <bean id="googlePage" class="com.google.GooglePage">
        <constructor-arg ref="browser"/>
        <constructor-arg ref="googleUrl"/>
    </bean>

    <bean id="uploadUrl" class="com.algocrafts.clickables.Url">
        <constructor-arg ref="browser"/>
        <constructor-arg value="${upload.url}"/>
    </bean>

    <bean id="uploadFile" class="java.io.File">
        <constructor-arg value="${upload.file}"/>
    </bean>
</beans>


text:
import {
  forEach
} from 'lodash';
import Application from '../../lib/runtime/application';
import Model from '../../lib/data/model';
import ORMAdapter from '../../lib/data/orm-adapter';
import container, { lookup } from '../../lib/metal/container';

export default {
  name: 'define-orm-models',

  /**
   * Find all models, group them by their orm adapter, then give each adapter the chance to define
   * any internal model representation necessary.
   */
  async initialize(application: Application): Promise<void> {
    let models: { [modelName: string]: typeof Model } = container.lookupAll('model');
    let modelsGroupedByAdapter = new Map<ORMAdapter, typeof Model[]>();
    forEach(models, (ModelClass, modelName) => {
      if (ModelClass.hasOwnProperty('abstract') && ModelClass.abstract) {
        return;
      }
      let Adapter = lookup<ORMAdapter>(`orm-adapter:${ modelName }`, { loose: true }) || container.lookup<ORMAdapter>('orm-adapter:application');
      if (!modelsGroupedByAdapter.has(Adapter)) {
        modelsGroupedByAdapter.set(Adapter, []);
      }
      modelsGroupedByAdapter.get(Adapter).push(ModelClass);
    });
    for (let [Adapter, models] of modelsGroupedByAdapter) {
      if (Adapter.defineModels) {
        await Adapter.defineModels(models);
      }
    }
  }
};


text:
require "spec_helper"
require "music_classes"

describe Redistent::Accessor do
  let(:klass) { Class.new.tap { |klass| klass.send(:include, Redistent::Accessor) } }

  context "a new instance" do
    it "is initialized with redis config" do
      accessor = klass.new(url: "redis://127.0.0.1:6379/7")
      expect(accessor.key.redis.client.port).to eq(6379)
    end

    it "finalizes the config" do
      klass.config.should_receive(:finalize!)
      klass.new(redis_config)
    end
  end

  context "DSL" do
    let(:config) { klass.config }

    it "adds a hook to run before writing with #before_write" do
      klass.before_write { |model| "arg is #{model}" }
      expect(config.hooks[:before_write].first.call("hello")).to eq("arg is hello")
    end

    it "adds a hook to run after writing with #after_write" do
      klass.after_write { |model| "arg is #{model}" }
      expect(config.hooks[:after_write].first.call("goodbye")).to eq("arg is goodbye")
    end

    it "adds a model with #model" do
      klass.model :team
      expect(config.models.keys).to include(:team)
    end

    it "specify the namespace with #namespace" do
      klass.model :team
      klass.namespace Hash
      expect(config.models[:team].namespace).to eq(Hash)
    end

    it "forwards the model definition block to the config object if any" do
      block_caller = nil
      klass.model :queue do
        block_caller = self
      end
      expect(block_caller).to eq(config)
    end
  end

  context "accessor operations" do
    let(:accessor) { klass.new(redis_config) }

    it "delegates #write to a writer" do
      Redistent::Writer.any_instance.should_receive(:write).with(:the, :arguments)
      accessor.write(:the, :arguments)
    end

    it "delegates #read to a reader" do
      Redistent::Reader.any_instance.should_receive(:read).with(:the, :arguments)
      accessor.read(:the, :arguments)
    end

    it "delegates #erase to an eraser" do
      Redistent::Eraser.any_instance.should_receive(:erase).with(:the, :arguments)
      accessor.erase(:the, :arguments)
    end
  end

  context "exclusif access to redis connection" do
    let(:accessor) { klass.new(redis_config) }

    it "exposes the use of its unique mutex" do
      operation = ->(messages) { messages << :start; sleep 0.2; messages << :finish }

      parallel = []
      threads = Array.new(5).map do
        Thread.new { operation.call(parallel) }
      end
      threads.each(&:join)
      expect(parallel).to eq([:start] * 5 + [:finish] * 5)

      sequential = []
      threads = Array.new(5).map do
        Thread.new do
          accessor.with_lock { operation.call(sequential) }
        end
      end
      threads.each(&:join)
      expect(sequential).to eq([:start, :finish] * 5)
    end

    it "doesn't execute more than one operation at a time" do
      # klass for the delegate double that will just push messages and sleep
      delegate_klass = Struct.new(:messages) do
        def write(*args)
          messages << :start
          sleep 0.1
          messages << :finish
        end
        alias :read :write
        alias :erase :write
      end
      # use the delegate double rather than the accessor delegates
      accessor.instance_eval do
        @delegate = delegate_klass.new([])
        def delegate; @delegate; end
        alias :writer :delegate
        alias :reader :delegate
        alias :eraser :delegate
        def messages; delegate.messages; end
      end

      threads = []
      threads << Thread.new { accessor.read }
      threads << Thread.new { accessor.write }
      threads << Thread.new { accessor.erase }
      threads.each(&:join)
      expect(accessor.messages).to eq([:start, :finish, :start, :finish, :start, :finish])
    end
  end

  context "referenced collection" do
    let(:band) { MusicClasses::Band.new(uid: "12") }
    let(:accessor) { klass.new(redis_config) }
    before(:each) do
      klass.config.add_model :musician do
        references :band
      end
    end

    it "returns a collection if it exists" do
      Redistent::Collection.should_receive(:new) do |ze_accessor, ze_model, description|
        expect(ze_accessor).to eq(accessor)
        expect(ze_model).to eq(band)
        expect(description.model).to eq(:musician)
        expect(description.type).to eq(:referenced)
        expect(description.attribute).to eq(:band_uid)
      end
      collection = accessor.collection(band, :musicians)
    end

    it "raises an error if the collection doesn't exist" do
      expect { accessor.collection(band, :blah) }.to raise_error(Redistent::CollectionNotFound)
      expect { accessor.collection(Object.new, :zorglub) }.to raise_error(Redistent::ConfigError)
    end
  end
end


text:
package net.bull.javamelody.internal.model;

import java.io.File;
import java.io.FilenameFilter;
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

/**
 * HsErrPid files.
 * @author Emeric Vernat
 */
public final class HsErrPid implements Serializable {
	private static final String XX_ERROR_FILE = "-XX:ErrorFile=";

	private static final long serialVersionUID = 1L;

	private static final FilenameFilter FILENAME_FILTER = new FilenameFilter() {
		@Override
		public boolean accept(File dir, String name) {
			return name.startsWith("hs_err_pid") && name.endsWith(".log");
		}
	};

	private final String file;

	private final Date date;

	/**
	 * Comparateur de HsErrPid par date.
	 */
	static final class HsErrPidComparator implements Comparator<HsErrPid>, Serializable {
		private static final long serialVersionUID = 1L;

		/** {@inheritDoc} */
		@Override
		public int compare(HsErrPid hsErrPid1, HsErrPid hsErrPid2) {
			return hsErrPid2.getDate().compareTo(hsErrPid1.getDate());
		}
	}

	private HsErrPid(String file, Date date) {
		super();
		this.file = file;
		this.date = date;
	}

	public static List<HsErrPid> buildHsErrPidList() {
		final List<File> directories = new ArrayList<>();
		// locations of fatal error log:
		// http://www.oracle.com/technetwork/java/javase/felog-138657.html
		directories.add(new File("./"));
		// linux:
		directories.add(new File("/tmp"));
		// windows:
		final String tmp = System.getenv("TMP");
		if (tmp != null) {
			directories.add(new File(tmp));
		}
		final List<String> args = ManagementFactory.getRuntimeMXBean().getInputArguments();
		for (final String arg : args) {
			if (arg.startsWith(XX_ERROR_FILE)) {
				final String errorFile = arg.substring(XX_ERROR_FILE.length());
				final File dir = new File(errorFile).getParentFile();
				if (dir != null) {
					directories.add(dir);
				}
			}
		}

		final List<HsErrPid> result = new ArrayList<>();
		for (final File dir : directories) {
			final File[] files = dir.listFiles(FILENAME_FILTER);
			if (files != null) {
				for (final File file : files) {
					result.add(new HsErrPid(file.getAbsolutePath(), new Date(file.lastModified())));
				}
			}
		}
		return result;
	}

	public static List<HsErrPid> getHsErrPidList(List<JavaInformations> javaInformationsList) {
		final List<HsErrPid> result = new ArrayList<>();
		for (final JavaInformations javaInformations : javaInformationsList) {
			final List<HsErrPid> hsErrPidList = javaInformations.getHsErrPidList();
			if (hsErrPidList != null) {
				result.addAll(hsErrPidList);
			}
		}
		Collections.sort(result, new HsErrPidComparator());
		return result;
	}

	public String getFile() {
		return file;
	}

	public Date getDate() {
		return date;
	}
}


text:
from mod_python import apache
import cgi, fakefile

class Error(Exception):
  pass

class InputStream(fakefile.FakeInput):
  def __init__(self, modpy_req):
    fakefile.FakeInput.__init__(self)
    self._modpy_req = modpy_req

  def _read(self, size=-1):
    return self._modpy_req.read(size)

class Request(cgi.Request):
  def _init(self, modpy_req):
    self._modpy_req = modpy_req
    self._build_environ()
    self._redirected = 0
    self.stdin = InputStream(modpy_req)
    super(Request, self)._init()

  def _build_environ(self):
    modpy_req = self._modpy_req
    modpy_req.add_common_vars()
    self.environ = {}
    env = self.environ
    for key in modpy_req.subprocess_env.keys():
      env[key] = modpy_req.subprocess_env[key]
    if len(modpy_req.path_info):
      env["SCRIPT_NAME"] = modpy_req.uri[:-len(modpy_req.path_info)]
    else:
      env["SCRIPT_NAME"] = modpy_req.uri

  def output_headers(self):
    if self._doneHeaders:
      raise cgi.SequencingError("output_headers() called twice")
    if self._redirected:
      self._modpy_req.status = apache.HTTP_MOVED_TEMPORARILY
    self._modpy_req.send_http_header()
    self._doneHeaders = 1

  def clear_headers(self):
    if self._doneHeaders:
      raise cgi.SequencingError("cannot clear_headers() after output_headers()")
    for key in self._modpy_req.headers_out.keys():
      del self._modpy_req.headers_out[key]
    self._redirected = 0

  def add_header(self, hdr, val):
    if self._doneHeaders:
      raise cgi.SequencingError(
        "cannot add_header(%s) after output_headers()" % repr(hdr))
    if hdr.lower() == "content-type":
      self._modpy_req.content_type = val
    else:
      self._modpy_req.headers_out.add(hdr, val)
    if hdr.lower() == "location":
      self._redirected = 1

  def set_header(self, hdr, val):
    if self._doneHeaders:
      raise cgi.SequencingError(
        "cannot set_header(%s) after output_headers()" % repr(hdr))
    if hdr.lower() == "content-type":
      self._modpy_req.content_type = val
    else:
      self._modpy_req.headers_out[hdr] = val
    if hdr.lower() == "location":
      self._redirected = 1

  def get_header(self, hdr, index=0):
    val = self._modpy_req.headers_out.get(hdr)
    if val is None:
      return val
    if isinstance(val, str):
      if index == 0:
        return val
      return None
    if len(val) > index:
      return val[index]
    return None

  def del_header(self, hdr, val):
    if self._doneHeaders:
      raise cgi.SequencingError(
        "cannot del_header(%s) after output_headers()" % repr(hdr))
    if hdr.lower() == "content-Type":
      raise Error("cannot del_header(\"Content-Type\")")
    del self._modpy_req.headers_out[hdr]
    if hdr.lower() == "location":
      self._redirected = 0

  def process(self, modpy_req):
    self._init(modpy_req)
    try:
      handler = self._handler_type()
    except:
      self.traceback()
    else:
      try:
        handler.process(self)
      except:
        handler.traceback(self)
    self.flush()
    return apache.OK

  def error(self, s):
    apache.log_error(s, apache.APLOG_ERR, self._modpy_req.server)

  def _write(self, s):
    if not self.aborted:
      self._modpy_req.write(s)

class GZipRequest(cgi.GZipMixIn, Request):
  pass


text:
package im.actor.images.loading.tasks;

import android.net.Uri;
import android.provider.MediaStore;
import im.actor.images.loading.AbsTask;
import im.actor.images.util.HashUtil;

/**
 * Preview task for images from Media Store
 */
public class PreviewContentTask extends AbsTask {
    private Uri uri;
    private int kind;

    /**
     * @param uri  Media Store uri
     * @param kind MediaStore.Images.Thumbnails.MICRO_KIND or MediaStore.Images.Thumbnails.MINI_KIND
     */
    public PreviewContentTask(Uri uri, int kind) {
        if (kind != MediaStore.Images.Thumbnails.MICRO_KIND && kind != MediaStore.Images.Thumbnails.MINI_KIND) {
            throw new RuntimeException("Kind must be MICRO_KIND or MINI_KIND");
        }
        this.uri = uri;
        this.kind = kind;
    }

    public Uri getUri() {
        return uri;
    }

    public int getKind() {
        return kind;
    }

    @Override
    public String getKey() {
        return "uri:" + ((kind == MediaStore.Images.Thumbnails.MICRO_KIND) ? "micro" : "mini") + ":" + HashUtil.md5(uri.toString());
    }
}


text:
crafty_base
===========

Baseline, boilerplate Crafty code


text:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="EslintConfiguration">
    <custom-configuration-file used="true" path="$PROJECT_DIR$/.eslintrc.yml" />
    <extra-options value="--rulesdir node_modules/eslint-config-cappuccino/lib/rules" />
  </component>
</project>