Skip to content

Commit

Permalink
(#106) Created skeleton and some implementations of data-related classes
Browse files Browse the repository at this point in the history
  • Loading branch information
rocket-3 committed Nov 15, 2021
1 parent e752f4d commit c7b53ba
Show file tree
Hide file tree
Showing 26 changed files with 1,125 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2018-2021 FusionSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied.
*
* See the License for the specific language governing permissions
* and limitations under the License.
*/

package org.fusionsoft.database.mapping.dbd;

import com.amihaiemil.eoyaml.YamlMapping;
import org.fusionsoft.lib.yaml.YamlMappingEnvelope;

public class DbdDataMapping extends YamlMappingEnvelope {

/**
* Instantiates a new Yaml mapping envelope.
* @param mapping The YamlMapping to be encapsulated.
*/
public DbdDataMapping(final YamlMapping mapping) {
super(mapping);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2018-2021 FusionSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied.
*
* See the License for the specific language governing permissions
* and limitations under the License.
*/
package org.fusionsoft.database.mapping.dbd.ofobjects;

import com.amihaiemil.eoyaml.StrictYamlMapping;
import org.cactoos.iterable.IterableEnvelope;
import org.cactoos.iterable.IterableOf;
import org.cactoos.iterator.Mapped;
import org.fusionsoft.database.mapping.dbd.DbdColumnMapping;
import org.fusionsoft.database.mapping.dbd.DbdTableMapping;
import org.fusionsoft.database.mapping.fields.DbdTableFields;
import org.fusionsoft.database.snapshot.DbObject;

public class DbdColumnsOfTable extends IterableEnvelope<DbdColumnMapping> {

public DbdColumnsOfTable(final DbObject<DbdTableMapping> object) {
this(object.asYaml());
}

public DbdColumnsOfTable(final DbdTableMapping mapping) {
super(
new IterableOf<>(
() -> new Mapped<>(
x -> new DbdColumnMapping(x.asMapping()),
new StrictYamlMapping(mapping)
.value(DbdTableFields.COLUMNS.asString())
.asSequence()
.iterator()
)
)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
package org.fusionsoft.database.mapping.dbd.ofobjects;

import com.amihaiemil.eoyaml.YamlNode;
import java.util.Map;
import org.cactoos.Text;
import org.cactoos.iterable.IterableOf;
import org.cactoos.iterable.Joined;
import org.cactoos.map.MapEntry;
import org.cactoos.text.TextOfScalar;
import org.fusionsoft.database.mapping.dbd.DbdConstraintMapping;
import org.fusionsoft.database.mapping.dbd.DbdDataMapping;
import org.fusionsoft.database.mapping.dbd.DbdIndexMapping;
import org.fusionsoft.database.mapping.dbd.DbdTableMapping;
import org.fusionsoft.database.mapping.dbd.DbdTriggerMapping;
Expand All @@ -30,13 +33,14 @@
import org.fusionsoft.lib.yaml.EntriesOfYamlMapping;
import org.fusionsoft.lib.yaml.MappingWithoutNullScalars;
import org.fusionsoft.lib.yaml.YamlMappingOfEntries;
import org.fusionsoft.lib.yaml.YamlMappingOfScalar;

/**
* The DBD/sequences/#sequence/tables/#table node mapping.
* @since 0.1
* @checkstyle ClassDataAbstractionCouplingCheck (100 lines)
*/
public class DbdTableMappingWithChildObjects extends DbdTableMapping {
public class DbdTableMappingOfEntries extends DbdTableMapping {

/**
* Instantiates a new Dbd table mapping of entries.
Expand All @@ -49,11 +53,40 @@ public class DbdTableMappingWithChildObjects extends DbdTableMapping {
* entries to be encapsulated.
* @checkstyle ParameterNumberCheck (100 lines)
*/
public DbdTableMappingWithChildObjects(
public DbdTableMappingOfEntries(
final DbdTableMapping table,
final Iterable<MapEntry<Text, DbdIndexMapping>> indexes,
final Iterable<MapEntry<Text, DbdConstraintMapping>> constraints,
final Iterable<MapEntry<Text, DbdTriggerMapping>> triggers
final Iterable<? extends Map.Entry<Text, DbdIndexMapping>> indexes,
final Iterable<? extends Map.Entry<Text, DbdConstraintMapping>> constraints,
final Iterable<? extends Map.Entry<Text, DbdTriggerMapping>> triggers
) {
this(
table,
indexes,
new IterableOf<>(),
constraints,
triggers
);
}

/**
* Instantiates a new Dbd table mapping of entries.
* @param table The table DbObject entry to take data from.
* @param indexes The Iterable of Text -> {@link DbdIndexMapping}
* entries to be encapsulated.
* @param data The Iterable of Text -> {@link DbdDataMapping}
* entries to be encapsulated.
* @param constraints The Iterable of Text -> {@link DbdConstraintMapping}
* entries to be encapsulated.
* @param triggers The Iterable of Text -> {@link DbdTriggerMapping}
* entries to be encapsulated.
* @checkstyle ParameterNumberCheck (100 lines)
*/
public DbdTableMappingOfEntries(
final DbdTableMapping table,
final Iterable<? extends Map.Entry<Text, DbdIndexMapping>> indexes,
final Iterable<? extends Map.Entry<Text, DbdDataMapping>> data,
final Iterable<? extends Map.Entry<Text, DbdConstraintMapping>> constraints,
final Iterable<? extends Map.Entry<Text, DbdTriggerMapping>> triggers
) {
super(
new MappingWithoutNullScalars(
Expand All @@ -74,11 +107,15 @@ public DbdTableMappingWithChildObjects(
DbdTableFields.PARTKEYRANGE,
DbdTableFields.DEPENDENCIES
),
new EntriesWithKeys(
new EntriesOfYamlMapping(table),
DbdTableFields.DATA
),
new IterableOf<MapEntry<? extends Text, ? extends YamlNode>>(
new IterableOf<Map.Entry<? extends Text, ? extends YamlNode>>(
new MapEntry<>(
new TextOfScalar(
() -> data.iterator().next().getKey().asString()
),
new YamlMappingOfScalar(
() -> data.iterator().next().getValue()
)
),
new MapEntry<>(
DbdTableFields.CONSTRAINTS,
new YamlMappingOfEntries(constraints)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.fusionsoft.database.mapping.MappingOfRepresentative;
import org.fusionsoft.database.mapping.dbd.DbdConstraintMapping;
import org.fusionsoft.database.mapping.dbd.DbdDataMapping;
import org.fusionsoft.database.mapping.dbd.DbdIndexMapping;
import org.fusionsoft.database.mapping.dbd.DbdTableMapping;
import org.fusionsoft.database.mapping.dbd.DbdTriggerMapping;
Expand Down Expand Up @@ -44,7 +45,7 @@ public DbdTableMappingOfObjects(
final DbObject<?> table
) {
super(
new DbdTableMappingWithChildObjects(
new DbdTableMappingOfEntries(
new DbdTableMapping(
new MappingOfRepresentative(table)
),
Expand All @@ -59,6 +60,17 @@ public DbdTableMappingOfObjects(
new MappingOfRepresentative(obj)
)
),
new UnwrapEntriesOfObjects<DbdDataMapping>(
objects,
new ObjectsWithParentAndType(
table,
ObjectType.DATA,
objects
),
(objs, obj) -> new DbdDataMapping(
new MappingOfRepresentative(obj)
)
),
new UnwrapEntriesOfObjects<>(
objects,
new ObjectsWithParentAndType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.fusionsoft.database.mapping.entries;

import com.amihaiemil.eoyaml.YamlMapping;
import com.amihaiemil.eoyaml.YamlNode;
import org.cactoos.BiFunc;
import org.cactoos.Text;
import org.cactoos.iterable.IterableEnvelope;
Expand All @@ -31,7 +31,7 @@
* @param <M> The type of YamlMapping parameter.
* @since 0.1
*/
public class UnwrapEntriesOfObjects<M extends YamlMapping>
public class UnwrapEntriesOfObjects<M extends YamlNode>
extends IterableEnvelope<MapEntry<Text, M>> {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2018-2021 FusionSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied.
*
* See the License for the specific language governing permissions
* and limitations under the License.
*/

package org.fusionsoft.database.mapping.value;

import org.cactoos.Text;

public enum IuTypeValues implements Text {
NUMBER("number"),
STRING("sting"),
DATE("date"),
BOOLEAN("boolean"),
BINARY("binary"),
ARRAY("array"),
JSON("json"),
NATIVE("native");

private final String text;

IuTypeValues(final String text) {
this.text = text;
}

@Override
public String asString() {
return this.text;
}
}
42 changes: 42 additions & 0 deletions src/main/java/org/fusionsoft/database/snapshot/data/ArrayRow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2018-2021 FusionSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied.
*
* See the License for the specific language governing permissions
* and limitations under the License.
*/
package org.fusionsoft.database.snapshot.data;

import org.cactoos.Text;
import org.cactoos.text.TextOf;

public class ArrayRow implements Row {

private final long num;

private final String[] array;

public ArrayRow(final long num, final String[] array) {
this.num = num;
this.array = array;
}

@Override
public Text textOf(final Column column) {
return new TextOf(array[column.order().intValue()]);
}

@Override
public long number() {
return this.num;
}

}
25 changes: 25 additions & 0 deletions src/main/java/org/fusionsoft/database/snapshot/data/Column.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2018-2021 FusionSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied.
*
* See the License for the specific language governing permissions
* and limitations under the License.
*/

package org.fusionsoft.database.snapshot.data;

import org.cactoos.Text;

public interface Column {
Text name();
Number order();
ValueFormat format();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2018-2021 FusionSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied.
*
* See the License for the specific language governing permissions
* and limitations under the License.
*/
package org.fusionsoft.database.snapshot.data;

import org.cactoos.scalar.NumberOf;
import org.fusionsoft.database.mapping.dbd.DbdColumnMapping;
import org.fusionsoft.database.mapping.fields.DbdColumnFields;
import org.fusionsoft.lib.yaml.artefacts.TextOfMappingValue;

public class ColumnOfDbdColumnMapping extends ColumnOfScalar {

public ColumnOfDbdColumnMapping(final DbdColumnMapping column) {
super(
() -> new SimpleColumn(
new TextOfMappingValue(column, DbdColumnFields.DBNAME),
new NumberOf(
new TextOfMappingValue(column, DbdColumnFields.ORDER)
),
new ValueFormatOfIuType(
new TextOfMappingValue(column, DbdColumnFields.IUTYPE)
)
)
);
}

}
Loading

0 comments on commit c7b53ba

Please sign in to comment.