diff --git a/src/main/java/org/caosdb/server/CaosDBServer.java b/src/main/java/org/caosdb/server/CaosDBServer.java index 5781f2e1ae1df961e6c85eb2b469996950c56cf9..8a09883b779a9c75ecaf14775ff06f2ed112c1b8 100644 --- a/src/main/java/org/caosdb/server/CaosDBServer.java +++ b/src/main/java/org/caosdb/server/CaosDBServer.java @@ -3,8 +3,8 @@ * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * Copyright (C) 2019-2021 IndiScale GmbH <info@indiscale.com> - * Copyright (C) 2019-2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2019-2021,2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2019-2021,2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -129,7 +129,7 @@ public class CaosDBServer extends Application { private static boolean NO_TLS = false; public static final String REQUEST_TIME_LOGGER = "REQUEST_TIME_LOGGER"; public static final String REQUEST_ERRORS_LOGGER = "REQUEST_ERRORS_LOGGER"; - private static boolean USE_CACHE = false; + private static boolean USE_CACHE = true; private static Scheduler SCHEDULER; public static String getServerProperty(final String key) { diff --git a/src/main/java/org/caosdb/server/database/BackendTransaction.java b/src/main/java/org/caosdb/server/database/BackendTransaction.java index 7021dfbb0ba8e580b104d5639b9acb1a397064ea..c014972ac52246e87a1d9e6f575a645125ab4c57 100644 --- a/src/main/java/org/caosdb/server/database/BackendTransaction.java +++ b/src/main/java/org/caosdb/server/database/BackendTransaction.java @@ -3,8 +3,8 @@ * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * Copyright (C) 2019-2021 IndiScale GmbH <info@indiscale.com> - * Copyright (C) 2019-2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2019-2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2019-2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -133,6 +133,18 @@ import org.caosdb.server.database.misc.TransactionBenchmark; import org.caosdb.server.utils.UndoHandler; import org.caosdb.server.utils.Undoable; +/** + * Abstract class for backend transactions. + * + * <p>This class is the glue between the Transaction layer and the actual implementation of the + * communication with the back end. + * + * <p>This class also acts as a registry which stores which implementation is being used for which + * backend transaction interface. + * + * @see {@link Transaction} + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public abstract class BackendTransaction implements Undoable { private final UndoHandler undoHandler = new UndoHandler(); diff --git a/src/main/java/org/caosdb/server/database/access/AbstractAccess.java b/src/main/java/org/caosdb/server/database/access/AbstractAccess.java index 680b18275a27d9d55ffecffa8b66e65eb87237bb..574dabedd0db28ded611411ed8848f00be56a293 100644 --- a/src/main/java/org/caosdb/server/database/access/AbstractAccess.java +++ b/src/main/java/org/caosdb/server/database/access/AbstractAccess.java @@ -3,6 +3,8 @@ * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -25,6 +27,12 @@ import org.caosdb.server.database.misc.RollBackHandler; import org.caosdb.server.transaction.TransactionInterface; import org.caosdb.server.utils.UseCacheResourceDelegate; +/** + * Abstract implementation of an Access. + * + * @see {@link Access} + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public abstract class AbstractAccess<T extends TransactionInterface> extends UseCacheResourceDelegate implements Access { diff --git a/src/main/java/org/caosdb/server/database/access/Access.java b/src/main/java/org/caosdb/server/database/access/Access.java index a98afa2737656a9f5bdd0e3d720354b742030584..6b8a521cffd5f0d817f9a9b0a4ecce357fb82d76 100644 --- a/src/main/java/org/caosdb/server/database/access/Access.java +++ b/src/main/java/org/caosdb/server/database/access/Access.java @@ -3,6 +3,8 @@ * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -22,6 +24,22 @@ package org.caosdb.server.database.access; import org.caosdb.server.database.misc.DBHelper; import org.caosdb.server.utils.UseCacheResource; +/** + * Access Interface. + * + * <p>The access object is part of a Transactions state and it is the glue between the Transaction + * and the actual backend implementation of those transactions. It represents different levels of + * access (RO, RW) and provides all the helper objects shared by all the single calls to the backend + * (package .../database/backend/implementation/...). + * + * <p>It is further used to commit or roll-back the owning transaction. + * + * <p>The DatabaseAccessManager issues the Access to a requesting Transaction. + * + * @see {@link Transaction} + * @see {@link DatabaseAccessManager} + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public interface Access extends UseCacheResource { public abstract void setHelper(String name, DBHelper helper); diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLDeleteEntityProperties.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLDeleteEntityProperties.java index 615adca41a021003700ae73fc6943a9ee795521b..747cf50d8390d943fce5ffbf596debe5659b8df9 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLDeleteEntityProperties.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLDeleteEntityProperties.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.database.backend.implementation.MySQL; diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLDeleteSparseEntity.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLDeleteSparseEntity.java index b634864656ce601cb59915f9b6fd92cf3f6c428a..a1ab389b6878c06c5fd965d0952d422f11134c0e 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLDeleteSparseEntity.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLDeleteSparseEntity.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.database.backend.implementation.MySQL; diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetDependentEntities.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetDependentEntities.java index bb33b4df1adcf38466bcaeaa72923ddc7fe30b65..2af80f802ca19eca806856bb653788b50ae5ecf9 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetDependentEntities.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetDependentEntities.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.database.backend.implementation.MySQL; @@ -31,6 +30,15 @@ import org.caosdb.server.database.backend.interfaces.GetDependentEntitiesImpl; import org.caosdb.server.database.exceptions.TransactionException; import org.caosdb.server.entity.EntityID; +/** + * Get a list of ids of all entities which require the given entity to exists. + * + * <p>That is the list of all direct child entities (by is-a relation), referenced entities (i.e. + * the given entity is a property's value), all properties which have this entity as their data type + * and all implemented properties which use this entity as their abtract property. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class MySQLGetDependentEntities extends MySQLTransaction implements GetDependentEntitiesImpl { diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetFileRecordByPath.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetFileRecordByPath.java index 922c2b6b9814a4431604a91687f41948ef715ccf..0dd10ec1bcdc97a095da661cb6cb2e2209da0955 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetFileRecordByPath.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetFileRecordByPath.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.database.backend.implementation.MySQL; @@ -30,6 +29,11 @@ import org.caosdb.server.database.backend.interfaces.GetFileRecordByPathImpl; import org.caosdb.server.database.exceptions.TransactionException; import org.caosdb.server.database.proto.SparseEntity; +/** + * Retrieve the entity id of a file with the given path (or null). + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class MySQLGetFileRecordByPath extends MySQLTransaction implements GetFileRecordByPathImpl { public MySQLGetFileRecordByPath(final Access access) { diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetIDByName.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetIDByName.java index 4837fc591df2ba6a61f28b6608b469ab0fb0f5cb..5d3e3a7d707c0d7d451d0229426a959fc827e8ef 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetIDByName.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetIDByName.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.database.backend.implementation.MySQL; @@ -32,6 +31,11 @@ import org.caosdb.server.database.backend.interfaces.GetIDByNameImpl; import org.caosdb.server.database.exceptions.TransactionException; import org.caosdb.server.entity.EntityID; +/** + * Retrieve the entity id of an entity with the given name (or null). + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class MySQLGetIDByName extends MySQLTransaction implements GetIDByNameImpl { public MySQLGetIDByName(final Access access) { diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetUpdateableChecksums.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetUpdateableChecksums.java index 2081b026903026a0aa704290d6fa16d8d5e64800..81c0dfd6d489a104183e052aba6156372a96f8e9 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetUpdateableChecksums.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetUpdateableChecksums.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.database.backend.implementation.MySQL; @@ -30,6 +29,12 @@ import org.caosdb.server.database.backend.interfaces.GetUpdateableChecksumsImpl; import org.caosdb.server.database.exceptions.TransactionException; import org.caosdb.server.entity.EntityID; +/** + * Retrieve the entity ids of all files which have a checksum which should be updated (because the + * checksum is NULL, currently). + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class MySQLGetUpdateableChecksums extends MySQLTransaction implements GetUpdateableChecksumsImpl { diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertEntityDatatype.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertEntityDatatype.java index 7aa692e4dc61db462573d55e39f1eb376ec7416e..4260ae03e76eec7fab1e33957a00dedc2ef77e17 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertEntityDatatype.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertEntityDatatype.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ package org.caosdb.server.database.backend.implementation.MySQL; import java.sql.PreparedStatement; @@ -8,6 +27,15 @@ import org.caosdb.server.database.exceptions.IntegrityException; import org.caosdb.server.database.exceptions.TransactionException; import org.caosdb.server.database.proto.SparseEntity; +/** + * Insert an entity's (meaning: an abstract property's) data type. + * + * <p>This inserts the abstract property's data type as opposed to the (overridden data type which + * is being inserted/updated via InsertEntityPropertiesImpl. + * + * @see {@link InsertEntityPropertiesImpl} + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class MySQLInsertEntityDatatype extends MySQLTransaction implements InsertEntityDatatypeImpl { diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertEntityProperties.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertEntityProperties.java index 2fb7c95f766748571009177fa38bf99405637101..2b28a3d97d7951d84542e6c11a16ebc8b87a0e4d 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertEntityProperties.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertEntityProperties.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.database.backend.implementation.MySQL; @@ -48,6 +47,17 @@ import org.caosdb.server.entity.EntityID; import org.caosdb.server.entity.EntityInterface; import org.caosdb.server.entity.wrapper.Property; +/** + * Insert the entity's properties. + * + * <p>This implementation transforms a deep tree of properties into a flat representation. This + * transformation is a MySQL-backend implementation detail and should not be leaked to the clients. + * + * <p>The reverse transformation happens in MySQLRetrieveProperties. + * + * @see {@link MySQLRetrieveProperties} + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class MySQLInsertEntityProperties extends MySQLTransaction implements InsertEntityPropertiesImpl { diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertSparseEntity.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertSparseEntity.java index 5dcd2634f8e8518865021e02c2eb9e3c10ff45d0..fa70a1453b8dd2f2c761cf3e4e658cb77c5a445f 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertSparseEntity.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertSparseEntity.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.database.backend.implementation.MySQL; diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLRetrieveCurrentMaxId.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLRetrieveCurrentMaxId.java index 1bc9a89dd119a66eecc33799849977019422fde1..9f56324f84cea47081f4f9901f10c772508309d4 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLRetrieveCurrentMaxId.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLRetrieveCurrentMaxId.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ package org.caosdb.server.database.backend.implementation.MySQL; import java.sql.PreparedStatement; @@ -7,6 +26,11 @@ import org.caosdb.server.database.access.Access; import org.caosdb.server.database.backend.interfaces.RetrieveCurrentMaxIdImpl; import org.caosdb.server.database.exceptions.TransactionException; +/** + * Implements {@link RetrieveCurrentMaxIdImpl} for a MySQL/MariaDB back-end. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class MySQLRetrieveCurrentMaxId extends MySQLTransaction implements RetrieveCurrentMaxIdImpl { diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLRetrieveProperties.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLRetrieveProperties.java index 30a0f530bb77458f95d21278f0474e2cdc89a457..97fe4dc1b2453aac7e501db796da23ae25f2e317 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLRetrieveProperties.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLRetrieveProperties.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.database.backend.implementation.MySQL; @@ -35,6 +34,16 @@ import org.caosdb.server.database.exceptions.TransactionException; import org.caosdb.server.database.proto.ProtoProperty; import org.caosdb.server.entity.EntityID; +/** + * Retrieve the entity's properties. + * + * <p>This implemation transforms the flat structure of properties which is stored in the back end + * to a deep tree of properties (if applicable) which is the reverse transformation to that + * happening in MySQLInsertEntityProperties. + * + * @see {@link MySQLInsertEntityProperties} + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class MySQLRetrieveProperties extends MySQLTransaction implements RetrievePropertiesImpl { public MySQLRetrieveProperties(final Access access) { diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLSetFileChecksum.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLSetFileChecksum.java index 69ecfba5089e96176766db402b9e07eade354df3..79c7253103f1ed578c45102ee2bf1a920b2c6049 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLSetFileChecksum.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLSetFileChecksum.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ package org.caosdb.server.database.backend.implementation.MySQL; import java.sql.PreparedStatement; @@ -10,7 +29,7 @@ import org.caosdb.server.entity.EntityID; /** * Implements {@link SetFileChecksumImpl} for a MySQL/MariaDB back-end. * - * @author Timm Fitschen (t.fitschen@indiscale.com) + * @author Timm Fitschen <t.fitschen@indiscale.com> */ public class MySQLSetFileChecksum extends MySQLTransaction implements SetFileChecksumImpl { diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLSetQueryTemplateDefinition.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLSetQueryTemplateDefinition.java index b03630f56f571e21533b8a5a932ea5259c07309e..ad1f40c763f6e36671095583ddfa79d002edc1d3 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLSetQueryTemplateDefinition.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLSetQueryTemplateDefinition.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.database.backend.implementation.MySQL; @@ -29,6 +28,11 @@ import org.caosdb.server.database.backend.interfaces.SetQueryTemplateDefinitionI import org.caosdb.server.database.exceptions.TransactionException; import org.caosdb.server.entity.EntityID; +/** + * Implements {@link SetQueryTemplateDefinitionImpl} for a MySQL/MariaDB back-end. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class MySQLSetQueryTemplateDefinition extends MySQLTransaction implements SetQueryTemplateDefinitionImpl { diff --git a/src/main/java/org/caosdb/server/database/backend/interfaces/RetrieveCurrentMaxIdImpl.java b/src/main/java/org/caosdb/server/database/backend/interfaces/RetrieveCurrentMaxIdImpl.java index 2a3ce327bef98501c53fae26ce053071cb5a3f99..ca711d52c3983b4f71bf41aa5ef63583430866a8 100644 --- a/src/main/java/org/caosdb/server/database/backend/interfaces/RetrieveCurrentMaxIdImpl.java +++ b/src/main/java/org/caosdb/server/database/backend/interfaces/RetrieveCurrentMaxIdImpl.java @@ -1,5 +1,31 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ package org.caosdb.server.database.backend.interfaces; +import org.caosdb.server.database.backend.transaction.RetrieveCurrentMaxId; + +/** + * Interface for the backend implementation of {@link RetrieveCurrentMaxId} + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public interface RetrieveCurrentMaxIdImpl extends BackendTransactionImpl { public Integer execute(); diff --git a/src/main/java/org/caosdb/server/database/backend/transaction/RetrieveCurrentMaxId.java b/src/main/java/org/caosdb/server/database/backend/transaction/RetrieveCurrentMaxId.java index a3b9f6d96eddf4583e60a329dec971830dcee72a..4dd76d30cd0cf1c63d5eb8ad48054093f064629f 100644 --- a/src/main/java/org/caosdb/server/database/backend/transaction/RetrieveCurrentMaxId.java +++ b/src/main/java/org/caosdb/server/database/backend/transaction/RetrieveCurrentMaxId.java @@ -1,8 +1,37 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ package org.caosdb.server.database.backend.transaction; import org.caosdb.server.database.BackendTransaction; import org.caosdb.server.database.backend.interfaces.RetrieveCurrentMaxIdImpl; +/** + * Retrieve the maximum currently known entity id. + * + * <p>This is used by the EntityIdRegistry for the legacy ids (i.e. integer ids) to generate + * sequential ids which have not been used yet. + * + * @see {@link EntityIdRegistry} + * @see {@link LegacyIds} + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class RetrieveCurrentMaxId extends BackendTransaction { private Integer maxId; diff --git a/src/main/java/org/caosdb/server/datatype/ReferenceValue.java b/src/main/java/org/caosdb/server/datatype/ReferenceValue.java index 20620a4327ddbc46fb5f5f29abad4ef93e4fee88..4c84a760c05356b292e9e39e48f7af3b3d9a4668 100644 --- a/src/main/java/org/caosdb/server/datatype/ReferenceValue.java +++ b/src/main/java/org/caosdb/server/datatype/ReferenceValue.java @@ -1,5 +1,4 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, @@ -20,8 +19,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ /** @review Daniel Hornung 2022-03-04 */ @@ -41,7 +38,13 @@ import org.jdom2.Element; * <p>Differently from other properties, they may be versioned, i.e. they may reference to a * specific version of an entity. * - * <p>TODO: Ways to specify a reference value, what are the consequences of versioned references? + * <p>Ways to specify a reference value: {id}@{version} using either the version id (a hex'ed sha256 + * string) or "HEAD", "HEAD~1", "HEAD~2" and so on. Note: "HEAD" always means the "HEAD" + * <i>after</i> the transaction. So, if you are changing the referenced entity in the same + * transaction and you want to reference the entity in the version before the change you need to use + * "HEAD~1" because that is the old version of the future. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> */ public class ReferenceValue implements SingleValue { private EntityInterface entity = null; diff --git a/src/main/java/org/caosdb/server/entity/Entity.java b/src/main/java/org/caosdb/server/entity/Entity.java index dd80101f28ecc47aa099697dd6a6c8ffed1fb372..16dbbdd5f399905fc29ab2a8f1629fbcd163b6b6 100644 --- a/src/main/java/org/caosdb/server/entity/Entity.java +++ b/src/main/java/org/caosdb/server/entity/Entity.java @@ -1,11 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> - * Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2020 - 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2020 - 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.entity; @@ -62,6 +59,17 @@ import org.caosdb.server.utils.TransactionLogMessage; import org.caosdb.unit.Unit; import org.jdom2.Element; +/** + * Abstract base class for all the important entity classes. + * + * <p>This is the central data class of the server. It represents Records, RecordTypes, Properties, + * and Files. + * + * <p>This class holds the messages and other transient information as well as the actual data that + * is being retrieved from or written to the back-end during a transaction. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public abstract class Entity extends AbstractObservable implements EntityInterface { public static final String DATATYPE_CHANGED_EVENT = "DatatypeChangedEvent"; diff --git a/src/main/java/org/caosdb/server/entity/EntityID.java b/src/main/java/org/caosdb/server/entity/EntityID.java index 469b2e50ef124061eb400878d59b98de1ebbe840..9f61127db2969578300fbe2f12091c0f9f258d90 100644 --- a/src/main/java/org/caosdb/server/entity/EntityID.java +++ b/src/main/java/org/caosdb/server/entity/EntityID.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2022 - 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2022 - 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ package org.caosdb.server.entity; import java.io.Serializable; @@ -11,6 +30,8 @@ import java.util.Objects; * <p>It also allows to link entities together, e.g. an Entity's Property with the corresponding * abstract Property, even when the abstract Property does not have a valid ID yet (during bulk * inserts). + * + * @author Timm Fitschen <t.fitschen@indiscale.com> */ public class EntityID implements Serializable { diff --git a/src/main/java/org/caosdb/server/entity/EntityIdRegistry.java b/src/main/java/org/caosdb/server/entity/EntityIdRegistry.java index c6010eda5e1b8b590fae2afbf5f5964021ef8a99..e3cfd736ed5c3793c5bf0babe6519d0ce5af62be 100644 --- a/src/main/java/org/caosdb/server/entity/EntityIdRegistry.java +++ b/src/main/java/org/caosdb/server/entity/EntityIdRegistry.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ package org.caosdb.server.entity; import java.lang.reflect.Constructor; @@ -5,11 +24,24 @@ import java.lang.reflect.InvocationTargetException; import org.caosdb.server.database.exceptions.TransactionException; import org.caosdb.server.transaction.Transaction; +/** + * An abstract layer for managing entity ids. + * + * <p>That is, checking wether something is a well-formed id, generating well-formed ids and more. + * + * <p>This class follows a Strategy Pattern. The actual implemenation can be found in one of the + * implementations of the {@link EntityIdRegistryStrategy} interface. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class EntityIdRegistry { private EntityIdRegistryStrategy strategy; public EntityIdRegistry(Transaction<?> t) { + // This is the place where we will inject the new string id behavior in the + // future: + // // this("org.caosdb.server.entity.StringIds", t); this("org.caosdb.server.entity.LegacyIds", t); } @@ -18,6 +50,7 @@ public class EntityIdRegistry { this.strategy = strategy; } + /** Return a well-formed, new and unused entity id. */ public String generate() { return this.strategy.generate(); } @@ -40,6 +73,7 @@ public class EntityIdRegistry { } } + /** Return true if the id is a well-formed id. */ public boolean matchIdPattern(String id) { return this.strategy.matchIdPattern(id); } diff --git a/src/main/java/org/caosdb/server/entity/EntityIdRegistryStrategy.java b/src/main/java/org/caosdb/server/entity/EntityIdRegistryStrategy.java index 66235e980d1c82ecf6a7d3ef5b5fd30b702b41dd..e70f4f52d2e402e62d3442bfe4af91652247216b 100644 --- a/src/main/java/org/caosdb/server/entity/EntityIdRegistryStrategy.java +++ b/src/main/java/org/caosdb/server/entity/EntityIdRegistryStrategy.java @@ -1,7 +1,31 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ package org.caosdb.server.entity; import org.caosdb.server.transaction.Transaction; +/** + * Strategy interface for {@link EntityIdRegistry}. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public abstract class EntityIdRegistryStrategy { private Transaction<?> transaction; diff --git a/src/main/java/org/caosdb/server/entity/LegacyIds.java b/src/main/java/org/caosdb/server/entity/LegacyIds.java index 38f5bfefdc8f3028585881c489f3ff143498acfc..0454129397b90772a505ad5b791a823eabd3ea97 100644 --- a/src/main/java/org/caosdb/server/entity/LegacyIds.java +++ b/src/main/java/org/caosdb/server/entity/LegacyIds.java @@ -1,8 +1,36 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ package org.caosdb.server.entity; import org.caosdb.server.database.backend.transaction.RetrieveCurrentMaxId; import org.caosdb.server.transaction.Transaction; +/** + * Implementation of {@link EntityIdRegistryStrategy} which re-implements the legacy integer-based + * entity ids. + * + * <p>This implementation will generate sequences of entity ids and matches all strings which can be + * cast to integer as well-formed entity ids. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class LegacyIds extends EntityIdRegistryStrategy { private boolean isInit; diff --git a/src/main/java/org/caosdb/server/entity/StringIds.java b/src/main/java/org/caosdb/server/entity/StringIds.java index ca60730a0efac6b24060077dbbbb0185cfb1763c..e1f5cb04be995253cd16cdc0a809421122b3dc8e 100644 --- a/src/main/java/org/caosdb/server/entity/StringIds.java +++ b/src/main/java/org/caosdb/server/entity/StringIds.java @@ -1,8 +1,33 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ package org.caosdb.server.entity; import java.util.UUID; import org.caosdb.server.transaction.Transaction; +/** + * Example implementation for string ids based on UUID. + * + * @see {@link EntityIdRegistryStrategy} + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class StringIds extends EntityIdRegistryStrategy { public StringIds(Transaction<?> t) { diff --git a/src/main/java/org/caosdb/server/entity/container/RetrieveContainer.java b/src/main/java/org/caosdb/server/entity/container/RetrieveContainer.java index d58d85dc1d6a627757a9e0c8fd851aef899901bd..99262f56d15d90ba86fb1a9cd8fd76b90c4dbf22 100644 --- a/src/main/java/org/caosdb/server/entity/container/RetrieveContainer.java +++ b/src/main/java/org/caosdb/server/entity/container/RetrieveContainer.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.entity.container; @@ -27,6 +26,23 @@ import org.apache.shiro.subject.Subject; import org.caosdb.server.entity.EntityID; import org.caosdb.server.entity.RetrieveEntity; +/** + * A container of entities which are about to be retrieved. + * + * <p>A suitable name would also be `ReadOnlyEntitiesContainer` because entities in this container + * will only be retrieved, not changed, inserted or deleted. + * + * <p>Because all entities are expected to be existing, all entities can theoretically be identified + * via their (valid) entity id (plus version id, if applicable). + * + * <p>However, sometimes, entities are being retrieved via the name instead of the id. Then the id + * has to be resolved first. This happens during the init stage of the owning transaction. + * + * <p>The container also holds the flags of the current transaction (e.g. cache=false, ACL=true, + * ...). + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class RetrieveContainer extends TransactionContainer { private static final long serialVersionUID = 4816050921531043503L; diff --git a/src/main/java/org/caosdb/server/entity/container/TransactionContainer.java b/src/main/java/org/caosdb/server/entity/container/TransactionContainer.java index f2f2c0254a2b9092e8c33c00a4b60f35d88fdeee..049f54cd1ded0ece71c7082ddc960c4246ef0b28 100644 --- a/src/main/java/org/caosdb/server/entity/container/TransactionContainer.java +++ b/src/main/java/org/caosdb/server/entity/container/TransactionContainer.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.entity.container; @@ -38,6 +37,12 @@ import org.caosdb.server.query.Query; import org.caosdb.server.utils.EntityStatus; import org.jdom2.Element; +/** + * Base class for transaction containers used by classes such as {@link RetrieveContainer} or {@link + * WritableContainer}. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class TransactionContainer extends Container<EntityInterface> implements ToElementable, JobTarget { @@ -122,7 +127,6 @@ public class TransactionContainer extends Container<EntityInterface> private TransactionBenchmark benchmark; private Query query; - private Integer currentMaxId = null; public void setFiles(final HashMap<String, FileProperties> files) { this.files = files; diff --git a/src/main/java/org/caosdb/server/grpc/EntityTransactionServiceImpl.java b/src/main/java/org/caosdb/server/grpc/EntityTransactionServiceImpl.java index c8f56610f64deaadcddfbf10a1c0dfbdc43277b9..3386676855dcaaae154a00700b83dc5e2852edff 100644 --- a/src/main/java/org/caosdb/server/grpc/EntityTransactionServiceImpl.java +++ b/src/main/java/org/caosdb/server/grpc/EntityTransactionServiceImpl.java @@ -1,8 +1,8 @@ /* * This file is a part of the CaosDB Project. * - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2021,2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021,2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -18,7 +18,6 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ - package org.caosdb.server.grpc; import io.grpc.stub.StreamObserver; @@ -68,6 +67,11 @@ import org.caosdb.server.transaction.UpdateACL; import org.caosdb.server.transaction.WriteTransaction; import org.caosdb.server.utils.ServerMessages; +/** + * Main entry point for the entity transaction service of the servers GRPC API. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBase { // TODO(tf) let the clients define the time zone of the date time values which are being returned. diff --git a/src/main/java/org/caosdb/server/grpc/GrpcToCaosDBConverters.java b/src/main/java/org/caosdb/server/grpc/GrpcToCaosDBConverters.java index 1c0b0f429d1702c9e952e3aeda95bcd13355b4df..587b89662456272d9a81aa910db3b1a962d67499 100644 --- a/src/main/java/org/caosdb/server/grpc/GrpcToCaosDBConverters.java +++ b/src/main/java/org/caosdb/server/grpc/GrpcToCaosDBConverters.java @@ -1,8 +1,8 @@ /* * This file is a part of the CaosDB Project. * - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -16,9 +16,7 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * */ - package org.caosdb.server.grpc; import java.util.ArrayList; @@ -64,14 +62,13 @@ import org.caosdb.server.permissions.EntityACLFactory; import org.caosdb.server.utils.EntityStatus; import org.caosdb.server.utils.ServerMessages; +/** + * Utility class for converting GRPC's native objects into our own CaosDB objects. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class GrpcToCaosDBConverters { - /* - public EntityID getId(final String id) { - return new EntityID(Integer.parseInt(id)); - } - */ - public Role convert(final EntityRole role) { switch (role) { case ENTITY_ROLE_FILE: diff --git a/src/main/java/org/caosdb/server/jobs/JobConfig.java b/src/main/java/org/caosdb/server/jobs/JobConfig.java index ab6cd819fd338931aa32c41e2d9923ca716c9bf0..b2bb0d4a1b13a98dd68893c9f0cad7bc8192edba 100644 --- a/src/main/java/org/caosdb/server/jobs/JobConfig.java +++ b/src/main/java/org/caosdb/server/jobs/JobConfig.java @@ -1,8 +1,8 @@ /* * This file is a part of the CaosDB Project. * - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2021,2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021,2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/main/java/org/caosdb/server/jobs/LazyEntityResolver.java b/src/main/java/org/caosdb/server/jobs/LazyEntityResolver.java index 285378e16329d0a171eb55e550d916ac2a209a28..a85b0ca075ae058afffe8777c8488631b2681bac 100644 --- a/src/main/java/org/caosdb/server/jobs/LazyEntityResolver.java +++ b/src/main/java/org/caosdb/server/jobs/LazyEntityResolver.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ package org.caosdb.server.jobs; import org.caosdb.server.database.backend.transaction.RetrieveParents; @@ -8,12 +27,30 @@ import org.caosdb.server.entity.container.PropertyContainer; import org.caosdb.server.entity.wrapper.EntityWrapper; import org.caosdb.server.transaction.Transaction; +/** + * Implementation of {@link EntityInterface} which retrieves the parents and properties only when + * requested via getProperties and getParents. + * + * <p>This is particularly useful for jobs sharing the same entity object between jobs which need + * different parts of it while reducing the logic of checking whether the entity is "only" sparse, + * or has been retrieved fully and so on. + * + * <p>However, when the entities parents or properties are being retrieved after the transaction's + * access has been released, a {@link IllegalStateException} will be thrown. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class LazyEntityResolver extends EntityWrapper { private Transaction<?> transaction; private boolean propertiesResolved = false; private boolean parentsResolved = false; + /** + * Constructor. + * + * <p>Initialize this with a sparse entity. + */ public LazyEntityResolver(EntityInterface entity, Transaction<?> transaction) { super(entity); this.transaction = transaction; diff --git a/src/main/java/org/caosdb/server/jobs/Schedule.java b/src/main/java/org/caosdb/server/jobs/Schedule.java index ab0f63a2105dacfea0fce0a7c5d553799b0ae222..bc51fca9b69cb30ebd4567fb5355546aeffd904d 100644 --- a/src/main/java/org/caosdb/server/jobs/Schedule.java +++ b/src/main/java/org/caosdb/server/jobs/Schedule.java @@ -3,8 +3,8 @@ * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * Copyright (C) 2020-2021 IndiScale GmbH <info@indiscale.com> - * Copyright (C) 2020-2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2020-2021,2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2020-2021,2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -35,6 +35,8 @@ import org.caosdb.server.entity.EntityInterface; * <p>The Schedule class orders jobs by {@link TransactionStage} and also assures that jobs are * skipped when appropriate and to prevent that jobs run more than once (because sometimes they * trigger each other). + * + * @author Timm Fitschen <t.fitschen@indiscale.com> */ public class Schedule { diff --git a/src/main/java/org/caosdb/server/jobs/ScheduledJob.java b/src/main/java/org/caosdb/server/jobs/ScheduledJob.java index f729e0047c2f2ccc9b924b6650cbb64c7ec3749a..1754f19f5fdab5b32e19fcba7758481f0dba8948 100644 --- a/src/main/java/org/caosdb/server/jobs/ScheduledJob.java +++ b/src/main/java/org/caosdb/server/jobs/ScheduledJob.java @@ -1,8 +1,8 @@ /* * This file is a part of the CaosDB Project. * - * Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> - * Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2020,2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -28,7 +28,7 @@ import org.caosdb.server.entity.Message; * <p>It is mainly a means to have simplified interface for the Scheduler which also measures the * execution time of the job "from outside". * - * @author Timm Fitschen (t.fitschen@indiscale.com) + * @author Timm Fitschen <t.fitschen@indiscale.com> */ public class ScheduledJob { diff --git a/src/main/java/org/caosdb/server/jobs/core/CheckDatatypePresent.java b/src/main/java/org/caosdb/server/jobs/core/CheckDatatypePresent.java index adc02cafb3c27162d00c8aded5db2eea9a2aa240..257e1895924fc3199ee269c86331da970b625d84 100644 --- a/src/main/java/org/caosdb/server/jobs/core/CheckDatatypePresent.java +++ b/src/main/java/org/caosdb/server/jobs/core/CheckDatatypePresent.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.jobs.core; @@ -41,10 +40,11 @@ import org.caosdb.server.utils.EntityStatus; import org.caosdb.server.utils.ServerMessages; /** - * Check whether the entity has a data type. Assign the data type of the abstract property if - * necessary + * Check whether the entity has a data type. + * + * <p>Assign the data type of the abstract property if necessary. * - * @author tf + * @author Timm Fitschen <t.fitschen@indiscale.com> */ public final class CheckDatatypePresent extends EntityJob { diff --git a/src/main/java/org/caosdb/server/jobs/core/CheckDependenciesBeforeDeletion.java b/src/main/java/org/caosdb/server/jobs/core/CheckDependenciesBeforeDeletion.java index c9f6de7cc1d39cead5998ad680bfe444f38a36ea..ecbbf4af7fb4a81605d61a3d251b88c4f1d0917a 100644 --- a/src/main/java/org/caosdb/server/jobs/core/CheckDependenciesBeforeDeletion.java +++ b/src/main/java/org/caosdb/server/jobs/core/CheckDependenciesBeforeDeletion.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.jobs.core; diff --git a/src/main/java/org/caosdb/server/jobs/core/CheckParValid.java b/src/main/java/org/caosdb/server/jobs/core/CheckParValid.java index e125e5dda8edbbecd3873a53e04755faba0874e3..fd235c21319d7b573db1cd42b23d9184aa7e56e6 100644 --- a/src/main/java/org/caosdb/server/jobs/core/CheckParValid.java +++ b/src/main/java/org/caosdb/server/jobs/core/CheckParValid.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.jobs.core; @@ -42,7 +41,7 @@ import org.caosdb.server.utils.ServerMessages; /** * Check whether all parents of an entity are valid/qualified. * - * @author tf + * @author Timm Fitschen <t.fitschen@indiscale.com> */ @JobAnnotation(stage = TransactionStage.PRE_CHECK) public class CheckParValid extends EntityJob { diff --git a/src/main/java/org/caosdb/server/jobs/core/CheckPropValid.java b/src/main/java/org/caosdb/server/jobs/core/CheckPropValid.java index b57e7abbb1b98b24c107c17372a602370f79afe2..bfd2bc3019d1d4ae6204ebbe5b5975932603ed76 100644 --- a/src/main/java/org/caosdb/server/jobs/core/CheckPropValid.java +++ b/src/main/java/org/caosdb/server/jobs/core/CheckPropValid.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.jobs.core; @@ -41,7 +40,7 @@ import org.caosdb.server.utils.ServerMessages; /** * Check whether all properties of an entity are valid or qualified. * - * @author tf + * @author Timm Fitschen <t.fitschen@indiscale.com> */ @JobAnnotation(stage = TransactionStage.PRE_CHECK) public class CheckPropValid extends EntityJob { diff --git a/src/main/java/org/caosdb/server/jobs/core/CheckRefidIsaParRefid.java b/src/main/java/org/caosdb/server/jobs/core/CheckRefidIsaParRefid.java index af7269a31756eb556729bf71f43bb0feda02bd67..7b0a9977680c378db98dca4d3e7ee31dba06e840 100644 --- a/src/main/java/org/caosdb/server/jobs/core/CheckRefidIsaParRefid.java +++ b/src/main/java/org/caosdb/server/jobs/core/CheckRefidIsaParRefid.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.jobs.core; @@ -41,10 +40,11 @@ import org.caosdb.server.utils.Observer; import org.caosdb.server.utils.ServerMessages; /** - * Check if the referenced entity is in the scope of the data type. E.g. if the data type is - * 'Person' the referenced entity is to be a child of 'Person'. + * Check if the referenced entity is in the scope of the data type. + * + * <p>E.g. if the data type is 'Person' the referenced entity is to be a child of 'Person'. * - * @author tf + * @author Timm Fitschen <t.fitschen@indiscale.com> */ public class CheckRefidIsaParRefid extends EntityJob implements Observer { diff --git a/src/main/java/org/caosdb/server/jobs/core/CheckRefidValid.java b/src/main/java/org/caosdb/server/jobs/core/CheckRefidValid.java index b01c5bf389175d1c087ced9acf4f135d7679a5be..86e95542aaa0e6f373521149d9f7376f09d3972c 100644 --- a/src/main/java/org/caosdb/server/jobs/core/CheckRefidValid.java +++ b/src/main/java/org/caosdb/server/jobs/core/CheckRefidValid.java @@ -1,11 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * Copyright (C) 2020-2021 IndiScale GmbH <info@indiscale.com> - * Copyright (C) 2020-2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2020-2021,2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2020-2021,2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.jobs.core; @@ -43,7 +40,7 @@ import org.caosdb.server.utils.ServerMessages; /** * Check whether a reference property is pointing to a valid entity. * - * @author tf + * @author Timm Fitschen <t.fitschen@indiscale.com> */ public class CheckRefidValid extends EntityJob implements Observer { @Override diff --git a/src/main/java/org/caosdb/server/jobs/core/EntityIdHandler.java b/src/main/java/org/caosdb/server/jobs/core/EntityIdHandler.java deleted file mode 100644 index bd4d4b807cfeb283a784cee1b62df6d259ff2332..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/jobs/core/EntityIdHandler.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.caosdb.server.jobs.core; - -import org.caosdb.server.entity.EntityInterface; -import org.caosdb.server.entity.InsertEntity; -import org.caosdb.server.entity.Message; -import org.caosdb.server.jobs.EntityJob; -import org.caosdb.server.jobs.JobAnnotation; -import org.caosdb.server.jobs.TransactionStage; -import org.caosdb.server.transaction.WriteTransactionInterface; -import org.caosdb.server.utils.EntityStatus; - -@JobAnnotation(stage = TransactionStage.PRE_TRANSACTION) -public class EntityIdHandler extends EntityJob { - - @Override - protected void run() throws Message { - EntityInterface entity = getEntity(); - if (entity instanceof InsertEntity - && getTransaction() instanceof WriteTransactionInterface - && entity.getEntityStatus() == EntityStatus.QUALIFIED) { - String id = ((WriteTransactionInterface) getTransaction()).generateId(); - entity.getId().setId(id); - } - } -} diff --git a/src/main/java/org/caosdb/server/jobs/core/EntityStateJob.java b/src/main/java/org/caosdb/server/jobs/core/EntityStateJob.java index 409718012086063c7de9f5db003b965a188cc061..01b0ecb2274a85635dee3fe88f041e50178936fe 100644 --- a/src/main/java/org/caosdb/server/jobs/core/EntityStateJob.java +++ b/src/main/java/org/caosdb/server/jobs/core/EntityStateJob.java @@ -1,8 +1,8 @@ /* * This file is a part of the CaosDB Project. * - * Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> - * Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2020,2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/main/java/org/caosdb/server/jobs/core/GenerateEntityId.java b/src/main/java/org/caosdb/server/jobs/core/GenerateEntityId.java new file mode 100644 index 0000000000000000000000000000000000000000..4bb23ab4c7399e3660998029927cb7cb860af928 --- /dev/null +++ b/src/main/java/org/caosdb/server/jobs/core/GenerateEntityId.java @@ -0,0 +1,50 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + */ +package org.caosdb.server.jobs.core; + +import org.caosdb.server.entity.EntityInterface; +import org.caosdb.server.entity.InsertEntity; +import org.caosdb.server.entity.Message; +import org.caosdb.server.jobs.EntityJob; +import org.caosdb.server.jobs.JobAnnotation; +import org.caosdb.server.jobs.TransactionStage; +import org.caosdb.server.transaction.WriteTransactionInterface; +import org.caosdb.server.utils.EntityStatus; + +/** + * Generates entity ids for newly inserted entities. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ +@JobAnnotation(stage = TransactionStage.PRE_TRANSACTION) +public class GenerateEntityId extends EntityJob { + + @Override + protected void run() throws Message { + EntityInterface entity = getEntity(); + if (entity instanceof InsertEntity + && getTransaction() instanceof WriteTransactionInterface + && entity.getEntityStatus() == EntityStatus.QUALIFIED) { + String id = ((WriteTransactionInterface) getTransaction()).generateId(); + entity.getId().setId(id); + } + } +} diff --git a/src/main/java/org/caosdb/server/jobs/core/Inheritance.java b/src/main/java/org/caosdb/server/jobs/core/Inheritance.java index 7bcda3b96cd64bf233444e429b72bb74ca69333d..70aea11281774230e90e586cad3e897426df8e83 100644 --- a/src/main/java/org/caosdb/server/jobs/core/Inheritance.java +++ b/src/main/java/org/caosdb/server/jobs/core/Inheritance.java @@ -1,11 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * Copyright (C) 2019-2021 IndiScale GmbH <info@indiscale.com> - * Copyright (C) 2019-2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2019-2021,2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2019-2021,2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.jobs.core; diff --git a/src/main/java/org/caosdb/server/jobs/core/NoCache.java b/src/main/java/org/caosdb/server/jobs/core/NoCache.java index 6ad38f49268fae7d38612cbf552b7c8cd2d68b85..78b54f6c7ecf97669889097241a9ee5f595a9416 100644 --- a/src/main/java/org/caosdb/server/jobs/core/NoCache.java +++ b/src/main/java/org/caosdb/server/jobs/core/NoCache.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.jobs.core; @@ -26,6 +25,13 @@ import org.caosdb.server.jobs.FlagJob; import org.caosdb.server.jobs.JobAnnotation; import org.caosdb.server.jobs.TransactionStage; +/** + * Turn off caching, just for the current transaction. + * + * <p>If the caching is disabled globally this has no effect. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ @JobAnnotation( flag = "cache", defaultValue = "true", diff --git a/src/main/java/org/caosdb/server/jobs/core/ProcessNameProperties.java b/src/main/java/org/caosdb/server/jobs/core/ProcessNameProperties.java index 1fdd59e2327425b56b02d478eb1b31f4c135ce5b..ecac050455b385d2ecf27bb4ff5d39d46c941508 100644 --- a/src/main/java/org/caosdb/server/jobs/core/ProcessNameProperties.java +++ b/src/main/java/org/caosdb/server/jobs/core/ProcessNameProperties.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.jobs.core; @@ -42,9 +41,13 @@ import org.caosdb.server.utils.EntityStatus; import org.caosdb.server.utils.ServerMessages; /** - * To be called after CheckPropValid and Inheritance. + * Checks if a property is a subproperty of "name" and flags the entity accordingly. + * + * <p>This enables a different behavior in the search. + * + * <p>To be called after CheckPropValid and Inheritance. * - * @author tf + * @author Timm Fitschen <t.fitschen@indiscale.com> */ @JobAnnotation(stage = TransactionStage.PRE_TRANSACTION) public class ProcessNameProperties extends EntityJob { diff --git a/src/main/java/org/caosdb/server/jobs/core/ResolveNames.java b/src/main/java/org/caosdb/server/jobs/core/ResolveNames.java index d1ab07b7bf5edb967abda9d23bb9828c0acfd69e..b19aca6d30e6743ad59814fc1b755634c228f33d 100644 --- a/src/main/java/org/caosdb/server/jobs/core/ResolveNames.java +++ b/src/main/java/org/caosdb/server/jobs/core/ResolveNames.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.jobs.core; @@ -36,6 +35,18 @@ import org.caosdb.server.jobs.ContainerJob; import org.caosdb.server.utils.EntityStatus; import org.caosdb.server.utils.ServerMessages; +/** + * Resolve the names to ids for all entities in the current retrieval. + * + * <p>If an entity has a name which looks like an id: Check whether that is an existing id first. + * + * <p>Otherwise, search via the name. + * + * <p>It there are multiple matching entities, add all of them to the current container. The clients + * may handle the ambiguity. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class ResolveNames extends ContainerJob { @Override diff --git a/src/main/java/org/caosdb/server/query/IDFilter.java b/src/main/java/org/caosdb/server/query/IDFilter.java index c00890344d9c9ff4c91532543ae8f44f2ebda571..8011139796abff42c0e8109621c849d3e6328137 100644 --- a/src/main/java/org/caosdb/server/query/IDFilter.java +++ b/src/main/java/org/caosdb/server/query/IDFilter.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.query; @@ -32,6 +31,11 @@ import java.sql.SQLException; import org.caosdb.server.query.Query.QueryException; import org.jdom2.Element; +/** + * Applies an ID filter to the query's current result set. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class IDFilter implements EntityFilterInterface { private final String operator; diff --git a/src/main/java/org/caosdb/server/query/POV.java b/src/main/java/org/caosdb/server/query/POV.java index af5b446f6024f62d04788036a80bb5cfa41b8b97..6ee5f9d0122aa417c357e71ef6d6ea0516007215 100644 --- a/src/main/java/org/caosdb/server/query/POV.java +++ b/src/main/java/org/caosdb/server/query/POV.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.query; @@ -50,6 +49,11 @@ import org.jdom2.Element; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * Applies a POV (Property-operator-value) filter to the query's current result set. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class POV implements EntityFilterInterface { public static final Pattern NUMBER_PATTERN = Pattern.compile( diff --git a/src/main/java/org/caosdb/server/resource/UserResource.java b/src/main/java/org/caosdb/server/resource/UserResource.java index 362e5eb661cd05ef2098aad5baa1604f8cd5dc09..e7561dd8437fba41c74c77f82093451cd819bd4d 100644 --- a/src/main/java/org/caosdb/server/resource/UserResource.java +++ b/src/main/java/org/caosdb/server/resource/UserResource.java @@ -1,9 +1,10 @@ /* - * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header */ package org.caosdb.server.resource; @@ -48,7 +47,7 @@ import org.restlet.representation.Representation; /** * This class handles requests for Users. * - * @author Timm Fitschen + * @author Timm Fitschen <t.fitschen@indiscale.com> */ public class UserResource extends AbstractCaosDBServerResource { diff --git a/src/main/java/org/caosdb/server/resource/transaction/EntityResource.java b/src/main/java/org/caosdb/server/resource/transaction/EntityResource.java index c920d8c92ce48258822d3ac1c6eed913fbbe84d7..8aa5bbb4e77b0a2f491c736b782a9817dd95051b 100644 --- a/src/main/java/org/caosdb/server/resource/transaction/EntityResource.java +++ b/src/main/java/org/caosdb/server/resource/transaction/EntityResource.java @@ -3,8 +3,8 @@ * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021,2023 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2021,2023 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -53,11 +53,16 @@ import org.restlet.representation.Representation; * * <p>The GET requests (Retrieval) is handled in the superclass {@link RetrieveEntityResource}. * - * @author Timm Fitschen (t.fitschen@indiscale.com) + * @author Timm Fitschen <t.fitschen@indiscale.com> */ public class EntityResource extends RetrieveEntityResource { - /** Handle entity deletions (DELETE requests). */ + /** + * Handle entity deletions (DELETE requests). + * + * <p>Note: The list of entity "specifier" is treated strictly as a list of entity ids. You cannot + * delete an entity by name. + */ @Override protected final Representation httpDeleteInChildClass() throws Exception { diff --git a/src/main/java/org/caosdb/server/resource/transaction/RetrieveEntityResource.java b/src/main/java/org/caosdb/server/resource/transaction/RetrieveEntityResource.java index 8f2809b27e420da7e014088a15a07d7b5405b098..7a4ca37388379a8a368fc0fc3ff06f67c5998259 100644 --- a/src/main/java/org/caosdb/server/resource/transaction/RetrieveEntityResource.java +++ b/src/main/java/org/caosdb/server/resource/transaction/RetrieveEntityResource.java @@ -3,8 +3,8 @@ * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021,2023 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2021,2023 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -27,6 +27,7 @@ import java.sql.SQLException; import org.caosdb.server.CaosDBException; import org.caosdb.server.database.backend.implementation.MySQL.ConnectionException; import org.caosdb.server.entity.container.RetrieveContainer; +import org.caosdb.server.jobs.core.ResolveNames; import org.caosdb.server.resource.AbstractCaosDBServerResource; import org.caosdb.server.transaction.Retrieve; import org.jdom2.Document; @@ -37,14 +38,15 @@ import org.restlet.representation.Representation; * Handles GET requests for different subclasses which all have in common that they retrieve * Entities (plus other information in some cases). * - * @author Timm Fitschen (t.fitschen@indiscale.com) + * @author Timm Fitschen <t.fitschen@indiscale.com> */ public abstract class RetrieveEntityResource extends AbstractCaosDBServerResource { /** - * Parse the segment which specifies the entities which are to be retrieved + * Parse the segment which specifies the entities which are to be retrieved. * - * @param container + * <p>The segments are being treated as names here. The {@link ResolveNames} job is responsible + * for detecting whether the name is actually an id. */ protected void handleRetrieveContainer(final RetrieveContainer container) { diff --git a/src/main/java/org/caosdb/server/transaction/EntityTransactionInterface.java b/src/main/java/org/caosdb/server/transaction/EntityTransactionInterface.java index dc98f826bff2c3ebed809f45b1f05a197e61b9a7..9d96c4e7499728ca11c348ac1875d94ece100a72 100644 --- a/src/main/java/org/caosdb/server/transaction/EntityTransactionInterface.java +++ b/src/main/java/org/caosdb/server/transaction/EntityTransactionInterface.java @@ -1,7 +1,32 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ package org.caosdb.server.transaction; import org.caosdb.server.entity.EntityID; +/** + * This interface is implemented by all transactions of entities (as opposed to transaction which + * only concern users or other kinds of transactions). + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public interface EntityTransactionInterface extends TransactionInterface { public boolean matchIdPattern(String id); diff --git a/src/main/java/org/caosdb/server/transaction/Retrieve.java b/src/main/java/org/caosdb/server/transaction/Retrieve.java index 4fc4fbc2c534aba2d24793d1efd3cbc6d1512914..643c1201b530af9821c9a5c1a7b62f7c5d04cf52 100644 --- a/src/main/java/org/caosdb/server/transaction/Retrieve.java +++ b/src/main/java/org/caosdb/server/transaction/Retrieve.java @@ -115,21 +115,6 @@ public class Retrieve extends Transaction<RetrieveContainer> { private void retrieveFullEntities(final RetrieveContainer container, final Access access) throws Exception { execute(new RetrieveFullEntityTransaction(container), access); - for (EntityInterface e : container) { - if (e.getEntityStatus() == EntityStatus.NONEXISTENT - && e.hasId() - && e.hasName() - && e.getName().equals(e.getId().toString())) { - // remove duplicates by name - for (EntityInterface o : container) { - if (o.getEntityStatus() == EntityStatus.VALID - && o.hasName() - && e.getName().equalsIgnoreCase(o.getName())) { - e.setEntityStatus(EntityStatus.IGNORE); - } - } - } - } } @Override diff --git a/src/main/java/org/caosdb/server/transaction/Transaction.java b/src/main/java/org/caosdb/server/transaction/Transaction.java index 8474125d3c83d6445bb44c9d8ef0ff20759d20b7..2ccff7b28b6497b2a537117583b0e142286cea51 100644 --- a/src/main/java/org/caosdb/server/transaction/Transaction.java +++ b/src/main/java/org/caosdb/server/transaction/Transaction.java @@ -3,8 +3,8 @@ * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * Copyright (C) 2019-2021 IndiScale GmbH <info@indiscale.com> - * Copyright (C) 2019-2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2019-2021,2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2019-2021,2023 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -55,6 +55,14 @@ import org.caosdb.server.utils.Observer; import org.caosdb.server.utils.UseCacheResource; import org.caosdb.server.utils.UseCacheResourceDelegate; +/** + * The NoOpCache is used when the caching is diabled (globally or for the current transaction. + * + * <p>It results in much simpler code when the callers do not need to check whether the caching is + * active all the time. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ @SuppressWarnings("rawtypes") class NoOpCache implements Map { @@ -117,6 +125,14 @@ class NoOpCache implements Map { } } +/** + * Abstract base implementation for all EntityTransactions (Transaction involving entities). + * + * <p>Handles caching, benchmark timing, the access to the back end, generates and checks entity + * ids, holds the state of the transaction and triggers the scheduler to run the jobs. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public abstract class Transaction<C extends TransactionContainer> extends AbstractObservable implements EntityTransactionInterface, UseCacheResource { diff --git a/src/main/java/org/caosdb/server/transaction/WriteTransaction.java b/src/main/java/org/caosdb/server/transaction/WriteTransaction.java index 9a355410c9c29429296d4329e697a2cbca1d5980..b780d3d68f20cb6973c902cbe92fbd4fd46d51c1 100644 --- a/src/main/java/org/caosdb/server/transaction/WriteTransaction.java +++ b/src/main/java/org/caosdb/server/transaction/WriteTransaction.java @@ -3,8 +3,8 @@ * * Copyright (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * Copyright (C) 2019-2022 IndiScale GmbH <info@indiscale.com> - * Copyright (C) 2019-2022 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2019-2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2019-2023 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2022 Daniel Hornung <d.hornung@indiscale.com> * * This program is free software: you can redistribute it and/or modify diff --git a/src/main/java/org/caosdb/server/utils/UseCacheResource.java b/src/main/java/org/caosdb/server/utils/UseCacheResource.java index 2319601260a7116d4299f6823628ef2c4346875e..89057f51c59f0f99a3eed3346ec18ab29ada74c0 100644 --- a/src/main/java/org/caosdb/server/utils/UseCacheResource.java +++ b/src/main/java/org/caosdb/server/utils/UseCacheResource.java @@ -1,5 +1,30 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ package org.caosdb.server.utils; +/** + * Interface which indicates that a class can turn on and off the caching of the current transaction + * and inform the caller about the state of the transactions's caching. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public interface UseCacheResource { public default boolean useCache() { diff --git a/src/main/java/org/caosdb/server/utils/UseCacheResourceDelegate.java b/src/main/java/org/caosdb/server/utils/UseCacheResourceDelegate.java index 81d862b07c9c6e1cf1309e085213fe9ffeb0b780..c537f0a813fe149b7338909f0dc95e8f3728dec1 100644 --- a/src/main/java/org/caosdb/server/utils/UseCacheResourceDelegate.java +++ b/src/main/java/org/caosdb/server/utils/UseCacheResourceDelegate.java @@ -1,7 +1,35 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ package org.caosdb.server.utils; import org.caosdb.server.CaosDBServer; +/** + * Basic implementation of the {@link UseCacheResource} interface. + * + * <p>This implementation uses a Delegator Pattern to link different UseCacheResources together. + * This is uses to delegate the responsibility to the transaction as the final Object of the + * delegation. + * + * @author Timm Fitschen <t.fitschen@indiscale.com> + */ public class UseCacheResourceDelegate implements UseCacheResource { private boolean useCache = CaosDBServer.useCache(); private UseCacheResource delegate = null;