guião para criar aplicações simples em apex (parte...
TRANSCRIPT
Guião para criar aplicações simples em APEX (parte I)
Guide to create simple Apex applications (part I)
O guião que se segue usará uma base de dados que decorre do seguinte DER:
The following script will use a database from the following DER:
Ao qual correpondem as seguintes tabelas:
Corresponding to the following tables:
Socio=(num_socio, nome_socio, bi_socio,data_nsc_socio, morada_socio,
tlf_socio, sexo_socio)
Genero=(cod_genero, nome_genero)
Editora=(cod_editora, nome_editora)
Actor=(cod_actor, nome_actor)
Realizador=(cod_realizador, nome_realizador)
Filme=(cod_filme, nome_filme, ano_filme, preço_dia_filme,
dias_sem_multa_filme, multa_dia_filme, cod_genero, cod_editora)
Filme_actor=(cod_filme,cod_actor)
Filme_realizador=(cod_filme,cod_realizador)
Copia=(cod_filme,num_copia)
Aluguer=(cod_filme,num_copia,data_aluguer, num_socio, data_prev_dev_aluguer)
Devolucao=(cod_filme, num_copia, data_aluguer, num_socio,
data_devolucao, estado_devolucao)
Estão também disponíveis sequências que foram criadas com os seguintes comandos SQL:
Also available are sequences that were created with the following SQL
commands:
create sequence seq_socio increment by 1 start with 1; create sequence seq_genero increment by 1 start with 1; create sequence seq_editora increment by 1 start with 1; create sequence seq_filme increment by 1 start with 1; create sequence seq_actor increment by 1 start with 1; create sequence seq_realizador increment by 1 start with 1;
Assim, para entrar no APEX, aceda ao seguinte endereço :
So, to enter the APEX, go to the following address:
http://10.170.138.40:8080/ords
Em que nnnnn deve ser substituído pelo número de aluno. / where nnnnn must be substituted
by the number of the student.
Wnnnnn é a identificação dum workspace que está ligado ao user SQL IBDnnnnn
previamente criado e já usado em ambiente SQL. Por outro lado, unnnnn identifica um user
Apex particular (o aluno). Este user está ligado ao workspace Wnnnnn.
Wnnnnn is the ID of a workspace that is connected to the SQL user IBDnnnnn previously
created and already used in SQL environment. On the other hand, unnnnn identifies a
particular Apex user (the student). This user is connected to the Wnnnnn workspace.
A partir de agora, apenas por razões de conveniência, neste guião será usado “jfs” em vez do
número em nnnnn. Assim, onde surgir a string “jfs” neste guião, deverá surgir no contexto na
interação com a iterface APEX, para cada aluno, o seu número; nalguns casos precedido pelo
prefixo “IBD”.
From now on, just for the sake of convenience, this guide will use "jfs" instead of the number in nnnnn. Thus, whenever the string "jfs" appears in this guide, the student number should appear in the context of the interaction with APEX; in some cases it will be preceded by the prefix "IBD".
Depois de entrar verá / after entering you will see:
Depois clique em App Builder e verá:/ Then click on App Builder and you see:
Uma aplicação Apex assenta numa coleção de páginas ligadas usando tabs, buttons e links hypertext.
An Apex application lies on a collection of linked pages using tabs, buttons and
hypertext links.
Clique em Create / Click on Create.
Escolha Desktop e Next / choose Desktop and Next
Em vez de “Schema JFS” deverá ver “Schema IBDnnnnn”. Em Name indique um nome para a
sua aplicação; neste guia vamos usar o nome AppVideoClub. Deixe os outros campos como
estão e clique em Next.
Instead of "Schema JFS" you should see "Schema IBDnnnnn". In Name enter a name for
your application; in this guide we will use the name AppVideoClub. Leave the other
fields as they are and click Next.
A primeira página, chamada Home – se quisermos podemos mudar-lhe o nome – é do tipo
Blank (destinada a página menú)
The first page, named Home – if we want we can change this name – is of type Blank (it
will be the menu page).
Clique Next /Click Next
Aceite o default e clique Next / Accept the default and click Next
Pode aceitar o default e clique Next / you may accept the default and click Next
Clique em Create Application / Click Create Application
Vamos agora criar outra página; clique em Create Page
Now we are going to create another page; click on Create Page.
Selecione Report e clique em Next / select Report and click Next
Basicamente, uma página do tipo Report serve para mostrar conteúdos de tabelas, views ou
resultados de queries; nesta página não é permitido alterar dados da base de dados.
Basically, a Report page is used to display table contents, views, or query results; on this page it is not allowed to change data from the database.
Depois selecione Interactive Report e Click Next / Then select Interactive Report and Click
Next
Vamos tratar do report das editoras disponíveis na tabela editora. Como está na figura acima,
dê o nome Editora à página, e escolha Breadcrumb para que esta página fique ligada à
página inicial Parent Entry. Assim, à frente de Parent Key deverá selecionar Home, que
funionará como página menú da aplicação. Nessa página Home existirá uma entrada para
aceder a este Report, entrada essa que aqui deverá indicar ao preencher Entry Name com o
nome Editora. Depois clique em Next.
Let's look at the Editora (publisher) report available in the editora table. As it is in the
figure above, give the Editora name to the page, and choose Breadcrumb so that this
page is linked to the Parent Entry home page. So, ahead of Parent Key you should se-
lect Home, which will work as the application menu. On this Home page there will be an
entry to access this Report, which entry you enter here when filling in Entry Name with
the name Editora. Then click Next.
Agora preencha como na figura acima e clique Next.
Now fill in as in the picture above and click Next.
Depois há que indicar em Souce Type que a fonte do report é do tipo Table e selecionar a tabela Editora . Clique no botão >> para selecionar todos os atributos da tabela; depois Next.
Then you have to indicate in Souce Type that the source of the report is of Table type
and select the table Editora. Click >> to select all attributes from the table; then Next.
Depois clique em Application nnn / Then click Application nnn
Agora faça Run Application / Now click Run Application
Agora entre na aplicação com os seus user e password / Now enter in your application
with your user and password
Clique na entrada Editora /click on Editora entry
E verá o conteúdo da tabela / and you will see the table content
Pode agora, por exemplo, clicar em Actions, escolher Filter e indicar uma condição como no exemplo abixo
You can click on Actions, select Filter and indicate a condition as in the example below
E verá / and you will see:
Criação de um report sobre junção de tabelas
Building a report on a join of tables.
Clique em Application nnn e Create page/ Click on Application nnn and Create page
Depois escolha Report / Then select Report
E depois interactive Report / and then Interactive Report
Em seguida aceite o número da página, indique Filme como nome na nova página e como nome da entrada. Preencha o resto dos campos como se indica. Depois faça Next
Then accept the page number, enter Filme as the name on the new page and entry. Fill
the rest of the fields as indicated. Then do Next.
Em seguida indique que vai ligar esta nova página ao menú Home e faça Next
Then indicate that you will link this new page to the Home menu and click Next
Depois indique o nome da tabela (Filme) e clique em Create
After indicating the name of the table (Filme) click on Create
Agora pode clicar em Save and Run Page para ver correr esta página
You can now click Save and Run Page to see this page working.
Assim, este é o resultado do SQL interno que é guiado pelo conjunto de atributos na tabela Filme. Para além dos outros atributos, são mostrados os códigos de editora e de género, que são valores núméricos que não permitem uma leitura digamos “natural e imediata” como a que se conseguiria se em vez deles, estivessem os nomes da editora e do género,
respetivamente. Em face desta contingência, vamos contornar o problema. Clique em Edit Page n (o número desta última página).
Thus, this is the result of the internal SQL that is guided by the set of attributes in table
Filme, which shows in addition to the other attributes, the editora and género codes,
which are numeric values that do not allow a reading to say "natural and immediate" as
that would be obtained if the names of the editora and the género were present, instead
of the codes. In face of this contingency, we will work around the problem. Click Edit
Page n (the number of this last page)
Agora, na zona Content Body, clique em Filme e verá à direita o código SQL que gerou a
leitura do conteúdo da tabela Filme (seta vermelha).
Now, in the zone Content Body, click on Filme and you will see the SQL code that
showed the table Filme content (red arrow).
Agora substitua aquele código SQL pelo seguinte, cuja alteração usa no report do Filme os nomes da editora e do género em vez dos respetivos códigos que são de leitura, à partida, não entendível.
Now replace that SQL code with the following, which uses in the Filme report, the
names of the editora and the género instead of their codes that are not easily readable.
select nome_filme as nome,ano_filme as ano,preco_dia_filme as "preco
dia",dias_sem_multa_filme as "dias sem multa",multa_dia_filme as "multa
dia",nome_genero as genero,nome_editora as editorafrom filme natural inner join editora
natural inner join genero
Junto à zona do código escrito de SQL, por cima e à direita (seta vermelaha), click em Code Editor – SQL Query para obter uma janela onde pode escrever ou alterar o novo códigon SQL. Depois clique em OK para validar. Se houver erros, emende e volte a clicar em Ok.
Next to the area of the written SQL code, above and to the right (red arraw), click Code
Editor - SQL Query to get a window where you can write or change the new SQL code.
Then click OK to validate. If there are errors, amend and click OK again.
Quando não hover erros, corra a página para ver este resultado onde os códigos e os nomes
dos atritutos foram visualmente “substituídos” por forma a permitir uma compreensão plena.
When there are no errors, run the page to see this result where the codes and names of
the attributes have been visually “replaced” in order to allow a full understanding.
Criar uma página Form para inserir e modificar dados
Create a Form page to insert and modify data
Clicar em Application nnn e Create Page / Click Application nnn and Create Page
Selecione Form / select Form
Escolha Report with Form on Table / choose Report with Form on Table
Dê nomes ao Report e ao Form, e dê indicação de que quer que haja uma entrada no menú em Home para estas páginas, como indicado acima
Name the Report and the Form, and indicate that you want an entry in the Home menu
for these pages, as indicated above.
Depois faça Next / then click Next
Na janela anterior escolha a tabela sobre a qual vai incidir este Report; neste caso é socio. Depois clique em Next.
In the previous window choose the table on which this report will focus; in this case it
is socio. Then click Next.
Agora, tal como se mostra no quadro de cima, escolha “select Primary Key Columns”,
carregue em >> para incluir no forms todas os atributos da tabela, aceite NUM_SOCIO como
chave e escolha “Existing sequence” como forma de gerar um novo número para cada futuro
novo tuplo na tabela socio. Depois faça Create.
Now, as shown in the table above, choose "select Primary Key Columns", click on >> to
include all attributes of the table in the form, accept NUM_SOCIO as the key and choose
"Existing sequence" as a way to generate a new number for each future new tuple in
socio table. Then click Create.
De seguida, caso não tenha indicado anteriormente o nome da sequência a usar para a
geração dos valores para a chave NUM_SOCIO, faça o seguinte: edite a última página (esta do
Forms) e, clicando em Get Pk (na zona Page Processing) verá à direita o código SQL que deverá
alterar através dum clique no canto superior direito que lhe dará acesso à seguinte janela de
edição (setas a vermelho):
Then, if you did not previously indicate the name of the sequence to use for generating
the values for the NUM_SOCIO key, do the following: edit the last page (this one from
Forms) and clicking Get Pk (in the Page Processing zone) to the right the SQL code that
you will have to change through a click in the upper right corner that will give you ac-
cess to the following editing window (see arrows in red):
Depois faça OK e, se não houver erros de edição, corra a página.
Then click OK and, if there are no editing errors, run the page.
Agora, para criar um novo socio, vamos preencher os campos dele, excepto o número de sócio que, por ser chave, optámos pela sua geração automática através de sequência, como foi dito atrás. Depois clicar Create. Nota: por vezes a palavra sócio é aqui escrita sem acento por se referir à tabela,cuja designação não incluiu o acento. O mesmo se passa com género.
Now, to create a new socio (member), we will fill in its fields except the socio number
that, because it is the key, we have chosen to be generated automatically. Then click
Create.
E deverá ver o resultado da inserção deste novo socio
And you should see the result of inserting this new socio.
Socio cujos valores dos atributos pode alterar ou apagar clicando primeiro no lapis de edição à esquerda (seta vermelha).
Socio whose attribute values can be changed or deleted by first clicking on the edit
pencil on the left (see red arrow).
Joaquim F Ferreira da Silva
Abril de 2019