start working to persist the analyzed structure

Esse commit está contido em:
Felipe Nascimento de Moura
2011-03-22 19:11:39 -03:00
commit 5fad27f97c
19 arquivos alterados com 256 adições e 31 exclusões
+2 -1
Ver Arquivo
@@ -111,7 +111,8 @@
type:'POST',
url:'../../',
data:{
program:'analyze'
program:'analyze',
commit:true
},
success: function(ret){
document.getElementById('result').innerHTML= ret;
+19
Ver Arquivo
@@ -0,0 +1,19 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
namespace DAO;
/**
* Description of Project
*
* @author felipe
*/
class Project{
public function __construct()
{
$this->db= new \MindDB();
}
}
+73
Ver Arquivo
@@ -0,0 +1,73 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
namespace DAO;
/**
* Description of TableFactory
*
* @author felipe
*/
class ProjectFactory extends Project{
private $data= null;
private $tag= '';
private $description= '';
private $originalCode= '';
private $framework= '';
public function addNewVersion()
{
$this->data['version']++;
$qr_vsProj= "INSERT into version
(
version,
tag,
obs,
originalcode,
machine_lang,
framework,
database,
fk_project,
fk_user
)
values
(
'".$this->data['version']."',
'".$this->tag."',
'".$this->description."',
'".$this->originalCode."',
'".$this->data['technology']."',
'".$this->framework."',
'".$this->data['database_drive']."',
".$this->data['pk_project'].",
".$_SESSION['pk_user']."
)";
if($this->db->execute($qr_vsProj))
return true;
return false;
}
public function __construct(Array $projectData)
{
parent::__construct();
$this->data= $projectData;
$qr_newProj= "SELECT pk_version,
v.version as version,
p.creator as creator
from project p,
version v
where p.pk_project = v.fk_project
and p.pk_project = ".$this->data['pk_project']."
ORDER by pk_version desc
LIMIT 1";
$data= $this->db->query($qr_newProj);
$this->data= array_merge($this->data, $data[0]);
print_r($this->data);
$this->addNewVersion();
}
}
+19
Ver Arquivo
@@ -0,0 +1,19 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
namespace DAO;
/**
* Description of Table
*
* @author felipe
*/
class Table extends \MindDB{
public function __construct()
{
}
}
+15
Ver Arquivo
@@ -0,0 +1,15 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
namespace DAO;
/**
* Description of TableFactory
*
* @author felipe
*/
class TableFactory extends Table{
//put your code here
}
+1 -1
Ver Arquivo
@@ -43,7 +43,7 @@ class MindDB {
public function __construct()
{
if(!$db = sqlite_open(_MINDSRC_.'/mind3rd/SQLite/mind'))
if(!$db = sqlite_open(_MINDSRC_.SQLITE))
{
Mind::message('Database', '[Fail]');
return false;
+12 -8
Ver Arquivo
@@ -149,36 +149,40 @@ class MindProject extends VersionManager{
public static function analyze($autoCommit=false)
{
self::setUp();
$init= false;
foreach(self::$sourceContent as $k=>&$content)
{
$currentSource= $k;
// search for special/unknown characters
if(!Mind::$lexer->sweep($content))
return false;
continue;
// keep substantives and verbs on their canonical form
if(!Mind::$canonic->sweep())
return false;
continue;
// mark specific tokens
if(!Mind::$tokenizer->sweep())
return false;
continue;
// prepares the model to be used to process data
// it transforms the original text into the mind code
// itself
if(!Mind::$syntaxer->sweep())
return false;
continue;
if($autoCommit)
{
MindProject::commit();
}
if(sizeof(Analyst::$entities) > 0)
$init= true;
}
MindTimer::end();
// do NOT print it if you have MANY entities, the webbrowser freezes
//print_r(Analyst::getUniverse());
echo Analyst::printWhatYouGet();
if($init)
echo Analyst::printWhatYouGet();
else
echo " Nothing to show\n";
echo "--------------------\n";
echo "Time: ".
MindTimer::getElapsedTime().
+10 -3
Ver Arquivo
@@ -7,9 +7,16 @@
class VersionManager {
public static function commit()
{
// TODO: commiting a project should save the current
// situation of the current project
echo "COMMITING";
/*
* selecionar todas as tabelas e propriedades q nao esteam marcadas como drop
* ver diferenças entre cada tabela
* ver tabelas q ficaram sobrando na lista recem analisada(novas)
* ver tabelas q ficaram sobrando na lista antiga(para dropar)
* insere novas
* marca antigas como dropped
*/
$project= new DAO\ProjectFactory(Mind::$currentProject);
}
public static function setUp()
+1
Ver Arquivo
@@ -158,6 +158,7 @@ class Analyst extends Analysis {
{
if(!$rel)
continue;
echo " ".$rel->name;
if($detailed)
{
+3 -2
Ver Arquivo
@@ -73,6 +73,9 @@
{
$rel= &Analyst::$relations[$rel->name];
if(is_null($rel) || is_null($rel->focus) || is_null($rel->rel))
continue;
if($rel->focus === $rel->rel)
{
// self referred (1)
@@ -80,8 +83,6 @@
continue;
}
if(is_null($rel) || is_null($rel->focus) || is_null($rel->rel))
continue;
// defining the focus
$entities= self::setByRelevance($rel->focus, $rel->rel);
self::$focus= $entities[0];
+1 -1
Ver Arquivo
@@ -218,7 +218,7 @@ class Tokenizer extends Token{
foreach(self::$dataTypes as $type=>$options)
{
$cont= preg_replace(
"/\:".implode('((\(|[\., \n]))?+|\:', $options)."(\(| )/i",
"/\:".implode(PROP_FIX, $options)."(\(| )/i",
':'.$type.'(',
$cont
);
+3 -3
Ver Arquivo
@@ -5,19 +5,19 @@
; to use in your application
;
; The idiom is the human language you want to use
idiom=en
idiom=<idiom>
; The technology you specify here, will be used as
; the backend of your application
; this will be the name of the model you want to apply
; to your app, of course, it depends on the models
; you've got installed
technology=php-zf
technology=<technology>
; You can also set the title for your app
title=Mind3rd Generated Application
; You will need to configure your database
; the module you choose will probably try to implement
; some PDO drivers, so, put the one you want, here
database_drive=pgsql
database_drive=<dbms>
; now, the ip address or host name
database_addr=localhost
; then, the port
+4 -3
Ver Arquivo
@@ -48,9 +48,11 @@ EOT
if(!parent::HTTPExecute())
return false;
if(isset($_REQ['data']['namespace']))
$this->nameSpace= $_REQ['data']['namespace'];
$this->nameSpace= $_REQ['data']['namespace'];
if(isset($_REQ['data']['commit']))
{
$this->autoCommit= $_REQ['data']['commit'];
}
$this->runAction();
}
@@ -62,8 +64,7 @@ EOT
Mind::write('currentProjectRequiredTip');
return false;
}
MindProject::analyze();
MindProject::analyze($this->autoCommit? true: false);
return $this;
}
+48
Ver Arquivo
@@ -94,6 +94,7 @@ EOT
private function action()
{
GLOBAL $_MIND;
switch($this->what)
{
case 'project':
@@ -115,6 +116,7 @@ EOT
}
Mind::copyDir(Mind::$modelsDir.'mind/', $this->projectfile);
chmod($this->projectfile, 0777);
$db= new MindDB();
@@ -144,10 +146,56 @@ EOT
".$_SESSION['pk_user']."
)";
$db->execute($qr_userProj);
//Mind::$currentProject[''];
$iniSource= Mind::$projectsDir.$this->argName.'/mind.ini';
$cP= $_MIND->defaults;
$qr_vsProj= "INSERT into version
(
version,
tag,
obs,
originalcode,
machine_lang,
framework,
database,
fk_project,
fk_user
)
values
(
'0',
'Project Started',
'',
'',
'".$cP['default_machine_language']."',
'',
'".$cP['default_dbms']."',
".$key.",
".$_SESSION['pk_user']."
)";
$db->execute($qr_vsProj);
$db->execute("COMMIT");
Mind::write('projectCreated', true, $this->argName);
$ini= file_get_contents($iniSource);
$ini= str_replace('<idiom>',
$cP['default_human_language'],
$ini);
$ini= str_replace('<technology>',
$cP['default_machine_language'],
$ini);
$ini= str_replace('<dbms>',
$cP['default_dbms'],
$ini);
file_put_contents(Mind::$projectsDir.
$this->argName.
'/mind.ini',
$ini);
Mind::openProject(Array('pk_project'=>$key,
'name'=>$this->argName));
+6 -1
Ver Arquivo
@@ -21,6 +21,7 @@
define('COMPOSED_SUBST', "/SCS/");
define('FIX_PROP_NAME', "/\\\|\,|\./");
define('IMPORT_SOURCE', "/@import [a-z0-9_\-\/\\\]+/i");
define('PROP_FIX', "((\(|[\., \n]))?+|\:");
// addresses
define('PROJECTS_DIR', '/mind3rd/projects/');
@@ -30,9 +31,13 @@
define('MIND_CONF', '/mind3rd/env/mind.ini');
define('L10N_DIR', '/mind3rd/API/L10N/');
define('LANG_PATH', '/mind3rd/API/languages/');
define('SQLITE', '/mind3rd/SQLite/mind');
// other constants
define('QUANTIFIER_MAX_MAX', 'n');
define('QUANTIFIER_MAX_MIN', 1);
define('PROPERTY_SEPARATOR', "_");
define('AUTOINCREMENT_DEFVAL', 0123);
define('AUTOINCREMENT_DEFVAL', 0123);
define('COMMIT_STATUS_OK' , 0);
define('COMMIT_STATUS_CHANGED',1);
define('COMMIT_STATUS_DROP', 2);
+35 -4
Ver Arquivo
@@ -68,8 +68,8 @@ CREATE TABLE object
name varchar(256) ,
version int4 ,
locked int4 default 0,
info varchar(2048) ,
fk_version integer ,
info varchar(2048),
fk_version integer,
PRIMARY KEY(pk_object),
FOREIGN KEY (fk_version) REFERENCES version(pk_version)
);
@@ -87,7 +87,7 @@ CREATE TABLE component
/* DDL: table property */
CREATE TABLE property
/*CREATE TABLE property
(
pk_property integer unique not null,
name varchar(255) not null ,
@@ -97,9 +97,10 @@ CREATE TABLE property
PRIMARY KEY(pk_property),
FOREIGN KEY (fk_component) REFERENCES component(pk_component)
);
*/
/* DDL: table property_pointer */
/*
CREATE TABLE property_pointer
(
pk_property_pointer integer unique not null,
@@ -108,3 +109,33 @@ CREATE TABLE property_pointer
PRIMARY KEY(pk_property_pointer),
FOREIGN KEY (fk_property) REFERENCES property(pk_property)
);
*/
/* DDL: creating the entities to deal with tables and relations */
CREATE TABLE entity
(
pk_entity integer,
status integer default 0, /* 0=ok 1=changed 2=dropped */
name varchar(80),
varsion integer default 1,
fk_version integer,
FOREIGN KEY (fk_version) REFERENCES version(pk_version)
);
CREATE TABLE property
(
pk_property integer,
name varchar(80),
type varchar(16),
size float,
options varchar(1024), /* insert the json value */
default_value text,
unique_value boolean,
required boolean,
comment text,
status integer default 0, /* 0=ok 1=changed 2=dropped */
fk_entity integer,
ref_to_property integer,
FOREIGN KEY (fk_entity) REFERENCES entity(pk_entity),
FOREIGN KEY (ref_to_property) REFERENCES property(pk_property)
);
+2 -1
Ver Arquivo
@@ -7,7 +7,8 @@ default_human_languageName=en
; default timezone
timezone=America/Sao_paulo
; the default programming language
default_machine_language=php ; not yet implemented
default_machine_language=php
default_dbms=pgsql
; default framework to be generated with, if any
; use the name of the framework here, or none to not use any
; the framework will be availiable or not, to the choosen machine language
+1 -1
Ver Arquivo
@@ -10,7 +10,7 @@ abstract class Setup {
if($db = new SQLiteDatabase('mind3rd/SQLite/mind'))
{
$DDL= file_get_contents('mind3rd/SQLite/ddl.sql');
if(!@$db->queryExec($DDL))
if(!$db->queryExec($DDL))
{
echo " <[INFO] Database already exists...it wont be touched>\n";
}
+1 -2
Ver Arquivo
@@ -43,5 +43,4 @@ abstract class UnixSetup extends Setup{
self::createExecFile();
self::createDatabase();
}
}
?>
}