• Welcome to TUKE FÓRUM - Fórum pre študentov Technickej Univerzity v Košiciach.
 

MaGSA - Modelovanie a generovanie softvérových architektúr

Started by jan, 04.02.2011, 22:09:45

« predchdzajce - alie »

domino3d

super, som to spravil cez for-y tak dufam ze pojde
len jeden problem ked spustim tak findEntity Oddelenie najde, ale Zamestanca uz nie.
tera zto skusam tak ze som si dal vypis do tejto metody a volam ju v make  ako
model.findEntity("Zamestnanec");
model.findEntity("Oddelenie");

no neviem kde je chyba
 
    public Entity findEntity(String name){
        Entity ent = null;
        for (Entity entity : this.getEntities()) {
            if (entity.getName().equals(name)) {
                return ent=entity;
            }   
            else{
                System.out.printf("nenasiel som nic(%s)",name.toString());
                return  null;
            }
        }
        return ent;
    }


PS: ahaaaa, diki qwert, vyskusam
vivat academicus

qwerty

skus to takto:
    public Entity findEntity(String name){
        Entity ent = null;
        //System.out.printf("%s... ",name.toString());
        for (Entity entity : this.getEntities()) {
            //System.out.print(entity.getName());
            if (entity.getName().equals(name)) {
                System.out.printf("nasiel som : %s",name.toString());
                return ent=entity;
            }
        }
        System.out.printf("nenasiel som nic(%s)",name.toString());
        return ent;
    }
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.

domino3d

...

edit. @Easoft: diki, ja som tam pchal getConstraints namiesto getConstraint
vivat academicus

Easoft

Quote from: Domino3D on  22.03.2011, 03:05:37
ako sa ja z DatabaseScriptGeneratora ja dostanem k entitam kde su ulozene definície obmedzení ?

for (Entity entity : getModel().getEntities()) {
  for (Property property : entity.getProperties()) {
    Regex c = property.getConstraint(Regex.class);
    if(c != null) System.out.println("Tato entita ma vlastnost s obmedzenim Regex");
  }
}

domino3d

nerozumiem tomu ze mi hodi null point exception pri volani  getConstraint, a nasmeruje ma do property.java na riadku s forom, zrejme to bude ked vola this.constraints) tak tam nema nic

uz ma napadlo v Make spravit tak ze najprv srpavi builder s obmedzeniami a potom vygeneruje skript pre db, no to iste

run:
model [entity Oddelenie [nazov, kod, poschodie], entity Zamestnanec [meno, priezvisko, vek]]
Exception in thread "main" java.lang.NullPointerException
        at sk.tuke.magsa.tools.metamodel.Property.getConstraint(Property.java:59)
        at sk.tuke.magsa.tools.generator.DatabaseScriptGenerator.generate(DatabaseScriptGenerator.java:45)
        at Make.main(Make.java:31)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

vivat academicus

qwerty

Quote from: Domino3D on  22.03.2011, 19:58:50
nerozumiem tomu ze mi hodi null point exception pri volani  getConstraint, a nasmeruje ma do property.java na riadku s forom, zrejme to bude ked vola this.constraints) tak tam nema nic

uz ma napadlo v Make spravit tak ze najprv srpavi builder s obmedzeniami a potom vygeneruje skript pre db, no to iste

nezabudol si na tuto poznamku?
Poznámka: Nezabudnite, že pri kompozícii dvoch jazykov je nutné vložiť do príslušnej vlastnosti Property definované obmedzenia cez setConstraints. (cv.5,ul.7)

P.S.: a s tym builderom obmedzeni pred generaciou db skriptu mas pravdu, lebo najprv musis spracovat obmedzenia, aby si z nich mohol potom generovat db skript zohladnujuci tebou definovane obmedzenia...
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.

domino3d


no na konci validate mam toto co by malo zabezpecovat, doteraz som myslel ze to ide jak ma


edit: getConstraints som obalil do try catch aby nedaval nullpointex.. myslim ze to do buducna nie je ciste tiesenie ale ked pojde...
vivat academicus

mishelka

Quote from: Domino3D on  23.03.2011, 02:24:51
no na konci validate mam toto co by malo zabezpecovat, doteraz som myslel ze to ide jak ma


edit: getConstraints som obalil do try catch aby nedaval nullpointex.. myslim ze to do buducna nie je ciste tiesenie ale ked pojde...


Neviem ci sa toto hodi do validate (skor za jej volanie)... Inak brutal stack :)
  

#define TRUE FALSE //Happy debugging suckers :D

jan

Úloha: Použite anotáciu @References v konštruktore triedy Reference pre určenie automatického  ;D ;D ;D ;D vytárania  ;D ;D ;D ;D referencií.
- Understanding is a three edged sword. (Your side, their side, and the truth) [Vorlons' saying]
(thanks to Agamemnon)

tuxik

Quote from: jan on  26.03.2011, 01:11:33
toto mi to vygenerovalo po 8. cviceni

z chybami:
-----------
- package sk.tuke.magsa.tools.parserext.javacc does not exist
- can not find symbol ParseException

package sk.tuke.magsa.tools.parserext;

public class Parser {
 private static sk.tuke.magsa.tools.parserext.javacc.Parser _parser;

 public sk.tuke.magsa.tools.metamodel.Model parse(String input) throws ParseException {
   sk.tuke.magsa.tools.parserext.javacc.ParserTokenManager tm = new sk.tuke.magsa.tools.parserext.javacc.ParserTokenManager(input);
   if (_parser == null) {
     _parser = new sk.tuke.magsa.tools.parserext.javacc.Parser(tm);
   } else {
     _parser.ReInit(tm);
   }

   try {
     tuke.pargen.ReferenceResolver referenceResolver = tuke.pargen.ReferenceResolver.createInstance();
     sk.tuke.magsa.tools.metamodel.Model root = sk.tuke.magsa.tools.parserext.javacc.Parser.parse();
     referenceResolver.resolveReferences();
     return root;
   } catch (sk.tuke.magsa.tools.parserext.javacc.ParseException e) {
     throw new ParseException("Problem parsing source code ", e);
   }
 }

 public sk.tuke.magsa.tools.metamodel.Model parse(java.io.Reader reader) throws ParseException {
   try {
     return parse(readAsString(reader));
   } catch(java.io.IOException e) {
     throw new ParseException("Problem reading input file", e);
   }
 }

 private String readAsString(java.io.Reader r) throws java.io.IOException {
   StringBuilder sb = new StringBuilder();
   java.io.BufferedReader br = new java.io.BufferedReader(r);
   String line;
   while ((line = br.readLine()) != null) {
     sb.append(line + "\n");
   }
   return sb.toString();
 }
}


Vyskusaj súbor nbproject/project.properties zmenit takto: build.generated.sources.dir=${basedir}/src-framework ... mne to takto ide

jan

Quote from: tuxik on  26.03.2011, 05:09:33
Vyskusaj súbor nbproject/project.properties zmenit takto: build.generated.sources.dir=${basedir}/src-framework ... mne to takto ide

diki ide
- Understanding is a three edged sword. (Your side, their side, and the truth) [Vorlons' saying]
(thanks to Agamemnon)

jan

Quote from: tuxik on  26.03.2011, 05:09:33
Vyskusaj súbor nbproject/project.properties zmenit takto: build.generated.sources.dir=${basedir}/src-framework ... mne to takto ide

teda az na to ze do vygenerovanych suborov dava

package sk.tuke.magsa.tools.parserext

ale generuje to do packagu

ap-source-output.sk.tuke.magsa.tools.parserext

Ale funguje to aj tak.
- Understanding is a three edged sword. (Your side, their side, and the truth) [Vorlons' saying]
(thanks to Agamemnon)

jan

este pre takych ako som ja, co nevedia co cinia  ;),
anotacie treba pridat podla ukazok v postupe do tychto suborov:
- Entity
- Model
- Property
- Reference
- Type
- Length
- Range
- Required
- Regex
- Unique (u mna)
- Understanding is a three edged sword. (Your side, their side, and the truth) [Vorlons' saying]
(thanks to Agamemnon)

mishelka

Quote from: jan on  25.03.2011, 16:08:18
Úloha: Použite anotáciu @References v konštruktore triedy Reference pre určenie automatického  ;D ;D ;D ;D vytárania  ;D ;D ;D ;D referencií.
Co je na tom ";D"? Ved bolo treba spravit cely nastroj na to, aby ti to tam zahlasilo ci mozes taku anotaciu pouzit na danom mieste alebo nie a ako ju mozes pouzit... A taky vyvoj urcite netrval tri dni ;) Nie je to take jednoduche ako to vyzera na prve pouzitie ;) Ale ak mas nejaky navrh, napis ako by sa to dalo zlepsit, mozno sa posnazime :)
  

#define TRUE FALSE //Happy debugging suckers :D

t0Mi

Quote from: mishelka on  28.03.2011, 15:04:16
Quote from: jan on  25.03.2011, 16:08:18
Úloha: Použite anotáciu @References v konštruktore triedy Reference pre určenie automatického  ;D ;D ;D ;D vytárania  ;D ;D ;D ;D referencií.
Co je na tom ";D"? Ved bolo treba spravit cely nastroj na to, aby ti to tam zahlasilo ci mozes taku anotaciu pouzit na danom mieste alebo nie a ako ju mozes pouzit... A taky vyvoj urcite netrval tri dni ;) Nie je to take jednoduche ako to vyzera na prve pouzitie ;) Ale ak mas nejaky navrh, napis ako by sa to dalo zlepsit, mozno sa posnazime :)
veď "vytárania" :)

jan

Quote from: mishelka on  28.03.2011, 15:04:16
Quote from: jan on  25.03.2011, 16:08:18
Úloha: Použite anotáciu @References v konštruktore triedy Reference pre určenie automatického  ;D ;D ;D ;D vytárania  ;D ;D ;D ;D referencií.
Co je na tom ";D"? Ved bolo treba spravit cely nastroj na to, aby ti to tam zahlasilo ci mozes taku anotaciu pouzit na danom mieste alebo nie a ako ju mozes pouzit... A taky vyvoj urcite netrval tri dni ;) Nie je to take jednoduche ako to vyzera na prve pouzitie ;) Ale ak mas nejaky navrh, napis ako by sa to dalo zlepsit, mozno sa posnazime :)

jj, pekne ze si myslis, ze o tom az tak premyslam :), ale ja som fakt myslel len ten preklep :)
- Understanding is a three edged sword. (Your side, their side, and the truth) [Vorlons' saying]
(thanks to Agamemnon)

Kvacinka

Ide vam ten regex na databze ??? ja pouzivam normalnu derby JAVA a ked davam check like porovnat tak mi to nefunguje a na nete som nasiel ze sa regex v sql robi pomocou check like. Tabulku vytvori ale potom musim zadat presne do property kde mam regex presne ten string ktory som dal ako regex pricom cez test mi to prejde.

http://www.java2s.com/Tutorial/Oracle/0120__Table/SettingtheRegularexpressioncheckforvarcharfield.htm

tu je prikald ale mne to tak nefunguje neviem ci to derby nepodporuje.

a moj create

CREATE TABLE Zamestanenec (
  ident INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  meno  VARCHAR(32) NOT NULL CHECK( (LENGTH(meno) >= 2) AND (LENGTH(meno) <= 32)  AND (meno LIKE '[A-Za-z]+')),
  priezvisko  VARCHAR(16) NOT NULL CHECK( (LENGTH(priezvisko) >= 0) AND (LENGTH(priezvisko) <= 16) ),
  vek INT NOT NULL CHECK((vek >= 0) AND (vek <= 150))
);

cez test v dao mi prejde meno ale pri vkladani do db hodi ze sa nezhoduje z regexom a musim napisat presne [A-Za-z]+ inak nesplnim podmienku

a nefunguje ani ten ich regex neviem ci to derby potporuje alebo nie...

mishelka

Quote from: jan on  28.03.2011, 19:18:44
Quote from: mishelka on  28.03.2011, 15:04:16
Quote from: jan on  25.03.2011, 16:08:18
Úloha: Použite anotáciu @References v konštruktore triedy Reference pre určenie automatického  ;D ;D ;D ;D vytárania  ;D ;D ;D ;D referencií.
Co je na tom ";D"? Ved bolo treba spravit cely nastroj na to, aby ti to tam zahlasilo ci mozes taku anotaciu pouzit na danom mieste alebo nie a ako ju mozes pouzit... A taky vyvoj urcite netrval tri dni ;) Nie je to take jednoduche ako to vyzera na prve pouzitie ;) Ale ak mas nejaky navrh, napis ako by sa to dalo zlepsit, mozno sa posnazime :)

jj, pekne ze si myslis, ze o tom az tak premyslam :), ale ja som fakt myslel len ten preklep :)
Teda to som si fakt nevsimla :D :D :D :D nabuduce daj boldom lebo ja som slepa :D :D :D zabite :D :D :D
  

#define TRUE FALSE //Happy debugging suckers :D

mishelka

Quote from: Kvacinka on  29.03.2011, 06:00:06
Ide vam ten regex na databze ??? ja pouzivam normalnu derby JAVA a ked davam check like porovnat tak mi to nefunguje a na nete som nasiel ze sa regex v sql robi pomocou check like. Tabulku vytvori ale potom musim zadat presne do property kde mam regex presne ten string ktory som dal ako regex pricom cez test mi to prejde.

http://www.java2s.com/Tutorial/Oracle/0120__Table/SettingtheRegularexpressioncheckforvarcharfield.htm

tu je prikald ale mne to tak nefunguje neviem ci to derby nepodporuje.

a moj create

CREATE TABLE Zamestanenec (
  ident INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  meno  VARCHAR(32) NOT NULL CHECK( (LENGTH(meno) >= 2) AND (LENGTH(meno) <= 32)  AND (meno LIKE '[A-Za-z]+')),
  priezvisko  VARCHAR(16) NOT NULL CHECK( (LENGTH(priezvisko) >= 0) AND (LENGTH(priezvisko) <= 16) ),
  vek INT NOT NULL CHECK((vek >= 0) AND (vek <= 150))
);

cez test v dao mi prejde meno ale pri vkladani do db hodi ze sa nezhoduje z regexom a musim napisat presne [A-Za-z]+ inak nesplnim podmienku

a nefunguje ani ten ich regex neviem ci to derby potporuje alebo nie...
Regexy netreba kontrolovat  velmi na databaze (aspon u mna nie), ked vam to nejde, nerobte ho...
  

#define TRUE FALSE //Happy debugging suckers :D

Kvacinka

tak je to doplnkova... a nejde to len na lokalnej java db. Ked to davam do inej db tak to funguje...

lorddoom

zdravim, nerobil niekto nahodou obmedzenie Unique ? neviete ako by sa to dalo zapisat cez velocity aby mi to generovalo aj vystup ? pretoze tam by trebalo porovnavat vkladany s uz vlozenym v databaze a neviem ci sa to da nejako jednoducho zrobit, any idea ?? diky moc :))

jan

Unique.vm

        // Unique
        if(object.get${generator.toUCIdent($property.name)}() != null) {
            try {
                Class.forName("org.apache.derby.jdbc.ClientDriver");
                Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/magsa", "magsa", "magsa");

                String sql = "SELECT $property.name FROM $item.name WHERE $property.name = ?";
                PreparedStatement prest = con.prepareStatement(sql);

                prest.$generator.psSetMethod($property.type)(1, object.get${generator.toUCIdent($property.name)}());

                ResultSet rs1 = prest.executeQuery();

                if (rs1.next()) {
                    throw new ValidatorException("Property '$property.name' has to be unique!");
                }

            } catch (SQLException ex) {
                Logger.getLogger($item.name .class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger($item.name .class.getName()).log(Level.SEVERE, null, ex);
            }
           
        }
- Understanding is a three edged sword. (Your side, their side, and the truth) [Vorlons' saying]
(thanks to Agamemnon)

markus

dotaz. mam problem ked chcem buildnut magsu.
trebalo to aj minule odovzdavanie ale to som vedel obijst teraz mi to az tak nejde :D

ked chcem buildnut projekt vyhodi mi errory


E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\ApplicationException.java:3: duplicate class: sk.tuke.magsa.framework.ApplicationException
public class ApplicationException extends RuntimeException {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\CRUDDao.java:5: duplicate class: sk.tuke.magsa.framework.CRUDDao
public interface CRUDDao<T extends Entity> {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\CRUDDaoImpl.java:11: duplicate class: sk.tuke.magsa.framework.CRUDDaoImpl
public abstract class CRUDDaoImpl<T extends Entity> implements CRUDDao<T> {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\ConnectionPool.java:9: duplicate class: sk.tuke.magsa.framework.ConnectionPool
public class ConnectionPool {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\Entity.java:5: duplicate class: sk.tuke.magsa.framework.Entity
public abstract class Entity implements Serializable {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\Utilities.java:8: duplicate class: sk.tuke.magsa.framework.Utilities
public class Utilities {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\ValidatorException.java:3: duplicate class: sk.tuke.magsa.framework.ValidatorException
public class ValidatorException extends RuntimeException {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\ui\FormDialog.java:5: duplicate class: sk.tuke.magsa.framework.ui.FormDialog
public abstract class FormDialog<T extends Entity> {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\ui\TableDialog.java:8: duplicate class: sk.tuke.magsa.framework.ui.TableDialog
public abstract class TableDialog<T extends Entity> {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\ApplicationException.java:3: duplicate class: sk.tuke.magsa.framework.ApplicationException
public class ApplicationException extends RuntimeException {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\CRUDDao.java:5: duplicate class: sk.tuke.magsa.framework.CRUDDao
public interface CRUDDao<T extends Entity> {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\CRUDDaoImpl.java:11: duplicate class: sk.tuke.magsa.framework.CRUDDaoImpl
public abstract class CRUDDaoImpl<T extends Entity> implements CRUDDao<T> {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\ConnectionPool.java:9: duplicate class: sk.tuke.magsa.framework.ConnectionPool
public class ConnectionPool {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\Entity.java:5: duplicate class: sk.tuke.magsa.framework.Entity
public abstract class Entity implements Serializable {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\Utilities.java:8: duplicate class: sk.tuke.magsa.framework.Utilities
public class Utilities {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\ValidatorException.java:3: duplicate class: sk.tuke.magsa.framework.ValidatorException
public class ValidatorException extends RuntimeException {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\ui\FormDialog.java:5: duplicate class: sk.tuke.magsa.framework.ui.FormDialog
public abstract class FormDialog<T extends Entity> {
E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src-framework\sk\tuke\magsa\framework\ui\TableDialog.java:8: duplicate class: sk.tuke.magsa.framework.ui.TableDialog
public abstract class TableDialog<T extends Entity> {
Note: E:\Skola\4.rocnik\MaGSA\zadanie\magsa\src\sk\tuke\magsa\tools\metamodel\Property.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.


sameduplicate class.... neviete co s tym? stsalo sa to niekomu?

ropman

treba asi zmazat framework package z magsa-generated

markus

ja som ho mal z neznamych dovodov este raz v magse neviem jak sa tam nabral ... :D som si ho nevsimol