using System;
using System.Collections.Generic;
using Harlinn.Oracle.DBTool.Types.Projects;
using Harlinn.Oracle.DBTool.Types.CSharp;
using Oracle.DataAccess.Client;
using Harlinn.Oracle.DBTool.Generators.Utils;
namespace Harlinn.Oracle.DBTool.Generators.Reader
{
public class ReaderGenerator : GeneratorBase
{
ProjectTabular tabular;
SortedSet<string> createMethodMethods = new SortedSet<string>();
public ReaderGenerator(ProjectTabular tabular)
{
this.tabular = tabular;
}
public override string GetFilename()
{
string className = tabular.GetReaderClassName();
string directory = GetDirectory();
string result = directory + "\\" + className + ".cs";
return result;
}
public override string GetDirectory()
{
string namespace_ = Project.Current.DatabaseNamespace;
string directory = Project.Current.NamespaceToDirectory(namespace_);
return directory;
}
public void Generate()
{
string commonNamespace = Project.Current.CommonNamespace;
string dataNamespace = Project.Current.DataNamespace;
string databaseNamespace = Project.Current.DatabaseNamespace;
string className = tabular.GetReaderClassName();
string dataClassName = tabular.GetDataTypeClassName();
string dataPropertyName = tabular.GetBaseName();
string qualifiedDBName = tabular.GetQualifiedDBElementName();
WriteLine("using System;");
WriteLine("using System.Data;");
WriteLine("using System.Text;");
WriteLine("using System.ComponentModel;");
WriteLine("using System.Reflection;");
WriteLine("using Oracle.DataAccess.Client;");
WriteLine();
WriteLine();
WriteLine("using "+ commonNamespace + ";");
WriteLine("using "+ dataNamespace + ";");
WriteLine();
WriteLine("namespace " + databaseNamespace);
WriteLine("{");
WriteLine(" public partial class " + className+" : Reader");
WriteLine(" {");
WriteLine();
WriteLine(" private static readonly log4net.ILog sfLog = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);");
WriteLine();
WriteLine(" private static void LogException(Exception exc, MethodBase method)");
WriteLine(" {");
WriteLine(" " + commonNamespace + ".Logger.LogException(sfLog, exc, method);");
WriteLine(" }");
WriteLine();
List<ProjectTabularField> fields = tabular.GetFieldList();
List<ProjectTabularField> primaryKeyFields = tabular.GetPrimaryKeyFieldList();
WriteLine(" public const string DEFAULT_QUALIFIED_DBNAME = \""+qualifiedDBName+"\";");
WriteLine(" public const string FULL_SELECT = \"SELECT " + ColumnHelper.GetCommaSeparatedFieldList(fields) + " FROM {0}\";");
WriteLine(" public const string KEY_FIELDS = \"" + ColumnHelper.GetCommaSeparatedFieldList(primaryKeyFields) + "\";");
WriteLine();
for(int i = 0; i < fields.Count; i++ )
{
ProjectTabularField field = fields[i];
WriteLine(" public const int "+field.Name+" = " + i.ToString() + ";");
}
WriteLine();
if (tabular is ProjectTable)
{
ProjectTable projectTable = (ProjectTable)tabular;
if (projectTable.IsTagValue)
{
WriteLine(" private long tag;");
}
}
WriteLine();
WriteLine(" public " + className + " ( )");
WriteLine(" : base( CreateReader( DEFAULT_QUALIFIED_DBNAME ) )");
WriteLine(" {");
WriteLine(" }");
WriteLine();
WriteLine(" public " + className + " ( string qualifiedDBName )");
WriteLine(" : base( CreateReader( qualifiedDBName ) )");
WriteLine(" {");
WriteLine(" }");
WriteLine();
WriteLine(" public " + className + " ( OracleConnection oracleConnection )");
WriteLine(" : base( CreateReader( oracleConnection ) )");
WriteLine(" {");
WriteLine(" }");
WriteLine();
WriteLine(" public " + className + " ( OracleConnection oracleConnection, string qualifiedDBName )");
WriteLine(" : base( CreateReader( oracleConnection, qualifiedDBName ) )");
WriteLine(" {");
WriteLine(" }");
WriteLine();
WriteLine(" public " + className + " ( OracleDataReader reader )");
WriteLine(" : base( reader )");
WriteLine(" {");
WriteLine(" }");
WriteLine();
WriteLine();
WriteLine();
WriteLine();
WriteLine();
WriteLine(" private static OracleDataReader CreateReader( string qualifiedDBName )");
WriteLine(" {");
WriteLine(" try");
WriteLine(" {");
WriteLine(" OracleConnection oracleConnection = GetConnection();");
WriteLine(" OracleDataReader result = CreateReader(oracleConnection,qualifiedDBName);");
WriteLine(" return result;");
WriteLine(" }");
WriteLine(" catch (Exception exc)");
WriteLine(" {");
WriteLine(" LogException(exc, MethodBase.GetCurrentMethod());");
WriteLine(" throw;");
WriteLine(" }");
WriteLine(" }");
WriteLine();
WriteLine();
WriteLine(" private static OracleDataReader CreateReader( OracleConnection oracleConnection )");
WriteLine(" {");
WriteLine(" try");
WriteLine(" {");
WriteLine(" OracleDataReader result = CreateReader(oracleConnection,DEFAULT_QUALIFIED_DBNAME);");
WriteLine(" return result;");
WriteLine(" }");
WriteLine(" catch (Exception exc)");
WriteLine(" {");
WriteLine(" LogException(exc, MethodBase.GetCurrentMethod());");
WriteLine(" throw;");
WriteLine(" }");
WriteLine(" }");
WriteLine();
WriteLine();
WriteLine(" private static OracleDataReader CreateReader( OracleConnection oracleConnection, string qualifiedDBName )");
WriteLine(" {");
WriteLine(" try");
WriteLine(" {");
WriteLine(" string sql = string.Format(FULL_SELECT, qualifiedDBName) + \" ORDER BY \" + KEY_FIELDS;");
WriteLine(" OracleCommand oracleCommand = oracleConnection.CreateCommand();");
WriteLine(" using (oracleCommand)");
WriteLine(" {");
WriteLine(" oracleCommand.CommandText = sql;");
WriteLine(" OracleDataReader result = oracleCommand.ExecuteReader(CommandBehavior.SingleResult);");
WriteLine(" return result;");
WriteLine(" }");
WriteLine(" }");
WriteLine(" catch (Exception exc)");
WriteLine(" {");
WriteLine(" LogException(exc, MethodBase.GetCurrentMethod());");
WriteLine(" throw;");
WriteLine(" }");
WriteLine(" }");
WriteLine();
GenerateCreateMethods();
GenerateTagValueCreateMethods();
WriteLine();
if (tabular is ProjectTable)
{
ProjectTable projectTable = (ProjectTable)tabular;
if (projectTable.IsTagValue)
{
if (projectTable.IsTagValue)
{
WriteLine(" public long Tag");
WriteLine(" {");
WriteLine(" get");
WriteLine(" {");
WriteLine(" return tag;");
WriteLine(" }");
WriteLine(" set");
WriteLine(" {");
WriteLine(" this.tag = value;");
WriteLine(" }");
WriteLine(" }");
WriteLine();
}
}
}
WriteLine();
WriteLine();
for (int i = 0; i < fields.Count; i++)
{
ProjectTabularField field = fields[i];
string propertyType = field.PropertyType;
string propertyName = field.PropertyName;
string propertyReaderFunction = field.ReaderFunction;
if(string.IsNullOrWhiteSpace(field.Comments) == false)
{
WriteLine(" [Description(\""+field.Comments+"\")]");
}
if(string.IsNullOrWhiteSpace(field.DisplayName) == false)
{
WriteLine(" [DisplayName(\"" + field.DisplayName + "\")]");
}
WriteLine(" public " + propertyType + " " + propertyName);
WriteLine(" {");
WriteLine(" get");
WriteLine(" {");
WriteLine(" try");
WriteLine(" {");
if (field.AllowDBNull)
{
WriteLine(" if(IsDBNull(" + field.Name + ") == false)");
WriteLine(" {");
WriteLine(" " + propertyType + " result = " + TypeHelper.GetReaderConversion ( field.ReaderType, propertyType, propertyReaderFunction + "(" + field.Name + ")") + ";");
WriteLine(" return result;");
WriteLine(" }");
WriteLine(" return null;");
}
else
{
WriteLine(" " + propertyType + " result = " + TypeHelper.GetReaderConversion(field.ReaderType, propertyType, propertyReaderFunction + "(" + field.Name + ")") + ";");
WriteLine(" return result;");
}
WriteLine(" }");
WriteLine(" catch(Exception exc)");
WriteLine(" {");
WriteLine(" LogException(exc, MethodBase.GetCurrentMethod());");
WriteLine(" throw;");
WriteLine(" }");
WriteLine(" }");
WriteLine(" }");
WriteLine();
WriteLine();
}
WriteLine(" public " + dataClassName + " " + dataPropertyName);
WriteLine(" {");
WriteLine(" get");
WriteLine(" {");
WriteLine(" try");
WriteLine(" {");
string tagProperty = string.Empty;
if (tabular is ProjectTable)
{
ProjectTable projectTable = (ProjectTable)tabular;
if (projectTable.IsTagValue)
{
tagProperty = " Tag,";
}
}
if (dataPropertyName == "Tag")
{
WriteLine(" " + dataClassName + " result = " + dataClassName + ".Create(" + ColumnHelper.GetCommaSeparatedPropertyNameList(fields) + " );");
}
else
{
WriteLine(" " + dataClassName + " result = new " + dataClassName + "(" + tagProperty + ColumnHelper.GetCommaSeparatedPropertyNameList(fields) + " );");
}
if (tabular is ProjectTable)
{
ProjectTable projectTable = (ProjectTable)tabular;
ProjectTabularField concurrencyField = projectTable.GetConcurrencyField();
if (concurrencyField != null)
{
WriteLine(" result." + projectTable.ElementStatePropertyName + " = ElementState.Stored;");
}
}
WriteLine(" return result;");
WriteLine(" }");
WriteLine(" catch(Exception exc)");
WriteLine(" {");
WriteLine(" LogException(exc, MethodBase.GetCurrentMethod());");
WriteLine(" throw;");
WriteLine(" }");
WriteLine(" }");
WriteLine(" }");
WriteLine(" }");
WriteLine("}");
}
public void GenerateCreateMethods()
{
GenerateCreateByPrimaryKeyMethod();
ProjectTabularIndexes indexes = tabular.GetIndexes();
foreach(ProjectTabularIndex index in indexes.Children)
{
GenerateCreateByIndexMethod(index);
}
ProjectTabularReferences references = tabular.GetReferences();
foreach (ProjectTabularReference reference in references.Children)
{
GenerateCreateByReferenceMethod(reference);
}
}
public void GenerateCreateByPrimaryKeyMethod()
{
string className = tabular.GetReaderClassName();
ProjectTabularPrimaryKey primaryKey = tabular.GetPrimaryKey();
if (primaryKey != null)
{
string methodName = MethodNamesHelper.GetCreateReaderMethodName(primaryKey);
if (createMethodMethods.Contains(methodName))
{
return;
}
createMethodMethods.Add(methodName);
List<ProjectTabularField> argumentFields = primaryKey.GetFieldList();
string arguments = ColumnHelper.GetCommaSeparatedPropertyFieldNameList(argumentFields);
string argumentDeclaration = ColumnHelper.GetArgumentDeclarationList(argumentFields);
WriteLine(" public static " + className + " " + methodName + "( " + argumentDeclaration + ")");
WriteLine(" {");
WriteLine(" " + className + " result = " + methodName + "( GetConnection(), DEFAULT_QUALIFIED_DBNAME," + arguments + ");");
WriteLine(" return result;");
WriteLine(" }");
WriteLine();
WriteLine(" public static " + className + " " + methodName + "( OracleConnection oracleConnection ," + argumentDeclaration + ")");
WriteLine(" {");
WriteLine(" " + className + " result = " + methodName + "( oracleConnection, DEFAULT_QUALIFIED_DBNAME," + arguments + ");");
WriteLine(" return result;");
WriteLine(" }");
WriteLine();
WriteLine(" public static " + className + " " + methodName + "( string qualifiedDBName, " + argumentDeclaration + ")");
WriteLine(" {");
WriteLine(" " + className + " result = " + methodName + "( GetConnection(), qualifiedDBName," + arguments + ");");
WriteLine(" return result;");
WriteLine(" }");
WriteLine();
WriteLine(" public static " + className + " " + methodName + "( OracleConnection oracleConnection ,string qualifiedDBName, " + argumentDeclaration + ")");
WriteLine(" {");
WriteLine(" try");
WriteLine(" {");
WriteLine(" string fullSelect = string.Format(FULL_SELECT, qualifiedDBName);");
WriteLine(" OracleCommand oracleCommand = oracleConnection.CreateCommand();");
WriteLine(" using (oracleCommand)");
WriteLine(" {");
WriteLine(" oracleCommand.BindByName = true;");
WriteLine(OracleSqlSelectHelper.GetWhereCriteriaStatement(argumentFields, " "));
WriteLine(" string selectStatement = fullSelect + queryFilter;");
WriteLine(" oracleCommand.CommandText = selectStatement;");
WriteLine();
WriteLine(OracleSqlSelectHelper.GetParameterDeclarationsForWhereCriteriaStatement(argumentFields, " "));
WriteLine(" OracleDataReader result = oracleCommand.ExecuteReader(CommandBehavior.SingleResult);");
WriteLine(" return new " + className + "( result );");
WriteLine(" }");
WriteLine(" }");
WriteLine(" catch (Exception exc)");
WriteLine(" {");
WriteLine(" LogException(exc, MethodBase.GetCurrentMethod());");
WriteLine(" throw;");
WriteLine(" }");
WriteLine(" }");
WriteLine();
WriteLine();
}
}
public void GenerateCreateByIndexMethod(ProjectTabularIndex index)
{
string className = tabular.GetReaderClassName();
if (index != null)
{
string methodName = MethodNamesHelper.GetCreateReaderMethodName(index);
if (createMethodMethods.Contains(methodName))
{
return;
}
createMethodMethods.Add(methodName);
List<ProjectTabularField> argumentFields = index.GetFieldList();
string arguments = ColumnHelper.GetCommaSeparatedPropertyFieldNameList(argumentFields);
string argumentDeclaration = ColumnHelper.GetArgumentDeclarationList(argumentFields);
WriteLine(" public static " + className + " " + methodName + "( " + argumentDeclaration + ")");
WriteLine(" {");
WriteLine(" " + className + " result = " + methodName + "( GetConnection(), DEFAULT_QUALIFIED_DBNAME," + arguments + ");");
WriteLine(" return result;");
WriteLine(" }");
WriteLine();
WriteLine(" public static " + className + " " + methodName + "( OracleConnection oracleConnection, " + argumentDeclaration + ")");
WriteLine(" {");
WriteLine(" " + className + " result = " + methodName + "( oracleConnection, DEFAULT_QUALIFIED_DBNAME," + arguments + ");");
WriteLine(" return result;");
WriteLine(" }");
WriteLine();
WriteLine(" public static " + className + " " + methodName + "( string qualifiedDBName, " + argumentDeclaration + ")");
WriteLine(" {");
WriteLine(" " + className + " result = " + methodName + "( GetConnection(), qualifiedDBName," + arguments + ");");
WriteLine(" return result;");
WriteLine(" }");
WriteLine();
WriteLine(" public static " + className + " " + methodName + "( OracleConnection oracleConnection, string qualifiedDBName," + argumentDeclaration + ")");
WriteLine(" {");
WriteLine(" try");
WriteLine(" {");
WriteLine(" string fullSelect = string.Format(FULL_SELECT, qualifiedDBName);");
WriteLine(" OracleCommand oracleCommand = oracleConnection.CreateCommand();");
WriteLine(" using (oracleCommand)");
WriteLine(" {");
WriteLine(" oracleCommand.BindByName = true;");
WriteLine(OracleSqlSelectHelper.GetWhereCriteriaStatement(argumentFields, " "));
WriteLine(" string selectStatement = fullSelect + queryFilter;");
WriteLine(" oracleCommand.CommandText = selectStatement;");
WriteLine();
WriteLine(OracleSqlSelectHelper.GetParameterDeclarationsForWhereCriteriaStatement(argumentFields, " "));
WriteLine(" OracleDataReader result = oracleCommand.ExecuteReader(CommandBehavior.SingleResult);");
WriteLine(" return new " + className + "( result );");
WriteLine(" }");
WriteLine(" }");
WriteLine(" catch (Exception exc)");
WriteLine(" {");
WriteLine(" LogException(exc, MethodBase.GetCurrentMethod());");
WriteLine(" throw;");
WriteLine(" }");
WriteLine(" }");
WriteLine();
WriteLine();
if (tabular is ProjectTable)
{
ProjectTable projectTable = (ProjectTable)tabular;
if ((projectTable.IsTimeSeries)&&(projectTable.IsTagValue == false))
{
methodName = MethodNamesHelper.GetCreateReaderForTimeStampMethodName(index);
if (createMethodMethods.Contains(methodName))
{
return;
}
createMethodMethods.Add(methodName);
WriteLine(" public static " + className + " " + methodName + "( " + argumentDeclaration + ")");
WriteLine(" {");
WriteLine(" " + className + " result = " + methodName + "( GetConnection(), DEFAULT_QUALIFIED_DBNAME," + arguments + ");");
WriteLine(" return result;");
WriteLine(" }");
WriteLine();
WriteLine(" public static " + className + " " + methodName + "( OracleConnection oracleConnection, " + argumentDeclaration + ")");
WriteLine(" {");
WriteLine(" " + className + " result = " + methodName + "( oracleConnection, DEFAULT_QUALIFIED_DBNAME," + arguments + ");");
WriteLine(" return result;");
WriteLine(" }");
WriteLine();
WriteLine(" public static " + className + " " + methodName + "( string qualifiedDBName, " + argumentDeclaration + ")");
WriteLine(" {");
WriteLine(" " + className + " result = " + methodName + "( GetConnection(), qualifiedDBName," + arguments + ");");
WriteLine(" return result;");
WriteLine(" }");
WriteLine();
WriteLine(" public static " + className + " " + methodName + "( OracleConnection oracleConnection, string qualifiedDBName," + argumentDeclaration + ")");
WriteLine(" {");
WriteLine(" try");
WriteLine(" {");
WriteLine(" OracleCommand oracleCommand = oracleConnection.CreateCommand();");
WriteLine(" using (oracleCommand)");
WriteLine(" {");
WriteLine(" oracleCommand.BindByName = true;");
WriteLine(OracleSqlSelectHelper.GetWhereCriteriaStatementForTimeStamp(argumentFields, " "));
WriteLine(" string selectStatement = string.Format( FULL_SELECT + queryFilter, qualifiedDBName);");
WriteLine(" oracleCommand.CommandText = selectStatement;");
WriteLine();
WriteLine(OracleSqlSelectHelper.GetParameterDeclarationsForWhereCriteriaStatement(argumentFields, " "));
WriteLine(" OracleDataReader result = oracleCommand.ExecuteReader(CommandBehavior.SingleResult);");
WriteLine(" return new " + className + "( result );");
WriteLine(" }");
WriteLine(" }");
WriteLine(" catch (Exception exc)");
WriteLine(" {");
WriteLine(" LogException(exc, MethodBase.GetCurrentMethod());");
WriteLine(" throw;");
WriteLine(" }");
WriteLine(" }");
WriteLine();
WriteLine();
}
}
}
}
public void GenerateCreateByReferenceMethod(ProjectTabularReference reference)
{
string className = tabular.GetReaderClassName();
if (reference != null)
{
string methodName = MethodNamesHelper.GetCreateReaderMethodName(reference);
if (createMethodMethods.Contains(methodName))
{
return;
}
createMethodMethods.Add(methodName);
List<ProjectTabularField> argumentFields = reference.GetFieldList();
string arguments = ColumnHelper.GetCommaSeparatedPropertyFieldNameList(argumentFields);
string argumentDeclaration = ColumnHelper.GetArgumentDeclarationList(argumentFields);
WriteLine(" public static " + className + " " + methodName + "( " + argumentDeclaration + ")");
WriteLine(" {");
WriteLine(" " + className + " result = " + methodName + "( DEFAULT_QUALIFIED_DBNAME," + arguments + ");");
WriteLine(" return result;");
WriteLine(" }");
WriteLine();
WriteLine(" public static " + className + " " + methodName + "( string qualifiedDBName," + argumentDeclaration + ")");
WriteLine(" {");
WriteLine(" try");
WriteLine(" {");
WriteLine(" string fullSelect = string.Format(FULL_SELECT, qualifiedDBName);");
WriteLine(" OracleConnection oracleConnection = GetConnection();");
WriteLine(" OracleCommand oracleCommand = oracleConnection.CreateCommand();");
WriteLine(" using (oracleCommand)");
WriteLine(" {");
WriteLine(" oracleCommand.BindByName = true;");
WriteLine(OracleSqlSelectHelper.GetWhereCriteriaStatement(argumentFields, " "));
WriteLine(" string selectStatement = fullSelect + queryFilter + \" ORDER BY \" + KEY_FIELDS;");
WriteLine(" oracleCommand.CommandText = selectStatement;");
WriteLine();
WriteLine(OracleSqlSelectHelper.GetParameterDeclarationsForWhereCriteriaStatement(argumentFields, " "));
WriteLine(" OracleDataReader result = oracleCommand.ExecuteReader(CommandBehavior.SingleResult);");
WriteLine(" return new " + className + "( result );");
WriteLine(" }");
WriteLine(" }");
WriteLine(" catch (Exception exc)");
WriteLine(" {");
WriteLine(" LogException(exc, MethodBase.GetCurrentMethod());");
WriteLine(" throw;");
WriteLine(" }");
WriteLine(" }");
WriteLine();
WriteLine();
}
}
private void GenerateTagValueCreateMethods()
{
if (tabular is ProjectTable)
{
ProjectTable projectTable = (ProjectTable)tabular;
if (projectTable.IsTagValue)
{
string className = tabular.GetReaderClassName();
string methodName = "Create" + tabular.GetBaseName() + "ForTimeStamp";
WriteLine(" public static " + className + " " + methodName + "( OracleConnection oracleConnection, string qualifiedDBName, DateTime ts )");
WriteLine(" {");
WriteLine(" try");
WriteLine(" {");
WriteLine(" string fullSelect = string.Format(FULL_SELECT, qualifiedDBName);");
WriteLine(" string queryFilter = string.Format(\" WHERE TS = (SELECT MAX(TS) FROM {0} WHERE TS <= :timeStamp_ )\", qualifiedDBName);");
WriteLine(" OracleCommand oracleCommand = oracleConnection.CreateCommand();");
WriteLine(" using (oracleCommand)");
WriteLine(" {");
WriteLine(" oracleCommand.BindByName = true;");
WriteLine(" string selectStatement = fullSelect + queryFilter;");
WriteLine(" oracleCommand.CommandText = selectStatement;");
WriteLine();
WriteLine(" oracleCommand.Parameters.Add(\":timeStamp_\", OracleDbType.Decimal).Value = ts.ToUniversalTime().Ticks;");
WriteLine();
WriteLine(" OracleDataReader result = oracleCommand.ExecuteReader(CommandBehavior.SingleResult);");
WriteLine(" return new " + className + "( result );");
WriteLine(" }");
WriteLine(" }");
WriteLine(" catch (Exception exc)");
WriteLine(" {");
WriteLine(" LogException(exc, MethodBase.GetCurrentMethod());");
WriteLine(" throw;");
WriteLine(" }");
WriteLine(" }");
WriteLine();
methodName = "Create" + tabular.GetBaseName() + "ForLastTimeStamp";
WriteLine(" public static " + className + " " + methodName + "( OracleConnection oracleConnection, string qualifiedDBName )");
WriteLine(" {");
WriteLine(" try");
WriteLine(" {");
WriteLine(" string fullSelect = string.Format(FULL_SELECT, qualifiedDBName);");
WriteLine(" string queryFilter = string.Format(\" WHERE TS = ( SELECT MAX(TS) FROM {0} )\", qualifiedDBName);");
WriteLine(" OracleCommand oracleCommand = oracleConnection.CreateCommand();");
WriteLine(" using (oracleCommand)");
WriteLine(" {");
WriteLine(" oracleCommand.BindByName = true;");
WriteLine(" string selectStatement = fullSelect + queryFilter;");
WriteLine(" oracleCommand.CommandText = selectStatement;");
WriteLine();
WriteLine(" OracleDataReader result = oracleCommand.ExecuteReader(CommandBehavior.SingleResult);");
WriteLine(" return new " + className + "( result );");
WriteLine(" }");
WriteLine(" }");
WriteLine(" catch (Exception exc)");
WriteLine(" {");
WriteLine(" LogException(exc, MethodBase.GetCurrentMethod());");
WriteLine(" throw;");
WriteLine(" }");
WriteLine(" }");
WriteLine();
methodName = "Create" + tabular.GetBaseName() + "ForInterval";
WriteLine(" public static " + className + " " + methodName + "( OracleConnection oracleConnection, string qualifiedDBName, DateTime startOfInterval, DateTime endOfInterval )");
WriteLine(" {");
WriteLine(" try");
WriteLine(" {");
WriteLine(" string fullSelect = string.Format(FULL_SELECT, qualifiedDBName);");
WriteLine(" string queryFilter = string.Format(\" WHERE TS BETWEEN ( SELECT MAX(TS) FROM {0} WHERE TS <= :startTimeStamp ) AND ( SELECT MAX(TS) FROM {0} WHERE TS <= :endTimeStamp )\", qualifiedDBName) + \" ORDER BY \" + KEY_FIELDS;");
WriteLine(" OracleCommand oracleCommand = oracleConnection.CreateCommand();");
WriteLine(" using (oracleCommand)");
WriteLine(" {");
WriteLine(" oracleCommand.BindByName = true;");
WriteLine(" string selectStatement = fullSelect + queryFilter;");
WriteLine(" oracleCommand.CommandText = selectStatement;");
WriteLine();
WriteLine(" oracleCommand.Parameters.Add(\":startTimeStamp\", OracleDbType.Decimal).Value = startOfInterval.ToUniversalTime().Ticks;");
WriteLine(" oracleCommand.Parameters.Add(\":endTimeStamp\", OracleDbType.Decimal).Value = endOfInterval.ToUniversalTime().Ticks;");
WriteLine();
WriteLine(" OracleDataReader result = oracleCommand.ExecuteReader(CommandBehavior.SingleResult);");
WriteLine(" return new " + className + "( result );");
WriteLine(" }");
WriteLine(" }");
WriteLine(" catch (Exception exc)");
WriteLine(" {");
WriteLine(" LogException(exc, MethodBase.GetCurrentMethod());");
WriteLine(" throw;");
WriteLine(" }");
WriteLine(" }");
WriteLine();
WriteLine();
}
}
}
}
}