Skip to content

Commit

Permalink
Started with multitenancy
Browse files Browse the repository at this point in the history
Issue #15
  • Loading branch information
michael-schnell committed Apr 16, 2020
1 parent 22c9352 commit 484a568
Show file tree
Hide file tree
Showing 28 changed files with 989 additions and 330 deletions.
37 changes: 14 additions & 23 deletions api/src/main/java/org/fuin/esc/api/ProjectionStreamId.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,29 @@ public final String asString() {
return name;
}

@Override
public final String toString() {
return name;
}

// CHECKSTYLE:OFF Generated code

@Override
public final int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
return name.hashCode();
}

@Override
public final boolean equals(Object obj) {
if (this == obj)
public final boolean equals(final Object obj) {
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (!(obj instanceof ProjectionStreamId))
}
if (getClass() != obj.getClass()) {
return false;
ProjectionStreamId other = (ProjectionStreamId) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
final ProjectionStreamId other = (ProjectionStreamId) obj;
return name.equals(other.name);
}

// CHECKSTYLE:ON
@Override
public final String toString() {
return name;
}

}
37 changes: 14 additions & 23 deletions api/src/main/java/org/fuin/esc/api/SimpleStreamId.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,29 @@ public final String asString() {
return name;
}

@Override
public final String toString() {
return name;
}

// CHECKSTYLE:OFF Generated code

@Override
public final int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
return name.hashCode();
}

@Override
public final boolean equals(Object obj) {
if (this == obj)
public final boolean equals(final Object obj) {
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (!(obj instanceof SimpleStreamId))
}
if (getClass() != obj.getClass()) {
return false;
SimpleStreamId other = (SimpleStreamId) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
final SimpleStreamId other = (SimpleStreamId) obj;
return name.equals(other.name);
}

// CHECKSTYLE:ON
@Override
public final String toString() {
return name;
}

}
76 changes: 76 additions & 0 deletions api/src/main/java/org/fuin/esc/api/SimpleTenantId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Copyright (C) 2015 Michael Schnell. All rights reserved.
* http://www.fuin.org/
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option) any
* later version.
*
* This library 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 Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see http://www.gnu.org/licenses/.
*/
package org.fuin.esc.api;

import javax.validation.constraints.NotNull;

import org.fuin.objects4j.common.Contract;
import org.fuin.objects4j.common.Immutable;

/**
* Tenant identifier that is based on a name.
*/
@Immutable
public final class SimpleTenantId implements TenantId {

private static final long serialVersionUID = 1L;

private final String name;

/**
* Constructor with mandatory data.
*
* @param name
* Unique name.
*/
public SimpleTenantId(@NotNull final String name) {
Contract.requireArgNotNull("name", name);
this.name = name;
}

@Override
public final String asString() {
return name;
}

@Override
public final int hashCode() {
return name.hashCode();
}

@Override
public final boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final SimpleTenantId other = (SimpleTenantId) obj;
return name.equals(other.name);
}

@Override
public final String toString() {
return name;
}

}
22 changes: 8 additions & 14 deletions api/src/main/java/org/fuin/esc/api/StreamId.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
import org.fuin.objects4j.vo.KeyValue;

/**
* Name of a stream that is unique within the event store.
* Name of a stream that is unique within the event store.<br>
* <br>
* CAUTION: Stream identifier should only be compared based on their {@link #asString()} method.
*/
public interface StreamId extends Serializable {

/** Uniquely identifies the stream that contains all events. */
public StreamId ALL = new SimpleStreamId(StreamId.class.getName() + "ALL");

/**
* Returns the name of the stream.
*
Expand All @@ -43,16 +42,13 @@ public interface StreamId extends Serializable {
/**
* Returns the information if this identifier points to a projection.
*
* @return TRUE if this is an identifier for a projection, else FALSE
* (stream).
* @return TRUE if this is an identifier for a projection, else FALSE (stream).
*/
public boolean isProjection();

/**
* Convenience method that returns the one-and-only parameter value.
* CAUTION: This method will throw an exception if there are no parameters,
* more than one parameter or the type of the value cannot be casted to the
* expected result type.
* Convenience method that returns the one-and-only parameter value. CAUTION: This method will throw an exception if there are no
* parameters, more than one parameter or the type of the value cannot be casted to the expected result type.
*
* @return Value of the single parameter.
*
Expand All @@ -63,11 +59,9 @@ public interface StreamId extends Serializable {
public <T> T getSingleParamValue();

/**
* Returns the parameters used in addition to the pure stream name to
* identify the stream.
* Returns the parameters used in addition to the pure stream name to identify the stream.
*
* @return Ordered unmodifiable list of parameters - May be empty if no
* parameters exist.
* @return Ordered unmodifiable list of parameters - May be empty if no parameters exist.
*/
@NotNull
public List<KeyValue> getParameters();
Expand Down
36 changes: 36 additions & 0 deletions api/src/main/java/org/fuin/esc/api/TenantId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (C) 2015 Michael Schnell. All rights reserved.
* http://www.fuin.org/
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option) any
* later version.
*
* This library 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 Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see http://www.gnu.org/licenses/.
*/
package org.fuin.esc.api;

import java.io.Serializable;

/**
* Unique tenant identifier<br>
* <br>
* CAUTION: Tenant identifier should only be compared based on their {@link #asString()} method.
*/
public interface TenantId extends Serializable {

/**
* Returns the identifier as string.
*
* @return String representation of the ID.
*/
public String asString();

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void teardown() {

@Test
public void testEqualsHashCode() {
EqualsVerifier.forClass(ProjectionStreamId.class).verify();
EqualsVerifier.forClass(ProjectionStreamId.class).withNonnullFields("name").verify();
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion api/src/test/java/org/fuin/esc/api/SimpleStreamIdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void teardown() {

@Test
public void testEqualsHashCode() {
EqualsVerifier.forClass(SimpleStreamId.class).verify();
EqualsVerifier.forClass(SimpleStreamId.class).withNonnullFields("name").verify();
}

@Test
Expand Down
57 changes: 57 additions & 0 deletions api/src/test/java/org/fuin/esc/api/SimpleTenantIdTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright (C) 2015 Michael Schnell. All rights reserved.
* http://www.fuin.org/
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option) any
* later version.
*
* This library 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 Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see http://www.gnu.org/licenses/.
*/
package org.fuin.esc.api;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import nl.jqno.equalsverifier.EqualsVerifier;

/**
* Tests the {@link SimpleTenantId} class.
*/
public class SimpleTenantIdTest {

private static final String NAME = "mycompany";

private SimpleTenantId testee;

@Before
public void setup() {
testee = new SimpleTenantId(NAME);
}

@After
public void teardown() {
testee = null;
}

@Test
public void testEqualsHashCode() {
EqualsVerifier.forClass(SimpleTenantId.class).withNonnullFields("name").verify();
}

@Test
public void testGetter() {
assertThat(testee.asString()).isEqualTo(NAME);
}

}
Loading

0 comments on commit 484a568

Please sign in to comment.