Skip to content

Commit

Permalink
(#106) Make data objects fetching and rendering work, minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rocket-3 committed Nov 19, 2021
1 parent 34f305d commit ed4e1b7
Show file tree
Hide file tree
Showing 18 changed files with 1,395 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import com.amihaiemil.eoyaml.YamlMapping;
import org.fusionsoft.lib.yaml.YamlMappingEnvelope;

/**
* The DBD/schemas/#schema/tables/#table/data/# document node {@link YamlMapping}.
* @since 0.1
*/
public class DbdDataMapping extends YamlMappingEnvelope {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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;
Expand All @@ -30,7 +29,9 @@
import org.fusionsoft.database.mapping.entries.EntriesWithKeys;
import org.fusionsoft.database.mapping.entries.EntriesWithoutKeys;
import org.fusionsoft.database.mapping.fields.DbdTableFields;
import org.fusionsoft.lib.collection.SingleOrEmptyFallback;
import org.fusionsoft.lib.yaml.EntriesOfYamlMapping;
import org.fusionsoft.lib.yaml.MappingEmpty;
import org.fusionsoft.lib.yaml.MappingWithoutNullScalars;
import org.fusionsoft.lib.yaml.YamlMappingOfEntries;
import org.fusionsoft.lib.yaml.YamlMappingOfScalar;
Expand Down Expand Up @@ -109,11 +110,15 @@ public DbdTableMappingOfEntries(
),
new IterableOf<Map.Entry<? extends Text, ? extends YamlNode>>(
new MapEntry<>(
new TextOfScalar(
() -> data.iterator().next().getKey().asString()
),
DbdTableFields.DATA,
new YamlMappingOfScalar(
() -> data.iterator().next().getValue()
() -> new SingleOrEmptyFallback<>(
data,
new MapEntry<>(
DbdTableFields.DATA,
new MappingEmpty()
)
).value().getValue()
)
),
new MapEntry<>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.entries;

import java.util.Map;
import org.cactoos.Scalar;
import org.cactoos.scalar.Unchecked;

public class MapEntryOfScalar<K,V> implements Map.Entry<K,V> {

private final Unchecked<? extends Map.Entry<K,V>> scalar;

public MapEntryOfScalar(final Scalar<? extends Map.Entry<K, V>> scalar) {
this.scalar = new Unchecked<>(scalar);
}

@Override
public K getKey() {
return this.scalar.value().getKey();
}

@Override
public V getValue() {
return this.scalar.value().getValue();
}

@Override
public V setValue(final V value) {
return this.scalar.value().setValue(value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,9 @@

public class ColumnsOfTable extends IterableEnvelope<Column> {

public ColumnsOfTable(final DbObject<DbdTableMapping> table) {
this(new DbdColumnsOfTable(table));
}

public ColumnsOfTable(final DbdTableMapping mapping) {
this(new DbdColumnsOfTable(mapping));
}

public ColumnsOfTable(final Iterable<DbdColumnMapping> cols) {
super(
new Sorted<Column>(
new Sorted<>(
Comparator.comparing(x -> x.order().intValue()),
new Mapped<Column>(
ColumnOfDbdColumnMapping::new,
Expand All @@ -46,4 +38,12 @@ public ColumnsOfTable(final Iterable<DbdColumnMapping> cols) {
);
}

public ColumnsOfTable(final DbObject<DbdTableMapping> table) {
this(new DbdColumnsOfTable(table));
}

public ColumnsOfTable(final DbdTableMapping mapping) {
this(new DbdColumnsOfTable(mapping));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,45 @@
import java.sql.Connection;
import java.util.Map;
import org.cactoos.Text;
import org.cactoos.iterable.IterableEnvelope;
import org.cactoos.iterable.IterableOf;
import org.cactoos.iterable.Mapped;
import org.cactoos.iterable.Sticky;
import org.cactoos.list.ListEnvelope;
import org.cactoos.list.ListOf;
import org.fusionsoft.database.mapping.dbd.DbdTableMapping;
import org.fusionsoft.database.snapshot.DbObject;

public class DbdDataEntriesOfTable extends ListEnvelope<Map.Entry<Text, YamlNode>> {
public class DbdDataEntriesOfTable extends IterableEnvelope<Map.Entry<Text, YamlNode>> {

public DbdDataEntriesOfTable(
final Connection connection,
final DbObject<DbdTableMapping> table
) {
this(
connection,
table,
new Sticky<>(
new ColumnsOfTable(table)
)
);
}

public DbdDataEntriesOfTable(
final Connection connection,
final DbObject<DbdTableMapping> table,
final Iterable<Column> columns
) {
super(
new ListOf<>(
new IterableOf<>(
() -> {
// try(
//
// ) {
final RowsOfTable rows = new RowsOfTable(
connection,
table
);
final Iterable<Column> cols = new Sticky<>(
new ColumnsOfTable(
table
)
);
return new Mapped<Map.Entry<Text, YamlNode>>(
x -> new DbdDataEntryOfRow(x, cols),
rows
).iterator();
// }
}
)
new IterableOf<>(
() -> new ListOf<>(
new Mapped<Map.Entry<Text, YamlNode>>(
x -> new DbdDataEntryOfRow(x, columns),
new RowsOfTable(
connection,
table
)
)
).iterator()
)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 java.sql.Connection;
import org.fusionsoft.database.mapping.dbd.DbdDataMapping;
import org.fusionsoft.database.mapping.dbd.DbdTableMapping;
import org.fusionsoft.database.mapping.fields.DbdTableFields;
import org.fusionsoft.database.snapshot.DbObject;
import org.fusionsoft.database.snapshot.objects.ObjectType;
import org.fusionsoft.database.snapshot.objects.SimpleDbObject;
import org.fusionsoft.database.snapshot.objectsignature.FullObjectName;
import org.fusionsoft.database.snapshot.objectsignature.SimpleObjectSignature;
import org.fusionsoft.lib.yaml.YamlMappingOfEntries;

public class InlineDataObjectOfTable extends SimpleDbObject<DbdDataMapping> {

/**
* Instantiates a new simple db object.
*/
public InlineDataObjectOfTable(
final DbObject<DbdTableMapping> table,
final Connection connection
) {
super(
new DbdDataMapping(
new YamlMappingOfEntries(
new DbdDataEntriesOfTable(
connection,
table
)
)
),
new SimpleObjectSignature(
new FullObjectName(
table.signature().name().parent(),
table.signature().name().first(),
DbdTableFields.DATA
),
ObjectType.DATA
)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public RowOfArray(final long num, final String[] array) {

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

@Override
Expand Down
Loading

0 comments on commit ed4e1b7

Please sign in to comment.