Esempio n. 1
0
 public function testBug45771()
 {
     $data_factory = SDO_DAS_DataFactory::getDataFactory();
     $data_factory->addType(DAS_NAMESPACE, DAS_ROOT_TYPE);
     $data_factory->addPropertyToType(DAS_NAMESPACE, DAS_ROOT_TYPE, 'cs', SDO_TYPE_NAMESPACE_URI, 'ChangeSummary');
     $data_factory->addType(APP_NAMESPACE, 'company');
     $data_factory->addType(APP_NAMESPACE, 'department');
     // add company to the root type
     $data_factory->addPropertyToType(DAS_NAMESPACE, DAS_ROOT_TYPE, 'company', APP_NAMESPACE, 'company', array('many' => true));
     $data_factory->addPropertyToType(APP_NAMESPACE, 'company', 'name', SDO_TYPE_NAMESPACE_URI, 'String');
     $data_factory->addPropertyToType(APP_NAMESPACE, 'company', 'department', APP_NAMESPACE, 'department', array('many' => true));
     $data_factory->addPropertyToType(APP_NAMESPACE, 'department', 'name', SDO_TYPE_NAMESPACE_URI, 'String');
     $data_factory->addPropertyToType(APP_NAMESPACE, 'department', 'location', SDO_TYPE_NAMESPACE_URI, 'String');
     $data_factory->addPropertyToType(APP_NAMESPACE, 'department', 'postcode', SDO_TYPE_NAMESPACE_URI, 'String');
     $root = $data_factory->create(DAS_NAMESPACE, DAS_ROOT_TYPE);
     $acme = $root->createDataObject('company');
     $shoe = $acme->createDataObject('department');
     $shoe->name = 'Shoe';
     $shoe->location = null;
     $root->getChangeSummary()->beginLogging();
     $shoe->name = null;
     $shoe->location = 'A-block';
     $shoe->postcode = 'SO21 2JN';
     $change_summary = $root->getChangeSummary();
     $changed_data_objects = $change_summary->getChangedDataObjects();
     $this->assertEquals(1, $changed_data_objects->count(), 'Wrong number of changed objects');
     $settings = $change_summary->getOldValues($changed_data_objects[0]);
     $this->assertEquals(3, $settings->count(), 'Wrong number of old values');
     $this->assertTrue($settings[0]->isset(), 'Incorrect isset flag when new value is null');
     $this->assertEquals('Shoe', $settings[0]->getValue(), 'Wrong old value when new value is null');
     $this->assertTrue($settings[1]->isset(), 'Incorrect isset flag when old value is null');
     $this->assertNull($settings[1]->getValue(), 'Wrong old value when old value is null');
     // tracker 46236
     $this->assertFalse($settings[2]->isset(), 'Incorrect isset flag when old value is unset');
 }
Esempio n. 2
0
File: Proxy.php Progetto: psagi/sdo
 /**
  * Constructor for simpledb Proxy
  * Use the values from the configuration file provided to create a PDO for the database
  * Query the database to obtain column metadata and primary key
  *
  * @param string $target                     Target
  * @param string $immediate_caller_directory Directory
  * @param string $binding_config             Config
  */
 public function __construct($target, $immediate_caller_directory, $binding_config)
 {
     SCA::$logger->log('Entering constructor');
     try {
         $this->table = $target;
         $this->config = SCA_Helper::mergeBindingIniAndConfig($binding_config, $immediate_caller_directory);
         if (array_key_exists('username', $this->config)) {
             $username = $this->config['username'];
         } else {
             $username = null;
         }
         if (array_key_exists('password', $this->config)) {
             $password = $this->config['password'];
         } else {
             $password = null;
         }
         if (array_key_exists('namespace', $this->config)) {
             $this->namespace = $this->config['namespace'];
         }
         if (array_key_exists('case', $this->config)) {
             $this->case = $this->config['case'];
         } else {
             $this->case = 'lower';
         }
         if (!array_key_exists('dsn', $this->config)) {
             throw new SCA_RuntimeException("Data source name should be specified");
         }
         $tableName = $this->table;
         // Special processing for IBM databases:
         // IBM table names can contain schema name as prefix
         // Column metadata returned by pdo_ibm does not specify the primary key
         // Hence primary key for IBM databases has to be obtained using
         // db2_primary_key.
         if (strpos($this->config["dsn"], "ibm:") === 0 || strpos($this->config["dsn"], "IBM:") === 0) {
             $this->isIBM = true;
             // Table could be of format schemaName.tableName
             $schemaName = null;
             if (($pos = strrpos($tableName, '.')) !== false) {
                 $schemaName = substr($tableName, 0, $pos);
                 $tableName = substr($tableName, $pos + 1);
             }
             // DSN for IBM databases can be a database name or a connection string
             // Both can be passed onto db2_connect. Remove the dsn prefix if specified
             $database = substr($this->config["dsn"], 4);
             if (strpos($database, "dsn=") === 0 || strpos($database, "DSN=") === 0) {
                 $database = substr($database, 4);
             }
             // Need to make sure the name is in DB2 uppercase style
             $db2TableName = strtoupper($tableName);
             $conn = db2_connect($database, $username, $password);
             $stmt = db2_primary_keys($conn, null, $schemaName, $db2TableName);
             $keys = db2_fetch_array($stmt);
             if (count($keys) > 3) {
                 $this->primary_key = $keys[3];
             } else {
                 throw new SCA_RuntimeException("Table '{$tableName}' does not appear to have a primary key.");
             }
         }
         $this->table_name = $this->_getName($tableName);
         if ($username != null) {
             $this->pdo = new PDO($this->config["dsn"], $username, $password, $this->config);
         } else {
             $this->pdo = new PDO($this->config["dsn"]);
         }
         $this->pdo_driver = $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
         $stmt = $this->pdo->prepare('SELECT * FROM ' . $this->table);
         if (!$stmt->execute()) {
             throw new SCA_RuntimeException(self::_getPDOError($stmt, "select"));
         }
         $columns = array();
         for ($i = 0; $i < $stmt->columnCount(); $i++) {
             $meta = $stmt->getColumnMeta($i);
             $name = $this->_getName($meta["name"]);
             if (in_array("primary_key", $meta["flags"], true)) {
                 $this->primary_key = $name;
             }
             $columns[] = $name;
         }
         //$pk = $this->_getName($this->primary_key);
         SCA::$logger->log("Table {$tableName} PrimaryKey {$this->primary_key}");
         /*
         $metadata = array(
         'name' => $this->table_name,
         'columns' => $columns,
         'PK' => $pk
         );
         */
         $this->datafactory = SDO_DAS_DataFactory::getDataFactory();
         // Define the model on the data factory (from the database)
         $this->datafactory->addType(SCA_Bindings_simpledb_Proxy::ROOT_NS, SCA_Bindings_simpledb_Proxy::ROOT_TYPE);
         $this->datafactory->addType($this->namespace, $this->table_name);
         foreach ($columns as $name) {
             $this->datafactory->addPropertyToType($this->namespace, $this->table_name, $name, 'commonj.sdo', 'String');
         }
         $this->datafactory->addPropertyToType(SCA_Bindings_simpledb_Proxy::ROOT_NS, SCA_Bindings_simpledb_Proxy::ROOT_TYPE, $this->table_name, $this->namespace, $this->table_name, array('many' => true));
     } catch (Exception $e) {
         throw new SCA_RuntimeException($e->getMessage());
     }
     SCA::$logger->log("Exiting constructor");
 }
Esempio n. 3
0
File: Das.php Progetto: psagi/sdo
 /**
  * Builds a SDO_DAS_DataFactory containing a single generic open type
  * This is required when converting XMLRPC types into an SDO. As XMLRPC provides
  * no schema for the data we are going to read so this is the most basic
  * generic type model.
  */
 public function __construct()
 {
     $this->data_factory = SDO_DAS_DataFactory::getDataFactory();
     $this->data_factory->addType($this->default_namespace, 'GenericType', array('open' => true));
 }
Esempio n. 4
0
File: Json.php Progetto: psagi/sdo
 /**
  * Take a PHP Object and convert it into an SDO
  */
 public function decodeFromPHPObject($json, $root_type = null, $root_namespace = null)
 {
     // copy the rpc elements into an SDO object. We force any
     // top level object here to be an SDO object on the assumption
     // that we will not be passed fragments of JSON. I.e. $jason_string
     // will always start with '{' and end with '}'
     $sdo = null;
     // guess the namespace if one is not provided
     if ($root_namespace == null) {
         $root_namespace = $this->default_namespace;
     }
     // currently do a different parse if types have specified
     // compared to the generic parse we started with
     // just want to keep the code separate while we move toward
     // the newer type driven parse.
     if ($this->is_smd_model == true && $root_type != null) {
         // walk the jason tree creating the correct types based
         // on the model from the specified root type down
         $sdo = $this->data_factory->create($root_namespace, $root_type);
         $this->_decodeObjectToSDONew($json, $sdo);
     } else {
         if ($this->is_xsd_model == true && $root_type != null) {
             // walk the jason tree creating the correct types based
             // on the model from the specified root type down
             $sdo = $this->xml_das->createDataObject($root_namespace, $root_type);
             $this->_decodeObjectToSDONew($json, $sdo);
         } else {
             // either there is no model or there is no root type
             // so we need to create a generic model
             $this->is_generic_model = true;
             if ($this->data_factory == null) {
                 // create an empty data factory
                 $this->data_factory = SDO_DAS_DataFactory::getDataFactory();
                 // first parse the incomming JSON message to construct
                 // a type hierarchy.
                 // TODO - I'm cheating here by just using a generic type
                 //        for now
                 $this->data_factory->addType('GenericNS', 'GenericType', array('open' => true));
             }
             // parse the JSON message using this type hierarchy
             $sdo = $this->data_factory->create('GenericNS', 'GenericType');
             $this->_decodeObjectToSDO($json, $sdo);
         }
     }
     return $sdo;
 }
Esempio n. 5
0
 public function __construct($database_metadata, $application_root_type = null, $containment_references_metadata = null)
 {
     if ($database_metadata == null) {
         throw new SDO_DAS_Relational_Exception('Database metadata (first argument to constructor) must not be null');
     }
     if ($containment_references_metadata == null) {
         $containment_references_metadata = array();
     }
     $this->database_model = new SDO_DAS_Relational_DatabaseModel($database_metadata);
     /*
             if ($application_root_type == null) {
                 $all_tables_names = $this->database_model->getAllTableNames();
                 if (count($all_tables_names) == 1) {
                     $application_root_type = $all_tables_names[0];
                 } else {
                     throw new SDO_DAS_Relational_Exception('Application root type (second argument to constructor) can only be null when there is exactly one table in the database metadata');
                 }
             }
     */
     $this->application_root_type = $application_root_type;
     $this->containment_references_model = new SDO_DAS_Relational_ContainmentReferencesModel($application_root_type, $containment_references_metadata, $this->database_model);
     $this->object_model = new SDO_DAS_Relational_ObjectModel($this->database_model, $this->containment_references_model);
     $this->data_factory = SDO_DAS_DataFactory::getDataFactory();
     $this->object_model->defineToSDO($this->data_factory);
 }