<commit_before>/*
 * Copyright (c)  [2011-2016] "Pivotal Software, Inc." / "Neo Technology" / "Graph Aware Ltd."
 *
 * This product is licensed to you under the Apache License, Version 2.0 (the "License").
 * You may not use this product except in compliance with the License.
 *
 * This product may include a number of subcomponents with
 * separate copyright notices and license terms. Your use of the source
 * code for these subcomponents is subject to the terms and
 * conditions of the subcomponent's license, as noted in the LICENSE file.
 *
 */

package org.springframework.data.neo4j.repository.support;

import org.neo4j.ogm.metadata.MetaData;
import org.neo4j.ogm.metadata.ClassInfo;
import org.neo4j.ogm.metadata.FieldInfo;
import org.neo4j.ogm.metadata.reflect.EntityAccessManager;
import org.springframework.data.repository.core.support.AbstractEntityInformation;

import java.io.Serializable;

/**
 * @author <NAME>
 */
public class GraphEntityInformation<T, ID extends Serializable> extends AbstractEntityInformation<T, ID> {

    private final MetaData metaData;

    public GraphEntityInformation(MetaData metaData, Class<T> type) {
        super(type);
        this.metaData = metaData;
    }

    @Override
    public ID getId(T entity) {
        final ClassInfo classInfo = metaData.classInfo(getJavaType().getName());
        final FieldInfo primaryIndex = classInfo.primaryIndexField();

        if (primaryIndex != null) {
            return (ID) EntityAccessManager.getPropertyReader(classInfo, primaryIndex.getName()).readProperty(entity);
        }
        else {
            return (ID) EntityAccessManager.getPropertyReader(classInfo, classInfo.identityField().getName()).readProperty(entity);
        }
    }

    @Override
    public Class<ID> getIdType() {
        final FieldInfo primaryIndex = metaData.classInfo(getJavaType().getName()).primaryIndexField();

        if (primaryIndex != null) {
            return (Class<ID>) primaryIndex.convertedType();
        }
        return (Class<ID>) Long.class;<commit_msg>DATAGRAPH-974 - Update SDN with OGM API changes.<commit_after>/*
 * Copyright (c)  [2011-2016] "Pivotal Software, Inc." / "Neo Technology" / "Graph Aware Ltd."
 *
 * This product is licensed to you under the Apache License, Version 2.0 (the "License").
 * You may not use this product except in compliance with the License.
 *
 * This product may include a number of subcomponents with
 * separate copyright notices and license terms. Your use of the source
 * code for these subcomponents is subject to the terms and
 * conditions of the subcomponent's license, as noted in the LICENSE file.
 *
 */

package org.springframework.data.neo4j.repository.support;

import org.neo4j.ogm.metadata.MetaData;
import org.neo4j.ogm.metadata.ClassInfo;
import org.neo4j.ogm.metadata.FieldInfo;
import org.neo4j.ogm.metadata.reflect.EntityAccessManager;
import org.springframework.data.repository.core.support.AbstractEntityInformation;

import java.io.Serializable;

/**
 * @author <NAME>
 */
public class GraphEntityInformation<T, ID extends Serializable> extends AbstractEntityInformation<T, ID> {

    private final MetaData metaData;

    public GraphEntityInformation(MetaData metaData, Class<T> type) {
        super(type);
        this.metaData = metaData;
    }

    @Override
    public ID getId(T entity) {
        final ClassInfo classInfo = metaData.classInfo(getJavaType().getName());
        final FieldInfo primaryIndex = classInfo.primaryIndexField();

        if (primaryIndex != null) {
            return (ID) classInfo.propertyField(primaryIndex.getName()).readProperty(entity);
        }
        else {
            return (ID) classInfo.propertyField(classInfo.identityField().getName()).readProperty(entity);
        }
    }

    @Override
    public Class<ID> getIdType() {
        final FieldInfo primaryIndex = metaData.classInfo(getJavaType().getName()).primaryIndexField();

        if (primaryIndex != null) {
            return (Class<ID>) primaryIndex.convertedType();
        }
        return (Class<ID>) Long.class;
{'fraction_non_alphanumeric': 0.10203082945926108, 'fraction_numerical': 0.008074382187423538, 'mean_word_length': 3.608793686583991, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6726361', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1102, 'n_words': 319}