Exemple #1
0
// Run statisfies the Statement Interface
func (i *QueryStatement) Run(s *ponyExpress.StoreFront) {

	// Set the tracer
	i.Tracer = ponyExpress.NewTracer(i.tags())

	vals := make(map[string]interface{})

	var point models.Point

	runtime := time.Now()

	for j := 0; j < i.Count; j++ {

		// If the query is a simple query, send it.
		if len(i.Args) == 0 {
			b := []byte(i.TemplateString)

			// Make the package
			p := ponyExpress.NewPackage(ponyExpress.Query, b, i.StatementID, i.Tracer)

			// Increment the tracer
			i.Tracer.Add(1)

			// Send the package
			s.SendPackage(p)

		} else {
			// Otherwise cherry pick field values from the commune?

			// TODO: Currently the program lock up here if s.GetPoint
			//       cannot return a value, which can happen.
			// Seee insert.go
			s.Lock()
			point = s.GetPoint(i.Name, s.Precision)
			s.Unlock()

			setMapValues(vals, point)

			// Set the template string with args from the commune
			b := []byte(fmt.Sprintf(i.TemplateString, setArgs(vals, i.Args)...))

			// Make the package
			p := ponyExpress.NewPackage(ponyExpress.Query, b, i.StatementID, i.Tracer)

			// Increment the tracer
			i.Tracer.Add(1)

			// Send the package
			s.SendPackage(p)

		}
	}

	// Wait for all operations to finish
	i.Tracer.Wait()

	// Stop time timer
	i.runtime = time.Since(runtime)
}