diff --git a/.gitignore b/.gitignore index c6fdfc4d387f8be1bb3a4f51a73230aabcc9b02b..a76a3a9fa4aa990310cced6e486b1934da9bb80b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ # typical build dirs build/ bin/ +lib/ target/ _apidoc/ src/doc/development/api/xml/out/ diff --git a/src/main/java/org/caosdb/server/database/DatabaseUtils.java b/src/main/java/org/caosdb/server/database/DatabaseUtils.java deleted file mode 100644 index ad8810418015deebc81a587f30ce904ac3401a4a..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/DatabaseUtils.java +++ /dev/null @@ -1,402 +0,0 @@ -/* - * ** 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 - * - * 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/>. - * - * ** end header - */ -package org.caosdb.server.database; - -import com.google.common.base.Objects; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.caosdb.server.database.proto.FlatProperty; -import org.caosdb.server.database.proto.ProtoProperty; -import org.caosdb.server.database.proto.SparseEntity; -import org.caosdb.server.database.proto.VerySparseEntity; -import org.caosdb.server.datatype.AbstractCollectionDatatype; -import org.caosdb.server.datatype.CollectionValue; -import org.caosdb.server.datatype.IndexedSingleValue; -import org.caosdb.server.datatype.ReferenceValue; -import org.caosdb.server.datatype.SingleValue; -import org.caosdb.server.entity.EntityID; -import org.caosdb.server.entity.EntityInterface; -import org.caosdb.server.entity.Message; -import org.caosdb.server.entity.RetrieveEntity; -import org.caosdb.server.entity.Role; -import org.caosdb.server.entity.StatementStatus; -import org.caosdb.server.entity.wrapper.Domain; -import org.caosdb.server.entity.wrapper.Parent; -import org.caosdb.server.entity.wrapper.Property; -import org.caosdb.server.filesystem.FileSystem.ObjectType; -import org.caosdb.server.filesystem.Hash; -import org.caosdb.server.filesystem.Path; - -public class DatabaseUtils { - - public static final String bytes2UTF8(final byte[] bytes) { - if (bytes == null) { - return null; - } else { - return new String(bytes); - } - } - - private static Domain makeReplacement(final EntityInterface p) { - // add a new helper domain. - final Domain d = - new Domain(p.getProperties(), p.getDatatype(), p.getValue(), p.getStatementStatus()); - d.setDescOverride(p.isDescOverride()); - d.setNameOverride(p.isNameOverride()); - d.setDatatypeOverride(p.isDatatypeOverride()); - d.setName(p.getName()); - d.setDescription(p.getDescription()); - p.setReplacement(d); - return d; - } - - public static void deriveStage1Inserts( - final List<EntityInterface> stage1Inserts, final EntityInterface e) { - // entity value - if (e.hasValue()) { - final Property p = new Property(e); - p.setStatementStatus(StatementStatus.FIX); - p.setPIdx(0); - processPropertiesStage1(stage1Inserts, p, e); - } - - for (final EntityInterface p : e.getProperties()) { - processPropertiesStage1(stage1Inserts, p, e); - } - } - - private static void processPropertiesStage1( - final List<EntityInterface> stage1Inserts, final EntityInterface p, final EntityInterface e) { - stage1Inserts.add(p); - if (!p.isDescOverride() - && !p.isNameOverride() - && !p.isDatatypeOverride() - && (!p.hasProperties() || hasUniquePropertyId(p, e)) - && !(p.getDatatype() instanceof AbstractCollectionDatatype)) { - // if p has no sub-properties, just add it - } else { - stage1Inserts.add(makeReplacement(p)); - } - processSubPropertiesStage1(stage1Inserts, p); - } - - public static int deriveStage2Inserts( - final List<EntityInterface> stage2Inserts, final List<EntityInterface> stage1Inserts) { - int domainCount = 0; - for (final EntityInterface p : stage1Inserts) { - if (p.hasRole() && p.getRole() == Role.Domain) { - domainCount++; - } - if (!p.hasReplacement() && p.hasProperties()) { - stage2Inserts.addAll(p.getProperties()); - } - } - return domainCount; - } - - private static boolean hasUniquePropertyId(final EntityInterface p, final EntityInterface e) { - final EntityID id = p.getId(); - for (final EntityInterface p2 : e.getProperties()) { - if (Objects.equal(p2.getId(), id) && p2 != p) { - return false; - } - } - return true; - } - - private static void processSubPropertiesStage1( - final List<EntityInterface> stage1Inserts, final EntityInterface p) { - for (final EntityInterface subP : p.getProperties()) { - if (subP.hasProperties()) { - stage1Inserts.add(makeReplacement(subP)); - processSubPropertiesStage1(stage1Inserts, subP); - } - } - } - - public static void parseFromSparseEntities(final EntityInterface e, final SparseEntity spe) { - if (spe != null) { - e.parseSparseEntity(spe); - } - } - - public static void parseOverrides(final List<FlatProperty> properties, final ResultSet rs) - throws SQLException { - while (rs.next()) { - final int property_id = rs.getInt("property_id"); - for (final FlatProperty p : properties) { - if (p.id == property_id) { - final String name = bytes2UTF8(rs.getBytes("name_override")); - if (name != null) { - p.name = name; - } - final String desc = bytes2UTF8(rs.getBytes("desc_override")); - if (desc != null) { - p.desc = desc; - } - final String type = bytes2UTF8(rs.getBytes("type_override")); - if (type != null) { - p.type = type; - } - final String coll = bytes2UTF8(rs.getBytes("collection_override")); - if (coll != null) { - p.collection = coll; - } - } - } - } - } - - public static List<FlatProperty> parsePropertyResultset(final ResultSet rs) throws SQLException { - final ArrayList<FlatProperty> ret = new ArrayList<FlatProperty>(); - while (rs.next()) { - final FlatProperty fp = new FlatProperty(); - fp.id = rs.getInt("PropertyID"); - fp.value = bytes2UTF8(rs.getBytes("PropertyValue")); - fp.status = bytes2UTF8(rs.getBytes("PropertyStatus")); - fp.idx = rs.getInt("PropertyIndex"); - ret.add(fp); - } - return ret; - } - - /** - * Helper function for parsing MySQL results. - * - * <p>This function creates SparseEntities and parses only the name, the role and the acl of an - * entity. - * - * <p>Never returns null. - */ - public static SparseEntity parseNameRoleACL(final ResultSet rs) throws SQLException { - final SparseEntity ret = new SparseEntity(); - ret.role = bytes2UTF8(rs.getBytes("EntityRole")); - ret.name = bytes2UTF8(rs.getBytes("EntityName")); - ret.acl = bytes2UTF8(rs.getBytes("ACL")); - return ret; - } - - /** - * Helper function for parsing MySQL results. - * - * <p>This function creates SparseEntities and parses all fields which belong to a SparseEntity: - * id, name, role, acl, description, datatype, and the file properties. - * - * <p>Never returns null. - */ - public static SparseEntity parseEntityResultSet(final ResultSet rs) throws SQLException { - final SparseEntity ret = parseNameRoleACL(rs); - ret.id = rs.getInt("EntityID"); - ret.description = bytes2UTF8(rs.getBytes("EntityDesc")); - ret.datatype = bytes2UTF8(rs.getBytes("Datatype")); - ret.collection = bytes2UTF8(rs.getBytes("Collection")); - ret.versionId = bytes2UTF8(rs.getBytes("Version")); - - parseFSODescriptorFields(rs, ret); - return ret; - } - - public static void parseFSODescriptorFields(final ResultSet rs, final SparseEntity ret) - throws SQLException { - final String key = bytes2UTF8(rs.getBytes("FileKey")); - if (key != null) { - // ret.fileParentId = rs.getInt("FileParentID"); - ret.filePath = new Path(bytes2UTF8(rs.getBytes("FilePath"))); - ret.fileSize = rs.getLong("FileSize"); - if (rs.wasNull()) { - ret.fileSize = null; - } - ret.fileHash = - Hash.create( - bytes2UTF8(rs.getBytes("FileHash")), - rs.getLong("FileHashChecked"), - bytes2UTF8(rs.getBytes("FileHashAlgo"))); - final String mimetype = bytes2UTF8(rs.getBytes("FileMimeType")); - ret.fileType = - java.util.Objects.equals("inode/directory", mimetype) - ? ObjectType.DIRECTORY - : (Objects.equal("inode/link", mimetype) ? ObjectType.LINK : ObjectType.FILE); - if (ret.fileType == ObjectType.FILE) { - ret.fileMimeType = mimetype; - } - ret.fileStorageId = bytes2UTF8(rs.getBytes("FileStorageID")); - ret.fileKey = key; - } - } - - public static ArrayList<VerySparseEntity> parseParentResultSet(final ResultSet rs) - throws SQLException { - final ArrayList<VerySparseEntity> ret = new ArrayList<VerySparseEntity>(); - while (rs.next()) { - final VerySparseEntity vsp = new VerySparseEntity(); - vsp.id = rs.getInt("ParentID"); - vsp.name = bytes2UTF8(rs.getBytes("ParentName")); - vsp.description = bytes2UTF8(rs.getBytes("ParentDescription")); - vsp.role = bytes2UTF8(rs.getBytes("ParentRole")); - vsp.acl = bytes2UTF8(rs.getBytes("ACL")); - ret.add(vsp); - } - return ret; - } - - public static <K extends EntityInterface> K parseEntityFromVerySparseEntity( - final K entity, final VerySparseEntity vse) { - entity.setId(new EntityID(vse.id)); - entity.setName(vse.name); - entity.setRole(vse.role); - entity.setDescription(vse.description); - return entity; - } - - public static void parseParentsFromVerySparseEntity( - final EntityInterface entity, final List<VerySparseEntity> pars) { - for (final VerySparseEntity vsp : pars) { - final Parent p = new Parent(new RetrieveEntity(new EntityID(vsp.id))); - p.setName(vsp.name); - p.setDescription(vsp.description); - entity.addParent(p); - } - } - - private static void replace( - final Property p, final Map<EntityID, Property> domainMap, final boolean isHead) { - // ... find the corresponding domain and replace it - ReferenceValue ref; - try { - ref = ReferenceValue.parseReference(p.getValue()); - } catch (final Message e) { - throw new RuntimeException("This should never happen."); - } - final EntityInterface replacement = domainMap.get(ref.getId()); - if (replacement == null) { - if (isHead) { - throw new NullPointerException("Replacement was null"); - } - // entity has been deleted (we are processing properties of an old entity version) - p.setValue(null); - p.addWarning( - new Message( - "The referenced entity has been deleted in the mean time and is not longer available.")); - return; - } - if (replacement.isDescOverride()) { - p.setDescOverride(true); - p.setDescription(replacement.getDescription()); - } - if (replacement.isNameOverride()) { - p.setNameOverride(true); - p.setName(replacement.getName()); - } - if (replacement.isDatatypeOverride()) { - p.setDatatypeOverride(true); - p.setDatatype(replacement.getDatatype()); - } - p.setProperties(replacement.getProperties()); - p.setStatementStatus(replacement.getStatementStatus()); - p.setValue(replacement.getValue()); - } - - public static void transformToDeepPropertyTree( - final EntityInterface e, final List<Property> protoProperties) { - // here we will store every domain we can find and we will index it by - // its id. - final Map<EntityID, Property> domainMap = new HashMap<>(); - - // loop over all properties and collect the domains - for (final Property p : protoProperties) { - // if this is a domain it represents a deeper branch of the property - // tree. - if (p.getRole() == Role.Domain) { - if (domainMap.containsKey(p.getId())) { - // aggregate the multiple values. - final Property domain = domainMap.get(p.getId()); - if (!(domain.getValue() instanceof CollectionValue)) { - final SingleValue singleValue = (SingleValue) domain.getValue(); - final CollectionValue vals = new CollectionValue(); - final IndexedSingleValue iSingleValue = - new IndexedSingleValue(domain.getPIdx(), singleValue); - vals.add(iSingleValue); - domain.setValue(vals); - } - ((CollectionValue) domain.getValue()).add(p.getPIdx(), p.getValue()); - } else { - domainMap.put(p.getId(), p); - } - } - } - - // loop over all properties - final boolean isHead = - e.getVersion().getSuccessors() == null || e.getVersion().getSuccessors().isEmpty(); - for (final Property p : protoProperties) { - - // if this is a replacement - if (p.getStatementStatus() == StatementStatus.REPLACEMENT) { - replace(p, domainMap, isHead); - } - - for (final Property subP : p.getProperties()) { - if (subP.getStatementStatus() == StatementStatus.REPLACEMENT) { - replace(subP, domainMap, isHead); - } - } - - if (p.getId().equals(e.getId())) { - // this is the value of an abstract property. - e.setValue(p.getValue()); - } else if (p.getRole() != Role.Domain) { - // if this is not a domain it is to be added to the properties - // of e. - e.addProperty(p); - } - } - } - - public static ArrayList<Property> parseFromProtoProperties(final List<ProtoProperty> protos) { - final ArrayList<Property> ret = new ArrayList<Property>(); - for (final ProtoProperty pp : protos) { - final Property property = parseFlatProperty(pp.property); - parseFromFlatProperties(property.getProperties(), pp.subProperties); - ret.add(property); - } - return ret; - } - - private static void parseFromFlatProperties( - final List<Property> properties, final List<FlatProperty> props) { - for (final FlatProperty fp : props) { - final Property property = parseFlatProperty(fp); - properties.add(property); - } - } - - private static Property parseFlatProperty(final FlatProperty fp) { - final Property property = new Property(new RetrieveEntity()); - property.parseFlatProperty(fp); - return property; - } -} diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/DatabaseUtils.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/DatabaseUtils.java index ccadd6b17d5af0218d60db5f485a9bdd360f6509..d9dae7278ff1b8d74927e76ae9a47c9c52a589e2 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/DatabaseUtils.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/DatabaseUtils.java @@ -47,8 +47,9 @@ import org.caosdb.server.entity.Message; import org.caosdb.server.entity.RetrieveEntity; import org.caosdb.server.entity.StatementStatus; import org.caosdb.server.entity.wrapper.Property; +import org.caosdb.server.filesystem.FileSystem.ObjectType; import org.caosdb.server.filesystem.Hash; -import org.caosdb.server.filesystem.Hasher; +import org.caosdb.server.filesystem.Path; public class DatabaseUtils { @@ -229,14 +230,39 @@ public class DatabaseUtils { ret.datatype_name = bytes2UTF8(rs.getBytes("DatatypeName")); ret.collection = bytes2UTF8(rs.getBytes("Collection")); - ret.filePath = bytes2UTF8(rs.getBytes("FilePath")); - ret.fileSize = rs.getLong("FileSize"); - ret.fileHash = Hash.create(rs.getString("FileHash"), 0, Hasher.SHA512); - ret.versionId = bytes2UTF8(rs.getBytes("Version")); + parseFSODescriptorFields(rs, ret); return ret; } + public static void parseFSODescriptorFields(final ResultSet rs, final SparseEntity ret) + throws SQLException { + final String key = bytes2UTF8(rs.getBytes("FileKey")); + if (key != null) { + // ret.fileParentId = rs.getInt("FileParentID"); + ret.filePath = new Path(bytes2UTF8(rs.getBytes("FilePath"))); + ret.fileSize = rs.getLong("FileSize"); + if (rs.wasNull()) { + ret.fileSize = null; + } + ret.fileHash = + Hash.create( + bytes2UTF8(rs.getBytes("FileHash")), + rs.getLong("FileHashChecked"), + bytes2UTF8(rs.getBytes("FileHashAlgo"))); + final String mimetype = bytes2UTF8(rs.getBytes("FileMimeType")); + ret.fileType = + java.util.Objects.equals("inode/directory", mimetype) + ? ObjectType.DIRECTORY + : (Objects.equal("inode/link", mimetype) ? ObjectType.LINK : ObjectType.FILE); + if (ret.fileType == ObjectType.FILE) { + ret.fileMimeType = mimetype; + } + ret.fileStorageId = bytes2UTF8(rs.getBytes("FileStorageID")); + ret.fileKey = key; + } + } + public static LinkedList<VerySparseEntity> parseParentResultSet(final ResultSet rs) throws SQLException { final LinkedList<VerySparseEntity> ret = new LinkedList<>(); diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetFileEntityByPath.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetFileEntityByPath.java index 54234d86ad9ab8029d9ed313caacd333ecd933b3..cbb7ea6030467e1c642a267474acced3153fc29a 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetFileEntityByPath.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetFileEntityByPath.java @@ -25,7 +25,6 @@ package org.caosdb.server.database.backend.implementation.MySQL; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import org.caosdb.server.database.DatabaseUtils; import org.caosdb.server.database.access.Access; import org.caosdb.server.database.backend.interfaces.GetFileEntityByPathImpl; import org.caosdb.server.database.exceptions.TransactionException; @@ -74,7 +73,7 @@ public class MySQLGetFileEntityByPath extends MySQLTransaction implements GetFil try (ResultSet rs = stmt.executeQuery()) { if (rs.next()) { final SparseEntity ret = new SparseEntity(); - ret.id = rs.getInt("FileId"); + ret.id = rs.getString("FileId"); DatabaseUtils.parseFSODescriptorFields(rs, ret); return ret; } else { @@ -86,7 +85,7 @@ public class MySQLGetFileEntityByPath extends MySQLTransaction implements GetFil private SparseEntity retrieveEntityACL(final SparseEntity entity) throws SQLException, ConnectionException { final PreparedStatement stmt = prepareStatement(STMT_GET_ACL); - stmt.setInt(1, entity.id); + stmt.setString(1, entity.id); try (ResultSet rs = stmt.executeQuery()) { rs.next(); entity.acl = DatabaseUtils.bytes2UTF8(rs.getBytes("ACL")); 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 deleted file mode 100644 index 33f6bacfd29e0c1999d3a4681f5daa45d1a59c5b..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetFileRecordByPath.java +++ /dev/null @@ -1,75 +0,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 - * 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; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.caosdb.server.database.access.Access; -import org.caosdb.server.database.backend.interfaces.GetFileRecordByPathImpl; -import org.caosdb.server.database.exceptions.TransactionException; -import org.caosdb.server.database.proto.SparseEntity; -import org.caosdb.server.filesystem.Hash; -import org.caosdb.server.filesystem.Hasher; - -/** - * 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) { - super(access); - } - - public static final String STMT_GET_ID_BY_PATH = - "SELECT (Select id from entity_ids WHERE internal_id = files.file_id) as entity_id, size, hex(hash) AS file_hash, checked_timestamp FROM files WHERE path=?"; - - @Override - public SparseEntity execute(final String path) throws TransactionException { - try { - final PreparedStatement stmt = prepareStatement(STMT_GET_ID_BY_PATH); - - stmt.setString(1, path); - final ResultSet rs = stmt.executeQuery(); - try { - if (rs.next()) { - final SparseEntity ret = new SparseEntity(); - ret.id = rs.getString("entity_id"); - ret.fileSize = rs.getLong("size"); - ret.fileChecked = rs.getLong("checked_timestamp"); - ret.fileHash = Hash.create(rs.getString("file_hash"), 0, Hasher.SHA512); - return ret; - } else { - return null; - } - } finally { - rs.close(); - } - } catch (final SQLException e) { - throw new TransactionException(e); - } catch (final ConnectionException e) { - throw new TransactionException(e); - } - } -} diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetFilesInDirectory.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetFilesInDirectory.java index 05eb01e2856e1af061b8f884dad4e7cd75469ce5..cd743d5ed9d37271d53fd86af69a2ec6303b3e87 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetFilesInDirectory.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetFilesInDirectory.java @@ -5,7 +5,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.LinkedList; import java.util.List; -import org.caosdb.server.database.DatabaseUtils; import org.caosdb.server.database.access.Access; import org.caosdb.server.database.exceptions.TransactionException; import org.caosdb.server.database.proto.SparseEntity; @@ -25,12 +24,12 @@ public class MySQLGetFilesInDirectory extends MySQLTransaction public List<SparseEntity> execute(final EntityID directory_id) { try { final PreparedStatement stmt = prepareStatement(STMT_GET_FILES_IN_DIR); - stmt.setInt(1, directory_id.toInteger()); + stmt.setString(1, directory_id.toString()); final List<SparseEntity> result = new LinkedList<>(); try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { final SparseEntity entity = new SparseEntity(); - entity.id = rs.getInt("FileId"); + entity.id = rs.getString("FileId"); DatabaseUtils.parseFSODescriptorFields(rs, entity); result.add(entity); } diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetVirtualFSO.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetVirtualFSO.java index 71b0ba1e99789e9fd08d7d1ca5abd5639baf2939..e2b1331f814396259af3a37858ad2318da9defbf 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetVirtualFSO.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLGetVirtualFSO.java @@ -3,7 +3,6 @@ package org.caosdb.server.database.backend.implementation.MySQL; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import org.caosdb.server.database.DatabaseUtils; import org.caosdb.server.database.access.Access; import org.caosdb.server.database.backend.interfaces.GetVirtualFSOImpl; import org.caosdb.server.database.exceptions.TransactionException; @@ -18,7 +17,7 @@ public class MySQLGetVirtualFSO extends MySQLTransaction implements GetVirtualFS } public static final String STMT_GET_FSO = - "SELECT 'SHA-512' AS FileHashAlgo, file_id AS FileId, " + "SELECT 'SHA-512' AS FileHashAlgo, (SELECT id FROM entity_ids WHERE internal_id = file_id LIMIT 1) AS FileId, " + /*parent_directory AS FileParentID,*/ " path AS FilePath, size AS FileSize, hex(hash) AS FileHash, checked_timestamp AS FileHashChecked, mimetype AS FileMimeType, file_storage_id AS FileStorageID, file_key AS FileKey FROM files WHERE file_storage_id = ? AND file_key = ?"; @Override @@ -30,7 +29,7 @@ public class MySQLGetVirtualFSO extends MySQLTransaction implements GetVirtualFS ResultSet resultSet = stmt.executeQuery(); if (resultSet.next()) { SparseEntity e = new SparseEntity(); - e.id = resultSet.getInt("FileId"); + e.id = resultSet.getString("FileId"); DatabaseUtils.parseFSODescriptorFields(resultSet, e); return new FSODescriptor(e); } diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertFSODescriptor.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertFSODescriptor.java index f12f6a4488726862f787ab7dbc0bf6a2e7697411..6f3cdc7a955dd8528d5e5cb628599e21256e8981 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertFSODescriptor.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLInsertFSODescriptor.java @@ -24,7 +24,7 @@ public class MySQLInsertFSODescriptor extends MySQLTransaction implements Insert try { final PreparedStatement insertFilePropsStmt = prepareStatement(STMT_INSERT_FILE_PROPERTIES); if (entity.filePath != null) { - insertFilePropsStmt.setInt(1, entity.id); + insertFilePropsStmt.setString(1, entity.id); if (entity.fileHash != null) { insertFilePropsStmt.setString(2, entity.fileHash.value); insertFilePropsStmt.setString(3, entity.fileHash.algorithm); 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 b752abd0d16d759d796dada00610ec039588f71a..345dc5e91ecb83bd4e5f07817d3dce3200704cc7 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 @@ -24,7 +24,6 @@ package org.caosdb.server.database.backend.implementation.MySQL; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLIntegrityConstraintViolationException; -import org.caosdb.server.database.DatabaseUtils; import org.caosdb.server.database.access.Access; import org.caosdb.server.database.backend.interfaces.InsertSparseEntityImpl; import org.caosdb.server.database.exceptions.IntegrityException; diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLListFiles.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLListFiles.java index 504f992a8fc26cccea4c93eb6970c6e7655ab2d7..72d8365f2d6cc69b10b91e8c1e48d3e0f0333d89 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLListFiles.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLListFiles.java @@ -5,7 +5,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.LinkedList; import java.util.List; -import org.caosdb.server.database.DatabaseUtils; import org.caosdb.server.database.access.Access; import org.caosdb.server.database.backend.interfaces.ListFilesImpl; import org.caosdb.server.database.exceptions.TransactionException; @@ -40,7 +39,7 @@ public class MySQLListFiles extends MySQLTransaction implements ListFilesImpl { try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { final SparseEntity entity = new SparseEntity(); - entity.id = rs.getInt("FileId"); + entity.id = rs.getString("FileId"); DatabaseUtils.parseFSODescriptorFields(rs, entity); result.add(new FSODescriptor(entity)); } diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLUpdateSparseEntity.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLUpdateSparseEntity.java index 887b1ed5128277582299750d39ae50ade2e5764a..036a9b4fbcd6b0f6489988441a5b2df45d7a7c23 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLUpdateSparseEntity.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLUpdateSparseEntity.java @@ -74,9 +74,9 @@ public class MySQLUpdateSparseEntity extends MySQLTransaction implements UpdateS updateFilePropsStmt.setString(7, spe.fileStorageId); // FileStorageId updateFilePropsStmt.setString(8, spe.fileKey); // FileKey if (spe.fileParentId != null) { - updateFilePropsStmt.setInt(9, spe.fileParentId); + updateFilePropsStmt.setString(9, spe.fileParentId); } else { - updateFilePropsStmt.setNull(9, Types.INTEGER); // FileParentDirectory + updateFilePropsStmt.setNull(9, Types.VARCHAR); // FileParentDirectory } } else { // move file to archive diff --git a/src/main/java/org/caosdb/server/database/proto/SparseEntity.java b/src/main/java/org/caosdb/server/database/proto/SparseEntity.java index 22bcf045603fd020d6d47334689327c93e9aa7dc..94c875ceb4d01c5f1fa6f8feb9e0e1f99cc461d5 100644 --- a/src/main/java/org/caosdb/server/database/proto/SparseEntity.java +++ b/src/main/java/org/caosdb/server/database/proto/SparseEntity.java @@ -46,7 +46,7 @@ public class SparseEntity extends VerySparseEntity { public String fileStorageId = null; public String fileKey = null; public String fileMimeType = null; - public Integer fileParentId; + public String fileParentId; public FileSystem.ObjectType fileType = ObjectType.FILE; public String versionId = null; public Long versionSeconds = null; diff --git a/src/main/java/org/caosdb/server/entity/Entity.java b/src/main/java/org/caosdb/server/entity/Entity.java index cf7bbecc7dfa324a61b66ebe44cb94118c295b4b..20d86fcc48e0cb3fb1c9c51efc982ead9fa1bb09 100644 --- a/src/main/java/org/caosdb/server/entity/Entity.java +++ b/src/main/java/org/caosdb/server/entity/Entity.java @@ -392,7 +392,7 @@ public abstract class Entity extends AbstractObservable implements EntityInterfa ret.fileStorageId = getFSODescriptor().getFileStorageId(); ret.fileKey = getFSODescriptor().getKey(); if (getFSODescriptor().getParentDirectoryID() != null) { - ret.fileParentId = getFSODescriptor().getParentDirectoryID().toInteger(); + ret.fileParentId = getFSODescriptor().getParentDirectoryID().toString(); } } return ret; diff --git a/src/main/java/org/caosdb/server/filesystem/FSODescriptor.java b/src/main/java/org/caosdb/server/filesystem/FSODescriptor.java index 1949c31d558ac44d1e48937a551bb346108cf90e..212b35ace3f8cc33f79f8420a5e68aaecd939437 100644 --- a/src/main/java/org/caosdb/server/filesystem/FSODescriptor.java +++ b/src/main/java/org/caosdb/server/filesystem/FSODescriptor.java @@ -79,7 +79,7 @@ public class FSODescriptor implements VirtualFSODescriptorInterface { this.key = spe.fileKey; this.type = spe.fileType; this.mimeType = spe.fileMimeType; - this.parentDirectory = new EntityID(spe.fileParentId); + // this.parentDirectory = new EntityID(spe.fileParentId); } public FSODescriptor(final Path path, final Long size) { diff --git a/src/main/java/org/caosdb/server/resource/FileSystemResource.java b/src/main/java/org/caosdb/server/resource/FileSystemResource.java index ddfbc5acf976faee5471b884b0af2282edd3e15c..66ee11bcd29e8533660283d1649e0ae67ce4afa2 100644 --- a/src/main/java/org/caosdb/server/resource/FileSystemResource.java +++ b/src/main/java/org/caosdb/server/resource/FileSystemResource.java @@ -131,7 +131,7 @@ public class FileSystemResource extends AbstractCaosDBServerResource { throw new UnsupportedOperationException( "Unknown FileSystem.ObjectType: " + child.getObjectType().toString()); } - if (child.getEntityId().toInteger() != null) { + if (child.getEntityId().toString() != null) { celem.setAttribute("id", child.getEntityId().toString()); } diff --git a/src/test/java/org/caosdb/server/database/backend/transaction/BackendTransactionTest.java b/src/test/java/org/caosdb/server/database/backend/transaction/BackendTransactionTest.java index e0cb425a25ed4d3c27e1cdbb610607077ed0fb92..0ea5f871925524bba650cc47a63d717e6b2f8437 100644 --- a/src/test/java/org/caosdb/server/database/backend/transaction/BackendTransactionTest.java +++ b/src/test/java/org/caosdb/server/database/backend/transaction/BackendTransactionTest.java @@ -19,7 +19,7 @@ public class BackendTransactionTest { final BackendTransaction transaction = new InsertTransactionHistory(null, null, null, null); assertEquals("Retrieve", transaction.getTransactionType(new RetrieveEntity("test"))); assertEquals("Insert", transaction.getTransactionType(new InsertEntity("test", Role.Record))); - assertEquals("Delete", transaction.getTransactionType(new DeleteEntity(new EntityID(1234)))); + assertEquals("Delete", transaction.getTransactionType(new DeleteEntity(new EntityID("1234")))); assertEquals("Update", transaction.getTransactionType(new UpdateEntity(new Element("Record")))); } }