Returns the entity with the required fields for an insert set.

@return
357209
public Candidate instantiateForInsert() {
		Candidate entity = new Candidate();
		entity.setCategory(new Category(512973));
		entity.setComments("New lead candidate");
		entity.setEmployeeType("W2");
		entity.setIsDeleted(Boolean.FALSE);
		entity.setIsEditable(Boolean.TRUE);
		entity.setPreferredContact("Email");
		entity.setStatus("New Lead");
		entity.setOwner(new CorporateUser(1));
		entity.setName("");
		entity.setFirstName("");
		entity.setLastName("");
		entity.setUsername(new DateTime().toString());
		entity.setPassword("secret");
		return entity;
	}
703646
protected Identity getIdentityFromResultSet() throws PersistenceBrokerException
    {
        // fill primary key values from Resultset
        FieldDescriptor fld;
        FieldDescriptor[] pkFields = getQueryObject().getClassDescriptor().getPkFields();
        Object[] pkValues = new Object[pkFields.length];

        for (int i = 0; i < pkFields.length; i++)
        {
            fld = pkFields[i];
            pkValues[i] = getRow().get(fld.getColumnName());
        }

        // return identity object build up from primary keys
        return getBroker().serviceIdentity().buildIdentity(
                getQueryObject().getClassDescriptor().getClassOfObject(), getTopLevelClass(), pkValues);
    }
1097401
private function insert() {
        if ($this->isPersistent()) throw new RuntimeException('Cannot insert already persistent '.$this);

        // pre-processing hook
        if ($this->beforeInsert() !== true)
            return $this;

        $mapping = $this->dao()->getMapping();

        // collect column values
        $values = [];
        foreach ($mapping['columns'] as $column => $property) {
            $values[$column] = $this->getPhysicalValue($column);
        };

        // perform insertion
        $id = $this->doInsert($values);
        $this->_modified = false;

        // assign the returned identity value
        $idName = $mapping['identity']['name'];
        if ($this->$idName === null)
            $this->$idName = $id;

        // post-processing hook
        $this->afterInsert();
        return $this;
    }
968018
private Set<OWLEntity> getChangeSignature() {
        Set<OWLEntity> result = new HashSet<OWLEntity>();
        final OWLOntologyChangeDataVisitor<Set<OWLEntity>, RuntimeException> visitor = new OWLOntologyChangeDataVisitor<Set<OWLEntity>, RuntimeException>() {
            @Override
            public Set<OWLEntity> visit(AddAxiomData data) throws RuntimeException {
                return data.getAxiom().getSignature();
            }

            @Override
            public Set<OWLEntity> visit(RemoveAxiomData data) throws RuntimeException {
                return data.getAxiom().getSignature();
            }

            @Override
            public Set<OWLEntity> visit(AddOntologyAnnotationData data) throws RuntimeException {
                return data.getAnnotation().getSignature();
            }

            @Override
            public Set<OWLEntity> visit(RemoveOntologyAnnotationData data) throws RuntimeException {
                return data.getAnnotation().getSignature();
            }

            @Override
            public Set<OWLEntity> visit(SetOntologyIDData data) throws RuntimeException {
                return Collections.emptySet();
            }

            @Override
            public Set<OWLEntity> visit(AddImportData data) throws RuntimeException {
                return Collections.emptySet();
            }

            @Override
            public Set<OWLEntity> visit(RemoveImportData data) throws RuntimeException {
                return Collections.emptySet();
            }
        };

        for(OWLOntologyChangeRecord record : changeRecords) {
            result.addAll(record.getData().accept(visitor));
        }
        return result;
    }
1312275
public Long getInsertNumber() {
        Long insertNumber = 0L;
        if (items.size() != 0) {
            for (TableStat item : items) {
                insertNumber += item.getInsertCount();
            }
        }
        return insertNumber;
    }
273981
private function getInsertQuery()
    {
        return 'INSERT INTO '.$this->parts['from'][0]['table'].
               ' ('.implode(', ', array_keys($this->parts['set'])).')'.
               ' VALUES'.
               ' ('.implode(', ', $this->parts['set']).')';
    }
928819
public ResultSet executeWithKeys() {
        context = startContext(connection(), metadata, entity);
        try {
            if (configuration.getTemplates().isNativeMerge()) {
                PreparedStatement stmt = null;
                if (batches.isEmpty()) {
                    stmt = createStatement(true);
                    listeners.notifyMerge(entity, metadata, keys, columns, values, subQuery);

                    listeners.preExecute(context);
                    stmt.executeUpdate();
                    listeners.executed(context);
                } else {
                    Collection<PreparedStatement> stmts = createStatements(true);
                    if (stmts != null && stmts.size() > 1) {
                        throw new IllegalStateException("executeWithKeys called with batch statement and multiple SQL strings");
                    }
                    stmt = stmts.iterator().next();
                    listeners.notifyMerges(entity, metadata, batches);

                    listeners.preExecute(context);
                    stmt.executeBatch();
                    listeners.executed(context);
                }

                final Statement stmt2 = stmt;
                ResultSet rs = stmt.getGeneratedKeys();
                return new ResultSetAdapter(rs) {
                    @Override
                    public void close() throws SQLException {
                        try {
                            super.close();
                        } finally {
                            stmt2.close();
                            reset();
                            endContext(context);
                        }
                    }
                };
            } else {
                if (hasRow()) {
                    // update
                    SQLUpdateClause update = new SQLUpdateClause(connection(), configuration, entity);
                    update.addListener(listeners);
                    populate(update);
                    addKeyConditions(update);
                    reset();
                    endContext(context);
                    return EmptyResultSet.DEFAULT;
                } else {
                    // insert
                    SQLInsertClause insert = new SQLInsertClause(connection(), configuration, entity);
                    insert.addListener(listeners);
                    populate(insert);
                    return insert.executeWithKeys();
                }
            }
        } catch (SQLException e) {
            onException(context,e);
            reset();
            endContext(context);
            throw configuration.translate(queryString, constants, e);
        }
    }
455089
private function getPreparedInsert()
    {
        if (is_null($this->preparedInsert)) {
            $this->preparedInsert = $this->getServer()
                ->insert($this->tableName, true)
                ->set($this->keyColumnName, ':id')
                ->set($this->valueColumnName, ':value')
                ->set($this->expireColumnName, ':expire');
        }

        return $this->preparedInsert;
    }
837144
@ManyToOne(targetEntity = org.openprovenance.prov.sql.QualifiedName.class, cascade = {
        CascadeType.ALL
    })
    @JoinColumn(name = "GENERATED_ENTITY")
    public org.openprovenance.prov.model.QualifiedName getGeneratedEntity() {
        return generatedEntity;
    }
505206
protected function _getSelect() {
        $fields = $this->_entity->fields();

        switch ($this->_type) {
            case self::QUERY_SELECT :
                $this->_query .= 'SELECT ';

                $nFields = count($fields);
                $i = 0;

                //We add all fields to the select
                foreach ($fields as $value) {
                    //We mustn't add fields which don't exist in the SQL table
                    if ($value->foreign == null || in_array($value->foreign->type(), [ForeignKey::ONE_TO_ONE, ForeignKey::MANY_TO_ONE])) {
                        $this->_query .= $this->_entity->name() . '.' . $value->name . ' AS ' . $this->_entity->name() . '_' . $value->name;

                        if ($i < $nFields - 1) {
                            $this->_query .= ', ';
                        }
                    }
                    //To optimize the relation ONE TO MANY, we replace the join value by the number of element in this join
                    else if ($value->foreign != null && $value->foreign->type() == ForeignKey::ONE_TO_MANY) {
                        $currentEntity = $value->foreign->entity();
                        $currentField = $value->foreign->field();
                        $referenceEntity = $value->foreign->referenceEntity();
                        $referenceField = $value->foreign->referenceField();

                        $this->_query .= '(SELECT COUNT(*) FROM ' . $referenceEntity . ' WHERE ' . $referenceEntity . '.' . $referenceField . ' = ' . $currentEntity . '.' . $currentField . ') AS count_one_' . $this->_entity->name() . '_' . $value->name;

                        if ($i < $nFields - 1) {
                            $this->_query .= ', ';
                        }
                    }
                    //To optimize the relation MANY TO MANY, we replace the join value by the number of element in this join
                    else if ($value->foreign != null && $value->foreign->type() == ForeignKey::MANY_TO_MANY) {
                        $currentEntity = $value->foreign->entity();
                        $currentField = $this->_entity->primary();
                        $referenceEntity = $value->foreign->referenceEntity();
                        $referenceField = $value->foreign->referenceField();
                        $current = strtolower($currentEntity . $currentField);
                        $reference = strtolower($referenceEntity . $referenceField);
                        $table = [$current, $reference];
                        sort($table, SORT_STRING);
                        $table = ucfirst($table[0] . $table[1]);

                        $this->_query .= '(SELECT COUNT(*) FROM ' . $table . ' WHERE ' . $table . '.' . $currentEntity . '_' . $currentField . ' = ' . $currentEntity . '.' . $currentField . ') AS count_many_' . $this->_entity->name() . '_' . $value->name;

                        if ($i < $nFields - 1) {
                            $this->_query .= ', ';
                        }
                    }

                    $i++;
                }

                $this->_query = preg_replace('#^(.*)(, )$#isU', '$1', $this->_query);

                //if some fields have a relation one to one or many to one, we had a join
                foreach ($fields as $value) {
                    if ($value->foreign != null && in_array($value->foreign->type(), [ForeignKey::ONE_TO_ONE, ForeignKey::MANY_TO_ONE])) {
                        $this->_query .= ', ';

                        $class = $this->_getTableEntity($value->foreign->referenceEntity());

                        $fieldsRelation = $class->fields();
                        $nFieldsRelation = count($fieldsRelation);
                        $i = 0;

                        foreach ($fieldsRelation as $relation) {
                            if ($relation->foreign == null || in_array($relation->foreign->type(), [ForeignKey::ONE_TO_ONE, ForeignKey::MANY_TO_ONE])) {
                                $this->_query .= $value->name . '_' . $class->name() . '.' . $relation->name . ' AS ' . $value->name . '_' . $class->name() . '_' . $relation->name;

                                if ($i < $nFieldsRelation - 1) {
                                    $this->_query .= ', ';
                                }
                            }

                            $i++;
                        }

                        $this->_query = preg_replace('#^(.*)(, )$#isU', '$1', $this->_query);
                    }
                }
                break;

            case self::QUERY_DISTINCT :
                $primaryColumn = $this->_entity->name() . '.' . $this->_entity->fields()[$this->_entity->primary()]->name;

                if (preg_match('(' . $primaryColumn . ')', $this->_distinct)) {
                    $this->_query .= 'SELECT DISTINCT ' . $this->_distinct . ' ';
                }
                else {
                    $this->_query .= 'SELECT DISTINCT ' . $this->_distinct . ', ' . $primaryColumn . ' ';
                }
                break;

            case self::QUERY_COUNT :
                $this->_query .= 'SELECT COUNT(*) ';
                break;
        }

        $this->_query .= ' FROM ' . $this->_entity->name();

        /** If there are relations like one to one, many to one or many to many */
        foreach ($fields as $value) {
            if ($value->foreign != null && in_array($value->foreign->type(), [ForeignKey::ONE_TO_ONE, ForeignKey::MANY_TO_ONE])) {
                $entity = $value->foreign->entity();
                $field = $value->foreign->field();
                $referenceEntity = $value->foreign->referenceEntity();
                $referenceField = $value->foreign->referenceField();
                $this->join($value->foreign->join(), $referenceEntity, $entity . '.' . $field . ' = ' . $field . '_' . $referenceEntity . '.' . $referenceField, $field);
            }
            else if ($value->foreign != null && in_array($value->foreign->type(), [ForeignKey::MANY_TO_MANY])) {
                //We add here two join (relation table and table linked)
                $currentEntity = $value->foreign->entity();
                $currentField = $this->_entity->primary();
                $referenceEntity = $value->foreign->referenceEntity();
                $referenceField = $value->foreign->referenceField();

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

                $this->join($value->foreign->join(), $table, $table . '.' . $this->_entity->name() . '_' . $currentField . ' = ' . $this->_entity->name() . '.' . $currentField);
                $this->join($value->foreign->join(), $value->foreign->referenceEntity(), $table . '.' . $referenceEntity . '_' . $referenceField . ' = ' . $referenceEntity . '.' . $referenceField);
            }
        }
    }
394256
public Map<String, EntityMetadata> getEntityMetadataMap()
    {
        if (entityMetadataMap == null)
        {
            entityMetadataMap = new HashMap<String, EntityMetadata>();
        }
        return entityMetadataMap;
    }
392175
public static EntitySet getEntitySetByEntity(EntityDataModel entityDataModel, Object entity)
            throws ODataEdmException {
        return getEntitySetByEntityTypeName(entityDataModel,
                getAndCheckEntityType(entityDataModel, entity.getClass()).getFullyQualifiedName());
    }
151120
protected TableSchema getSchema() {
    List<TableFieldSchema> fields = new ArrayList<>();
    for (Map.Entry<String, FieldInfo<InputT>> entry : fieldInfo.entrySet()) {
      String key = entry.getKey();
      FieldInfo<InputT> fcnInfo = entry.getValue();
      String bqType = fcnInfo.getFieldType();
      fields.add(new TableFieldSchema().setName(key).setType(bqType));
    }
    return new TableSchema().setFields(fields);
  }
1149783
public PartialResponseInsertType<PartialResponseChangesType<T>> getOrCreateInsert()
   {
      List<Node> nodeList = childNode.get("insert");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new PartialResponseInsertTypeImpl<PartialResponseChangesType<T>>(this, "insert", childNode, nodeList.get(0));
      }
      return createInsert();
   }
690840
public String getInsertPrepareSQL(T bean) {
        if (this.tableStrategy == null) return insertPrepareSQL;
        return insertPrepareSQL.replace("${newtable}", getTable(bean));
    }
524678
public Sendout instantiateForInsert() {
        Sendout entity = new Sendout();
        entity.setIsRead(Boolean.FALSE);
        entity.setCandidate(new Candidate(1));
        entity.setUser(new CorporateUser(1));
        return entity;
    }
672875
private String createInsertQuery() {
        StringBuilder query = new StringBuilder();
        query.append("insert into ").append(m_tableName)
                .append("(").append(m_propertyNames[0]);
        for (int i = 1; i < m_propertyNames.length; i++) {
            query.append(",").append(m_propertyNames[i]);
        }
        query.append(") values (?");
        for (int i = 1; i < m_propertyNames.length; i++) {
            query.append(",?");
        }
        query.append(")");
        return query.toString();
    }