// Path: fx-inject-examples/addressbook-app/src/main/java/com/cathive/fx/apps/contacts/model/converter/SexConverter.java
// @Converter
// public class SexConverter implements AttributeConverter<Sex, Integer> {
// 
//     @Override
//     public Integer convertToDatabaseColumn(final Sex attribute) {
//         return attribute == null ? Sex.NOT_KNOWN.getValue() :  Integer.valueOf(attribute.getValue());
//     }
// 
//     @Override
//     public Sex convertToEntityAttribute(final Integer dbData) {
//         return dbData == null ? Sex.NOT_KNOWN : Sex.valueOf(dbData.intValue());
//     }
// 
// }


import com.cathive.fx.apps.contacts.model.converter.SexConverter;
import javafx.beans.NamedArg;
import javafx.beans.binding.Bindings;
import javafx.beans.property.*;
import javax.persistence.*;
import java.io.Serializable;
import static javafx.beans.binding.Bindings.createObjectBinding;
import static javafx.beans.binding.Bindings.createStringBinding;
/*
 * Copyright (C) 2013,2014 The Cat Hive Developers.
 *
 * 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.cathive.fx.apps.contacts.model;




/**
 * Encapsulates a person entity.
 *
 * @author Benjamin P. Jung
 */
@Entity
@Table(name = "contact_person")
@DiscriminatorValue(value = "P")
public class Person extends Contact
                    implements Serializable {

    /** @see java.io.Serializable */
    private static final long serialVersionUid = 1L;


    public Person() {
        super();
    }

    public Person(@NamedArg(FIRST_NAME_PROPERTY) final String firstName,
                  @NamedArg(LAST_NAME_PROPERTY) final String lastName) {
        this();
        this.setFirstName(firstName);
        this.setLastName(lastName);
    }


    @Override
    public ContactType getType() {
        return ContactType.PERSON;
    }

    // <editor-fold desc="Property: last name">
    public static final String LAST_NAME_PROPERTY = "lastName";
    private final StringProperty lastName = new SimpleStringProperty(this, LAST_NAME_PROPERTY);
    public StringProperty lastNameProperty() {
        return this.lastName;
    }
    @Column(name = "last_name")
    public String getLastName() {
        return this.lastName.get();
    }
    public void setLastName(final String lastName) {
        this.lastName.set(lastName);
    }
    // </editor-fold>

    // <editor-fold desc="Property: first name">
    public static final String FIRST_NAME_PROPERTY = "firstName";
    private final StringProperty firstName = new SimpleStringProperty(this, FIRST_NAME_PROPERTY);
    @Column(name = "first_name")
    public String getFirstName() {
        return this.firstName.get();
    }
    public void setFirstName(final String firstName) {
        this.firstName.set(firstName);
    }
    public StringProperty firstNameProperty() {
        return this.firstName;
    }
    // </editor-fold>

    // <editor-fold desc="Property: sex">
    public static final String SEX_PROPERTY = "sex";
    private final ObjectProperty<Sex> sex = new SimpleObjectProperty<>(this, SEX_PROPERTY, Sex.NOT_KNOWN);
    @Column(name = "sex")
// Path: fx-inject-examples/addressbook-app/src/main/java/com/cathive/fx/apps/contacts/model/converter/SexConverter.java
// @Converter
// public class SexConverter implements AttributeConverter<Sex, Integer> {
// 
//     @Override
//     public Integer convertToDatabaseColumn(final Sex attribute) {
//         return attribute == null ? Sex.NOT_KNOWN.getValue() :  Integer.valueOf(attribute.getValue());
//     }
// 
//     @Override
//     public Sex convertToEntityAttribute(final Integer dbData) {
//         return dbData == null ? Sex.NOT_KNOWN : Sex.valueOf(dbData.intValue());
//     }
// 
// }


// Path: fx-inject-examples/addressbook-app/src/main/java/com/cathive/fx/apps/contacts/model/Person.java
import com.cathive.fx.apps.contacts.model.converter.SexConverter;
import javafx.beans.NamedArg;
import javafx.beans.binding.Bindings;
import javafx.beans.property.*;
import javax.persistence.*;
import java.io.Serializable;
import static javafx.beans.binding.Bindings.createObjectBinding;
import static javafx.beans.binding.Bindings.createStringBinding;

/*
 * Copyright (C) 2013,2014 The Cat Hive Developers.
 *
 * 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.cathive.fx.apps.contacts.model;




/**
 * Encapsulates a person entity.
 *
 * @author Benjamin P. Jung
 */
@Entity
@Table(name = "contact_person")
@DiscriminatorValue(value = "P")
public class Person extends Contact
                    implements Serializable {

    /** @see java.io.Serializable */
    private static final long serialVersionUid = 1L;


    public Person() {
        super();
    }

    public Person(@NamedArg(FIRST_NAME_PROPERTY) final String firstName,
                  @NamedArg(LAST_NAME_PROPERTY) final String lastName) {
        this();
        this.setFirstName(firstName);
        this.setLastName(lastName);
    }


    @Override
    public ContactType getType() {
        return ContactType.PERSON;
    }

    // <editor-fold desc="Property: last name">
    public static final String LAST_NAME_PROPERTY = "lastName";
    private final StringProperty lastName = new SimpleStringProperty(this, LAST_NAME_PROPERTY);
    public StringProperty lastNameProperty() {
        return this.lastName;
    }
    @Column(name = "last_name")
    public String getLastName() {
        return this.lastName.get();
    }
    public void setLastName(final String lastName) {
        this.lastName.set(lastName);
    }
    // </editor-fold>

    // <editor-fold desc="Property: first name">
    public static final String FIRST_NAME_PROPERTY = "firstName";
    private final StringProperty firstName = new SimpleStringProperty(this, FIRST_NAME_PROPERTY);
    @Column(name = "first_name")
    public String getFirstName() {
        return this.firstName.get();
    }
    public void setFirstName(final String firstName) {
        this.firstName.set(firstName);
    }
    public StringProperty firstNameProperty() {
        return this.firstName;
    }
    // </editor-fold>

    // <editor-fold desc="Property: sex">
    public static final String SEX_PROPERTY = "sex";
    private final ObjectProperty<Sex> sex = new SimpleObjectProperty<>(this, SEX_PROPERTY, Sex.NOT_KNOWN);
    @Column(name = "sex")
    @Convert(converter = SexConverter.class)