Class DatabaseRecord


  • public class DatabaseRecord
    extends java.lang.Object
    A convenience container that provides a generic mapping class to a row in a database table. It is not advisable to use this generic container for large volume I/O against a database.
    Author:
    Xavier Witdouck
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  DatabaseRecord.Mapping
      A DatabaseMapping for the DatabaseRecord class
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.String,​java.lang.Object> values  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private DatabaseRecord​(java.util.Map<java.lang.String,​java.lang.Object> values)
      Constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> com.d3x.core.util.Option<T> getValue​(java.lang.String name)
      Returns an option on the value with the name
      <T> T getValueOrFail​(java.lang.String name)
      Returns an option on the value with the name
      java.util.Map<java.lang.String,​java.lang.Object> getValues()  
      java.util.Set<java.lang.String> names()
      Returns the set of field names for record
      static DatabaseRecord of​(java.util.function.Consumer<java.util.Map<java.lang.String,​java.lang.Object>> consumer)
      Returns a newly created record based on what the consumer puts in map
      int size()
      Returns the number of entries for this record
      java.util.Collection<java.lang.Object> values()
      Returns the field values for this record
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • values

        private java.util.Map<java.lang.String,​java.lang.Object> values
    • Constructor Detail

      • DatabaseRecord

        private DatabaseRecord​(java.util.Map<java.lang.String,​java.lang.Object> values)
        Constructor
        Parameters:
        values - the key-value pairs for this record
    • Method Detail

      • of

        public static DatabaseRecord of​(java.util.function.Consumer<java.util.Map<java.lang.String,​java.lang.Object>> consumer)
        Returns a newly created record based on what the consumer puts in map
        Parameters:
        consumer - the consumer to populate the field key-value pairs
        Returns:
        the newly created record
      • size

        public int size()
        Returns the number of entries for this record
        Returns:
        the number of entries
      • names

        public java.util.Set<java.lang.String> names()
        Returns the set of field names for record
        Returns:
        the field names
      • values

        public java.util.Collection<java.lang.Object> values()
        Returns the field values for this record
        Returns:
        the field values for record
      • getValue

        public <T> com.d3x.core.util.Option<T> getValue​(java.lang.String name)
        Returns an option on the value with the name
        Type Parameters:
        T - the value type
        Parameters:
        name - the field name
        Returns:
        the option on value
      • getValueOrFail

        public <T> T getValueOrFail​(java.lang.String name)
        Returns an option on the value with the name
        Type Parameters:
        T - the value type
        Parameters:
        name - the field name
        Returns:
        the option on value
      • getValues

        public java.util.Map<java.lang.String,​java.lang.Object> getValues()