= DataTable _(record)_
:Notice: 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.

Represents a collection of domain objects (typically entity instances).

== API

[source,java]
.DataTable.java
----
record DataTable {
  DataTable(ObjectSpecification elementType)     // <.>
  DataTable(ObjectSpecification elementType, Predicate<ObjectAssociation> columnFilter)     // <.>
  DataTable(ObjectSpecification elementType, Can<? extends ObjectAssociation> dataColumns)     // <.>
  DataTable(ObjectSpecification elementType, String tableFriendlyName, Can<? extends ObjectAssociation> dataColumns, Can<ManagedObject> dataElements)
  DataTable forDomainType(Class<?> domainType)     // <.>
  DataTable forDomainType(Class<?> domainType, Predicate<ObjectAssociation> columnFilter)     // <.>
  String getLogicalName()     // <.>
  int getElementCount()     // <.>
  Stream<ManagedObject> streamDataElements()
  DataTable withDataElementsFrom(DataTable otherTable)     // <.>
  DataTable withDataElements(Iterable<ManagedObject> dataElements)     // <.>
  DataTable withDataElementPojos(Iterable<?> dataElementPojos)     // <.>
  DataTable withEntities()     // <.>
  DataTable withEntities(Query<?> query)     // <.>
  DataTable visit(CellVisitor visitor)
  DataTable visit(CellVisitor visitor, Predicate<DataColumn> columnFilter)
  TabularSheet toTabularSheet(AccessMode accessMode)
  Blob exportToBlob(TabularExporter exporter, AccessMode accessMode)     // <.>
  Predicate<ObjectAssociation> columnFilterIncluding(Where whereToInclude)
  Predicate<ObjectAssociation> columnFilterExcludingMixins()
  Predicate<ObjectAssociation> columnFilterIncludingEnabledForSnapshot()
}
----

<.> xref:#DataTable_ObjectSpecification[DataTable(ObjectSpecification)]
+
--
Returns an empty xref:refguide:core:index/metamodel/tabular/simple/DataTable.adoc[DataTable] for given domain object type, with all properties as columns, excluding mixed-in ones. (For more control on which columns to include, consider a different constructor.)
--
<.> xref:#DataTable_ObjectSpecification_Predicate[DataTable(ObjectSpecification, Predicate)]
+
--
Returns an empty xref:refguide:core:index/metamodel/tabular/simple/DataTable.adoc[DataTable] for given domain object type, with all (including mixed-in) associations as columns, that pass given _columnFilter_ . If the filter is _null_ it acts as a pass-through.
--
<.> xref:#DataTable_ObjectSpecification_Can[DataTable(ObjectSpecification, Can)]
+
--
Returns an empty xref:refguide:core:index/metamodel/tabular/simple/DataTable.adoc[DataTable] for given domain object type.
--
<.> xref:#forDomainType_Class[forDomainType(Class)]
+
--
Returns an empty xref:refguide:core:index/metamodel/tabular/simple/DataTable.adoc[DataTable] for given domain object type, with all properties as columns, excluding mixed-in ones. (For more control on which columns to include, consider _#forDomainType(Class, Predicate)_ or a constructor that fits.)
--
<.> xref:#forDomainType_Class_Predicate[forDomainType(Class, Predicate)]
+
--
Returns an empty xref:refguide:core:index/metamodel/tabular/simple/DataTable.adoc[DataTable] for given domain object type, with all (including mixed-in) associations as columns, that pass given _columnFilter_ . If the filter is _null_ it acts as a pass-through.
--
<.> xref:#getLogicalName_[getLogicalName()]
+
--
Unique within application scope, can act as an id.
--
<.> xref:#getElementCount_[getElementCount()]
+
--
Count data rows.
--
<.> xref:#withDataElementsFrom_DataTable[withDataElementsFrom(DataTable)]
+
--
Returns a new table, populated from this and the other table.
--
<.> xref:#withDataElements_Iterable[withDataElements(Iterable)]
+
--
Returns a new table instance with the data-elements, which make up the rows of the new table.
--
<.> xref:#withDataElementPojos_Iterable[withDataElementPojos(Iterable)]
+
--
Returns a new table instance with data-elements from given pojos, that are adapted to xref:refguide:core:index/metamodel/object/ManagedObject.adoc[ManagedObject] (s)..
--
<.> xref:#withEntities_[withEntities()]
+
--
Returns a new table, populated from the underlying (default) persistence layer.
--
<.> xref:#withEntities_Query[withEntities(Query)]
+
--
Returns a new table, populated from the underlying (default) persistence layer, using given xref:refguide:applib:index/query/Query.adoc[Query] to refine the result.
--
<.> xref:#exportToBlob_TabularExporter_AccessMode[exportToBlob(TabularExporter, AccessMode)]
+
--
Typical use-case:
--

== Members

[#DataTable_ObjectSpecification]
=== DataTable(ObjectSpecification)

Returns an empty xref:refguide:core:index/metamodel/tabular/simple/DataTable.adoc[DataTable] for given domain object type, with all properties as columns, excluding mixed-in ones. (For more control on which columns to include, consider a different constructor.)

The table can be populated later on using _DataTable#withDataElements(Iterable)_ or _#withDataElementPojos(Iterable)_ .

[#DataTable_ObjectSpecification_Predicate]
=== DataTable(ObjectSpecification, Predicate)

Returns an empty xref:refguide:core:index/metamodel/tabular/simple/DataTable.adoc[DataTable] for given domain object type, with all (including mixed-in) associations as columns, that pass given _columnFilter_ . If the filter is _null_ it acts as a pass-through.

The table can be populated later on using _DataTable#withDataElements(Iterable)_ or _#withDataElementPojos(Iterable)_ .

[#DataTable_ObjectSpecification_Can]
=== DataTable(ObjectSpecification, Can)

Returns an empty xref:refguide:core:index/metamodel/tabular/simple/DataTable.adoc[DataTable] for given domain object type.

The table can be populated later on using _DataTable#withDataElements(Iterable)_ or _#withDataElementPojos(Iterable)_ .

[#forDomainType_Class]
=== forDomainType(Class)

Returns an empty xref:refguide:core:index/metamodel/tabular/simple/DataTable.adoc[DataTable] for given domain object type, with all properties as columns, excluding mixed-in ones. (For more control on which columns to include, consider _#forDomainType(Class, Predicate)_ or a constructor that fits.)

The table can be populated later on using _DataTable#withDataElements(Iterable)_ or _#withDataElementPojos(Iterable)_ .

[#forDomainType_Class_Predicate]
=== forDomainType(Class, Predicate)

Returns an empty xref:refguide:core:index/metamodel/tabular/simple/DataTable.adoc[DataTable] for given domain object type, with all (including mixed-in) associations as columns, that pass given _columnFilter_ . If the filter is _null_ it acts as a pass-through.

The table can be populated later on using _DataTable#withDataElements(Iterable)_ or _#withDataElementPojos(Iterable)_ .

[#getLogicalName_]
=== getLogicalName()

Unique within application scope, can act as an id.

[#getElementCount_]
=== getElementCount()

Count data rows.

[#withDataElementsFrom_DataTable]
=== withDataElementsFrom(DataTable)

Returns a new table, populated from this and the other table.

[#withDataElements_Iterable]
=== withDataElements(Iterable)

Returns a new table instance with the data-elements, which make up the rows of the new table.

[#withDataElementPojos_Iterable]
=== withDataElementPojos(Iterable)

Returns a new table instance with data-elements from given pojos, that are adapted to xref:refguide:core:index/metamodel/object/ManagedObject.adoc[ManagedObject] (s)..

[#withEntities_]
=== withEntities()

Returns a new table, populated from the underlying (default) persistence layer.

[#withEntities_Query]
=== withEntities(Query)

Returns a new table, populated from the underlying (default) persistence layer, using given xref:refguide:applib:index/query/Query.adoc[Query] to refine the result.

[#exportToBlob_TabularExporter_AccessMode]
=== exportToBlob(TabularExporter, AccessMode)

Typical use-case:

----
@Inject TabularExcelExporter excelExporter;

Blob exportToBlob(List<MyDomainObject> myDomainObjects) {
    var dataTable = DataTable.forDomainType(MyDomainObject.class);
    dataTable.setDataElementPojos(myDomainObjects);
    return dataTable.exportToBlob(excelExporter, AccessMode.USER);
}
----
