Inserts an entity in to the database

@param collection the collection to query against
@param entity     the entity to insert
@param wc         the WriteConcern to use when deleting
@param <T>        the type of the entities
@return the key of entity
12610
public <T> Key<T> insert(final String collection, final T entity, final WriteConcern wc) {
        return insert(getCollection(collection), ProxyHelper.unwrap(entity), new InsertOptions().writeConcern(wc));
    }
232818
@Override
  public <T> void insert(Collection<? extends T> batchToSave, Class<T> entityClass) {
    insert(batchToSave, Util.determineCollectionName(entityClass));
  }
92908
@Deprecated
    <T> long[] insert(T[] entities, boolean withTransaction) {
        return insert(this.getTableNameByEntity(entities[0]), entities, withTransaction);
    }
314478
public int[] insert(Connection conn, Collection<Entity> records) throws SQLException {
		return insert(conn, records.toArray(new Entity[records.size()]));
	}
480644
public Long insertForGeneratedKey(Entity record) throws SQLException {
		Connection conn = null;
		try {
			conn = this.getConnection();
			return runner.insertForGeneratedKey(conn, record);
		} catch (SQLException e) {
			throw e;
		} finally {
			this.closeConnection(conn);
		}
	}
1020922
public List<Object> insertForGeneratedKeys(Connection conn, Entity record) throws SQLException {
		checkConn(conn);
		if(CollectionUtil.isEmpty(record)){
			throw new SQLException("Empty entity provided!");
		}
		
		PreparedStatement ps = null;
		try {
			ps = dialect.psForInsert(conn, record);
			ps.executeUpdate();
			return StatementUtil.getGeneratedKeys(ps);
		} catch (SQLException e) {
			throw e;
		} finally {
			DbUtil.close(ps);
		}
	}
1154407
public static Key marshalKey(DefaultEntityManager entityManager, Object entity) {
    Marshaller marshaller = new Marshaller(entityManager, entity, Intent.DELETE);
    marshaller.marshalKey();
    return (Key) marshaller.key;
  }
896858
public static <T extends Entity<?>> List<?> extractIds(Collection<T> entities) {
    List<Object> idList = CollectUtils.newArrayList();
    for (Iterator<T> iter = entities.iterator(); iter.hasNext();) {
      Entity<?> element = iter.next();
      try {
        idList.add(PropertyUtils.getProperty(element, "id"));
      } catch (Exception e) {
        logger.error("getProperty error", e);
        continue;
      }
    }
    return idList;
  }
1345015
@SuppressWarnings("unchecked")
    public <T extends IEntity> T add(T entity) throws FMSException {

        IntuitMessage intuitMessage = prepareAdd(entity);

        //execute interceptors
        executeInterceptors(intuitMessage);

        return (T) retrieveEntity(intuitMessage);
    }
731335
private Object setElementCollection(Object entity, Object thriftColumnValue, MetamodelImpl metaModel,
            Attribute attribute)
    {
        String cqlColumnMetadata = null;
        Map<ByteBuffer, String> schemaTypes = this.clientBase.getCqlMetadata().getValue_types();
        for (Map.Entry<ByteBuffer, String> schemaType : schemaTypes.entrySet())
        {

            String key = UTF8Serializer.instance.deserialize((schemaType.getKey()));
            if (key.equals(((AbstractAttribute) attribute).getJPAColumnName()))
            {
                cqlColumnMetadata = schemaType.getValue();
                break;
            }
        }

        Field field = (Field) ((AbstractAttribute) attribute).getJavaMember();
        Class embeddedClass = ((AbstractAttribute) attribute).getBindableJavaType();

        if (List.class.isAssignableFrom(((Field) attribute.getJavaMember()).getType()))
        {
            ListType listType = null;
            try
            {
                listType = ListType.getInstance(new TypeParser(cqlColumnMetadata.substring(
                        cqlColumnMetadata.indexOf("("), cqlColumnMetadata.length())));
            }
            catch (ConfigurationException | SyntaxException e)
            {
                log.error(e.getMessage());
                throw new KunderaException("Error while getting instance of ListType " + e);
            }
            return setElementCollectionList(listType, ByteBuffer.wrap((byte[]) thriftColumnValue), entity, field,
                    metaModel, embeddedClass, true);

        }
        else if (Set.class.isAssignableFrom(((Field) attribute.getJavaMember()).getType()))
        {
            SetType setType = null;
            try
            {
                setType = SetType.getInstance(new TypeParser(cqlColumnMetadata.substring(
                        cqlColumnMetadata.indexOf("("), cqlColumnMetadata.length())));
            }
            catch (ConfigurationException | SyntaxException e)
            {
                log.error(e.getMessage());
                throw new KunderaException("Error while getting instance of SetType " + e);
            }
            return setElementCollectionSet(setType, ByteBuffer.wrap((byte[]) thriftColumnValue), entity, field,
                    metaModel, embeddedClass, true);

        }
        else if (Map.class.isAssignableFrom(((Field) attribute.getJavaMember()).getType()))
        {
            MapType mapType = null;
            try
            {
                mapType = MapType.getInstance(new TypeParser(cqlColumnMetadata.substring(
                        cqlColumnMetadata.indexOf("("), cqlColumnMetadata.length())));
            }
            catch (ConfigurationException | SyntaxException e)
            {
                log.error(e.getMessage());
                throw new KunderaException("Error while getting instance of MapType " + e);
            }
            return setElementCollectionMap(mapType, ByteBuffer.wrap((byte[]) thriftColumnValue), entity, field,
                    metaModel, embeddedClass, true);
        }

        return entity;

    }
423838
public DBObject toDBObject(final Object entity) {
        try {
            return mapper.toDBObject(entity);
        } catch (Exception e) {
            throw new MappingException("Could not map entity to DBObject", e);
        }
    }
1092905
@Override
    public T remove(T entity) {
        EntityManager entityManager = getEntityManager();
        if (entityManager.contains(entity)) {
            entityManager.remove(entity);
        } else {
            entityManager.remove(entityManager.merge(entity));
        }
        return entity;
    }
559263
@SuppressWarnings("unchecked")
	@Override
	public int delete(final Object entity) {
		@SuppressWarnings("rawtypes")
		EntityHandler handler = this.getEntityHandler();
		if (!handler.getEntityType().isInstance(entity)) {
			throw new IllegalArgumentException("Entity type not supported");
		}

		try {
			Class<?> type = entity.getClass();
			TableMetadata metadata = handler.getMetadata(this.transactionManager, type);
			SqlContext context = handler.createDeleteContext(this, metadata, type, true);
			context.setSqlKind(SqlKind.DELETE);
			handler.setDeleteParams(context, entity);
			return handler.doDelete(this, context, entity);
		} catch (SQLException e) {
			throw new EntitySqlRuntimeException(SqlKind.DELETE, e);
		}
	}
462092
protected EntityKey getEntityKey(Tuple tuple, AssociatedEntityKeyMetadata associatedEntityKeyMetadata) {
		Object[] columnValues = new Object[ associatedEntityKeyMetadata.getAssociationKeyColumns().length];
		int i = 0;

		for ( String associationKeyColumn : associatedEntityKeyMetadata.getAssociationKeyColumns() ) {
			columnValues[i] = tuple.get( associationKeyColumn );
			i++;
		}

		return new EntityKey( associatedEntityKeyMetadata.getEntityKeyMetadata(), columnValues );
	}
841599
private RowKeyAndTuple createAndPutAssociationRowForInsert(Serializable key, PersistentCollection collection,
			AssociationPersister associationPersister, SharedSessionContractImplementor session, int i, Object entry) {
		RowKeyBuilder rowKeyBuilder = initializeRowKeyBuilder();
		Tuple associationRow = new Tuple();

		// the collection has a surrogate key (see @CollectionId)
		if ( hasIdentifier ) {
			final Object identifier = collection.getIdentifier( entry, i );
			String[] names = { getIdentifierColumnName() };
			identifierGridType.nullSafeSet( associationRow, identifier, names, session );
		}

		getKeyGridType().nullSafeSet( associationRow, key, getKeyColumnNames(), session );
		// No need to write to where as we don't do where clauses in OGM :)
		if ( hasIndex ) {
			Object index = collection.getIndex( entry, i, this );
			indexGridType.nullSafeSet( associationRow, incrementIndexByBase( index ), getIndexColumnNames(), session );
		}

		// columns of referenced key
		final Object element = collection.getElement( entry );
		getElementGridType().nullSafeSet( associationRow, element, getElementColumnNames(), session );

		RowKeyAndTuple result = new RowKeyAndTuple();
		result.key = rowKeyBuilder.values( associationRow ).build();
		result.tuple = associationRow;

		associationPersister.getAssociation().put( result.key, result.tuple );

		return result;
	}
412323
@Override
  public <T> T remove(Object objectToRemove, String collectionName) {
    if (null == objectToRemove) {
      throw new InvalidJsonDbApiUsageException("Null Object cannot be removed from DB");
    }
    Util.ensureNotRestricted(objectToRemove);

    CollectionMetaData collectionMeta = cmdMap.get(collectionName);
    collectionMeta.getCollectionLock().writeLock().lock();
    try {
      @SuppressWarnings("unchecked")
      Map<Object, T> collection = (Map<Object, T>) collectionsRef.get().get(collectionName);
      if (null == collection) {
        throw new InvalidJsonDbApiUsageException("Collection by name '" + collectionName + "' not found. Create collection first.");
      }

      CollectionMetaData cmd = cmdMap.get(collectionName);
      Object id = Util.getIdForEntity(objectToRemove, cmd.getIdAnnotatedFieldGetterMethod());
      if (!collection.containsKey(id)) {
        throw new InvalidJsonDbApiUsageException(String.format("Objects with Id %s not found in collection %s", id, collectionName));
      }

      JsonWriter jw;
      try {
        jw = new JsonWriter(dbConfig, cmd, collectionName, fileObjectsRef.get().get(collectionName));
      } catch (IOException ioe) {
        logger.error("Failed to obtain writer for " + collectionName, ioe);
        throw new JsonDBException("Failed to save " + collectionName, ioe);
      }
      boolean substractResult = jw.removeFromJsonFile(collection, id);
      if(substractResult) {
        T objectRemoved = collection.remove(id);
        // Don't need to clone it, this object no more exists in the collection
        return objectRemoved;
      } else {
        return null;
      }
    } finally {
      collectionMeta.getCollectionLock().writeLock().unlock();
    }
  }
724658
public void insertDocIntoMongoDBCollection(String collection, String document) {

        DBObject dbObject = (DBObject) JSON.parse(document);
        this.dataBase.getCollection(collection).insert(dbObject);

    }