本文整理汇总了C++中ProjectDatabase::commitTransaction方法的典型用法代码示例。如果您正苦于以下问题:C++ ProjectDatabase::commitTransaction方法的具体用法?C++ ProjectDatabase::commitTransaction怎么用?C++ ProjectDatabase::commitTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProjectDatabase
的用法示例。
在下文中一共展示了ProjectDatabase::commitTransaction方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updatePathData
void ProjectDatabaseRecord::updatePathData(ProjectDatabase database,
const openstudio::path& originalBase,
const openstudio::path& newBase)
{
bool didStartTransaction = database.startTransaction();
ProjectDatabaseRecord record = getProjectDatabaseRecord(database);
record.getImpl<detail::ProjectDatabaseRecord_Impl>()->updatePathData(originalBase,newBase);
if (didStartTransaction) {
bool test = database.commitTransaction();
OS_ASSERT(test);
}
}
示例2: record
// Test not yet to scale re: data points.
TEST_F(ProjectFixture,Profile_SaveAnalysis) {
Analysis analysis = getAnalysisToRun(100,500);
// time the process of saving to database
ptime start = microsec_clock::local_time();
ProjectDatabase db = getCleanDatabase(toPath("./SaveAnalysis"));
ASSERT_TRUE(db.startTransaction());
AnalysisRecord record(analysis,db);
db.save();
ASSERT_TRUE(db.commitTransaction());
time_duration saveTime = microsec_clock::local_time() - start;
std::cout << "Time: " << to_simple_string(saveTime) << std::endl;
}
示例3: rubyMeasure
TEST_F(ProjectFixture, RubyMeasureRecord_RubyScript) {
// Measures
MeasureVector measures;
// Null Measure
measures.push_back(NullMeasure());
openstudio::path rubyLibDirPath = openstudio::toPath(rubyLibDir());
openstudio::path perturbScript = rubyLibDirPath/openstudio::toPath("openstudio/runmanager/rubyscripts/PerturbObject.rb");
RubyMeasure rubyMeasure(perturbScript,
FileReferenceType::OSM,
FileReferenceType::OSM);
rubyMeasure.addArgument("inputPath", "in.osm");
rubyMeasure.addArgument("outputPath", "out.osm");
rubyMeasure.addArgument("objectType", "OS:Material");
rubyMeasure.addArgument("nameRegex", "I02 50mm insulation board");
rubyMeasure.addArgument("field", "3");
rubyMeasure.addArgument("value", "0.10");
// RubyMeasure
measures.push_back(rubyMeasure);
// Variables
VariableVector variables;
variables.push_back(MeasureGroup("Wall Construction",measures));
// Workflow
openstudio::runmanager::Workflow workflow;
// Problem
Problem problem("Variable",variables,workflow);
// Save to database
{
ProjectDatabase database = getCleanDatabase("RubyMeasureRecord_RubyScript");
bool didStartTransaction = database.startTransaction();
EXPECT_TRUE(didStartTransaction);
// Problem Record
ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problem,database);
database.save();
if (didStartTransaction) {
EXPECT_TRUE(database.commitTransaction());
}
// Variable Records
InputVariableRecordVector measureGroupRecords = problemRecord.inputVariableRecords();
EXPECT_EQ(1u,measureGroupRecords.size());
// Discrete Variable Record
MeasureGroupRecord measureGroupRecord = measureGroupRecords.at(0).cast<MeasureGroupRecord>();
EXPECT_EQ(2u,measureGroupRecord.measureRecordIds(true).size());
EXPECT_EQ(2u,measureGroupRecord.measureRecords(true).size());
RubyMeasureRecord rubyMeasureRecord(rubyMeasure,measureGroupRecord,0);
EXPECT_EQ("MeasureRecords",rubyMeasureRecord.databaseTableName());
ObjectRecordVector objectRecordVector = rubyMeasureRecord.children();
EXPECT_EQ(6u,objectRecordVector.size()); // arguments
objectRecordVector = rubyMeasureRecord.resources();
EXPECT_EQ(1u,objectRecordVector.size()); // script
FileReferenceRecord scriptRecord = rubyMeasureRecord.fileReferenceRecord();
EXPECT_EQ("FileReferenceRecords",scriptRecord.databaseTableName());
Measure measure = rubyMeasureRecord.measure();
EXPECT_EQ(true,measure.isSelected());
ASSERT_TRUE(measure.optionalCast<RubyMeasure>());
RubyMeasure rubyMeasureCopy = measure.cast<RubyMeasure>();
EXPECT_FALSE(rubyMeasureCopy.usesBCLMeasure());
EXPECT_FALSE(rubyMeasureCopy.isUserScript());
EXPECT_EQ(6u,rubyMeasureCopy.arguments().size());
MeasureGroupRecord measureGroupRecordFromRuby = rubyMeasureRecord.measureGroupRecord().get();
EXPECT_EQ(measureGroupRecord.databaseTableName(),measureGroupRecordFromRuby.databaseTableName());
EXPECT_EQ(measureGroupRecord.id(),measureGroupRecordFromRuby.id());
}
// Reopen database
{
ProjectDatabase database = getExistingDatabase("RubyMeasureRecord_RubyScript");
ProblemRecordVector problemRecords = ProblemRecord::getProblemRecords(database);
ASSERT_FALSE(problemRecords.empty());
EXPECT_EQ(1u,problemRecords.size());
ProblemRecord problemRecord = problemRecords[0];
// COPY-PASTED FROM ABOVE
// Variable Records
InputVariableRecordVector measureGroupRecords = problemRecord.inputVariableRecords();
EXPECT_EQ(1u,measureGroupRecords.size());
// Discrete Variable Record
MeasureGroupRecord measureGroupRecord = measureGroupRecords.at(0).cast<MeasureGroupRecord>();
EXPECT_EQ(2u,measureGroupRecord.measureRecordIds(true).size());
EXPECT_EQ(2u,measureGroupRecord.measureRecords(true).size());
RubyMeasureRecord rubyMeasureRecord(rubyMeasure,measureGroupRecord,0);
EXPECT_EQ("MeasureRecords",rubyMeasureRecord.databaseTableName());
ObjectRecordVector objectRecordVector = rubyMeasureRecord.children();
//.........这里部分代码省略.........
示例4: problem
TEST_F(ProjectFixture, RubyMeasureRecord_BCLMeasure) {
// Construct problem with RubyMeasure that points to BCLMeasure
Problem problem("Problem",VariableVector(),runmanager::Workflow());
MeasureGroup dvar("Variable",MeasureVector());
problem.push(dvar);
openstudio::path measuresPath = resourcesPath() / toPath("/utilities/BCL/Measures");
openstudio::path dir = measuresPath / toPath("SetWindowToWallRatioByFacade");
BCLMeasure measure = BCLMeasure::load(dir).get();
RubyMeasure rpert(measure);
dvar.push(rpert);
OSArgument arg = OSArgument::makeDoubleArgument("wwr");
arg.setValue(0.4);
rpert.setArgument(arg);
arg = OSArgument::makeIntegerArgument("typo_arg");
arg.setDefaultValue(1);
rpert.setArgument(arg);
// Serialize to database
{
ProjectDatabase database = getCleanDatabase("RubyMeasureRecord_BCLMeasure");
bool didStartTransaction = database.startTransaction();
EXPECT_TRUE(didStartTransaction);
// Problem Record
ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problem,database);
database.save();
if (didStartTransaction) {
EXPECT_TRUE(database.commitTransaction());
}
}
// Re-open database, de-serialize, verify that RubyMeasure is intact.
openstudio::path tempDir1 = measuresPath / toPath(toString(createUUID()));
{
ProjectDatabase database = getExistingDatabase("RubyMeasureRecord_BCLMeasure");
ASSERT_EQ(1u,ProblemRecord::getProblemRecords(database).size());
ASSERT_EQ(1u,MeasureGroupRecord::getMeasureGroupRecords(database).size());
EXPECT_EQ(1u,RubyMeasureRecord::getRubyMeasureRecords(database).size());
MeasureRecordVector dprs = MeasureGroupRecord::getMeasureGroupRecords(database)[0].measureRecords(false);
ASSERT_EQ(1u,dprs.size());
ASSERT_TRUE(dprs[0].optionalCast<RubyMeasureRecord>());
RubyMeasureRecord rpr = dprs[0].cast<RubyMeasureRecord>();
RubyMeasure rp = rpr.rubyMeasure();
EXPECT_TRUE(rp.usesBCLMeasure());
EXPECT_TRUE(rp.measure());
EXPECT_EQ(dir,rp.measureDirectory());
EXPECT_EQ(measure.uuid(),rp.measureUUID());
EXPECT_EQ(measure.versionUUID(),rp.measureVersionUUID());
EXPECT_ANY_THROW(rp.perturbationScript());
EXPECT_EQ(2u,rp.arguments().size());
EXPECT_FALSE(rp.hasIncompleteArguments());
// Update measure and save
BCLMeasure newVersion = measure.clone(tempDir1).get();
newVersion.setDescription("Window to wall ratio with sill height configurable.");
newVersion.save();
EXPECT_NE(measure.versionUUID(),newVersion.versionUUID());
OSArgumentVector args;
args.push_back(OSArgument::makeDoubleArgument("wwr"));
args.push_back(OSArgument::makeDoubleArgument("sillHeight"));
Problem problemCopy = ProblemRecord::getProblemRecords(database)[0].problem();
problemCopy.updateMeasure(newVersion,args,false);
bool didStartTransaction = database.startTransaction();
EXPECT_TRUE(didStartTransaction);
// Problem Record
ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problemCopy,database);
database.save();
if (didStartTransaction) {
EXPECT_TRUE(database.commitTransaction());
}
}
// Re-open database, check that old argument records are gone, check that de-serialized object ok
openstudio::path tempDir2 = measuresPath / toPath(toString(createUUID()));
{
ProjectDatabase database = getExistingDatabase("RubyMeasureRecord_BCLMeasure");
ASSERT_EQ(1u,ProblemRecord::getProblemRecords(database).size());
EXPECT_EQ(1u,MeasureGroupRecord::getMeasureGroupRecords(database).size());
EXPECT_EQ(1u,RubyMeasureRecord::getRubyMeasureRecords(database).size());
EXPECT_EQ(1u,FileReferenceRecord::getFileReferenceRecords(database).size());
EXPECT_EQ(2u,OSArgumentRecord::getOSArgumentRecords(database).size());
Problem problemCopy = ProblemRecord::getProblemRecords(database)[0].problem();
InputVariableVector vars = problemCopy.variables();
ASSERT_FALSE(vars.empty());
ASSERT_TRUE(vars[0].optionalCast<MeasureGroup>());
MeasureVector dps = vars[0].cast<MeasureGroup>().measures(false);
ASSERT_FALSE(dps.empty());
ASSERT_TRUE(dps[0].optionalCast<RubyMeasure>());
RubyMeasure rp = dps[0].cast<RubyMeasure>();
EXPECT_TRUE(rp.usesBCLMeasure());
EXPECT_TRUE(rp.measure());
EXPECT_EQ(tempDir1,rp.measureDirectory());
//.........这里部分代码省略.........
示例5: analysis
TEST_F(ProjectFixture,DataPoint_DataPointRecord_Synchronization) {
// create analysis with one data point
ProjectDatabase database = getCleanDatabase("DataPoint_DataPointRecord_Synchronization");
analysis::Analysis analysis(
"Test Analysis",
analysis::Problem("Test Problem",analysis::VariableVector(),runmanager::Workflow()),
analysis::DesignOfExperiments(analysis::DesignOfExperimentsOptions(
analysis::DesignOfExperimentsType::FullFactorial)),
FileReference(toPath("in.osm")));
std::vector<QVariant> variableValues;
analysis::DataPoint original = analysis.problem().createDataPoint(variableValues).get();
analysis.addDataPoint(original);
// save analysis to database
{
bool didStartTransaction = database.startTransaction();
AnalysisRecord analysisRecord(analysis,database);
DataPointRecordVector dataPointRecords = DataPointRecord::getDataPointRecords(database);
ASSERT_EQ(1u,dataPointRecords.size());
DataPointRecord dataPointRecord = dataPointRecords[0];
EXPECT_FALSE(dataPointRecord.isComplete());
database.save();
if (didStartTransaction) {
database.commitTransaction();
}
}
// reload analysis, change data point, save back to database
// verify that change shows up in database
OptionalAnalysis loadedAnalysis;
{
AnalysisRecordVector loadedAnalysisRecords = AnalysisRecord::getAnalysisRecords(database);
ASSERT_EQ(1u,loadedAnalysisRecords.size());
loadedAnalysis = loadedAnalysisRecords[0].analysis();
analysis::DataPointVector loadedDataPoints = loadedAnalysis->dataPoints();
ASSERT_EQ(1u,loadedDataPoints.size());
loadedDataPoints[0].getImpl<analysis::detail::DataPoint_Impl>()->markComplete();
EXPECT_TRUE(loadedDataPoints[0].isComplete());
}
ASSERT_TRUE(loadedAnalysis);
{
bool didStartTransaction = database.startTransaction();
database.unloadUnusedCleanRecords();
AnalysisRecord analysisRecord(*loadedAnalysis,database);
database.save();
if (didStartTransaction) {
database.commitTransaction();
}
EXPECT_EQ(1u,AnalysisRecord::getAnalysisRecords(database).size());
DataPointRecordVector dataPointRecords = DataPointRecord::getDataPointRecords(database);
ASSERT_EQ(1u,dataPointRecords.size());
DataPointRecord dataPointRecord = dataPointRecords[0];
EXPECT_TRUE(dataPointRecord.isComplete());
}
}
示例6: analysis
TEST_F(ProjectFixture,AnalysisRecord_AddAndRemoveDataPoints) {
// create an analysis with data points, no results
Analysis analysis("My Analysis",
Problem("My Problem",VariableVector(),runmanager::Workflow()),
FileReferenceType::OSM);
Problem problem = analysis.problem();
DiscretePerturbationVector perturbations;
int pi = 1;
std::stringstream ss;
for (int i = 0; i < 3; ++i) {
perturbations.push_back(NullPerturbation());
for (int j = 0; j < 4; ++j) {
ss << "measure" << pi << ".rb";
perturbations.push_back(RubyPerturbation(toPath(ss.str()),
FileReferenceType::OSM,
FileReferenceType::OSM,true));
ss.str("");
++pi;
}
ss << "Variable " << i+1;
problem.push(DiscreteVariable(ss.str(),perturbations));
perturbations.clear();
ss.str("");
}
EXPECT_EQ(3u,analysis.problem().variables().size());
ASSERT_FALSE(problem.variables().empty());
EXPECT_EQ(5u,problem.variables()[0].cast<DiscreteVariable>().numPerturbations(true));
problem.pushResponse(
LinearFunction("Energy Use",
VariableVector(1u,OutputAttributeVariable("Energy Use","Total.Energy.Use"))));
EXPECT_EQ(1u,problem.responses().size());
std::vector<QVariant> values(3u,0);
OptionalDataPoint dataPoint = problem.createDataPoint(values);
ASSERT_TRUE(dataPoint);
bool test = analysis.addDataPoint(*dataPoint);
EXPECT_TRUE(test);
values[1] = 3;
dataPoint = problem.createDataPoint(values);
ASSERT_TRUE(dataPoint);
test = analysis.addDataPoint(*dataPoint);
EXPECT_TRUE(test);
values[0] = 1;
values[1] = 2;
values[2] = 4;
dataPoint = problem.createDataPoint(values);
ASSERT_TRUE(dataPoint);
test = analysis.addDataPoint(*dataPoint);
EXPECT_TRUE(test);
EXPECT_TRUE(analysis.isDirty());
EXPECT_TRUE(problem.isDirty());
BOOST_FOREACH(const Variable& variable, problem.variables()) {
EXPECT_TRUE(variable.isDirty());
ASSERT_TRUE(variable.optionalCast<DiscreteVariable>());
BOOST_FOREACH(const DiscretePerturbation& perturbation,variable.cast<DiscreteVariable>().perturbations(false)) {
EXPECT_TRUE(perturbation.isDirty());
}
}
BOOST_FOREACH(const Function& response, problem.responses()) {
EXPECT_TRUE(response.isDirty());
}
BOOST_FOREACH(const DataPoint& dataPoint, analysis.dataPoints()) {
EXPECT_TRUE(dataPoint.isDirty());
}
// save to database, make sure everything is there, make sure clean signal filters down
ProjectDatabase database = getCleanDatabase("AnalysisRecord_AddAndRemoveDataPoints");
{
bool transactionStarted = database.startTransaction();
EXPECT_TRUE(transactionStarted);
AnalysisRecord analysisRecord(analysis,database);
database.save();
test = database.commitTransaction();
EXPECT_TRUE(test);
EXPECT_EQ(analysis.uuid(),analysisRecord.handle());
EXPECT_EQ(analysis.versionUUID(),analysisRecord.uuidLast());
ASSERT_NO_THROW(analysisRecord.problemRecord());
ProblemRecord problemRecord = analysisRecord.problemRecord();
InputVariableRecordVector variableRecords = problemRecord.inputVariableRecords();
EXPECT_EQ(3u,variableRecords.size());
ASSERT_FALSE(variableRecords.empty());
ASSERT_TRUE(variableRecords[0].optionalCast<DiscreteVariableRecord>());
DiscretePerturbationRecordVector perturbationRecords = variableRecords[0].cast<DiscreteVariableRecord>().discretePerturbationRecords(false);
EXPECT_EQ(5u,perturbationRecords.size());
ASSERT_TRUE(perturbationRecords.size() > 1);
EXPECT_TRUE(perturbationRecords[0].optionalCast<NullPerturbationRecord>());
EXPECT_TRUE(perturbationRecords[1].optionalCast<RubyPerturbationRecord>());
EXPECT_EQ(3u,analysisRecord.dataPointRecords().size());
EXPECT_TRUE(analysisRecord.completeDataPointRecords().empty());
}
analysis.clearDirtyFlag();
EXPECT_FALSE(analysis.isDirty());
EXPECT_FALSE(problem.isDirty());
BOOST_FOREACH(const Variable& variable, problem.variables()) {
EXPECT_FALSE(variable.isDirty());
//.........这里部分代码省略.........