C# 클래스 Azavea.Open.DAO.CSV.CsvDaLayer

Data layer that implements reading/writing/modifying CSV files. NOTE: Updates/Deletes will require re-writing the file, so expect some churn if you're doing a lot of those. Inserts will be appended to the end of the file.
상속: Azavea.Open.DAO.Unqueryable.UnqueryableDaLayer
파일 보기 프로젝트 열기: azavea/net-dao-csv 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
_connDesc CsvDescriptor

공개 메소드들

메소드 설명
CoerceType ( Type desiredType, object input ) : object

Overridden to handle the case of converting an empty string to a non-string datatype. It's a slow check because you have to trim, and check type, etc, which is why it isn't in the base class. But CSV files apparently frequently use "" for blank numerical values which causes the base class implementation to error out.

CsvDaLayer ( CsvDescriptor connDesc ) : System

Instantiates the data access layer with the connection descriptor for the DB.

Delete ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit ) : int

Deletes a data object record using the mapping and criteria for what's deleted.

ExecuteQuery ( ITransaction transaction, ClassMapping mapping, IDaQuery query, DataReaderDelegate invokeMe, Hashtable parameters ) : void

Executes a query and invokes a method with a DataReader of results.

GetCount ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit, ICollection groupExpressions ) : List

Gets a count of records for the given criteria, aggregated by the given grouping expressions. This matches "GROUP BY" behavior in SQL.

GetCount ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit ) : int

Gets a count of records for the given criteria.

GetLastAutoGeneratedId ( ITransaction transaction, ClassMapping mapping, string idCol ) : object

Finds the last generated id number for a column.

GetNextSequenceValue ( ITransaction transaction, string sequenceName ) : int

Gets the next id number from a sequence in the data source.

Insert ( ITransaction transaction, ClassMapping mapping, object>.IDictionary propValues ) : int

Inserts a data object record using the "table" and a list of column/value pairs.

InsertBatch ( ITransaction transaction, ClassMapping mapping, object>.List propValueDictionaries ) : void

Inserts a list of data object records of the same type.

Truncate ( ClassMapping mapping ) : void

Blanks the file, leaving nothing but the header row (if there is one).

Update ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit, object>.IDictionary propValues ) : int

Updates a data object record using the "table" and a list of column/value pairs.

UpdateBatch ( ITransaction transaction, ClassMapping mapping, List criteriaList, object>.List propValueDictionaries ) : void

Updates a list of data object records of the same type. NOTE: At the moment this just loops calling Update().

보호된 메소드들

메소드 설명
DoneWithReader ( StreamReader reader ) : void

Returns the reader for closing (or not, if we were configured with it).

DoneWithWriter ( WriterInfo info ) : void

Returns the writer for closing (or not, if we were configured with it).

GetReader ( ClassMapping mapping ) : StreamReader

Gets a valid StreamReader that can be used to read CSV data. If we were configured with a StreamReader, it may be that one. If we are accessing a file we will open a new reader. You should not close it yourself, instead you should call DoneWithReader when you are done with it.

GetWriter ( ClassMapping mapping, bool append ) : WriterInfo

Gets a valid TextWriter that can be used to output CSV data. If we were configured with a TextWriter, it may be that one. If we are accessing a file we will open a new writer. You should not close it yourself, instead you should call DoneWithWriter when you are done with it.

UseNamedColumns ( ClassMapping mapping ) : bool

Checks whether this mapping is using column indexes or named columns. If named columns, returns true (and there must be a header row). If numerically indexed columns, returns false (we assume there is not a header row).

비공개 메소드들

메소드 설명
GetFileName ( ClassMapping mapping ) : string
MakeDataRow ( ClassMapping mapping, object>.IDictionary values ) : string

Creates a new row for the CSV file. Will create blanks (",,") if using numeric indexing and the numbers are not consecutive.

MakeHeaderRow ( ClassMapping mapping ) : string

Creates the first row of the CSV file, the header row.

QuoteValue ( object val ) : string

Uses the OutputQuoteLevel on the connection descriptor plus the value itself to determine if we need to quote it, and if so quote it. Also converts the value to a string, and if it is already a string, escapes internal quotes in it.

메소드 상세

CoerceType() 공개 메소드

Overridden to handle the case of converting an empty string to a non-string datatype. It's a slow check because you have to trim, and check type, etc, which is why it isn't in the base class. But CSV files apparently frequently use "" for blank numerical values which causes the base class implementation to error out.
public CoerceType ( Type desiredType, object input ) : object
desiredType System.Type Type we need the value to be.
input object Input value, may or may not already be the right type.
리턴 object

CsvDaLayer() 공개 메소드

Instantiates the data access layer with the connection descriptor for the DB.
public CsvDaLayer ( CsvDescriptor connDesc ) : System
connDesc CsvDescriptor The connection descriptor that is being used by this FastDaoLayer.
리턴 System

Delete() 공개 메소드

Deletes a data object record using the mapping and criteria for what's deleted.
public Delete ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit ) : int
transaction ITransaction Should be null, transactions are not supported.
mapping ClassMapping The mapping of the table from which to delete.
crit Azavea.Open.DAO.Criteria.DaoCriteria Criteria for deletion. NOTE: Only the expressions are observed, /// other things (like "order" or start / limit) are ignored. /// WARNING: A null or empty (no expression) criteria will /// delete ALL records!
리턴 int

DoneWithReader() 보호된 메소드

Returns the reader for closing (or not, if we were configured with it).
protected DoneWithReader ( StreamReader reader ) : void
reader System.IO.StreamReader The StreamReader obtained from a GetReader call.
리턴 void

DoneWithWriter() 보호된 메소드

Returns the writer for closing (or not, if we were configured with it).
protected DoneWithWriter ( WriterInfo info ) : void
info WriterInfo The WriterInfo obtained from a GetWriter call.
리턴 void

ExecuteQuery() 공개 메소드

Executes a query and invokes a method with a DataReader of results.
public ExecuteQuery ( ITransaction transaction, ClassMapping mapping, IDaQuery query, DataReaderDelegate invokeMe, Hashtable parameters ) : void
transaction ITransaction Should be null, transactions are not supported.
mapping ClassMapping Class mapping for the table we're querying against. Optional, /// but not all columns may be properly typed if it is null.
query IDaQuery The query to execute, should have come from CreateQuery.
invokeMe DataReaderDelegate The method to invoke with the IDataReader results.
parameters System.Collections.Hashtable A hashtable containing any values that need to be persisted through invoked method. /// The list of objects from the query will be placed here.
리턴 void

GetCount() 공개 메소드

Gets a count of records for the given criteria, aggregated by the given grouping expressions. This matches "GROUP BY" behavior in SQL.
public GetCount ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit, ICollection groupExpressions ) : List
transaction ITransaction The transaction to do this as part of.
mapping ClassMapping The mapping of the table for which to build the query string.
crit Azavea.Open.DAO.Criteria.DaoCriteria The criteria to use for "where" comparisons.
groupExpressions ICollection The fields/expressions to aggregate on when counting.
리턴 List

GetCount() 공개 메소드

Gets a count of records for the given criteria.
public GetCount ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit ) : int
transaction ITransaction Should be null, transactions are not supported.
mapping ClassMapping The mapping of the table for which to build the query string.
crit Azavea.Open.DAO.Criteria.DaoCriteria The criteria to use for "where" comparisons.
리턴 int

GetLastAutoGeneratedId() 공개 메소드

Finds the last generated id number for a column.
public GetLastAutoGeneratedId ( ITransaction transaction, ClassMapping mapping, string idCol ) : object
transaction ITransaction Should be null, transactions are not supported.
mapping ClassMapping The class mapping for the table being queried.
idCol string The ID column for which to find the last-generated ID.
리턴 object

GetNextSequenceValue() 공개 메소드

Gets the next id number from a sequence in the data source.
public GetNextSequenceValue ( ITransaction transaction, string sequenceName ) : int
transaction ITransaction Should be null, transactions are not supported.
sequenceName string The name of the sequence.
리턴 int

GetReader() 보호된 메소드

Gets a valid StreamReader that can be used to read CSV data. If we were configured with a StreamReader, it may be that one. If we are accessing a file we will open a new reader. You should not close it yourself, instead you should call DoneWithReader when you are done with it.
protected GetReader ( ClassMapping mapping ) : StreamReader
mapping ClassMapping The mapping for the object we intend to read.
리턴 System.IO.StreamReader

GetWriter() 보호된 메소드

Gets a valid TextWriter that can be used to output CSV data. If we were configured with a TextWriter, it may be that one. If we are accessing a file we will open a new writer. You should not close it yourself, instead you should call DoneWithWriter when you are done with it.
protected GetWriter ( ClassMapping mapping, bool append ) : WriterInfo
mapping ClassMapping The mapping for the object we intend to write.
append bool Whether to append to, or overwrite, the file if it exists. /// If it does not exist, this parameter doesn't matter and a new /// file is created.
리턴 WriterInfo

Insert() 공개 메소드

Inserts a data object record using the "table" and a list of column/value pairs.
public Insert ( ITransaction transaction, ClassMapping mapping, object>.IDictionary propValues ) : int
transaction ITransaction Should be null, transactions are not supported.
mapping ClassMapping The mapping of the table or other data container we're dealing with.
propValues object>.IDictionary A dictionary of "column"/value pairs for the object to insert.
리턴 int

InsertBatch() 공개 메소드

Inserts a list of data object records of the same type.
public InsertBatch ( ITransaction transaction, ClassMapping mapping, object>.List propValueDictionaries ) : void
transaction ITransaction Should be null, transactions are not supported.
mapping ClassMapping The mapping of the table or other data container we're dealing with.
propValueDictionaries object>.List A list of dictionaries of column/value pairs. /// Each item in the list should represent the dictionary of column/value pairs for /// each respective object being inserted.
리턴 void

Truncate() 공개 메소드

Blanks the file, leaving nothing but the header row (if there is one).
public Truncate ( ClassMapping mapping ) : void
mapping ClassMapping
리턴 void

Update() 공개 메소드

Updates a data object record using the "table" and a list of column/value pairs.
public Update ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit, object>.IDictionary propValues ) : int
transaction ITransaction Should be null, transactions are not supported.
mapping ClassMapping The mapping of the table or other data container we're dealing with.
crit Azavea.Open.DAO.Criteria.DaoCriteria All records matching this criteria will be updated per the dictionary of /// values.
propValues object>.IDictionary A dictionary of column/value pairs for all non-ID columns to be updated.
리턴 int

UpdateBatch() 공개 메소드

Updates a list of data object records of the same type. NOTE: At the moment this just loops calling Update().
public UpdateBatch ( ITransaction transaction, ClassMapping mapping, List criteriaList, object>.List propValueDictionaries ) : void
transaction ITransaction Should be null, transactions are not supported.
mapping ClassMapping The mapping of the table or other data container we're dealing with.
criteriaList List A list of DaoCriteria. /// Each item in the list should represent the criteria for /// rows that will be updated per the accompanying dictionary.
propValueDictionaries object>.List A list of dictionaries of column/value pairs. /// Each item in the list should represent the dictionary of non-ID column/value pairs for /// each respective object being updated.
리턴 void

UseNamedColumns() 보호된 정적인 메소드

Checks whether this mapping is using column indexes or named columns. If named columns, returns true (and there must be a header row). If numerically indexed columns, returns false (we assume there is not a header row).
protected static UseNamedColumns ( ClassMapping mapping ) : bool
mapping ClassMapping Mapping for this file.
리턴 bool

프로퍼티 상세

_connDesc 보호되어 있는 프로퍼티

We want to treat it as a CSV descriptor rather than a generic connection descriptor.
protected CsvDescriptor,Azavea.Open.DAO.CSV _connDesc
리턴 CsvDescriptor