Author: ts
Date: Mon Jan 28 16:50:37 2008
New Revision: 7251
Log:
- Started implementation of enhancement #10151 (Improved Database and
PersistentObject datatype support).
Modified:
trunk/PersistentObject/src/object/persistent_object_id_property.php
trunk/PersistentObject/src/object/persistent_object_property.php
trunk/PersistentObject/tests/object_id_property_test.php
trunk/PersistentObject/tests/object_property_test.php
Modified: trunk/PersistentObject/src/object/persistent_object_id_property.php
==============================================================================
--- trunk/PersistentObject/src/object/persistent_object_id_property.php
[iso-8859-1] (original)
+++ trunk/PersistentObject/src/object/persistent_object_id_property.php
[iso-8859-1] Mon Jan 28 16:50:37 2008
@@ -29,6 +29,12 @@
* - ezcPersistentSequenceGenerator
* - ezcPersistentManualGenerator
* - ezcPersistentNativeGenerator
+ * @property int $databaseType
+ * Type of the database column, as defined by PDO constants: [EMAIL
PROTECTED]
+ * PDO::PARAM_BOOL}, [EMAIL PROTECTED] PDO::PARAM_INT}, [EMAIL
PROTECTED] PDO::PARAM_STR}
+ * (default as defined by [EMAIL PROTECTED] ezcQuery::bindValue()})
or [EMAIL PROTECTED]
+ * PDO::PARAM_LOB} (important for binary data).
+ *
* @package PersistentObject
* @version //autogen//
*/
@@ -44,6 +50,7 @@
'propertyType' => ezcPersistentObjectProperty::PHP_TYPE_INT,
'generator' => null,
'visibility' => null,
+ 'databaseType' => PDO::PARAM_STR,
);
/**
@@ -55,17 +62,21 @@
* @param ezcPersistentGeneratorDefinition $generator Definition of the
identifier generator
* @param int $propertyType See [EMAIL PROTECTED]
ezcPersistentObjectProperty} for possible values.
*/
- public function __construct( $columnName = null,
- $propertyName = null,
- $visibility = null,
- ezcPersistentGeneratorDefinition $generator =
null,
- $propertyType =
ezcPersistentObjectProperty::PHP_TYPE_INT )
+ public function __construct(
+ $columnName = null,
+ $propertyName = null,
+ $visibility = null,
+ ezcPersistentGeneratorDefinition $generator = null,
+ $propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT,
+ $databaseType = PDO::PARAM_STR
+ )
{
$this->columnName = $columnName;
$this->propertyName = $propertyName;
$this->visibility = $visibility;
$this->generator = $generator;
$this->propertyType = $propertyType;
+ $this->databaseType = $databaseType;
}
/**
@@ -135,6 +146,16 @@
);
}
break;
+ case 'databaseType':
+ if ( $propertyValue !== PDO::PARAM_STR && $propertyValue !==
PDO::PARAM_LOB && $propertyValue !== PDO::PARAM_INT && PDO::PARAM_BOOL )
+ {
+ throw new ezcBaseValueException(
+ $propertyName,
+ $propertyValue,
+ 'PDO::PARAM_STR, PDO::PARAM_LOB, PDO::PARAM_INT or
PDO::PARAM_BOOL'
+ );
+ }
+ break;
default:
throw new ezcBasePropertyNotFoundException( $propertyName );
break;
@@ -171,17 +192,23 @@
{
if ( isset( $array['properties'] ) && count( $array ) === 1 )
{
- return new ezcPersistentObjectIdProperty(
$array['properties']['columnName'],
-
$array['properties']['propertyName'],
-
$array['properties']['visibility'],
-
$array['properties']['generator'] );
+ return new ezcPersistentObjectIdProperty(
+ $array['properties']['columnName'],
+ $array['properties']['propertyName'],
+ $array['properties']['visibility'],
+ $array['properties']['generator'],
+ ( isset( $array['properties']['databaseType'] ) ?
$array['properties']['databaseType'] : PDO::PARAM_STR )
+ );
}
else
{
- return new ezcPersistentObjectIdProperty( $array['columnName'],
- $array['propertyName'],
- $array['visibility'],
- $array['generator'] );
+ return new ezcPersistentObjectIdProperty(
+ $array['columnName'],
+ $array['propertyName'],
+ $array['visibility'],
+ $array['generator'],
+ ( isset( $array['databaseType'] ) ? $array['databaseType'] :
PDO::PARAM_STR )
+ );
}
}
}
Modified: trunk/PersistentObject/src/object/persistent_object_property.php
==============================================================================
--- trunk/PersistentObject/src/object/persistent_object_property.php
[iso-8859-1] (original)
+++ trunk/PersistentObject/src/object/persistent_object_property.php
[iso-8859-1] Mon Jan 28 16:50:37 2008
@@ -27,6 +27,11 @@
* @property ezcPersistentPropertyConverter|null $converter
* A converter object that will automatically perform converters on
* load and save of a property value.
+ * @property int $databaseType
+ * Type of the database column, as defined by PDO constants: [EMAIL
PROTECTED]
+ * PDO::PARAM_BOOL}, [EMAIL PROTECTED] PDO::PARAM_INT}, [EMAIL
PROTECTED] PDO::PARAM_STR}
+ * (default as defined by [EMAIL PROTECTED] ezcQuery::bindValue()})
or [EMAIL PROTECTED]
+ * PDO::PARAM_LOB} (important for binary data).
*
* @package PersistentObject
* @version //autogen//
@@ -50,6 +55,7 @@
'propertyName' => null,
'propertyType' => self::PHP_TYPE_STRING,
'converter' => null,
+ 'databaseType' => PDO::PARAM_STR,
);
/**
@@ -65,15 +71,19 @@
* @param string $propertyName
* @param int $type
*/
- public function __construct( $columnName = null,
- $propertyName = null,
- $type = self::PHP_TYPE_STRING,
- $converter = null )
+ public function __construct(
+ $columnName = null,
+ $propertyName = null,
+ $type = self::PHP_TYPE_STRING,
+ $converter = null,
+ $databaseType = PDO::PARAM_STR
+ )
{
$this->columnName = $columnName;
$this->propertyName = $propertyName;
$this->propertyType = $type;
$this->converter = $converter;
+ $this->databaseType = $databaseType;
}
/**
@@ -93,18 +103,24 @@
{
if ( isset( $array['properties'] ) )
{
- return new ezcPersistentObjectProperty(
$array['properties']['columnName'],
-
$array['properties']['propertyName'],
-
$array['properties']['propertyType'],
- ( isset(
$array['properties']['converter'] ) ? $array['properties']['converter'] : null
) );
+ return new ezcPersistentObjectProperty(
+ $array['properties']['columnName'],
+ $array['properties']['propertyName'],
+ $array['properties']['propertyType'],
+ ( isset( $array['properties']['converter'] ) ?
$array['properties']['converter'] : null ),
+ ( isset( $array['properties']['databaseType'] ) ?
$array['properties']['databaseType'] : PDO::PARAM_STR )
+ );
}
else
{
// Old style exports
- return new ezcPersistentObjectProperty( $array['columnName'],
- $array['propertyName'],
- $array['propertyType'],
- ( isset(
$array['converter'] ) ? $array['converter'] : null ) );
+ return new ezcPersistentObjectProperty(
+ $array['columnName'],
+ $array['propertyName'],
+ $array['propertyType'],
+ ( isset( $array['converter'] ) ? $array['converter'] : null ),
+ ( isset( $array['databaseType'] ) ? $array['databaseType'] :
PDO::PARAM_STR )
+ );
}
}
@@ -174,6 +190,16 @@
);
}
break;
+ case 'databaseType':
+ if ( $propertyValue !== PDO::PARAM_STR && $propertyValue !==
PDO::PARAM_LOB && $propertyValue !== PDO::PARAM_INT && PDO::PARAM_BOOL )
+ {
+ throw new ezcBaseValueException(
+ $propertyName,
+ $propertyValue,
+ 'PDO::PARAM_STR, PDO::PARAM_LOB, PDO::PARAM_INT or
PDO::PARAM_BOOL'
+ );
+ }
+ break;
default:
throw new ezcBasePropertyNotFoundException( $propertyName );
break;
Modified: trunk/PersistentObject/tests/object_id_property_test.php
==============================================================================
--- trunk/PersistentObject/tests/object_id_property_test.php [iso-8859-1]
(original)
+++ trunk/PersistentObject/tests/object_id_property_test.php [iso-8859-1] Mon
Jan 28 16:50:37 2008
@@ -39,6 +39,7 @@
'propertyType' => ezcPersistentObjectProperty::PHP_TYPE_INT,
'generator' => null,
'visibility' => null,
+ 'databaseType' => PDO::PARAM_STR,
),
'properties',
$property
@@ -52,7 +53,8 @@
new ezcPersistentGeneratorDefinition(
new ezcPersistentNativeGenerator()
),
- ezcPersistentObjectProperty::PHP_TYPE_INT
+ ezcPersistentObjectProperty::PHP_TYPE_INT,
+ PDO::PARAM_LOB
);
$this->assertAttributeEquals(
array(
@@ -62,7 +64,8 @@
'generator' => new ezcPersistentGeneratorDefinition(
new ezcPersistentNativeGenerator()
),
- 'visibility' =>
ezcPersistentObjectProperty::VISIBILITY_PROTECTED
+ 'visibility' =>
ezcPersistentObjectProperty::VISIBILITY_PROTECTED,
+ 'databaseType' => PDO::PARAM_LOB,
),
'properties',
$property
@@ -80,7 +83,8 @@
new ezcPersistentGeneratorDefinition(
new ezcPersistentManualGenerator()
),
- ezcPersistentObjectProperty::PHP_TYPE_INT
+ ezcPersistentObjectProperty::PHP_TYPE_INT,
+ PDO::PARAM_LOB
);
$this->fail( 'ezcBaseValueException not thrown on invalid value
for parameter $columnName.' );
}
@@ -94,7 +98,8 @@
new ezcPersistentGeneratorDefinition(
new ezcPersistentManualGenerator()
),
- ezcPersistentObjectProperty::PHP_TYPE_INT
+ ezcPersistentObjectProperty::PHP_TYPE_INT,
+ PDO::PARAM_LOB
);
$this->fail( 'ezcBaseValueException not thrown on invalid value
for parameter $propertyName.' );
}
@@ -108,7 +113,8 @@
new ezcPersistentGeneratorDefinition(
new ezcPersistentManualGenerator()
),
- ezcPersistentObjectProperty::PHP_TYPE_INT
+ ezcPersistentObjectProperty::PHP_TYPE_INT,
+ PDO::PARAM_LOB
);
$this->fail( 'ezcBaseValueException not thrown on invalid value of
type string for parameter $visibility.' );
}
@@ -122,6 +128,22 @@
new ezcPersistentGeneratorDefinition(
new ezcPersistentManualGenerator()
),
+ 'foo',
+ PDO::PARAM_LOB
+ );
+ $this->fail( 'ezcBaseValueException not thrown on invalid value
for parameter $propertyType.' );
+ }
+ catch ( ezcBaseValueException $e ) {}
+ try
+ {
+ $property = new ezcPersistentObjectIdProperty(
+ 'foo',
+ 'bar',
+ ezcPersistentObjectProperty::VISIBILITY_PROTECTED,
+ new ezcPersistentGeneratorDefinition(
+ new ezcPersistentManualGenerator()
+ ),
+ ezcPersistentObjectProperty::PHP_TYPE_INT,
'foo'
);
$this->fail( 'ezcBaseValueException not thrown on invalid value
for parameter $propertyType.' );
@@ -138,7 +160,8 @@
new ezcPersistentGeneratorDefinition(
new ezcPersistentManualGenerator()
),
- ezcPersistentObjectProperty::PHP_TYPE_INT
+ ezcPersistentObjectProperty::PHP_TYPE_INT,
+ PDO::PARAM_LOB
);
$this->assertEquals(
@@ -163,6 +186,10 @@
ezcPersistentObjectProperty::PHP_TYPE_INT,
$property->propertyType
);
+ $this->assertEquals(
+ PDO::PARAM_LOB,
+ $property->databaseType
+ );
}
public function testGetAccessFailure()
@@ -174,7 +201,8 @@
new ezcPersistentGeneratorDefinition(
new ezcPersistentManualGenerator()
),
- ezcPersistentObjectProperty::PHP_TYPE_INT
+ ezcPersistentObjectProperty::PHP_TYPE_INT,
+ PDO::PARAM_LOB
);
try
{
@@ -193,10 +221,11 @@
$property->columnName = 'column';
$property->propertyName ='property';
$property->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT;
- $property->visibility =
ezcPersistentObjectProperty::VISIBILITY_PROTECTED;
- $property->generator = new ezcPersistentGeneratorDefinition(
+ $property->visibility =
ezcPersistentObjectProperty::VISIBILITY_PROTECTED;
+ $property->generator = new ezcPersistentGeneratorDefinition(
new ezcPersistentManualGenerator()
);
+ $property->databaseType = PDO::PARAM_LOB;
$this->assertEquals(
'column',
@@ -220,6 +249,10 @@
),
$property->generator
);
+ $this->assertEquals(
+ PDO::PARAM_LOB,
+ $property->databaseType
+ );
}
public function testSetAccessFailure()
@@ -250,6 +283,11 @@
'generator',
array( true, false, 'foo', 23, 23.42, array(), new stdClass() )
);
+ $this->assertSetPropertyFails(
+ $property,
+ 'databaseType',
+ array( true, false, 'foo', 23, 23.42, array(), new stdClass() )
+ );
}
public function testIssetAccessSuccess()
@@ -273,6 +311,10 @@
);
$this->assertTrue(
isset( $property->generator ),
+ 'Property $generator seems not to be set.'
+ );
+ $this->assertTrue(
+ isset( $property->databaseType ),
'Property $generator seems not to be set.'
);
}
Modified: trunk/PersistentObject/tests/object_property_test.php
==============================================================================
--- trunk/PersistentObject/tests/object_property_test.php [iso-8859-1]
(original)
+++ trunk/PersistentObject/tests/object_property_test.php [iso-8859-1] Mon Jan
28 16:50:37 2008
@@ -37,7 +37,8 @@
'columnName' => null,
'propertyName' => null,
'propertyType' => ezcPersistentObjectProperty::PHP_TYPE_STRING,
- 'converter' => null
+ 'converter' => null,
+ 'databaseType' => PDO::PARAM_STR,
),
'properties',
$property
@@ -48,14 +49,16 @@
'column',
'property',
ezcPersistentObjectProperty::PHP_TYPE_INT,
- new ezcPersistentPropertyDateTimeConverter()
+ new ezcPersistentPropertyDateTimeConverter(),
+ PDO::PARAM_LOB
);
$this->assertAttributeEquals(
array(
'columnName' => 'column',
'propertyName' => 'property',
'propertyType' => ezcPersistentObjectProperty::PHP_TYPE_INT,
- 'converter' => new ezcPersistentPropertyDateTimeConverter(),
+ 'converter' => new ezcPersistentPropertyDateTimeConverter(),
+ 'databaseType' => PDO::PARAM_LOB,
),
'properties',
$property
@@ -70,7 +73,8 @@
23,
'foo',
ezcPersistentObjectProperty::PHP_TYPE_INT,
- new ezcPersistentPropertyDateTimeConverter()
+ new ezcPersistentPropertyDateTimeConverter(),
+ PDO::PARAM_LOB
);
$this->fail( 'ezcBaseValueException not thrown on invalid value
for parameter $columnName.' );
}
@@ -81,7 +85,8 @@
'foo',
23,
ezcPersistentObjectProperty::PHP_TYPE_INT,
- new ezcPersistentPropertyDateTimeConverter()
+ new ezcPersistentPropertyDateTimeConverter(),
+ PDO::PARAM_LOB
);
$this->fail( 'ezcBaseValueException not thrown on invalid value
for parameter $propertyName.' );
}
@@ -90,22 +95,36 @@
{
$property = new ezcPersistentObjectProperty(
'foo',
- 'bar',
+ 'foo',
'baz',
- new ezcPersistentPropertyDateTimeConverter()
- );
- $this->fail( 'ezcBaseValueException not thrown on invalid value of
type string for parameter $type.' );
- }
- catch ( ezcBaseValueException $e ) {}
- try
- {
- $property = new ezcPersistentObjectProperty(
- 'foo',
- 'bar',
- 'baz',
- 'bam'
- );
- $this->fail( 'ezcBaseValueException not thrown on invalid value of
type string for parameter $type.' );
+ new ezcPersistentPropertyDateTimeConverter(),
+ PDO::PARAM_LOB
+ );
+ $this->fail( 'ezcBaseValueException not thrown on invalid value
for parameter $propertyType.' );
+ }
+ catch ( ezcBaseValueException $e ) {}
+ try
+ {
+ $property = new ezcPersistentObjectProperty(
+ 'foo',
+ 'foo',
+ ezcPersistentObjectProperty::PHP_TYPE_INT,
+ 'bam',
+ PDO::PARAM_LOB
+ );
+ $this->fail( 'ezcBaseValueException not thrown on invalid value
parameter $converter.' );
+ }
+ catch ( ezcBaseValueException $e ) {}
+ try
+ {
+ $property = new ezcPersistentObjectProperty(
+ 'foo',
+ 'foo',
+ ezcPersistentObjectProperty::PHP_TYPE_INT,
+ new ezcPersistentPropertyDateTimeConverter(),
+ 23
+ );
+ $this->fail( 'ezcBaseValueException not thrown on invalid value
for parameter $databaseType.' );
}
catch ( ezcBaseValueException $e ) {}
}
@@ -116,7 +135,8 @@
'column',
'property',
ezcPersistentObjectProperty::PHP_TYPE_INT,
- new ezcPersistentPropertyDateTimeConverter()
+ new ezcPersistentPropertyDateTimeConverter(),
+ PDO::PARAM_LOB
);
$this->assertEquals(
@@ -135,6 +155,10 @@
new ezcPersistentPropertyDateTimeConverter(),
$property->converter
);
+ $this->assertEquals(
+ PDO::PARAM_LOB,
+ $property->databaseType
+ );
}
public function testGetAccessFailure()
@@ -143,7 +167,8 @@
'column',
'property',
ezcPersistentObjectProperty::PHP_TYPE_INT,
- new ezcPersistentPropertyDateTimeConverter()
+ new ezcPersistentPropertyDateTimeConverter(),
+ PDO::PARAM_LOB
);
try
{
@@ -162,7 +187,8 @@
$property->columnName = 'column';
$property->propertyName ='property';
$property->propertyType = ezcPersistentObjectProperty::PHP_TYPE_INT;
- $property->converter = new ezcPersistentPropertyDateTimeConverter();
+ $property->converter = new ezcPersistentPropertyDateTimeConverter();
+ $property->databaseType = PDO::PARAM_LOB;
$this->assertEquals(
'column',
@@ -179,6 +205,10 @@
$this->assertEquals(
new ezcPersistentPropertyDateTimeConverter(),
$property->converter
+ );
+ $this->assertEquals(
+ PDO::PARAM_LOB,
+ $property->databaseType
);
$property->converter = null;
@@ -210,6 +240,11 @@
'converter',
array( true, false, 'foo', 23.42, array(), new stdClass() )
);
+ $this->assertSetPropertyFails(
+ $property,
+ 'databaseType',
+ array( true, false, 'foo', 23, 23.42, array(), new stdClass() )
+ );
}
public function testIssetAccessSuccess()
@@ -230,6 +265,10 @@
$this->assertTrue(
isset( $property->converter ),
'Property $converter seems not to be set.'
+ );
+ $this->assertTrue(
+ isset( $property->databaseType ),
+ 'Property $databaseType seems not to be set.'
);
}
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components