Changeset 1068 for trunk

Show
Ignore:
Timestamp:
08/06/08 07:55:11 (4 months ago)
Author:
ron
Message:

Merge in changes from 1.3 branch: merge -r 832:1067

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/contrib/dbd2propel/dbd2propel.xsl

    r485 r1068  
    88 
    99==== Author: Jonathan Graham <jkgraham@gmail.com> 
    10 ==== Version: 0.4 (2006-11-13) (http://blog.tooleshed.com/?p=6) 
     10==== Version: 0.5 (2008-01-25) (http://blog.tooleshed.com/?p=6) 
    1111==== Description: 
    1212This XSL will transform a DB Designer 4 database model XML file into a 
     
    3333Michiel Hakvoort - onDelete 
    3434Michel D'HOOGE - FULLTEXT 
     35Oleg Marchuk <kingoleg@mail.ru> - version 0.5 
    3536 
    3637==== Software: 
     
    4647version 0.3 (2006-11-05) - added non-unique-INDEXes and onDelete 
    4748version 0.4 (2006-11-13) - added support for index names and FULLTEXT indexes, changed license to LGPL 
     49version 0.5 (2008-01-25) - added ENUM, GEOMETRY as BLOB, scale for DECIMAL; fixed size in ENUM and spaces in relation names 
    4850 
    4951--> 
     
    99101                <!-- ==== type ==== --> 
    100102                <xsl:attribute name="type"> 
    101                         <xsl:value-of select="$datatype"/> 
     103                        <xsl:choose> 
     104                                <xsl:when test="$datatype = 'ENUM'"> 
     105                                        <xsl:value-of select="'CHAR'" /> 
     106                                </xsl:when> 
     107                                <xsl:otherwise> 
     108                                        <xsl:value-of select="$datatype"/> 
     109                                </xsl:otherwise> 
     110                        </xsl:choose> 
    102111                </xsl:attribute> 
    103112 
     
    110119                                </xsl:call-template> 
    111120                        </xsl:attribute> 
    112                  
    113                         <xsl:if test="contains('FLOAT,DOUBLE',$datatype)"> 
     121 
     122                        <xsl:if test="contains('FLOAT,DOUBLE,DECIMAL',$datatype)"> 
    114123                                <!-- ==== scale ==== -->  
    115124                                <xsl:attribute name="scale"> 
     
    219228                <!-- name --> 
    220229                <xsl:attribute name="name"> 
    221                         <xsl:value-of select="$relation/@RelationName"/> 
     230                        <xsl:value-of select="translate($relation/@RelationName, ' ', '_')"/> 
    222231                </xsl:attribute> 
    223232 
     
    265274                <xsl:when test="$type = 'TEXT'" >LONGVARCHAR</xsl:when>  
    266275                <xsl:when test="$type = 'BOOL'" >BOOLEAN</xsl:when>  
     276                <xsl:when test="$type = 'GEOMETRY'" >BLOB</xsl:when>  
    267277                <xsl:otherwise>  
    268278                        <xsl:value-of select="$type"/> 
     
    279289 
    280290        <xsl:choose>  
    281                 <xsl:when test="contains('FLOAT,DOUBLE',$dtype)" >  
     291                <xsl:when test="contains('FLOAT,DOUBLE,DECIMAL',$dtype)" >  
    282292                        <xsl:value-of select="substring-before($dtpc,',')"/> 
    283                 </xsl:when>  
     293                </xsl:when> 
     294                <xsl:when test="$dtype = 'ENUM'"> 
     295                        <xsl:value-of select="''" /> 
     296                </xsl:when>      
    284297                <xsl:otherwise>  
    285298                        <xsl:value-of select="$dtpc"/> 
  • trunk/docs/build.xml

    • Property svn:keywords set to Id Rev Date Author HeadURL Revision
  • trunk/generator

    • Property svn:ignore set to
      build.properties
  • trunk/generator/build-propel.xml

    r833 r1068  
    5959    name="propel-creole-transform" 
    6060    classname="propel.phing.PropelCreoleTransformTask" classpathRef="propelclasses"/> 
     61   <taskdef 
     62    name="propel-schema-reverse" 
     63    classname="propel.phing.PropelSchemaReverseTask" classpathRef="propelclasses"/> 
    6164 
    6265  <taskdef 
     
    274277 
    275278  <!-- ================================================================ --> 
    276   <!-- C R E O L E  TO  X M L                                               --> 
     279  <!-- C R E O L E  T O   X M L                                        --> 
    277280  <!-- ================================================================ --> 
    278281 
     
    299302 
    300303  </target> 
     304   
     305  <!-- ================================================================ --> 
     306  <!-- N E W   R E V E R S E   T O   X M L                              --> 
     307  <!-- ================================================================ --> 
     308 
     309  <target 
     310    name="reverse" 
     311    description="==> generate xml schema from reverse-engineered database (new)"> 
     312 
     313    <echo message="+-----------------------------------------------+"/> 
     314    <echo message="|                                               |"/> 
     315    <echo message="| Generating XML from PDO connection !          |"/> 
     316    <echo message="|                                               |"/> 
     317    <echo message="+-----------------------------------------------+"/> 
     318 
     319    <propel-schema-reverse 
     320      databaseName="${propel.project}" 
     321      dbSchema="${propel.database.schema}" 
     322      dbEncoding="${propel.database.encoding}" 
     323      url="${propel.database.buildUrl}" 
     324      userId="${propel.database.user}" 
     325      password="${propel.database.password}" 
     326      outputFile="${propel.schema.dir}/${propel.default.schema.basename}.xml" 
     327      samePhpName="${propel.samePhpName}" 
     328      addVendorInfo="${propel.addVendorInfo}" 
     329      addValidators="${propel.addValidators}" 
     330    /> 
     331 
     332  </target> 
    301333 
    302334 
     
    357389      dbEncoding="${propel.database.encoding}" 
    358390      databaseUrl="${propel.database.url}" 
     391      databaseUser="${propel.database.user}" 
     392      databasePassword="${propel.database.password}" 
    359393      outputDirectory="${propel.schema.dir}"> 
    360394      <mapper type="glob" from="${propel.datadump.mapper.from}" to="${propel.datadump.mapper.to}"/> 
     
    476510      xmlConfFile="${propel.conf.dir}/${propel.runtime.conf.file}" 
    477511      outputDirectory="${propel.phpconf.dir}" 
    478       outputFile="${propel.runtime.phpconf.file}"> 
     512      outputFile="${propel.runtime.phpconf.file}" 
     513      packageObjectModel="${propel.packageObjectModel}" 
     514      outputClassmapFile="${propel.runtime.phpconf-classmap.file}"> 
    479515      <schemafileset dir="${propel.schema.dir}" 
    480516        includes="${propel.schema.sql.includes}" 
  • trunk/generator/build.xml

    r505 r1068  
    2222     property here.  If it wasn't set, then this will be bogus, but it will 
    2323     be overridden by the "set-project-dir" target. -->     
    24 <property name="propel.project.dir" value="${project.dir}"/> 
    25 <resolvepath propertyName="propel.project.dir" file="${propel.project.dir}" dir="${application.startdir}"/> 
     24<resolvepath propertyName="propel.project.dir" file="${project.dir}" dir="${application.startdir}"/> 
    2625 
    2726<!-- set a default target if none provided --> 
     
    102101 
    103102<target name="configure" depends="set-project-dir,check-buildprops-for-propel-gen,check-buildprops"> 
     103        <if> 
     104                <isset property="additional.properties"/> 
     105                <then> 
     106                        <echo>Processing additional properties file: ${additional.properties}</echo> 
     107                        <resolvepath propertyName="additional.properties.resolved" file="${additional.properties}" dir="${application.startdir}"/> 
     108                        <property file="${additional.properties.resolved}"/> 
     109                </then> 
     110        </if> 
    104111        <echo msg="Loading project-specific props from ${propel.project.dir}/${build.properties}"/> 
    105112        <property file="${propel.project.dir}/${build.properties}"/> 
     
    136143<target name="creole" depends="configure"> 
    137144        <phing phingfile="build-propel.xml" target="creole"/> 
     145</target> 
     146 
     147<target name="reverse" depends="configure"> 
     148        <phing phingfile="build-propel.xml" target="reverse"/> 
    138149</target> 
    139150 
  • trunk/generator/classes/propel/engine/builder/DataModelBuilder.php

    r833 r1068  
    2828 * files, input forms, etc. 
    2929 * 
    30  * This class has a static method to return the correct builder subclass identified by 
    31  * a given key.  Note that in order for this factory method to work, the properties have to have 
    32  * been loaded first.  Usage should look something like this (from within a AbstractProelDataModelTask subclass): 
    33  * 
    34  * <code> 
    35  * DataModelBuilder::setBuildProperties($this->getPropelProperties()); 
    36  * $builder = DataModelBuilder::builderFactory($table, 'peer'); 
    37  * // $builder (by default) instanceof PHP5ComplexPeerBuilder 
    38  * </code> 
     30 * The GeneratorConfig needs to be set on this class in order for the builders 
     31 * to be able to access the propel generator build properties.  You should be 
     32 * safe if you always use the GeneratorConfig to get a configured builder class 
     33 * anyway. 
    3934 * 
    4035 * @author     Hans Lellelid <hans@xmpl.org> 
     
    4338abstract class DataModelBuilder { 
    4439 
    45         // -------------------------------------------------------------- 
    46         // Static properties & methods 
    47         // -------------------------------------------------------------- 
    48  
    49         /** 
    50          * Build properties (after they've been transformed from "propel.some.name" => "someName"). 
     40        /** 
     41         * The current table. 
     42         * @var        Table 
     43         */ 
     44        private $table; 
     45 
     46        /** 
     47         * The generator config object holding build properties, etc. 
     48         * 
     49         * @var        GeneratorConfig 
     50         */ 
     51        private $generatorConfig; 
     52 
     53        /** 
     54         * An array of warning messages that can be retrieved for display (e.g. as part of phing build process). 
    5155         * @var        array string[] 
    5256         */ 
    53         private static $buildProperties = array(); 
    54  
    55         private static $cache = array(); 
    56  
    57         /** 
    58          * Sets the [name transformed] build properties to use. 
    59          * @param      array Property values keyed by [transformed] prop names. 
    60          */ 
    61         public static function setBuildProperties($props) 
    62         { 
    63                 self::$buildProperties = $props; 
     57        private $warnings = array(); 
     58 
     59        /** 
     60         * Peer builder class for current table. 
     61         * @var        DataModelBuilder 
     62         */ 
     63        private $peerBuilder; 
     64 
     65        /** 
     66         * Stub Peer builder class for current table. 
     67         * @var        DataModelBuilder 
     68         */ 
     69        private $stubPeerBuilder; 
     70 
     71        /** 
     72         * Object builder class for current table. 
     73         * @var        DataModelBuilder 
     74         */ 
     75        private $objectBuilder; 
     76 
     77        /** 
     78         * Stub Object builder class for current table. 
     79         * @var        DataModelBuilder 
     80         */ 
     81        private $stubObjectBuilder; 
     82 
     83        /** 
     84         * MapBuilder builder class for current table. 
     85         * @var        DataModelBuilder 
     86         */ 
     87        private $mapBuilderBuilder; 
     88 
     89        /** 
     90         * Stub Interface builder class for current table. 
     91         * @var        DataModelBuilder 
     92         */ 
     93        private $interfaceBuilder; 
     94 
     95        /** 
     96         * Stub child object for current table. 
     97         * @var        DataModelBuilder 
     98         */ 
     99        private $multiExtendObjectBuilder; 
     100 
     101        /** 
     102         * Node object builder for current table. 
     103         * @var        DataModelBuilder 
     104         */ 
     105        private $nodeBuilder; 
     106 
     107        /** 
     108         * Node peer builder for current table. 
     109         * @var        DataModelBuilder 
     110         */ 
     111        private $nodePeerBuilder; 
     112 
     113        /** 
     114         * Stub node object builder for current table. 
     115         * @var        DataModelBuilder 
     116         */ 
     117        private $stubNodeBuilder; 
     118 
     119        /** 
     120         * Stub node peer builder for current table. 
     121         * @var        DataModelBuilder 
     122         */ 
     123        private $stubNodePeerBuilder; 
     124 
     125        /** 
     126         * NestedSet object builder for current table. 
     127         * @var        DataModelBuilder 
     128         */ 
     129        private $nestedSetBuilder; 
     130 
     131        /** 
     132         * NestedSet peer builder for current table. 
     133         * @var        DataModelBuilder 
     134         */ 
     135        private $nestedSetPeerBuilder; 
     136 
     137        /** 
     138         * The DDL builder for current table. 
     139         * @var        DDLBuilder 
     140         */ 
     141        private $ddlBuilder; 
     142 
     143        /** 
     144         * The Data-SQL builder for current table. 
     145         * @var        DataSQLBuilder 
     146         */ 
     147        private $dataSqlBuilder; 
     148 
     149        /** 
     150         * The Pluralizer class to use. 
     151         * @var        Pluralizer 
     152         */ 
     153        private $pluralizer; 
     154 
     155 
     156        /** 
     157         * Creates new instance of DataModelBuilder subclass. 
     158         * @param      Table $table The Table which we are using to build [OM, DDL, etc.]. 
     159         */ 
     160        public function __construct(Table $table) 
     161        { 
     162                $this->table = $table; 
     163        } 
     164 
     165        /** 
     166         * Returns new or existing Peer builder class for this table. 
     167         * @return     PeerBuilder 
     168         */ 
     169        public function getPeerBuilder() 
     170        { 
     171                if (!isset($this->peerBuilder)) { 
     172                        $this->peerBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'peer'); 
     173                } 
     174                return $this->peerBuilder; 
     175        } 
     176 
     177        /** 
     178         * Returns new or existing Pluralizer class. 
     179         * @return     Pluralizer 
     180         */ 
     181        public function getPluralizer() 
     182        { 
     183                if (!isset($this->pluralizer)) { 
     184                        $this->pluralizer = $this->getGeneratorConfig()->getConfiguredPluralizer(); 
     185                } 
     186                return $this->pluralizer; 
     187        } 
     188 
     189        /** 
     190         * Returns new or existing stub Peer builder class for this table. 
     191         * @return     PeerBuilder 
     192         */ 
     193        public function getStubPeerBuilder() 
     194        { 
     195                if (!isset($this->stubPeerBuilder)) { 
     196                        $this->stubPeerBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'peerstub'); 
     197                } 
     198                return $this->stubPeerBuilder; 
     199        } 
     200 
     201        /** 
     202         * Returns new or existing Object builder class for this table. 
     203         * @return     ObjectBuilder 
     204         */ 
     205        public function getObjectBuilder() 
     206        { 
     207                if (!isset($this->objectBuilder)) { 
     208                        $this->objectBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'object'); 
     209                } 
     210                return $this->objectBuilder; 
     211        } 
     212 
     213        /** 
     214         * Returns new or existing stub Object builder class for this table. 
     215         * @return     ObjectBuilder 
     216         */ 
     217        public function getStubObjectBuilder() 
     218        { 
     219                if (!isset($this->stubObjectBuilder)) { 
     220                        $this->stubObjectBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'objectstub'); 
     221                } 
     222                return $this->stubObjectBuilder; 
     223        } 
     224 
     225        /** 
     226         * Returns new or existing MapBuilder builder class for this table. 
     227         * @return     ObjectBuilder 
     228         */ 
     229        public function getMapBuilderBuilder() 
     230        { 
     231                if (!isset($this->mapBuilderBuilder)) { 
     232                        $this->mapBuilderBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'mapbuilder'); 
     233                } 
     234                return $this->mapBuilderBuilder; 
     235        } 
     236 
     237        /** 
     238         * Returns new or existing stub Interface builder class for this table. 
     239         * @return     ObjectBuilder 
     240         */ 
     241        public function getInterfaceBuilder() 
     242        { 
     243                if (!isset($this->interfaceBuilder)) { 
     244                        $this->interfaceBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'interface'); 
     245                } 
     246                return $this->interfaceBuilder; 
     247        } 
     248 
     249        /** 
     250         * Returns new or existing stub child object builder class for this table. 
     251         * @return     ObjectBuilder 
     252         */ 
     253        public function getMultiExtendObjectBuilder() 
     254        { 
     255                if (!isset($this->multiExtendObjectBuilder)) { 
     256                        $this->multiExtendObjectBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'objectmultiextend'); 
     257                } 
     258                return $this->multiExtendObjectBuilder; 
     259        } 
     260 
     261        /** 
     262         * Returns new or existing node Object builder class for this table. 
     263         * @return     ObjectBuilder 
     264         */ 
     265        public function getNodeBuilder() 
     266        { 
     267                if (!isset($this->nodeBuilder)) { 
     268                        $this->nodeBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'node'); 
     269                } 
     270                return $this->nodeBuilder; 
     271        } 
     272 
     273        /** 
     274         * Returns new or existing node Peer builder class for this table. 
     275         * @return     PeerBuilder 
     276         */ 
     277        public function getNodePeerBuilder() 
     278        { 
     279                if (!isset($this->nodePeerBuilder)) { 
     280                        $this->nodePeerBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'nodepeer'); 
     281                } 
     282                return $this->nodePeerBuilder; 
     283        } 
     284 
     285        /** 
     286         * Returns new or existing stub node Object builder class for this table. 
     287         * @return     ObjectBuilder 
     288         */ 
     289        public function getStubNodeBuilder() 
     290        { 
     291                if (!isset($this->stubNodeBuilder)) { 
     292                        $this->stubNodeBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'nodestub'); 
     293                } 
     294                return $this->stubNodeBuilder; 
     295        } 
     296 
     297        /** 
     298         * Returns new or existing stub node Peer builder class for this table. 
     299         * @return     PeerBuilder 
     300         */ 
     301        public function getStubNodePeerBuilder() 
     302        { 
     303                if (!isset($this->stubNodePeerBuilder)) { 
     304                        $this->stubNodePeerBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'nodepeerstub'); 
     305                } 
     306                return $this->stubNodePeerBuilder; 
     307        } 
     308 
     309        /** 
     310         * Returns new or existing nested set object builder class for this table. 
     311         * @return     ObjectBuilder 
     312         */ 
     313        public function getNestedSetBuilder() 
     314        { 
     315                if (!isset($this->nestedSetBuilder)) { 
     316                        $this->nestedSetBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'nestedset'); 
     317                } 
     318                return $this->nestedSetBuilder; 
     319        } 
     320 
     321        /** 
     322         * Returns new or existing nested set Peer builder class for this table. 
     323         * @return     PeerBuilder 
     324         */ 
     325        public function getNestedSetPeerBuilder() 
     326        { 
     327                if (!isset($this->nestedSetPeerBuilder)) { 
     328                        $this->nestedSetPeerBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'nestedsetpeer'); 
     329                } 
     330                return $this->nestedSetPeerBuilder; 
     331        } 
     332 
     333        /** 
     334         * Returns new or existing ddl builder class for this table. 
     335         * @return     DDLBuilder 
     336         */ 
     337        public function getDDLBuilder() 
     338        { 
     339                if (!isset($this->ddlBuilder)) { 
     340                        $this->ddlBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'ddl'); 
     341                } 
     342                return $this->ddlBuilder; 
     343        } 
     344 
     345        /** 
     346         * Returns new or existing data sql builder class for this table. 
     347         * @return     DataSQLBuilder 
     348         */ 
     349        public function getDataSQLBuilder() 
     350        { 
     351                if (!isset($this->dataSqlBuilder)) { 
     352                        $this->dataSqlBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'datasql'); 
     353                } 
     354                return $this->dataSqlBuilder; 
     355        } 
     356 
     357        /** 
     358         * Convenience method to return a NEW Peer class builder instance 
     359         * . 
     360         * This is used very frequently from the peer and object builders to get 
     361         * a peer builder for a RELATED table. 
     362         * 
     363         * @param      Table $table 
     364         * @return     PeerBuilder 
     365         */ 
     366        public function getNewPeerBuilder(Table $table) 
     367        { 
     368                return $this->getGeneratorConfig()->getConfiguredBuilder($table, 'peer'); 
     369        } 
     370 
     371        /** 
     372         * Convenience method to return a NEW Object class builder instance. 
     373         * 
     374         * This is used very frequently from the peer and object builders to get 
     375         * an object builder for a RELATED table. 
     376         * 
     377         * @param      Table $table 
     378         * @return     ObjectBuilder 
     379         */ 
     380        public function getNewObjectBuilder(Table $table) 
     381        { 
     382                return $this->getGeneratorConfig()->getConfiguredBuilder($table, 'object'); 
     383        } 
     384 
     385        /** 
     386         * Gets the GeneratorConfig object. 
     387         * 
     388         * @return     GeneratorConfig 
     389         */ 
     390        public function getGeneratorConfig() 
     391        { 
     392                return $this->generatorConfig; 
    64393        } 
    65394 
    66395        /** 
    67396         * Get a specific [name transformed] build property. 
     397         * 
    68398         * @param      string $name 
    69399         * @return     string 
    70400         */ 
    71         public static function getBuildProperty($name) 
    72         { 
    73                 return isset(self::$buildProperties[$name]) ? self::$buildProperties[$name] : null; 
    74         } 
    75  
    76         /** 
    77          * Imports and returns the classname of the builder class for specified 'type'. 
    78          * @param      string $type The "key" for class to load. 
    79          * @return     string The unqualified classname. 
    80          */ 
    81         public static function getBuilderClass($type) 
    82         { 
    83                 if (empty(self::$buildProperties)) { 
    84                         throw new BuildException("Cannot determine builder class when no build properties have been loaded (hint: Did you call DataModelBuilder::setBuildProperties(\$props) first?)"); 
    85                 } 
    86                 $propname = 'builder' . ucfirst(strtolower($type)) . 'Class'; 
    87                 $classpath = self::getBuildProperty($propname); 
    88  
    89                 if (empty($classpath)) { 
    90                         throw new BuildException("Unable to find class path for '$propname' property."); 
    91                 } 
    92  
    93                 // This is a slig