From a05c15547ecdfd5f198c74ced0973bd4ae0f2151 Mon Sep 17 00:00:00 2001 From: aztech <> Date: Mon, 14 Jan 2008 08:28:23 +0000 Subject: [PL] Active Record translation --- .../protected/pages/Database/pl/ActiveRecord.page | 204 ++++++++++----------- 1 file changed, 93 insertions(+), 111 deletions(-) (limited to 'demos/quickstart') diff --git a/demos/quickstart/protected/pages/Database/pl/ActiveRecord.page b/demos/quickstart/protected/pages/Database/pl/ActiveRecord.page index 53bbdee5..a4fb3d75 100644 --- a/demos/quickstart/protected/pages/Database/pl/ActiveRecord.page +++ b/demos/quickstart/protected/pages/Database/pl/ActiveRecord.page @@ -273,7 +273,7 @@ $record = $finder->findAllByPks($keys);

find()

-

Znajduj pojedyńczy rekord, który spełnia kryteria. Kryteria mogą być częściowym łąńcuchem SQL lub obiektem TActiveRecordCriteria

+

Znajduje pojedyńczy rekord, który spełnia kryteria. Kryteria mogą być częściowym łąńcuchem SQL lub obiektem TActiveRecordCriteria

$finder = UserRecord::finder(); @@ -297,7 +297,7 @@ $finder->find($criteria); //drugi parametr dla find() jest zignorowany.
  • OrdersBy -- nazwa kolumny i sortowanie par
  • Condition -- część WHERE zapytania SQL
  • Limit -- maksymalna ilość rekordów, któe zostaną zwrócone.
  • -
  • Offset -- ofset rekordów w tablicy.
  • +
  • Offset -- offset rekordów w tablicy.
  • @@ -311,7 +311,7 @@ $criteria->Limit = 10; $criteria->Offset = 20; -
    Note: +
    Przypis: For MSSQL and when Limit and Offset are positive integer values. The actual query to be executed is modified by the Limit and Offset conditions.

    findAll()

    -

    Same as find() but returns an array of objects.

    +

    Podobnie jak find() ale zwraca tablicę obiektów.

    -

    findBy*() and findAllBy*()

    -

    Dynamic find method using parts of the method name as search criteria. -Method names starting with findBy return 1 record only -and method names starting with findAllBy return an array of records. -The condition is taken as part of the method name after findBy or findAllBy. +

    findBy*() oraz findAllBy*()

    +

    Dynamiczne metody wyszukujące używające część nazwy metody jako kryteria wyszukiwania. +Metody zaczynające się od słów findBy zwracają tylko 1 rekord natomiast metody zaczynające się findAllBy zwracają tablicę obiektów. +Warunej jest wzięty jako część nazwy metody po przedrostku findBy lub findAllBy. -The following blocks of code are equivalent: +Następujące bloki kodów są sobie równoważne:

    $finder->findByName($name) @@ -350,14 +349,13 @@ $finder->findAll('Age = ?', $age);
    Tip: -You may also use a combination of AND and OR as a condition in the dynamic methods. +Możesz również użyć połączenia AND oraz OR jako warunek w dynamicznych metodach.
    -

    findBySql() and findAllBySql()

    -

    Finds records using full SQL where findBySql() -return an Active Record and findAllBySql()returns an array of record objects. -For each column returned, the corresponding Active Record class must define a member variable or -property for each corresponding column name. +

    findBySql() oraz findAllBySql()

    +

    Znajdują rekordy używając pełnego zapytania SQL z tym, że findBySql() +zwraca Rekord Aktywny a findAllBySql()zwraca tablicę obiektów rekordów. +Dla każdej zwróconej kolumny, odpowiadająca klasa Rekordu Aktywnego musi posiadać zdefiniowaną zmienną lub właściwość odpowiadającą nazwie kolumny. class UserRecord2 extends UserRecord { @@ -368,140 +366,130 @@ $users = TActiveRecord::finder('UserRecord2')->findAllBySql($sql);

    count()

    -

    Find the number of matchings records, accepts same parameters as the findAll() method.

    +

    Zlicza ilość pasujących rekordów, akceptuje te same parametry co metoda findAll()

    -

    Inserting and updating records

    +

    Wstawianie i aktualizowanie rekordów

    -Add a new record using TActiveRecord is very simple, just create a new Active -Record object and call the save() method. E.g. +Dodanie nowego rekordu za pomocą TActiveRecord jest bardzo łatwe, po prostu stwórz nowy obiekt Rekordu Aktywnego i wywołaj metodę save(). Na przykład

    $user1 = new UserRecord(); $user1->username = "admin"; $user1->email = "admin@example.com"; -$user1->save(); //insert a new record +$user1->save(); //wstaw nowy rekord $data = array('username'=>'admin', 'email'=>'admin@example.com'); -$user2 = new UserRecord($data); //create by passing some existing data -$user2->save(); //insert a new record +$user2 = new UserRecord($data); //stwórz przekazując istniejące dane +$user2->save(); //wstaw nowy rekord -
    Tip: -The objects are update with the primary key of those the tables that contains -definitions that automatically creates a primary key for the newly insert records. -For example, if you insert a new record into a MySQL table that has columns -defined with "autoincrement", the Active Record objects will be updated with the new -incremented value.
    +
    Wskazówka: +Obiekty są aktualizowe automatycznie o wartość klucza głównego dla tych tablic, które zawierają definicję +określającą automatyczne tworzenie klucza głównego dla nowo tworzonych rekordów (przyp. tłum. autoincrement). +Na przykład jeśli wstawiasz nowy rekord do tablicy MySQL która posiada kolumnę zdefiniowaną jako to obiekt Rekordu Aktywnego +zostanie zaktualizowant o nową zwiększoną wartość.

    -To update a record in the database, just change one or more properties of -the Active Record object that has been loaded from the database and then -call the save() method. +Aby zaktualizować rekord w bazie danych po prostu zmień jedną lub więcej właściwości obiektu Rekordu Aktywnego które zostały odczytane z bazy a następnie wywołaj metodę save(). $user = UserRecord::finder()->findByName('admin'); -$user->email="test@example.com"; //change property -$user->save(); //update it. +$user->email="test@example.com"; //zmiana właściwości +$user->save(); //zaktualizuj ją

    -Active Record objects have a simple life-cycle illustrated in the following diagram. +Obiekt Rekordu Aktywnego posiada prosty cykl życia zilustrowany następujący diagram.

    alt="Active Records Life Cycle" id="fig:cycle.png" class="figure"/>

    -We see that new TActiveRecord objects are created by either using one of the find*() -methods or using creating a new instance by using PHP's new keyword. Objects -created by a find*() method starts with clean state. New instance of -TActiveRecord created other than by a find*() method starts with new state. -Whenever you -call the save() method on the TActiveRecord object, the object enters the clean -state. Objects in the clean becomes dirty whenever one of more of its -internal states are changed. Calling the delete() method on the object -ends the object life-cycle, no further actions can be performed on the object. -

    - -

    Deleting existing records

    +Widzimy, że nowe obiekty Rekordu Aktywnego są tworzone zarówno przez jedną z metod find*() +lub poprzez stworzenie nowej instancji poprzez użycie polecenia PHP new. Obiekty stworzone przez metodę find*() +zaczynają ze stanem czysty (ang. clean). Nowa instancja TActiveRecord stworzona inaczej niż za pomocą metod find*() zaczyna ze stanem nowy (ang. new). +Kiedykolwiek wywołasz metodę save() na obiekcie TActiveRecord, obiekt przyjmuje stan czysty. +Obiekty będące czystymi stają się brudne (ang. dirty) kiedy jeden lub więcej ze stwoich wewnętrznych stanów ulegnie zmianie. +Wywoałanie metody delete() obiektu kończy cykl życia, żadne inne akcje nie mogą być wywołane na obiekcie. +

    + +

    Usuwanie istniejących obiektów

    - To delete an existing record that is already loaded, just call the delete() method. - You can also delete records in the database by primary keys without - loading any records using the deleteByPk() method (and equivalently the deleteAllByPks() method). - For example, to delete one or several records with tables using one or more primary keys. + Aby usunąc istniejący rekord, który jest załadowany, po prostu wywołaj metodę delete. + Możesz rónież usunąć rekord w bazie danych poprzez klucz główny bez ładowania żadnego rekordu używając metody + deleteByPk() (również metoda deleteAllByPks()). + Na przykład, aby usunąć jeden lub więcej rekordów z tabeli używając jednego lub wielu kluczów głównych:

    -$finder->deleteByPk($primaryKey); //delete 1 record -$finder->deleteAllByPks($key1,$key2,...); //delete multiple records -$finder->deleteAllByPks(array($key1,$key2,...)); //delete multiple records +$finder->deleteByPk($primaryKey); //usuwanie 1 rekordu +$finder->deleteAllByPks($key1,$key2,...); //usuwanie wielu rekordów +$finder->deleteAllByPks(array($key1,$key2,...)); //usuwanie wielu rekordów

    -For composite keys (determined automatically from the table definitions): +Dla klucza złożonego (ustalanego automatycznie na podstawie definicji tablicy):

    -$finder->deleteByPk(array($key1,$key2)); //delete 1 record +$finder->deleteByPk(array($key1,$key2)); //usuwanie 1 rekordu -//delete multiple records +//usuwanie wielu rekordów $finder->deleteAllByPks(array($key1,$key2), array($key3,$key4),...); -//delete multiple records +//usuwanie wielu rekordów $finder->deleteAllByPks(array( array($key1,$key2), array($key3,$key4), .. )); -

    deleteAll() and deleteBy*()

    +

    deleteAll() oraz deleteBy*()

    -To delete by a criteria, use deleteAll($criteria) and deleteBy*() -with similar syntax to findAll($criteria) and findAllBy*() as -described above. +Aby usunąć używając kryteria użyj deleteAll($criteria) oraz deleteBy*() +z podobną składnią jak findAll($criteria) oraz findAllBy*() opisaną wcześniej.

    -//delete all records with matching Name +//usuwanie wszystkich rekordów z pasującym Name $finder->deleteAll('Name = ?', $name); $finder->deleteByName($name); -//delete by username and password +//usuwanie na podstawie Name oraz Password $finder->deleteBy_Username_And_Password($name,$pass); -

    Transactions

    -

    All Active Record objects contain the property DbConnection - that can be used to obtain a transaction object. +

    Tranzakcje

    +

    Wszystkie obiekkty Rekordu Aktywnego zawierają właściwość DbConnection, + która może być używana by uzyskać obiekt tranzakcyjny. $finder = UserRecord::finder(); -$finder->DbConnection->Active=true; //open if necessary +$finder->DbConnection->Active=true; //otwórz jeśli to konieczne $transaction = $finder->DbConnection->beginTransaction(); try { $user = $finder->findByPk('admin'); - $user->email = 'test@example.com'; //alter the $user object + $user->email = 'test@example.com'; //zmień obiekt użytkownika $user $user->save(); $transaction->commit(); } -catch(Exception $e) // an exception is raised if a query fails +catch(Exception $e) // wyjątek jest wołany jeśli zapytanie nie powiedzie się { $transaction->rollBack(); } -

    Events

    +

    Zdarzenia

    -The TActiveRecord offers two events, OnCreateCommand and OnExecuteCommand. +Rekord Aktywny oferuje dwa zdarzenia: OnCreateCommand oraz OnExecuteCommand.

    -

    The OnCreateCommand event is raised when a command is prepared and -parameter binding is completed. The parameter object is TDataGatewayEventParameter of which the -Command property can be inspected to obtain the SQL query to be executed. +

    Zdarzenie OnCreateCommand jest wołane gdy polecenie jest przygotowywane i przypisywanie (ang. binding) parametrów jest zakończone. + Parametrem obiektu jest TDataGatewayEventParameter, którego właściwość Command może być sprawdzona by otrzymać zapytanie, które będzie wykonane wykonywane.

    -The OnExecuteCommand event is raised when a command is executed and the -result from the database was returned. The parameter object is TDataGatewayResultEventParameter -of which the Result property contains the data return from the database. -The data returned can be changed by setting the Result property. +Zdarzenie OnExecuteCommand jest wywoływane kiedy polecenie jest wykonane i rezultat z bazy danych został zwrócony. + Parametrem obiektu jest TDataGatewayResultEventParameter, którego właściwość Result zawiera dane zwrócone z bazy danych. + Dane zwrócone mogą zostać zmienione poprzez ustawienie właściwości Result.

    -

    Logging Example

    -

    Using the OnExecuteCommand we can attach an event handler to log -the entire SQL query executed for a given TActiveRecord class or instance. For example, we define -a base class and override either the getDbConnection() or the constructor. +

    Przykład z logowaniem

    +

    Używając OnExecuteCommand możemy przypiąć uchwyt zdarzenia by logować całe +zapytanie SQL wwywoływane dla danej instancji lub klasy TActiveRecord. Na przykład definiujemy klasę bazową i nadpisujemy +metodę getDbConnection() lub konstruktor.

    @@ -528,45 +516,40 @@ function logger($sender,$param) var_dump($param->Command->Text); } TActiveRecord::finder('MyRecord')->OnExecuteCommand[] = 'logger'; -$obj->OnExecuteCommand[] = array($logger, 'log'); //any valid PHP callback. +$obj->OnExecuteCommand[] = array($logger, 'log'); //dowolny poprawny callback PHP -

    Active Record Relationships

    +

    Relacje dla Rekordu Aktywnego

    -The Prado Active Record implementation supports the foreign key mappings for database -that supports foreign key constraints. For Active Record relationships to function the -underlying database must support foreign key constraints (e.g. MySQL using InnoDB). +Implementacja Rekordu Aktywnego w Prado wspiera mapowanie kluczów obcych dla baz, które wspierają ograniczenia (ang. constraints) kluczów obcych. + Aby relacje dla Rekordu Aktywnego działały używana baza danych musi wspierać ograniczenia klucza głównego (np. MySQL używająca InnoDB)

    -In the following sections we will consider the following table relationships between -Teams, Players, Skills and Profiles. +W następnych sekcjach będziemy rozważać nastepujące relacje pomiędzy tabelami Teams, Players, Skills oraz Profiles.

    class="figure" /> -

    The goal is to obtain object models that represent to some degree the entity -relationships in the above figure. +

    Celem jest uzyskanie modelu obiektowego, który będzie reprezetnował w pewnym stopniu relacje pomiędzy polami z powyższego rysunku.

    class="figure" />

    -There is a mismatch between relationships with objects and table relationships. -First there's a difference in representation. Objects handle links by storing references -that are held by the runtime memory-managed environment. Relational databases handle -links by forming a key into another table. Second, objects can easily use collections -to handle multiple references from a single field, while normalization forces -all entity relation links to be single valued. This leads to reversals of the data -structure between objects and tables. The approach taken in the Prado Active Record -design is to use the table foreign key constraints to derive object relationships. This implies -that the underlying database must support foreign key constraints. +Istnieje rozbieżność pomiędzy relacjami w obiektach i relacjami w tablicach. + Po pierwsze jest różnica w reprezentacji. Obiekty trzymają powiązanie poprzez przechowywanie referencji, +które są trzymane poprzez zarządzające pamięcią środowiko uruchomieniowe. Bazy relacyjne trzymają powiązanie poprzez utworzenie klucza do innej tablicy. + Po drugie, obiekty mogą łatwo uzywać kolekcji by trzymać wielokrotnie referencje z jednego pola, +to handle multiple references from a single field, gdyż normalizacja zmusza wszystkie powiązania relacji encji by były pojedyńczymi wartościami. +To prowadzi do odwrócenia struktury danych pomiędzy obiektami i tablicami. +Podejście zastosowane w modelu Rekordu Aktywnego Prado uzywa ograniczeń kluczów obcych tablicy do wyprowadzenia relacji obiektów. +To implikuje fakt wspierania ograniczeń kluczów obcych dla bazy danych.

    Tip: -For SQLite database, you may create tables that defines the foreign key -constraints such as the example below. However, these constraints are NOT -enforced by the SQLite database itself. +Dla baz danych SQLite możesz stworzyć tablice, które definiują ograniczenia kluczó obcych tak jak na przykładzie poniżej. +Jednakże te ograniczenia NIE SĄ narzucane przez samą bazę SQLite. CREATE TABLE foo ( @@ -582,16 +565,15 @@ CREATE TABLE bar
    -

    Foreign Key Mapping

    -

    The entity relationship between the Teams and Players table is what is known -as an 1-M relationship. That is, one Team may contain 0 or more Players. In terms of -object relationships, we say that a TeamRecord object has many PlayerRecord objects. -(Notice the reversal of the direction of relationships between tables and objects.) +

    Mapowanie kluczów obcych

    +

    Relacja pól pomiędzy tablicami Teams and Players jest znana jako relacja jeden-do-wielu (ang. 1-M). Oznacza to, że jeden Team moze zawierać zero lub więcej Players. Z punktu widzenia relacji obiektów +powiemy, że obiekt TeamRecord posiada wiele (ang. has many) obiektów PlayerRecord. +(Zauważ odwrócenie kierunku relacji pomiędzy tablicami a obiektami)

    -

    Has Many Relationship

    +

    Relacja posiada wiele (ang. has Many Relationship)

    -We model the Team object as the following Active Record classes. +Zamodelujemy obiekt Team jako następującą klasę Rekordu Aktywnego.

    class TeamRecord extends TActiveRecord -- cgit v1.2.3