<commit_before>/*
 * Copyright 2012-2015 MarkLogic Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.marklogic.client.pojo;

import com.marklogic.client.FailedRequestException;
import com.marklogic.client.ForbiddenUserException;
import com.marklogic.client.ResourceNotFoundException;
import com.marklogic.client.Transaction;
import com.marklogic.client.io.marker.SearchReadHandle;
import com.marklogic.client.pojo.annotation.Id;
import com.marklogic.client.query.QueryManager;

import java.io.Serializable;

/** PojoRepository is the central class for the Pojo Facade.  It supports CRUD operations
 * and search.  Each PojoRepository instance operates on only one pojo class.  Create new
 * PojoRepository instances based on your custom pojo type like so:
 * <pre>    public class MyClass {
 *        {@literal @}Id
 *        public Integer getMyId() {
 *            ...
 *        }
 *        public void setMyId(Integer integer) {
 *            ...
 *        }
 *        ...
 *    }
 *    ...
 *    DatabaseClient client = ...;
 *    PojoRepository<MyClass, Integer> myClassRepo = 
 *        client.newPojoRepository(MyClass.class, Integer.class);</pre>
 *
 * Where MyClass is your custom pojo type, and myId is the bean property of type Integer
 * marked with the 
 * {@literal @}{@link Id Id annotation}.  The 
 * {@literal @}Id annotaiton can be attached to a public field or a public getter or a 
 * public setter.  The bean property marked with {@literal @}Id must be a native type or 
 * {@link java.io.Serializable} class and must contain an 
 * identifier value unique across all persisted instances of that
 * type or the instance will overwrite the persisted instance with the same identifier.
 *
 * The current implementation of the Pojo Facade uses 
 * <a href="https://github.com/FasterXML/jackson-databind/">Jackson databind</a> for serialization
 * and deserialization to json.  Thus only classes which can be serialized and deserialized 
 * directly by Jackson can be serialized by the Pojo Facade.  Every bean property
 * including the one marked with {@literal @}Id must either expose a public field or both a public 
 * getter and a public setter.  To test if your class can be directly serialized and 
 * deserialized by Jackson, perform the following:
 * <pre>    ObjectMapper objectMapper = new ObjectMapper();
 *    String value = objectMapper.writeValueAsString(myObjectIn);
 *    MyClass myObjectOut = objectMapper.readValue(value, MyClass.class);</pre>
 *
 * If that works but the configured objectMapper in the Pojo Facade is different and not
 * working, you can troubleshoot by directly accessing the objectMapper used by the Pojo 
 * Facade using an unsupported internal method attached to the current implementataion: 
 * <a 
 * href="https://github.com/marklogic/java-client-api/blob/master/src/main/java/com/marklogic/client/impl/PojoRepositoryImpl.java"
 * >com.marklogic.client.impl.PojoRepositoryImpl</a>.
 * <pre>    ObjectMapper objectMapper = ((PojoRepositoryImpl) myClassRepo).getObjectMapper();</pre>
 *
 * If your class has properties which are classes (non-native types) they will be automatically 
 * serialized and deserialized, but cannot be written, read, or searched directly.  If you 
 * wish to directly write, read, or search another class, create a new instance of 
 * PojoRepository specific to that class.
 */
public interface PojoRepository<T, ID extends Serializable> {
    /** Write this instance to the database.  Uses the field marked with {@literal @}Id 
     * annotation to generate a unique uri for the document.  Adds a collection with the 
     * fully qualified class name.  Uses a particular configuration of 
     * {@link com.fasterxml.jackson.databind.ObjectMapper ObjectMapper} to generate the
     * serialized JSON format.
     * @param entity your pojo instance of the type managed by this PojoRepository
     */
    public void write(T entity)
        throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException;
    /** Does everything in {@link #write(Object) write(T)} but also adds your collections to the 
     * persisted instance.
     * @param entity your pojo instance of the type managed by this PojoRepository
     * @param collections the collections to add to this instance in the database
     */
    public void write(T entity, String... collections)
        throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException;
    /** Does everything in {@link #write(Object) write(T)} but in your 
     * <a href="http://docs.marklogic.com/guide/app-dev/transactions">
     * multi-statement transaction</a> context.
     * @param entity your pojo instance of the type managed by this PojoRepository
     * @param transaction the open transaction in which to write this instance
     */
    public void write(T entity, Transaction transaction)
        throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException;<commit_msg>document loss of precision on JSON numbers<commit_after>/*
 * Copyright 2012-2015 MarkLogic Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.marklogic.client.pojo;

import com.marklogic.client.FailedRequestException;
import com.marklogic.client.ForbiddenUserException;
import com.marklogic.client.ResourceNotFoundException;
import com.marklogic.client.Transaction;
import com.marklogic.client.io.marker.SearchReadHandle;
import com.marklogic.client.pojo.annotation.Id;
import com.marklogic.client.query.QueryManager;

import java.io.Serializable;

/** PojoRepository is the central class for the Pojo Facade.  It supports CRUD operations
 * and search.  Each PojoRepository instance operates on only one pojo class.  Create new
 * PojoRepository instances based on your custom pojo type like so:
 * <pre>    public class MyClass {
 *        {@literal @}Id
 *        public Integer getMyId() {
 *            ...
 *        }
 *        public void setMyId(Integer integer) {
 *            ...
 *        }
 *        ...
 *    }
 *    ...
 *    DatabaseClient client = ...;
 *    PojoRepository<MyClass, Integer> myClassRepo = 
 *        client.newPojoRepository(MyClass.class, Integer.class);</pre>
 *
 * Where MyClass is your custom pojo type, and myId is the bean property of type Integer
 * marked with the 
 * {@literal @}{@link Id Id annotation}.  The 
 * {@literal @}Id annotaiton can be attached to a public field or a public getter or a 
 * public setter.  The bean property marked with {@literal @}Id must be a native type or 
 * {@link java.io.Serializable} class and must contain an 
 * identifier value unique across all persisted instances of that
 * type or the instance will overwrite the persisted instance with the same identifier.
 *
 * The current implementation of the Pojo Facade uses 
 * <a href="https://github.com/FasterXML/jackson-databind/">Jackson databind</a> for serialization
 * and deserialization to json.  Thus only classes which can be serialized and deserialized 
 * directly by Jackson can be serialized by the Pojo Facade.  Every bean property
 * including the one marked with {@literal @}Id must either expose a public field or both a public 
 * getter and a public setter.  To test if your class can be directly serialized and 
 * deserialized by Jackson, perform the following:
 * <pre>    ObjectMapper objectMapper = new ObjectMapper();
 *    String value = objectMapper.writeValueAsString(myObjectIn);
 *    MyClass myObjectOut = objectMapper.readValue(value, MyClass.class);</pre>
 *
 * If that works but the configured objectMapper in the Pojo Facade is different and not
 * working, you can troubleshoot by directly accessing the objectMapper used by the Pojo 
 * Facade using an unsupported internal method attached to the current implementataion: 
 * <a 
 * href="https://github.com/marklogic/java-client-api/blob/master/src/main/java/com/marklogic/client/impl/PojoRepositoryImpl.java"
 * >com.marklogic.client.impl.PojoRepositoryImpl</a>.
 * <pre>    ObjectMapper objectMapper = ((PojoRepositoryImpl) myClassRepo).getObjectMapper();</pre>
 *
 * If your class has properties which are classes (non-native types) they will be automatically 
 * serialized and deserialized, but cannot be written, read, or searched directly.  If you 
 * wish to directly write, read, or search another class, create a new instance of 
 * PojoRepository specific to that class.
 *
 * Since PojoRepository stores in JSON format, which limits number precision to 15
 * significant digits (IEEE754 double precision), you will lose precision on numbers
 * longer than 15 significant digits.  If you desire larger numbers with no loss of
 * precision, use Strings to persist those numbers.
 */
public interface PojoRepository<T, ID extends Serializable> {
    /** Write this instance to the database.  Uses the field marked with {@literal @}Id 
     * annotation to generate a unique uri for the document.  Adds a collection with the 
     * fully qualified class name.  Uses a particular configuration of 
     * {@link com.fasterxml.jackson.databind.ObjectMapper ObjectMapper} to generate the
     * serialized JSON format.
     * @param entity your pojo instance of the type managed by this PojoRepository
     */
    public void write(T entity)
        throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException;
    /** Does everything in {@link #write(Object) write(T)} but also adds your collections to the 
     * persisted instance.
     * @param entity your pojo instance of the type managed by this PojoRepository
     * @param collections the collections to add to this instance in the database
     */
    public void write(T entity, String... collections)
        throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException;
    /** Does everything in {@link #write(Object) write(T)} but in your 
     * <a href="http://docs.marklogic.com/guide/app-dev/transactions">
     * multi-statement transaction</a> context.
     * @param entity your pojo instance of the type managed by this PojoRepository
     * @param transaction the open transaction in which to write this instance
     */
    public void write(T entity, Transaction transaction)
        throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException;
{'fraction_non_alphanumeric': 0.07612334801762115, 'fraction_numerical': 0.0027312775330396474, 'mean_word_length': 3.7493723849372387, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5215248', 'n_tokens_mistral': 2964, 'n_tokens_neox': 2838, 'n_words': 1233}