IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

[Architecture Technique] Accès aux données


Sujet :

Spring Java

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    258
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 258
    Points : 171
    Points
    171
    Par défaut [Architecture Technique] Accès aux données
    Bonjour, je souhaite avoir votre avis.
    Je développe une application et je travaille actuellement sur l'accès aux données, après pas mal de lecture à droite à gauche voici le type d'architecture que je viens de mettre en place pour l'accès aux données.
    Prenons une table de ma base de données (Utilisateur).

    J'ai donc un POJO Utilisateur.
    Je défini une interface pour mon DAO --> UtilisateurDAO (CRUD)
    Implémentation grâce spring et son intégration d'hibernate --> UtilisateurDAOHibernate.
    Et enfin j'ai défini des services qui seront appelés par l'IHM
    Interface --> UtilisateurManager (CRUD)
    et son implémentation --> UtilisateurManagerImpl qui appel mon UtilisateurDAO

    Que pensez-vous de cela ? es pas un peu lourd de mettre deux niveaux service et DAO alors que les classes font la même chose (pour l'instant CRUD)?

  2. #2
    Membre du Club
    Inscrit en
    Novembre 2006
    Messages
    44
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 44
    Points : 53
    Points
    53
    Par défaut
    Bonjour,
    je me permet de donner mon humble avis sur la question.

    Effectivement cela peut paraître lourd, mais si c'était moi, je rajouterais encore quelque niveau de sépartion, par le biais de Business Delegate, entre la présentation et le "métier".


    L'évotubilité (je sais pas si le mot existe), ce paye au pris de la "lourdeur" de toute les couches que l'ont met, et qui peuvent sembler ne servir à rien.
    Mais le jour ou ... on se dit "Yeahhhh quelle bonne idée d'avoir 'alourdis' à l'époque, je n'ai qu'un endroit à changer pour évoluer".

    Donc pour ma part, la présentation ne devrait jamais faire appel à du CRUD ... il devrait y avoir un controlleur metier entre les deux.

    Entre la présenation et le controlleur métier, devrait y avoir une business delegate, et un service locator ....., idem entre le métier et l'accés au données.


    Mais bon je pense que je m'éloigne un peu du sujet, et il me semble que le peux que je connaissance de spring, simplifie la notion de service locator, par le biais, de l'injection, et de IOC.

    En espèrant avoir fait avancer les chose.

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    258
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 258
    Points : 171
    Points
    171
    Par défaut
    Bonjour,
    Merci de ta réponse, par contre au niveau séparation des couche présentation et métier cela ne te semble pas suffisant d'avoir mon interface UtilisateurManager ?


    Pour résumer j'ai :

    IHM --> Manager --> DAO --> Entity --> BDD.

    Cela me parais suffisant non ? je ne vois pas l'intérêt de rajouter encore une couche entre mon IHM et mes managers.
    De plus pour l'évolution de mon application, je travaille avec les interfaces et non pas les implémentation.
    L'intérête de Spring est que je peux définir quelle est l'implémentation utilisée et par inversion de controle, je peux initialiser correctement mes objets.

  4. #4
    Membre du Club
    Inscrit en
    Novembre 2006
    Messages
    44
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 44
    Points : 53
    Points
    53
    Par défaut
    Effectivement, on peut assimilier ton Manager, à ce que j'appelais Business Delagte (enfin ce n'est pas de moi, c'est un design pattern).

    Et il vrai qu'avec Spring, comme je l'ai dis à la fin de mon message, l'évolution sera plus simple.
    Ceci étant t'a présentation à quand même une connaissance "forte" du crud, ce que personnelement je n'aime guere

    Pour ma part, j'aurais au minimum dans ton cas :
    - Présentation - Métier - Données
    IHM --> Manager --> Controleur --> Entity --> DAO --> BDD.

    En se basant sur spring et le fait de pouvoir injecter les bonnes implémentations.

    Mais pour ma part, ne voulant pas être dépendant, même si j'utilise spring, je rajouterais toutes les couches, même si spring fait une "simple" injection dans certaines des couches, ca me permettrais, le jour ou je décide de me débarasser de spring, de le faire à "moindre" coup

  5. #5
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 274
    Points : 4 141
    Points
    4 141
    Par défaut
    J'ai travaillé sur un projet qui était basé sur la même architecture que toi.
    Je trouve cela bien suffisant, mais après ça dépend des besoins.
    Ce type d'architecture est recommandé dans le bouquin "spring par la pratique".
    Je ne comprends pas bien à quoi servirait les autres couches proposées, ne connaissant pas précisemment les patterns en question.

  6. #6
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Points : 2 336
    Points
    2 336
    Par défaut
    IHM -> Business Service + Business Entity-> DAO -> DB Entity -> DB

    cela permetd ignorer que tes objets que tu créer dans tes services sont des objets DB (visibilité d un objet DB uniquement en private)

  7. #7
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    258
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 258
    Points : 171
    Points
    171
    Par défaut
    Salut alexandre,
    Quelle sont les objets toujours sur mon exemple (Utilisateur) à mettre en place pour construire Business Service + Business Entity ?
    Peux tu également me préciser le type de méthode que l'on peut trouver dans les objets.

    Concernant mon architecture en effet il s'agit de celle proposée dans le livre "Spring par la pratique". Cette archi me semble très bien pour moi mais j'aimerais avoir vos avis là dessus c'est pour raison que j'ai crée le post.

  8. #8
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Points : 2 336
    Points
    2 336
    Par défaut
    Hello,

    Voici un exemple de classe définissant une Business Entity :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
     
    package com.mtsa.ebonus.core.business.action;
     
    import java.util.*;
     
    import com.mtsa.common.control.ErrorController;
    import com.mtsa.common.error.ErrorLevel;
    import com.mtsa.ebonus.core.business.*;
    import com.mtsa.ebonus.core.business.Currency;
    import com.mtsa.ebonus.core.business.product.*;
    import com.mtsa.ebonus.core.db.*;
    import com.mtsa.ebonus.core.db.action.*;
    import com.mtsa.ebonus.core.db.product.*;
     
    public class Action extends MultiLanguageEntity {
     
    	/* Logs and errors */
    	private static ErrorController ec = ErrorController.getErrorController(Action.class.getName(), ErrorLevel.DEBUG);
    	private static final String ERR_CLONE = "BUE1010";
    	private static final String ERR_CONVERT = "BUE1020";
    	private static final String ERR_EQUALS = "BUE1030";
    	/* Db entity */
    	public ActionDb dbEntity;
     
    	// ------------------- CONSTRUCTOR(S) -----------------------------//
    	Action(MessageService messageService) {
    		this(messageService, null, null);
    	}
     
    	/**
             * Constructor NEEDS a message service (can't be NULL) 
             * The dbEntity of the super must be "overwritten" with specific dbEntity
             * If selectedLanguageId is NULL, default language is used
             * 
             * @param messageService
             * @param dbEntity
             * @param selectedLanguageId
             */
    	Action(MessageService messageService, ActionDb dbEntity) {
    		this(messageService, dbEntity, null);
    	}
     
    	/**
             * Constructor NEEDS a message service (can't be NULL) 
             * The dbEntity of the super must be "overwritten" with specific dbEntity
             * If selectedLanguageId is NULL, default language is used
             * 
             * @param messageService
             * @param dbEntity
             * @param selectedLanguageId
             */
    	Action(MessageService messageService, ActionDb dbEntity, Integer selectedLanguageId) {
    		super(messageService, dbEntity, selectedLanguageId);
    		ec.log("Begin - CONSTRUCTOR");
    		if (dbEntity != null) {
    			this.setDbEntity(dbEntity);
    		} else {
    			this.setDbEntity(new ActionDb());
    		}
    		ec.log("End - CONSTRUCTOR");
    	}
     
    	// ------------- ATTRIBUTE for MULTI_LANGUAGE entity -----------------//
    	public ActionDb getDbEntity() {
    		return this.dbEntity;
    	}
     
    	public void setDbEntity(ActionDb dbEntity) {
    		this.dbEntity = dbEntity;
    		// to add manually
    		super.setDbEntity(dbEntity);
    	}
     
    	@Override
    	protected Integer getRefDescription() {
    		return this.getDbEntity().getRefDescription();
    	}
     
    	@Override
    	protected void setRefDescription(Integer refMessage) {
    		this.getDbEntity().setRefDescription(refMessage);
    	}
     
    	// --------------------- BASIC JAVA METHODS -----------------------//
    	/**
             * This method is especially used for logging (to avoid "null pointer" exception)
             */
    	public String toString() {
    		String result = "marketId=" + this.getMarketId();
    		result += " / actionTypeId=" + this.getActionTypeId();
    		result += " / actionId=" + this.getActionId();
    		result += " / refDescription=" + this.getRefDescription();
    		return result;
    	}
     
    	/**
             * Compare following values between "this" and the param Entity: 
             * - Market ID
             * - Action Type ID
             * - Action ID
             * 
             * @param buEntity 
             * 
             * @return boolean ("false" if this.getID or buEntity is NULL)
             */
    	public boolean equals(Action buEntity) {
    		ec.log("Begin - equals(), buEntity: " + buEntity);
    		boolean result = false;
    		try {
    			if (buEntity != null) {
    				result = this.getMarketId().equals(buEntity.getMarketId());
    				result = result && this.getActionTypeId().equals(buEntity.getActionTypeId());
    				result = result && this.getActionId().equals(buEntity.getActionId());
    			}
    		} catch (RuntimeException ex) {
    			ec.handleError(ERR_EQUALS, ex);
    		}
    		ec.log("End - equals(), result: " + result);
    		return result;
    	}
     
    	/**
             * Create a new Action with same parameters
             * 
             * @param message
             *            source Message
             * 
             * @return Message resulted from the copy
             */
    	public Action clone() {
    		ec.log("Begin - clone()");
    		Action result = null;
    		try {
    			result = new Action(this.getMessageService());
    			result.setMarketId(this.getMarketId());
    			result.setActionTypeId(this.getActionTypeId());
    			result.setActionId(this.getActionId());
    			// copying messages
    			List<Message> messages = this.getMessageService().getCopyMessages(this.getMessages());
    			result.setMessages(messages);
    			// TODO add copy all other business informations
     
    		} catch (RuntimeException ex) {
    			ec.handleError(ERR_CLONE, ex);
    		}
    		ec.log("End - clone(), result: " + result);
    		return result;
    	}
     
    	// -------------- CONVERSIONS ----------------------//
    	/**
             * Convert a list of DB entities to a list of BU entities (use default language)
             * 
             * @param dbEntities
             * @param messageService
             *  
             * @return (can be EMPTY, not null)
             */
    	public static List<Action> convertFromDbEntites(Collection<ActionDb> dbEntities, MessageService messageService) {
    		return convertFromDbEntites(dbEntities, messageService, null);
    	}
     
    	/**
             * Convert a list of DB Entities to a list of BU Entities
             * 
             * @param dbEntities
             * @param messageService
             * @param languageId
             * 
             * @return (can be EMPTY, not null)
             */
    	public static List<Action> convertFromDbEntites(Collection<ActionDb> dbEntities, MessageService messageService,
    			Integer languageId) {
    		ec.log("Begin - convertFromDbEntites, dbEntities: " + dbEntities);
    		List<Action> result = new ArrayList<Action>();
    		if (dbEntities != null && dbEntities.size() > 0) {
    			for (ActionDb dbEntity : dbEntities) {
    				Action myBuEntity = convertFromDbEntity(dbEntity, messageService, languageId);
    				result.add(myBuEntity);
    			}
    		}
    		ec.log("End - convertFromDbEntites, buEntites size: " + result.size());
    		return result;
    	}
     
    	/**
             * Convert a DB Entity to a BU Entity (use default language)
             * 
             * @param dbEntity
             * @param messageService
             * 
             * @return (can be NULL)
             */
    	public static Action convertFromDbEntity(ActionDb dbEntity, MessageService messageService) {
    		return convertFromDbEntity(dbEntity, messageService, null);
    	}
     
    	/**
             * Convert a DB Entity to a BU Entity
             * 
             * @param dbEntity
             * @param messageService
             * @param languageId
             * 
             * @return (can be NULL)
             */
    	public static Action convertFromDbEntity(ActionDb dbEntity, MessageService messageService, Integer languageId) {
    		ec.log("Begin - convertFromDbEntity, dbEntity: " + dbEntity);
    		Action result = null;
    		if (dbEntity != null) {
    			try {
    				result = new Action(messageService, dbEntity, languageId);
    			} catch (RuntimeException ex) {
    				ec.handleError(ERR_CONVERT, ex);
    			}
    		}
    		ec.log("End - convertFromDbEntity, result: " + result);
    		return result;
    	}
     
    	// ---------------------- DELEGATION -----------------------------//
    	public void setIds(String marketId, String actionTypeId, String actionId) {
    		this.setMarketId(marketId);
    		this.setActionTypeId(actionTypeId);
    		this.setActionId(actionId);
    	}
     
    	public String getMarketId() {
    		if (dbEntity.getId() == null)
    			dbEntity.setId(new ActionDbId());
    		return this.dbEntity.getId().getIdMarket();
    	}
     
    	public String getActionTypeId() {
    		if (dbEntity.getId() == null)
    			dbEntity.setId(new ActionDbId());
    		return this.dbEntity.getId().getIdActionType();
    	}
     
    	public String getActionId() {
    		if (dbEntity.getId() == null)
    			dbEntity.setId(new ActionDbId());
    		return this.dbEntity.getId().getActionId();
    	}
     
    	public void setMarketId(String marketId) {
    		if (dbEntity.getId() == null)
    			dbEntity.setId(new ActionDbId());
    		this.dbEntity.getId().setIdMarket(marketId);
    	}
     
    	public void setActionTypeId(String actionTypeId) {
    		if (dbEntity.getId() == null)
    			dbEntity.setId(new ActionDbId());
    		this.dbEntity.getId().setIdActionType(actionTypeId);
    	}
     
    	public void setActionId(String actionId) {
    		if (dbEntity.getId() == null)
    			dbEntity.setId(new ActionDbId());
    		this.dbEntity.getId().setActionId(actionId);
    	}
     
    	public String getActionExcel() {
    		return dbEntity.getActionExcel();
    	}
     
    	public String getActionPdf() {
    		return dbEntity.getActionPdf();
    	}
     
    	public Set getActionPeriods() {
    		return dbEntity.getActionPeriods();
    	}
     
    	public ActionState getActionState() {
    		return ActionState.convertFromDbEntity(dbEntity.getActionState(), this.getMessageService());
    	}
     
    	public ActionType getActionType() {
    		return ActionType.convertFromDbEntity(dbEntity.getActionType(), this.getMessageService());
    	}
     
    	public void setActionState(ActionState actionState) {
    		dbEntity.setActionState(actionState.getDbEntity());
    	}
     
    	public void setActionType(ActionType actionType) {
    		dbEntity.setActionType(actionType.getDbEntity());
    	}
     
    	public Integer getDayLimit() {
    		return dbEntity.getDayLimit();
    	}
     
    	public Set getActionProducts() {
    		return dbEntity.getActionProducts();
    	}
     
    	public String getActionUrl() {
    		return dbEntity.getActionUrl();
    	}
     
    	public String getActionWord() {
    		return dbEntity.getActionWord();
    	}
     
    	public String getAnalyticCode() {
    		return dbEntity.getAnalyticCode();
    	}
     
    	public Integer getBeneficiary() {
    		return dbEntity.getBeneficiary();
    	}
     
    	public String getCommessa() {
    		return dbEntity.getCommessa();
    	}
     
    	public String getCostCenter() {
    		return dbEntity.getCostCenter();
    	}
     
    	public String getFiscalYear() {
    		return dbEntity.getFiscalYear();
    	}
     
    	public Date getInputDelay() {
    		return dbEntity.getInputDelay();
    	}
     
    	public Boolean getIsBlocked() {
    		return dbEntity.getIsBlocked();
    	}
     
    	public Boolean getIsDeleted() {
    		return dbEntity.getIsDeleted();
    	}
     
    	public Boolean getIsExceptStandard() {
    		return dbEntity.getIsExceptStandard();
    	}
     
    	public Boolean getIsMinimumObjective() {
    		return dbEntity.getIsMinimumObjective();
    	}
     
    	public Boolean getIsPaymentCancelled() {
    		return dbEntity.getIsPaymentCancelled();
    	}
     
    	public Boolean getIsStepsRollup() {
    		return dbEntity.getIsStepsRollup();
    	}
     
    	public Boolean getIsVisibleAmount() {
    		return dbEntity.getIsVisibleAmount();
    	}
     
    	public Double getLimitAmount() {
    		return dbEntity.getLimitAmount();
    	}
     
    	public String getNatureCode() {
    		return dbEntity.getNatureCode();
    	}
     
    	public Integer getOperationalMode() {
    		return dbEntity.getOperationalMode();
    	}
     
    	public Integer getPriorityMode() {
    		return dbEntity.getPriorityMode();
    	}
     
    	public Integer getActionStateId() {
    		return dbEntity.getActionStateId();
    	}
     
    	public Integer getElementId() {
    		return dbEntity.getElementId();
    	}
     
    	public String getObjectiveSetId() {
    		return dbEntity.getObjectiveSetId();
    	}
     
    	public String getProductFamilyId() {
    		return dbEntity.getProductFamilyId();
    	}
     
    	public String getCurrencyId() {
    		return dbEntity.getCurrencyId();
    	}
     
    	public void setFromDate(Date fromDate) {
    		dbEntity.setFromDate(fromDate);
    	}
     
    	public Integer getSettlement() {
    		return dbEntity.getSettlement();
    	}
     
    	public Date getToDate() {
    		return dbEntity.getToDate();
    	}
     
    	public Date getFromDate() {
    		return dbEntity.getFromDate();
    	}
     
    	public void setActionExcel(String actionExcel) {
    		dbEntity.setActionExcel(actionExcel);
    	}
     
    	public void setActionPdf(String actionPdf) {
    		dbEntity.setActionPdf(actionPdf);
    	}
     
    	public void setActionPeriods(Set actionPeriods) {
    		dbEntity.setActionPeriods(actionPeriods);
    	}
     
    	public void setActionProducts(Set actionProducts) {
    		dbEntity.setActionProducts(actionProducts);
    	}
     
    	public void setActionUrl(String actionUrl) {
    		dbEntity.setActionUrl(actionUrl);
    	}
     
    	public ObjectiveSet getObjectiveSet() {
    		return ObjectiveSet.convertFromDbEntity(dbEntity.getObjectiveSet(), this.getMessageService(), null);
    	}
     
    	public void setObjectiveSet(ObjectiveSet objectiveSet) {
    		dbEntity.setObjectiveSet(objectiveSet.getDbEntity());
    	}
     
    	public void setActionWord(String actionWord) {
    		dbEntity.setActionWord(actionWord);
    	}
     
    	public void setAnalyticCode(String analyticCode) {
    		dbEntity.setAnalyticCode(analyticCode);
    	}
     
    	public void setBeneficiary(Integer beneficiary) {
    		dbEntity.setBeneficiary(beneficiary);
    	}
     
    	public void setCommessa(String commessa) {
    		dbEntity.setCommessa(commessa);
    	}
     
    	public void setCostCenter(String costCenter) {
    		dbEntity.setCostCenter(costCenter);
    	}
     
    	public void setDayLimit(Integer dayLimit) {
    		dbEntity.setDayLimit(dayLimit);
    	}
     
    	public void setFiscalYear(String fiscalYear) {
    		dbEntity.setFiscalYear(fiscalYear);
    	}
     
    	public void setInputDelay(Date inputDelay) {
    		dbEntity.setInputDelay(inputDelay);
    	}
     
    	public void setIsBlocked(Boolean isBlocked) {
    		dbEntity.setIsBlocked(isBlocked);
    	}
     
    	public void setIsDeleted(Boolean isDeleted) {
    		dbEntity.setIsDeleted(isDeleted);
    	}
     
    	public void setIsExceptStandard(Boolean isExceptStandard) {
    		dbEntity.setIsExceptStandard(isExceptStandard);
    	}
     
    	public void setIsMinimumObjective(Boolean isMinimumObjective) {
    		dbEntity.setIsMinimumObjective(isMinimumObjective);
    	}
     
    	public void setIsPaymentCancelled(Boolean isPaymentCancelled) {
    		dbEntity.setIsPaymentCancelled(isPaymentCancelled);
    	}
     
    	public void setIsStepsRollup(Boolean isStepsRollup) {
    		dbEntity.setIsStepsRollup(isStepsRollup);
    	}
     
    	public void setIsVisibleAmount(Boolean isVisibleAmount) {
    		dbEntity.setIsVisibleAmount(isVisibleAmount);
    	}
     
    	public void setLimitAmount(Double limitAmount) {
    		dbEntity.setLimitAmount(limitAmount);
    	}
     
    	public void setNatureCode(String natureCode) {
    		dbEntity.setNatureCode(natureCode);
    	}
     
    	public void setOperationalMode(Integer operationalMode) {
    		dbEntity.setOperationalMode(operationalMode);
    	}
     
    	public void setPriorityMode(Integer priorityMode) {
    		dbEntity.setPriorityMode(priorityMode);
    	}
     
    	public void setSettlement(Integer settlement) {
    		dbEntity.setSettlement(settlement);
    	}
     
    	public void setToDate(Date toDate) {
    		dbEntity.setToDate(toDate);
    	}
     
    	public ProductFamily getProductFamily() {
    		return ProductFamily.convertFromDbEntity(dbEntity.getProductFamily(), this.getMessageService());
    	}
     
    	public void setProductFamily(ProductFamily productFamily) {
    		dbEntity.setProductFamily(productFamily.getDbEntity());
    	}
     
    	public Currency getCurrency() {
    		return Currency.convertFromDbEntity(dbEntity.getCurrency());
    	}
     
    	public Element getElement() {
    		return Element.convertFromDbEntity(dbEntity.getElement(), this.getMessageService());
    	}
     
    	public void setCurrency(Currency currency) {
    		dbEntity.setCurrency(currency.getDbEntity());
    	}
     
    	public void setElement(Element element) {
    		dbEntity.setElement(element.getDbEntity());
    	}
     
    	public void setActionStateId(Integer actionStateId) {
    		dbEntity.setActionStateId(actionStateId);
    	}
     
    	public void setCurrencyId(String currencyId) {
    		dbEntity.setCurrencyId(currencyId);
    	}
     
    	public void setElementId(Integer elementId) {
    		dbEntity.setElementId(elementId);
    	}
     
    	public void setObjectiveSetId(String objectiveSetId) {
    		dbEntity.setObjectiveSetId(objectiveSetId);
    	}
     
    	public void setProductFamilyId(String productFamilyId) {
    		dbEntity.setProductFamilyId(productFamilyId);
    	}
    }
    Cette classe comporte les *delegates* sur les attributs de ta DbEntity (objet DB)

    Pour tes services, tu crées au début une interface avec la signature des métodes que tu veux proposer example :

    addAction
    saveAction
    deleteAction
    findActionById

    et tu définis l implémentation de ton service dans une classe "ServiceNameImpl" qui accède au DAO de ton objet

  9. #9
    Rédacteur
    Avatar de lunatix
    Homme Profil pro
    Architecte technique
    Inscrit en
    Novembre 2002
    Messages
    1 960
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Architecte technique

    Informations forums :
    Inscription : Novembre 2002
    Messages : 1 960
    Points : 3 736
    Points
    3 736
    Par défaut
    je pense qu'il faut adapter en fonction de tes besoins

    perso, je vire souvent les interfaces. ça m'économise du temps, et je bosse en fonction de l'implémentation : ok, c'est pas dans "la règle de l'art", mais sur des projets simple, ça change rien.

    pour la couche DAO CRUD, tu peux la gérer a l'aide d'un GenericDAO, du coup, pas de code a faire, et tu peux investir sur la couche service. (si tu veux un exemple de GenericDAO, je dois pouvoir trouver ca)

    a mon avis, tout est question d'adaptation, pas la peine de faire une architecture en 12 couches si c'est une application très simple, et vice versa.

  10. #10
    ego
    ego est déconnecté
    Rédacteur

    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Juillet 2004
    Messages
    1 883
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Architecte de système d'information
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 883
    Points : 3 510
    Points
    3 510
    Billets dans le blog
    2
    Par défaut
    Ben moi je fais comme le monsieur qui a lancé la discussion (inclues les interfaces).
    Pour les business delegate, je ne vois pas l'utilité dans un premier temps. L'objectif de ce pattern est avant tout d'adapter une interface pour des besoins nouveaux ou afin, par exemple, de réduire l'interface visible vis-à-vis des autres systèmes.

    Donc pour moi, tout est ok

  11. #11
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Points : 2 336
    Points
    2 336
    Par défaut
    Citation Envoyé par lunatix
    je pense qu'il faut adapter en fonction de tes besoins

    perso, je vire souvent les interfaces. ça m'économise du temps, et je bosse en fonction de l'implémentation : ok, c'est pas dans "la règle de l'art", mais sur des projets simple, ça change rien.

    pour la couche DAO CRUD, tu peux la gérer a l'aide d'un GenericDAO, du coup, pas de code a faire, et tu peux investir sur la couche service. (si tu veux un exemple de GenericDAO, je dois pouvoir trouver ca)

    a mon avis, tout est question d'adaptation, pas la peine de faire une architecture en 12 couches si c'est une application très simple, et vice versa.
    perso je trouve que les interfaces sont vraiment utiles lorsque l on doit simuler du multi heritage (mais c est hors sujet lol)

    j aimerais bien voir un des tes generic DAO voir si sa ressemble à un template DAO creer pour hibernate par example

  12. #12
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    258
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 258
    Points : 171
    Points
    171
    Par défaut
    Bonjour,
    Lunatix je suis intéressé pour voir à quoi ressemble tes GenericDAO.
    Peux tu nous poster cela ? merci d'avance.

  13. #13
    Rédacteur
    Avatar de lunatix
    Homme Profil pro
    Architecte technique
    Inscrit en
    Novembre 2002
    Messages
    1 960
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Architecte technique

    Informations forums :
    Inscription : Novembre 2002
    Messages : 1 960
    Points : 3 736
    Points
    3 736
    Par défaut
    Bon alors rien d'extraordinaire : c'est juste un truc super inspiré de cet article qui pousse le truc un poil loin pour moi en utilisant l'aop, et de quelques posts sur le forum hibernate. (je dois pouvoir retrouver pour ceux que ça intéresse)

    en gros un interface CRUD pour tous les DAO
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    public interface GenericDao<T, ID extends Serializable> {
     
        T findById(ID id);
     
        T findById(ID id, boolean lock);
     
        //List<T> findAll();
     
        //List<T> findByExample(T exampleInstance);
     
        T create(T entity);
     
        T saveOrUpdate(T entity);
     
        void delete(T entity);
    }
    et un impl de type hibernate

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    public class GenericHibernateDao<T, ID extends Serializable> extends
            HibernateDaoSupport implements GenericDao<T, ID> {
     
        private Class<T> type;
     
        public GenericHibernateDao() {
        }
     
        public GenericHibernateDao(Class<T> type) {
            type = type;
        }
     
        @SuppressWarnings("unchecked")
        public T findById(ID idType) {
            T entity = (T) getSessionFactory().getCurrentSession().get(getPersistentClass(), idType);
     
            return entity;
        }
     
        @SuppressWarnings("unchecked")
        public T findById(ID idType, boolean setLock) {
            T entity;
            if (setLock) {
                entity = (T) getSessionFactory().getCurrentSession().get(getPersistentClass(), idType, LockMode.UPGRADE);
            } else {
                entity = (T) getSessionFactory().getCurrentSession().get(getPersistentClass(), idType);
            }
            return entity;
        }
     
        public Class<T> getPersistentClass() {
            return type;
        }
     
        @SuppressWarnings("unchecked")
        public T create(T entity) {
            getSessionFactory().getCurrentSession().save(entity);
            return entity;
        }
     
        public T saveOrUpdate(T entity) {
            getSessionFactory().getCurrentSession().saveOrUpdate(entity);
            return entity;
        }
     
        public void delete(T entity) {
            getSessionFactory().getCurrentSession().delete(entity);
        }
     
    }

    ensuite pour tous les Dao CRUD plus qu'a les déclarer comme ça

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    <bean id="monObjetDao" class="package.GenericDaoHibernateImpl">
            <constructor-arg>
                <value>pakage.MonObjet</value>
            </constructor-arg>
            <property name="sessionFactory">
                <ref bean="sessionFactory"/>
            </property>
    </bean>
    pas une ligne de code a faire, et déjà un dao CRUD complet.

    on l'utilise en faisant un simple
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    GenericDao monObjetDao = (GenericDao) getBean("monObjetDao")
    et sinon, suffit d'en hériter pour avoir un comportement de base CRUD, et ajouter ses propres méthodes d'acces spécialisées

Discussions similaires

  1. Réponses: 23
    Dernier message: 08/04/2014, 17h56
  2. Réponses: 0
    Dernier message: 18/11/2013, 20h46
  3. Réponses: 0
    Dernier message: 03/10/2008, 22h45
  4. Architecture accès aux données.
    Par sybaris dans le forum C#
    Réponses: 4
    Dernier message: 18/08/2008, 08h45
  5. [Architecture] Couche accès aux données
    Par tatemilio2 dans le forum Hibernate
    Réponses: 3
    Dernier message: 12/06/2006, 10h23

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo