Пример #1
0
SQLiteObjectStorage::SQLiteObjectStorage(bool transactional, const String& pl)
 : mTransactional(transactional),
   mDBName(),
   mRetries(5),
   mBusyTimeout(1000)
{
    OptionValue*databaseFile;
    OptionValue*workQueueInstance;
    unsigned char * epoch=NULL;
    static AtomicValue<int> counter(0);
    int handle_offset=counter++;
    InitializeClassOptions("sqlite",epoch+handle_offset,
                           databaseFile=new OptionValue("databasefile","",OptionValueType<String>(),"Sets the database to be used for storage"),
                           workQueueInstance=new OptionValue("workqueue","0",OptionValueType<void*>(),"Sets the work queue to be used for disk reads to a common work queue"),NULL);
    (mOptions=OptionSet::getOptions("sqlite",epoch+handle_offset))->parse(pl);

    mDiskWorkQueue=(Task::WorkQueue*)workQueueInstance->as<void*>();
    mWorkQueueThread=NULL;
    if(mDiskWorkQueue==NULL) {
        mDiskWorkQueue=&_mLocalWorkQueue;
        mWorkQueueThread=mDiskWorkQueue->createWorkerThreads(1);
    }

    mDBName = databaseFile->as<String>();
    assert( !mDBName.empty() );

    SQLiteDBPtr db = SQLite::getSingleton().open(mDBName);
    sqlite3_busy_timeout(db->db(), mBusyTimeout);

    // Create the table for this object if it doesn't exist yet
    String table_create = "CREATE TABLE IF NOT EXISTS ";
    table_create += "\"" TABLE_NAME "\"";
    table_create += "(object TEXT, key TEXT, value TEXT, PRIMARY KEY(object, key))";

    int rc;
    char* remain;
    sqlite3_stmt* table_create_stmt;

    rc = sqlite3_prepare_v2(db->db(), table_create.c_str(), -1, &table_create_stmt, (const char**)&remain);
    SQLite::check_sql_error(db->db(), rc, NULL, "Error preparing table create statement");

    rc = sqlite3_step(table_create_stmt);
    SQLite::check_sql_error(db->db(), rc, NULL, "Error executing table create statement");
    rc = sqlite3_finalize(table_create_stmt);
    SQLite::check_sql_error(db->db(), rc, NULL, "Error finalizing table create statement");

    mDB = db;
}
Пример #2
0
ProximityConnection* SingleStreamProximityConnection::create(Network::IOService*io, const String&options){
    OptionValue*address=new OptionValue("address","localhost:6408",Network::Address("localhost","6408"),"sets the fully qualified address that runs the proximity manager.");
    OptionValue*host;
    OptionValue*port;
    OptionValue*streamlib;
    OptionValue*streamoptions;
    InitializeClassOptions("proximityconnection",address,
                           address,
                           host=new OptionValue("host","",OptionValueType<String>(),"sets the hostname that runs the proximity manager."),
                           port=new OptionValue("port","",OptionValueType<String>(),"sets the port that runs the proximity manager."),
                           streamlib=new OptionValue("protocol","",OptionValueType<String>(),"Sets the stream library to connect"),
                           streamoptions=new OptionValue("options","",OptionValueType<String>(),"Options for the created stream"),
						   NULL);
    OptionSet::getOptions("proximityconnection",address)->parse(options);
    if (host->as<String>().empty()||port->as<String>().empty()) {
        return new SingleStreamProximityConnection(address->as<Network::Address>(),*io,streamlib->as<String>(),streamoptions->as<String>());
    }
    return new SingleStreamProximityConnection(Network::Address(host->as<String>(),port->as<String>()),*io,streamlib->as<String>(),streamoptions->as<String>());

}