You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by "Arsnael (via GitHub)" <gi...@apache.org> on 2023/11/27 07:17:16 UTC
[PR] WIP JAMES-2586 PostgresMailboxAnnotationDAO and Mapper [james-project]
Arsnael opened a new pull request, #1817:
URL: https://github.com/apache/james-project/pull/1817
Just started last week on it... Not much done yet
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] WIP JAMES-2586 PostgresMailboxAnnotationDAO and Mapper [james-project]
Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on code in PR #1817:
URL: https://github.com/apache/james-project/pull/1817#discussion_r1405876732
##########
mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dao/PostgresMailboxAnnotationDAO.java:
##########
@@ -0,0 +1,77 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailbox.postgres.mail.dao;
+
+import static org.apache.james.mailbox.postgres.PostgresMailboxAnnotationModule.PostgresMailboxAnnotationTable.ANNOTATIONS;
+import static org.apache.james.mailbox.postgres.PostgresMailboxAnnotationModule.PostgresMailboxAnnotationTable.MAILBOX_ID;
+import static org.apache.james.mailbox.postgres.PostgresMailboxAnnotationModule.PostgresMailboxAnnotationTable.TABLE_NAME;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.james.backends.postgres.utils.PostgresExecutor;
+import org.apache.james.mailbox.model.MailboxAnnotation;
+import org.apache.james.mailbox.model.MailboxAnnotationKey;
+import org.apache.james.mailbox.postgres.PostgresMailboxId;
+import org.jooq.postgres.extensions.types.Hstore;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+public class PostgresMailboxAnnotationDAO {
+ private final PostgresExecutor postgresExecutor;
+
+ public PostgresMailboxAnnotationDAO(PostgresExecutor postgresExecutor) {
+ this.postgresExecutor = postgresExecutor;
+ }
+
+ public Flux<MailboxAnnotation> getAllAnnotations(PostgresMailboxId mailboxId) {
+ return postgresExecutor.executeRows(dslContext ->
+ Flux.from(dslContext.selectFrom(TABLE_NAME)
+ .where(MAILBOX_ID.eq(mailboxId.asUuid()))))
+ .singleOrEmpty()
+ .map(record -> record.get(ANNOTATIONS))
+ .flatMapIterable(this::hstoreToAnnotations);
+ }
+
+ private List<MailboxAnnotation> hstoreToAnnotations(Hstore hstore) {
+ return hstore.data()
+ .entrySet()
+ .stream()
+ .map(entry -> MailboxAnnotation.newInstance(new MailboxAnnotationKey(entry.getKey()), entry.getValue()))
+ .collect(Collectors.toList());
+ }
+
+ public Mono<Void> insertAnnotation(PostgresMailboxId mailboxId, MailboxAnnotation mailboxAnnotation) {
+ Preconditions.checkArgument(!mailboxAnnotation.isNil());
+
+ // TODO: likely wrong... might need to check if row exists with mailboxId and then insert if not, update if is
+ return postgresExecutor.executeVoid(dslContext ->
+ Mono.from(dslContext.insertInto(TABLE_NAME, MAILBOX_ID, ANNOTATIONS)
+ .values(mailboxId.asUuid(), annotationAsHstore(mailboxAnnotation))));
Review Comment:
Not only cause we have the case when the line with mailboxId does not exist yet, so we need to do an insert. Hung and Quan did something like that with quota DAOs, and I intend to reuse something similar
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] WIP JAMES-2586 PostgresMailboxAnnotationDAO and Mapper [james-project]
Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael closed pull request #1817: WIP JAMES-2586 PostgresMailboxAnnotationDAO and Mapper
URL: https://github.com/apache/james-project/pull/1817
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] WIP JAMES-2586 PostgresMailboxAnnotationDAO and Mapper [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #1817:
URL: https://github.com/apache/james-project/pull/1817#discussion_r1405754767
##########
mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dao/PostgresMailboxAnnotationDAO.java:
##########
@@ -0,0 +1,77 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailbox.postgres.mail.dao;
+
+import static org.apache.james.mailbox.postgres.PostgresMailboxAnnotationModule.PostgresMailboxAnnotationTable.ANNOTATIONS;
+import static org.apache.james.mailbox.postgres.PostgresMailboxAnnotationModule.PostgresMailboxAnnotationTable.MAILBOX_ID;
+import static org.apache.james.mailbox.postgres.PostgresMailboxAnnotationModule.PostgresMailboxAnnotationTable.TABLE_NAME;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.james.backends.postgres.utils.PostgresExecutor;
+import org.apache.james.mailbox.model.MailboxAnnotation;
+import org.apache.james.mailbox.model.MailboxAnnotationKey;
+import org.apache.james.mailbox.postgres.PostgresMailboxId;
+import org.jooq.postgres.extensions.types.Hstore;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+public class PostgresMailboxAnnotationDAO {
+ private final PostgresExecutor postgresExecutor;
+
+ public PostgresMailboxAnnotationDAO(PostgresExecutor postgresExecutor) {
+ this.postgresExecutor = postgresExecutor;
+ }
+
+ public Flux<MailboxAnnotation> getAllAnnotations(PostgresMailboxId mailboxId) {
+ return postgresExecutor.executeRows(dslContext ->
+ Flux.from(dslContext.selectFrom(TABLE_NAME)
+ .where(MAILBOX_ID.eq(mailboxId.asUuid()))))
+ .singleOrEmpty()
+ .map(record -> record.get(ANNOTATIONS))
+ .flatMapIterable(this::hstoreToAnnotations);
+ }
+
+ private List<MailboxAnnotation> hstoreToAnnotations(Hstore hstore) {
+ return hstore.data()
+ .entrySet()
+ .stream()
+ .map(entry -> MailboxAnnotation.newInstance(new MailboxAnnotationKey(entry.getKey()), entry.getValue()))
+ .collect(Collectors.toList());
+ }
+
+ public Mono<Void> insertAnnotation(PostgresMailboxId mailboxId, MailboxAnnotation mailboxAnnotation) {
+ Preconditions.checkArgument(!mailboxAnnotation.isNil());
+
+ // TODO: likely wrong... might need to check if row exists with mailboxId and then insert if not, update if is
+ return postgresExecutor.executeVoid(dslContext ->
+ Mono.from(dslContext.insertInto(TABLE_NAME, MAILBOX_ID, ANNOTATIONS)
+ .values(mailboxId.asUuid(), annotationAsHstore(mailboxAnnotation))));
Review Comment:
Here we use HStore on a mutable field.
Thus we likely need in place updates.
```
UPDATE votre_table
SET votre_colonne_hstore = votre_colonne_hstore || 'nouvelle_cle' => 'nouvelle_valeur'
WHERE votre_condition;
UPDATE votre_table
SET votre_colonne_hstore = votre_colonne_hstore - 'cle_a_retirer'
WHERE votre_condition;
```
```
dsl.update(table("votre_table"))
.set(field("votre_colonne_hstore"), field("votre_colonne_hstore").concat(field("'nouvelle_cle => nouvelle_valeur'")))
.where(votre_condition)
.execute();
dsl.update(table("votre_table"))
.set(field("votre_colonne_hstore"), field("votre_colonne_hstore").minus(field("'cle_a_retirer'")))
.where(votre_condition)
.execute();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] WIP JAMES-2586 PostgresMailboxAnnotationDAO and Mapper [james-project]
Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on code in PR #1817:
URL: https://github.com/apache/james-project/pull/1817#discussion_r1405876732
##########
mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dao/PostgresMailboxAnnotationDAO.java:
##########
@@ -0,0 +1,77 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailbox.postgres.mail.dao;
+
+import static org.apache.james.mailbox.postgres.PostgresMailboxAnnotationModule.PostgresMailboxAnnotationTable.ANNOTATIONS;
+import static org.apache.james.mailbox.postgres.PostgresMailboxAnnotationModule.PostgresMailboxAnnotationTable.MAILBOX_ID;
+import static org.apache.james.mailbox.postgres.PostgresMailboxAnnotationModule.PostgresMailboxAnnotationTable.TABLE_NAME;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.james.backends.postgres.utils.PostgresExecutor;
+import org.apache.james.mailbox.model.MailboxAnnotation;
+import org.apache.james.mailbox.model.MailboxAnnotationKey;
+import org.apache.james.mailbox.postgres.PostgresMailboxId;
+import org.jooq.postgres.extensions.types.Hstore;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+public class PostgresMailboxAnnotationDAO {
+ private final PostgresExecutor postgresExecutor;
+
+ public PostgresMailboxAnnotationDAO(PostgresExecutor postgresExecutor) {
+ this.postgresExecutor = postgresExecutor;
+ }
+
+ public Flux<MailboxAnnotation> getAllAnnotations(PostgresMailboxId mailboxId) {
+ return postgresExecutor.executeRows(dslContext ->
+ Flux.from(dslContext.selectFrom(TABLE_NAME)
+ .where(MAILBOX_ID.eq(mailboxId.asUuid()))))
+ .singleOrEmpty()
+ .map(record -> record.get(ANNOTATIONS))
+ .flatMapIterable(this::hstoreToAnnotations);
+ }
+
+ private List<MailboxAnnotation> hstoreToAnnotations(Hstore hstore) {
+ return hstore.data()
+ .entrySet()
+ .stream()
+ .map(entry -> MailboxAnnotation.newInstance(new MailboxAnnotationKey(entry.getKey()), entry.getValue()))
+ .collect(Collectors.toList());
+ }
+
+ public Mono<Void> insertAnnotation(PostgresMailboxId mailboxId, MailboxAnnotation mailboxAnnotation) {
+ Preconditions.checkArgument(!mailboxAnnotation.isNil());
+
+ // TODO: likely wrong... might need to check if row exists with mailboxId and then insert if not, update if is
+ return postgresExecutor.executeVoid(dslContext ->
+ Mono.from(dslContext.insertInto(TABLE_NAME, MAILBOX_ID, ANNOTATIONS)
+ .values(mailboxId.asUuid(), annotationAsHstore(mailboxAnnotation))));
Review Comment:
Not only cause we have the case when the line with mailboxId does not exist yet, so we need to do an insert. Hung and Quan did something like that with quota DAOs, where they try to insert and if key exists already they can fallback on an update instead (or the other way around I forgot), and I intend to reuse something similar
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] WIP JAMES-2586 PostgresMailboxAnnotationDAO and Mapper [james-project]
Posted by "hungphan227 (via GitHub)" <gi...@apache.org>.
hungphan227 commented on PR #1817:
URL: https://github.com/apache/james-project/pull/1817#issuecomment-1829623730
new PR https://github.com/apache/james-project/pull/1822
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] WIP JAMES-2586 PostgresMailboxAnnotationDAO and Mapper [james-project]
Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on PR #1817:
URL: https://github.com/apache/james-project/pull/1817#issuecomment-1831470125
Let me close this then.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org