All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.objectbox.Property Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2017-2024 ObjectBox Ltd. All rights reserved.
 *
 * 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 io.objectbox;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

import javax.annotation.Nullable;

import io.objectbox.annotation.HnswIndex;
import io.objectbox.annotation.apihint.Internal;
import io.objectbox.converter.PropertyConverter;
import io.objectbox.exception.DbException;
import io.objectbox.query.PropertyQueryCondition;
import io.objectbox.query.PropertyQueryConditionImpl.ByteArrayCondition;
import io.objectbox.query.PropertyQueryConditionImpl.DoubleCondition;
import io.objectbox.query.PropertyQueryConditionImpl.DoubleDoubleCondition;
import io.objectbox.query.PropertyQueryConditionImpl.IntArrayCondition;
import io.objectbox.query.PropertyQueryConditionImpl.LongArrayCondition;
import io.objectbox.query.PropertyQueryConditionImpl.LongCondition;
import io.objectbox.query.PropertyQueryConditionImpl.LongLongCondition;
import io.objectbox.query.PropertyQueryConditionImpl.NearestNeighborCondition;
import io.objectbox.query.PropertyQueryConditionImpl.NullCondition;
import io.objectbox.query.PropertyQueryConditionImpl.StringArrayCondition;
import io.objectbox.query.PropertyQueryConditionImpl.StringCondition;
import io.objectbox.query.PropertyQueryConditionImpl.StringCondition.Operation;
import io.objectbox.query.PropertyQueryConditionImpl.StringStringCondition;
import io.objectbox.query.Query;
import io.objectbox.query.QueryBuilder.StringOrder;

/**
 * Meta data describing a Property of an ObjectBox Entity.
 * Properties are typically used when defining {@link Query Query} conditions
 * using {@link io.objectbox.query.QueryBuilder QueryBuilder}.
 * Access properties using the generated underscore class of an entity (e.g. {@code Example_.id}).
 */
@SuppressWarnings("WeakerAccess,UnusedReturnValue, unused")
public class Property implements Serializable {
    private static final long serialVersionUID = 8613291105982758093L;

    public final EntityInfo entity;
    public final int ordinal;
    public final int id;

    /** One of the supported types to be mapped to the DB. */
    public final Class type;

    public final String name;
    public final boolean isId;
    public final boolean isVirtual;
    public final String dbName;
    @SuppressWarnings("rawtypes")
    // Use raw type of PropertyConverter to allow users to supply a generic implementation.
    public final Class converterClass;

    /** Type, which is converted to a type supported by the DB. */
    public final Class customType;

    // TODO verified state should be per DB -> move to BoxStore/Box.
    // Also, this should make the Property class truly @Immutable.
    private boolean idVerified;

    public Property(EntityInfo entity, int ordinal, int id, Class type, String name) {
        this(entity, ordinal, id, type, name, false, name, null, null);
    }

    public Property(EntityInfo entity, int ordinal, int id, Class type, String name, boolean isVirtual) {
        this(entity, ordinal, id, type, name, false, isVirtual, name, null, null);
    }

    public Property(EntityInfo entity, int ordinal, int id, Class type, String name, boolean isId,
                    @Nullable String dbName) {
        this(entity, ordinal, id, type, name, isId, dbName, null, null);
    }

    @SuppressWarnings("rawtypes")
    // Use raw type of PropertyConverter to allow users to supply a generic implementation.
    public Property(EntityInfo entity, int ordinal, int id, Class type, String name, boolean isId,
                    @Nullable String dbName, @Nullable Class converterClass,
                    @Nullable Class customType) {
        this(entity, ordinal, id, type, name, isId, false, dbName, converterClass, customType);
    }

    @SuppressWarnings("rawtypes")
    // Use raw type of PropertyConverter to allow users to supply a generic implementation.
    public Property(EntityInfo entity, int ordinal, int id, Class type, String name, boolean isId,
                    boolean isVirtual, @Nullable String dbName,
                    @Nullable Class converterClass, @Nullable Class customType) {
        this.entity = entity;
        this.ordinal = ordinal;
        this.id = id;
        this.type = type;
        this.name = name;
        this.isId = isId;
        this.isVirtual = isVirtual;
        this.dbName = dbName;
        this.converterClass = converterClass;
        this.customType = customType;
    }

    /** Creates an "IS NULL" condition for this property. */
    public PropertyQueryCondition isNull() {
        return new NullCondition<>(this, NullCondition.Operation.IS_NULL);
    }

    /** Creates an "IS NOT NULL" condition for this property. */
    public PropertyQueryCondition notNull() {
        return new NullCondition<>(this, NullCondition.Operation.NOT_NULL);
    }

    /** Creates an "equal ('=')" condition for this property. */
    public PropertyQueryCondition equal(boolean value) {
        return new LongCondition<>(this, LongCondition.Operation.EQUAL, value);
    }

    /** Creates a "not equal ('<>')" condition for this property. */
    public PropertyQueryCondition notEqual(boolean value) {
        return new LongCondition<>(this, LongCondition.Operation.NOT_EQUAL, value);
    }

    /** Creates an "equal ('=')" condition for this property. */
    public PropertyQueryCondition equal(short value) {
        return equal((long) value);
    }

    /** Creates a "not equal ('<>')" condition for this property. */
    public PropertyQueryCondition notEqual(short value) {
        return notEqual((long) value);
    }

    /** Creates a "greater than ('>')" condition for this property. */
    public PropertyQueryCondition greater(short value) {
        return greater((long) value);
    }

    /** Creates a "greater or equal ('>=')" condition for this property. */
    public PropertyQueryCondition greaterOrEqual(short value) {
        return greaterOrEqual((long) value);
    }

    /** Creates a "less than ('<')" condition for this property. */
    public PropertyQueryCondition less(short value) {
        return less((long) value);
    }

    /** Creates a "less or equal ('<=')" condition for this property. */
    public PropertyQueryCondition lessOrEqual(short value) {
        return lessOrEqual((long) value);
    }

    /**
     * Creates a "BETWEEN ... AND ..." condition for this property.
     * Finds objects with property value between and including the first and second value.
     */
    public PropertyQueryCondition between(short lowerBoundary, short upperBoundary) {
        return between((long) lowerBoundary, upperBoundary);
    }

    /** Creates an "equal ('=')" condition for this property. */
    public PropertyQueryCondition equal(int value) {
        return equal((long) value);
    }

    /** Creates a "not equal ('<>')" condition for this property. */
    public PropertyQueryCondition notEqual(int value) {
        return notEqual((long) value);
    }

    /** Creates a "greater than ('>')" condition for this property. */
    public PropertyQueryCondition greater(int value) {
        return greater((long) value);
    }

    /** Creates a "greater or equal ('>=')" condition for this property. */
    public PropertyQueryCondition greaterOrEqual(int value) {
        return greaterOrEqual((long) value);
    }

    /** Creates a "less than ('<')" condition for this property. */
    public PropertyQueryCondition less(int value) {
        return less((long) value);
    }

    /** Creates a "less or equal ('<=')" condition for this property. */
    public PropertyQueryCondition lessOrEqual(int value) {
        return lessOrEqual((long) value);
    }

    /**
     * Creates a "BETWEEN ... AND ..." condition for this property.
     * Finds objects with property value between and including the first and second value.
     */
    public PropertyQueryCondition between(int lowerBoundary, int upperBoundary) {
        return between((long) lowerBoundary, upperBoundary);
    }

    /** Creates an "IN (..., ..., ...)" condition for this property. */
    public PropertyQueryCondition oneOf(int[] values) {
        return new IntArrayCondition<>(this, IntArrayCondition.Operation.IN, values);
    }

    /** Creates a "NOT IN (..., ..., ...)" condition for this property. */
    public PropertyQueryCondition notOneOf(int[] values) {
        return new IntArrayCondition<>(this, IntArrayCondition.Operation.NOT_IN, values);
    }

    /** Creates an "equal ('=')" condition for this property. */
    public PropertyQueryCondition equal(long value) {
        return new LongCondition<>(this, LongCondition.Operation.EQUAL, value);
    }

    /** Creates a "not equal ('<>')" condition for this property. */
    public PropertyQueryCondition notEqual(long value) {
        return new LongCondition<>(this, LongCondition.Operation.NOT_EQUAL, value);
    }

    /** Creates a "greater than ('>')" condition for this property. */
    public PropertyQueryCondition greater(long value) {
        return new LongCondition<>(this, LongCondition.Operation.GREATER, value);
    }

    /** Creates a "greater or equal ('>=')" condition for this property. */
    public PropertyQueryCondition greaterOrEqual(long value) {
        return new LongCondition<>(this, LongCondition.Operation.GREATER_OR_EQUAL, value);
    }

    /** Creates a "less than ('<')" condition for this property. */
    public PropertyQueryCondition less(long value) {
        return new LongCondition<>(this, LongCondition.Operation.LESS, value);
    }

    /** Creates a "less or equal ('<=')" condition for this property. */
    public PropertyQueryCondition lessOrEqual(long value) {
        return new LongCondition<>(this, LongCondition.Operation.LESS_OR_EQUAL, value);
    }

    /**
     * Creates a "BETWEEN ... AND ..." condition for this property.
     * Finds objects with property value between and including the first and second value.
     */
    public PropertyQueryCondition between(long lowerBoundary, long upperBoundary) {
        return new LongLongCondition<>(this, LongLongCondition.Operation.BETWEEN, lowerBoundary, upperBoundary);
    }

    /** Creates an "IN (..., ..., ...)" condition for this property. */
    public PropertyQueryCondition oneOf(long[] values) {
        return new LongArrayCondition<>(this, LongArrayCondition.Operation.IN, values);
    }

    /** Creates a "NOT IN (..., ..., ...)" condition for this property. */
    public PropertyQueryCondition notOneOf(long[] values) {
        return new LongArrayCondition<>(this, LongArrayCondition.Operation.NOT_IN, values);
    }

    /**
     * Calls {@link #between(double, double)} with {@code value - tolerance} as lower bound and
     * {@code value + tolerance} as upper bound.
     */
    public PropertyQueryCondition equal(double value, double tolerance) {
        return new DoubleDoubleCondition<>(this, DoubleDoubleCondition.Operation.BETWEEN,
                value - tolerance, value + tolerance);
    }

    /** Creates a "greater than ('>')" condition for this property. */
    public PropertyQueryCondition greater(double value) {
        return new DoubleCondition<>(this, DoubleCondition.Operation.GREATER, value);
    }

    /** Creates a "greater or equal ('>=')" condition for this property. */
    public PropertyQueryCondition greaterOrEqual(double value) {
        return new DoubleCondition<>(this, DoubleCondition.Operation.GREATER_OR_EQUAL, value);
    }

    /** Creates a "less than ('<')" condition for this property. */
    public PropertyQueryCondition less(double value) {
        return new DoubleCondition<>(this, DoubleCondition.Operation.LESS, value);
    }

    /** Creates a "less or equal ('<=')" condition for this property. */
    public PropertyQueryCondition lessOrEqual(double value) {
        return new DoubleCondition<>(this, DoubleCondition.Operation.LESS_OR_EQUAL, value);
    }

    /**
     * Creates a "BETWEEN ... AND ..." condition for this property.
     * Finds objects with property value between and including the first and second value.
     */
    public PropertyQueryCondition between(double lowerBoundary, double upperBoundary) {
        return new DoubleDoubleCondition<>(this, DoubleDoubleCondition.Operation.BETWEEN,
                lowerBoundary, upperBoundary);
    }

    /**
     * Performs an approximate nearest neighbor (ANN) search to find objects near to the given {@code queryVector}.
     * 

* This requires the vector property to have an {@link HnswIndex}. *

* The dimensions of the query vector should be at least the dimensions of this vector property. *

* Use {@code maxResultCount} to set the maximum number of objects to return by the ANN condition. Hint: it can also * be used as the "ef" HNSW parameter to increase the search quality in combination with a query limit. For example, * use maxResultCount of 100 with a Query limit of 10 to have 10 results that are of potentially better quality than * just passing in 10 for maxResultCount (quality/performance tradeoff). *

* To change the given parameters after building the query, use {@link Query#setParameter(Property, float[])} and * {@link Query#setParameter(Property, long)} or their alias equivalent. */ public PropertyQueryCondition nearestNeighbors(float[] queryVector, int maxResultCount) { return new NearestNeighborCondition<>(this, queryVector, maxResultCount); } /** Creates an "equal ('=')" condition for this property. */ public PropertyQueryCondition equal(Date value) { return new LongCondition<>(this, LongCondition.Operation.EQUAL, value); } /** Creates a "not equal ('<>')" condition for this property. */ public PropertyQueryCondition notEqual(Date value) { return new LongCondition<>(this, LongCondition.Operation.NOT_EQUAL, value); } /** Creates a "greater than ('>')" condition for this property. */ public PropertyQueryCondition greater(Date value) { return new LongCondition<>(this, LongCondition.Operation.GREATER, value); } /** Creates a "greater or equal ('>=')" condition for this property. */ public PropertyQueryCondition greaterOrEqual(Date value) { return new LongCondition<>(this, LongCondition.Operation.GREATER_OR_EQUAL, value); } /** Creates a "less than ('<')" condition for this property. */ public PropertyQueryCondition less(Date value) { return new LongCondition<>(this, LongCondition.Operation.LESS, value); } /** Creates a "less or equal ('<=')" condition for this property. */ public PropertyQueryCondition lessOrEqual(Date value) { return new LongCondition<>(this, LongCondition.Operation.LESS_OR_EQUAL, value); } /** Creates an "IN (..., ..., ...)" condition for this property. */ public PropertyQueryCondition oneOf(Date[] value) { return new LongArrayCondition<>(this, LongArrayCondition.Operation.IN, value); } /** Creates a "NOT IN (..., ..., ...)" condition for this property. */ public PropertyQueryCondition notOneOf(Date[] value) { return new LongArrayCondition<>(this, LongArrayCondition.Operation.NOT_IN, value); } /** * Creates a "BETWEEN ... AND ..." condition for this property. * Finds objects with property value between and including the first and second value. */ public PropertyQueryCondition between(Date lowerBoundary, Date upperBoundary) { return new LongLongCondition<>(this, LongLongCondition.Operation.BETWEEN, lowerBoundary, upperBoundary); } /** * Creates an "equal ('=')" condition for this property * using {@link StringOrder#CASE_SENSITIVE StringOrder#CASE_SENSITIVE}. * * @see #equal(String, StringOrder) */ public PropertyQueryCondition equal(String value) { return new StringCondition<>(this, StringCondition.Operation.EQUAL, value); } /** * Creates an "equal ('=')" condition for this property. */ public PropertyQueryCondition equal(String value, StringOrder order) { return new StringCondition<>(this, StringCondition.Operation.EQUAL, value, order); } /** * Creates a "not equal ('<>')" condition for this property * using {@link StringOrder#CASE_SENSITIVE StringOrder#CASE_SENSITIVE}. * * @see #notEqual(String, StringOrder) */ public PropertyQueryCondition notEqual(String value) { return new StringCondition<>(this, StringCondition.Operation.NOT_EQUAL, value); } /** * Creates a "not equal ('<>')" condition for this property. */ public PropertyQueryCondition notEqual(String value, StringOrder order) { return new StringCondition<>(this, StringCondition.Operation.NOT_EQUAL, value, order); } /** * Creates a "greater than ('>')" condition for this property * using {@link StringOrder#CASE_SENSITIVE StringOrder#CASE_SENSITIVE}. * * @see #greater(String, StringOrder) */ public PropertyQueryCondition greater(String value) { return new StringCondition<>(this, StringCondition.Operation.GREATER, value); } /** * Creates a "greater than ('>')" condition for this property. */ public PropertyQueryCondition greater(String value, StringOrder order) { return new StringCondition<>(this, StringCondition.Operation.GREATER, value, order); } /** * Creates a "greater or equal ('>=')" condition for this property. */ public PropertyQueryCondition greaterOrEqual(String value, StringOrder order) { return new StringCondition<>(this, StringCondition.Operation.GREATER_OR_EQUAL, value, order); } /** * Creates a "less than ('<')" condition for this property * using {@link StringOrder#CASE_SENSITIVE StringOrder#CASE_SENSITIVE}. * * @see #less(String, StringOrder) */ public PropertyQueryCondition less(String value) { return new StringCondition<>(this, StringCondition.Operation.LESS, value); } /** * Creates a "less than ('<')" condition for this property. */ public PropertyQueryCondition less(String value, StringOrder order) { return new StringCondition<>(this, StringCondition.Operation.LESS, value, order); } /** * Creates a "less or equal ('<=')" condition for this property. */ public PropertyQueryCondition lessOrEqual(String value, StringOrder order) { return new StringCondition<>(this, StringCondition.Operation.LESS_OR_EQUAL, value, order); } /** * Creates a contains condition for this property * using {@link StringOrder#CASE_SENSITIVE StringOrder#CASE_SENSITIVE}. *

* Note: for a String array property, use {@link #containsElement} instead. * * @see #contains(String, StringOrder) */ public PropertyQueryCondition contains(String value) { checkNotStringArray(); return new StringCondition<>(this, StringCondition.Operation.CONTAINS, value); } public PropertyQueryCondition contains(String value, StringOrder order) { checkNotStringArray(); return new StringCondition<>(this, StringCondition.Operation.CONTAINS, value, order); } private void checkNotStringArray() { if (String[].class == type) { throw new IllegalArgumentException("For a String[] property use containsElement() instead."); } } /** * For a String array, list or String-key map property, matches if at least one element equals the given value * using {@link StringOrder#CASE_SENSITIVE StringOrder#CASE_SENSITIVE}. * * @see #containsElement(String, StringOrder) */ public PropertyQueryCondition containsElement(String value) { return new StringCondition<>(this, Operation.CONTAINS_ELEMENT, value); } public PropertyQueryCondition containsElement(String value, StringOrder order) { return new StringCondition<>(this, Operation.CONTAINS_ELEMENT, value, order); } /** * For a String-key map property, matches if at least one key and value combination equals the given values * using {@link StringOrder#CASE_SENSITIVE StringOrder#CASE_SENSITIVE}. * * @see #containsKeyValue(String, String, StringOrder) */ public PropertyQueryCondition containsKeyValue(String key, String value) { return new StringStringCondition<>(this, StringStringCondition.Operation.CONTAINS_KEY_VALUE, key, value, StringOrder.CASE_SENSITIVE); } /** * @see #containsKeyValue(String, String) */ public PropertyQueryCondition containsKeyValue(String key, String value, StringOrder order) { return new StringStringCondition<>(this, StringStringCondition.Operation.CONTAINS_KEY_VALUE, key, value, order); } /** * Creates a starts with condition using {@link StringOrder#CASE_SENSITIVE StringOrder#CASE_SENSITIVE}. * * @see #startsWith(String, StringOrder) */ public PropertyQueryCondition startsWith(String value) { return new StringCondition<>(this, Operation.STARTS_WITH, value); } public PropertyQueryCondition startsWith(String value, StringOrder order) { return new StringCondition<>(this, Operation.STARTS_WITH, value, order); } /** * Creates an ends with condition using {@link StringOrder#CASE_SENSITIVE StringOrder#CASE_SENSITIVE}. * * @see #endsWith(String, StringOrder) */ public PropertyQueryCondition endsWith(String value) { return new StringCondition<>(this, Operation.ENDS_WITH, value); } public PropertyQueryCondition endsWith(String value, StringOrder order) { return new StringCondition<>(this, Operation.ENDS_WITH, value, order); } /** * Creates an "IN (..., ..., ...)" condition for this property * using {@link StringOrder#CASE_SENSITIVE StringOrder#CASE_SENSITIVE}. * * @see #oneOf(String[], StringOrder) */ public PropertyQueryCondition oneOf(String[] values) { return new StringArrayCondition<>(this, StringArrayCondition.Operation.IN, values); } /** * Creates an "IN (..., ..., ...)" condition for this property. */ public PropertyQueryCondition oneOf(String[] values, StringOrder order) { return new StringArrayCondition<>(this, StringArrayCondition.Operation.IN, values, order); } /** Creates an "equal ('=')" condition for this property. */ public PropertyQueryCondition equal(byte[] value) { return new ByteArrayCondition<>(this, ByteArrayCondition.Operation.EQUAL, value); } /** Creates a "greater than ('>')" condition for this property. */ public PropertyQueryCondition greater(byte[] value) { return new ByteArrayCondition<>(this, ByteArrayCondition.Operation.GREATER, value); } /** Creates a "greater or equal ('>=')" condition for this property. */ public PropertyQueryCondition greaterOrEqual(byte[] value) { return new ByteArrayCondition<>(this, ByteArrayCondition.Operation.GREATER_OR_EQUAL, value); } /** Creates a "less than ('<')" condition for this property. */ public PropertyQueryCondition less(byte[] value) { return new ByteArrayCondition<>(this, ByteArrayCondition.Operation.LESS, value); } /** Creates a "less or equal ('<=')" condition for this property. */ public PropertyQueryCondition lessOrEqual(byte[] value) { return new ByteArrayCondition<>(this, ByteArrayCondition.Operation.LESS_OR_EQUAL, value); } ////// // Note: The following are deprecated conditions used with DAOcompat only. // They exist so library users need not update their code where new conditions are named differently. ////// /** * Creates an "equal ('=')" condition for this property. * * @deprecated Use {@link #equal} instead. */ @Deprecated public PropertyQueryCondition eq(Object value) { if (value instanceof Long) { return equal((Long) value); } else if (value instanceof Integer) { return equal((Integer) value); } else if (value instanceof String) { return equal((String) value); } else { throw new IllegalArgumentException("Only LONG, INTEGER or STRING values are supported."); } } /** * Creates an "not equal ('<>')" condition for this property. * * @deprecated Use {@link #notEqual} instead. */ @Deprecated public PropertyQueryCondition notEq(Object value) { if (value instanceof Long) { return notEqual((Long) value); } else if (value instanceof Integer) { return notEqual((Integer) value); } else if (value instanceof String) { return notEqual((String) value); } else { throw new IllegalArgumentException("Only LONG, INTEGER or STRING values are supported."); } } /** * Creates an "IN (..., ..., ...)" condition for this property. * * @deprecated Use {@link #oneOf} instead. */ @Deprecated public PropertyQueryCondition in(Object... values) { // just check the first value and assume all others are of the same type // maybe this is too naive and we should properly check values earlier if (values[0] instanceof Long) { long[] inValues = new long[values.length]; for (int i = 0; i < values.length; i++) { inValues[i] = (long) values[i]; } return oneOf(inValues); } else if (values[0] instanceof Integer) { int[] inValues = new int[values.length]; for (int i = 0; i < values.length; i++) { inValues[i] = (int) values[i]; } return oneOf(inValues); } else { throw new IllegalArgumentException("The IN condition only supports LONG or INTEGER values."); } } /** * Creates an "IN (..., ..., ...)" condition for this property. * * @deprecated Use {@link #oneOf} instead. */ @Deprecated public PropertyQueryCondition in(Collection inValues) { return in(inValues.toArray()); } /** * Creates an "greater than ('>')" condition for this property. * * @deprecated Use {@link #greater} instead. */ @Deprecated public PropertyQueryCondition gt(Object value) { if (value instanceof Long) { return greater((Long) value); } else if (value instanceof Integer) { return greater((Integer) value); } else if (value instanceof Double) { return greater((Double) value); } else if (value instanceof Float) { return greater((Float) value); } else { throw new IllegalArgumentException("Only LONG, INTEGER, DOUBLE or FLOAT values are supported."); } } /** * Creates an "less than ('<')" condition for this property. * * @deprecated Use {@link #less} instead. */ @Deprecated public PropertyQueryCondition lt(Object value) { if (value instanceof Long) { return less((Long) value); } else if (value instanceof Integer) { return less((Integer) value); } else if (value instanceof Double) { return less((Double) value); } else if (value instanceof Float) { return less((Float) value); } else { throw new IllegalArgumentException("Only LONG, INTEGER, DOUBLE or FLOAT values are supported."); } } /** * Creates an "IS NOT NULL" condition for this property. * * @deprecated Use {@link #notNull()} instead. */ @Deprecated public PropertyQueryCondition isNotNull() { return notNull(); } @Internal public int getEntityId() { return entity.getEntityId(); } @Internal public int getId() { if (this.id <= 0) { throw new IllegalStateException("Illegal property ID " + id + " for " + this); } return id; } boolean isIdVerified() { return idVerified; } void verifyId(int idInDb) { if (this.id <= 0) { throw new IllegalStateException("Illegal property ID " + id + " for " + this); } if (this.id != idInDb) { throw new DbException(this + " does not match ID in DB: " + idInDb); } idVerified = true; } @Override public String toString() { return "Property \"" + name + "\" (ID: " + id + ")"; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy