Search Results

Search found 445 results on 18 pages for 'dao'.

Page 1/18 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Relationship DAO, Servlet, JSP and POJO [closed]

    - by John Hendrik
    Possible Duplicate: Relationship DAO, Servlet, JSP and POJO I want to implement a JSP, POJO, DAO and Servlet in my J2EE program. However, I don't fully understand how the relationship between these elements should be. Is the following (MVC) setup the right way to do it? Main class creates servlet(controller) Servlet has a DAO defined in its class DAO has a POJO defined in its class Servlet communicates with the view (JSP page) Please give your feedback.

    Read the article

  • In MVC , DAO should be called from Controller or Model

    - by tito
    I have seen various arguments against the DAO being called from the Controller class directly and also the DAO from the Model class.Infact I personally feel that if we are following the MVC pattern , the controller should not coupled with the DAO , but the Model class should invoke the DAO from within and controller should invoke the model class.Why because , we can decouple the model class apart from a webapplication and expose the functionalities for various ways like for a REST service to use our model class. If we write the DAO invocation in the controller , it would not be possible for a REST service to reuse the functionality right ? I have summarized both the approaches below. Approach #1 public class CustomerController extends HttpServlet { proctected void doPost(....) { Customer customer = new Customer("xxxxx","23",1); new CustomerDAO().save(customer); } } Approach #2 public class CustomerController extends HttpServlet { proctected void doPost(....) { Customer customer = new Customer("xxxxx","23",1); customer.save(customer); } } public class Customer { ........... private void save(Customer customer){ new CustomerDAO().save(customer); } } Note- Here is what a definition of Model is : Model: The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react. I would need an expert opinion on this because I find many using #1 or #2 , So which one is it ?

    Read the article

  • Calling one DAO from another DAO?

    - by es11
    Can this ever make sense? Say I need to fetch an object from the DB which has a relation to another object (represented by a foreign key in the DB, and by a composition in my domain object). If in my first DAO I fetch the data for object 1, then call the dao for object 2, and finally (from within the first DAO, call the setter in object 1 and give it the previously fetched object 2). I know I could do a join instead, but it just seems more logical to me to decouple the functionality (which is why I am skeptical about calling one dao from another). Or should I move some of the logic to the service layer? Thanks Update: I think I solved the problem with help from the answers: all I needed to do was add the following to my mapping of Object 1: <one-to-one name="Object2" fetch="join" class="com...Object2"></one-to-one> I didn't have to change anything else. Thanks for the help!

    Read the article

  • DAO/Webservice Consumption in Web Application

    - by Gavin
    I am currently working on converting a "legacy" web-based (Coldfusion) application from single data source (MSSQL database) to multi-tier OOP. In my current system there is a read/write database with all the usual stuff and additional "read-only" databases that are exported daily/hourly from an Enterprise Resource Planning (ERP) system by SSIS jobs with business product/item and manufacturing/SCM planning data. The reason I have the opportunity and need to convert to multi-tier OOP is a newer more modern ERP system is being implemented business wide that will be a complete replacement. This newer ERP system offers several interfaces for third party applications like mine, from direct SQL access to either a dotNet web-service or a SOAP-like web-service. I have found several suitable frameworks I would be happy to use (Coldspring, FW/1) but I am not sure what design patterns apply to my data access object/component and how to manage the connection/session tokens, with this background, my question has the following three parts: Firstly I have concerns with moving from the relative safety of a SSIS job that protects me from downtime and speed of the ERP system to directly connecting with one of the web services which I note seem significantly slower than I expected (simple/small requests often take up to a whole second). Are there any design patterns I can investigate/use to cache/protect my data tier? It is my understanding data access objects (the component that connects directly with the web services and convert them into the data types I can then work with in my Domain Objects) should be singletons (and will act as an Adapter/Facade), am I correct? As part of the data access object I have to setup a connection by username/password (I could set up multiple users and/or connect multiple times with this) which responds with a session token that needs to be provided on every subsequent request. Do I do this once and share it across the whole application, do I setup a new "connection" for every user of my application and keep the token in their session scope (might quickly hit licensing limits), do I set the "connection" up per page request, or is there a design pattern I am missing that can manage multiple "connections" where a requests/access uses the first free "connection"? It is worth noting if the ERP system dies I will need to reset/invalidate all the connections and start from scratch, and depending on which web-service I use might need manually close the "connection/session"

    Read the article

  • EntityManager and two DAO with PersistenceContextType.EXTENDED

    - by hsd
    Hi All, I have a problem with my entity manager in my application. I have two DAO clasess like this: @Repository public abstract class DaoA { protected ClassA persistentClass; @PersistenceContext(name="my.persistence", type=PersistenceContextType.EXTENDED) protected EntityManager entityManager; -------------- some typical action for DAO -------------- } Second DAO is for ClassB and looks similar to DaoA. The rest of things are done for me by the Spring framework. When I'm debugging the application I recognize that both DAO objects have different instances of EntityManager. In the result my two different DAOs are connected with different PersistenceContext. Question is if this is correct behaviour or not? I would like to have the same PersistenceContext for all my DAO classes. Please give me a hint if this is possible and if I understood the JPA correctly? Regards Hsd

    Read the article

  • Hibernate GenericDAO for parent/child relationships and DAO/DTO patterns

    - by Marco
    Hi, I'm looking for a Generic DAO implementation in Hibernate that includes parent/child relationship management (adding, removing, getting childs, setting parents, etc). Actually the most used generic DAO on the web is the one i found on http://community.jboss.org/wiki/GenericDataAccessObjects. And also, i was looking for some DAO/DTO sample implementations and design patterns. Do you know some good resources out there?

    Read the article

  • How to test a DAO with JPA implementation ?

    - by smallufo
    Hi I came from the Spring camp , I don't want to use Spring , and am migrating to JavaEE6 , But I have problem testing DAO + JPA , here is my simplified sample : public interface PersonDao { public Person get(long id); } This is a very basic DAO , because I came from Spring , I believe DAO still have it value , so I decided to add a DAO layer . public class PersonDaoImpl implements PersonDao , Serializable { @PersistenceContext(unitName = "test", type = PersistenceContextType.EXTENDED) EntityManager entityManager ; public PersonDaoImpl() { } @Override public Person get(long id) { return entityManager .find(Person.class , id); } } This is a JPA-implemented DAO , I hope the EE container or the test container able to inject the EntityManager. public class PersonDaoImplTest extends TestCase { @Inject protected PersonDao personDao; @Override protected void setUp() throws Exception { //personDao = new PersonDaoImpl(); } public void testGet() { System.out.println("personDao = " + personDao); // NULL ! Person p = personDao.get(1L); System.out.println("p = " + p); } } This is my test file . OK , here comes the problem : Because JUnit doesn't understand @javax.inject.Inject , the PersonDao will not be able to injected , the test will fail. How do I find a test framework that able to inject the EntityManager to the PersonDaoImpl , and @Inject the PersonDaoImpl to the PersonDao of TestCase ? I tried unitils.org , but cannot find a sample like this , it just directly inject the EntityManagerFactory to the TestCast , not what I want ...

    Read the article

  • Converting DAO to ADO

    - by webworm
    I am working with an Access 2003 database that has a subroutine using DAO code. This code loops through the table definitions and refreshes the ODBC connection string. I would like to convert this to ADO so I do not have to reference the DAO object library. Here is the code ... Public Sub RefreshODBCLinks(newConnectionString As String) Dim db As DAO.Database Dim tb As DAO.TableDef Set db = CurrentDb For Each tb In db.TableDefs If Left(tb.Connect, 4) = "ODBC" Then tb.Connect = newConnectionString tb.RefreshLink Debug.Print "Refreshed ODBC table " & tb.Name End If Next tb Set db = Nothing MsgBox "New connection string is " & newConnectionString, vbOKOnly, "ODBC Links refreshed" End Sub The part I am unsure of is how to loop through the tables and get/set their connection strings.

    Read the article

  • ORM model and DAO in my particular case

    - by EugeneP
    I have the DB structure as follows: table STUDENT (say, id, surname, etc) table STUDENT_PROPERTIES (say, name_of_the_property:char, value_of_the_property:char, student_id:FK) table COURSE (id, name, statusofcourse_id) table STATUSOFCOURSE (id, name_of_status:char ('active','inactive','suspended' etc)) table STUDENT_COURSE (student_id,course_id,statusofcourse_id) Let's try to pick up domain objects in my database: Student and Course are main entities. Student has a list of courses he attends, also he has a list of properties, that is all for this student. Next, Course entitity. It may contain a list of students that attend it. But in fact, the whole structure looks like this: the starting point is Student, with it's PK we can look a list of his properties, then we look into the STUDENT_COURSE and extract both FK of the Course entity and also the Status of the combination, it would look like "Student named bla bla, with all his properties, attends math and the status of it is "ACTIVE". now, quotation 1) Each DAO instance is responsible for one primary domain object or entity. If a domain object has an independent lifecycle, it should have its own DAO. 2) The DAO is responsible for creations, reads (by primary key), updates, and deletions -- that is, CRUD -- on the domain object. Now, first question is What are entities in my case? Student, Course, Student_Course, Status = all except for StudentProperties? Do I have to create a separate DAO for every object?

    Read the article

  • DAO, Spring and Hibernate

    - by EugeneP
    Correct me if anything is wrong. Now when we use Spring DAO for ORM templates, when we use @Transactional attribute, we do not have control over the transaction and/or session when the method is called externally, not within the method. Lazy loading saves resources - less queries to the db, less memory to keep all the collections fetched in the app memory. So, if lazy=false, then everything is fetched, all associated collections, that is not effectively, if there are 10,000 records in a linked set. Now, I have a method in a DAO class that is supposed to return me a User object. It has collections that represent linked tables of the database. I need to get a object by id and then query its collections. Hibernate "failed to lazily initialize a collection" exception occurs when I try to access the linked collection that this DAO method returns. Explain please, what is a workaround here?

    Read the article

  • which scope should a DAO typically have.

    - by Andreas Petersson
    its out of question that a dao will not hold any state. however, for easiest access to the class, is it better to use prototype( = new every time) or singleton? simple object creation is cheap for dao's.. it typically only holds a sessionfactory, accessing the object from a list of singletons may be equally expensive. clarfication: the focus of this question is, if there is a common convention to the scoping of daos.

    Read the article

  • pattern to transfer search model to dao

    - by zeroed
    We have a dao as a project (jar file). Clients use its interfaces and factories to operate with database. Using standard CRUD operations, dao allows you to search an entity by some search criteria. What is the best way to represent this criteria? Is transfer object appropriate pattern in this situation? How should client create SearchModel instance? Please, share. Regards.

    Read the article

  • Jmock mock DAO object

    - by Gandalf StormCrow
    Hi all, I wrote a method that retrieves certain list of strings, given a correct string key. Now when I create a list(the one to be retrieved by method descibed in previous sentence) and create test I can easily get results and test passes successfully. Now on the other hand if I save the content of this list to database in 2 columns, key and value I wrote a class which retrieves this items with method inside it. And when I print it out to console the expected results are correct, now I initialize my DAO from application context where inside its bean it gets session and because of DAO works. Now I'm trying to write a test which will mock the DAO, because I'm running test localy not on the server .. so I told jmock to mock it : private MyDAO myDAO; in the setup() myDAO = context.mock(MyDAO.class); I think I'm mocking it correctly or not, how can I mock this data from database? what is the best way? Is there somewhere good Jmock documentation? on their official site its not very good and clear, you have to know what you seek in order to find it, can't discover something cool in the mean time.

    Read the article

  • generic DAO in java

    - by akshay
    I am trying to develop generic DAO in java.I have tried the following.Is this a good way to implement generic dao?I dont want to use hibernate.I am trying to make it as generic as possible so that i dont have to repeate the same code again and again. public abstract class AbstractDAO<T> { protected ResultSet findbyId(String tablename, Integer id){ ResultSet rs= null; try { // the following lins in not working; pStmt = cn.prepareStatement("SELECT * FROM "+ tablename+ "WHERE id = ?"); pStmt.setInt(1, id); rs = pStmt.executeQuery(); } catch (SQLException ex) { System.out.println("ERROR in findbyid " +ex.getMessage() +ex.getCause()); ex.printStackTrace(); }finally{ return rs; } } } Now i have public class UserDAO extends AbstractDAO<User>{ public List<User> findbyid(int id){ Resultset rs =findbyid("USERS",id) //USERS is tablename in db List<Users> users = convertToList(rs); return users; } private List<User> convertToList(ResultSet rs) { List<User> userList= new ArrayList(); User user= new User();; try { while (rs.next()) { user.setId(rs.getInt("id")); user.setUsername(rs.getString("username")); user.setFname(rs.getString("fname")); user.setLname(rs.getString("lname")); user.setUsertype(rs.getInt("usertype")); user.setPasswd(rs.getString("passwd")); userList.add(user); } } catch (SQLException ex) { Logger.getLogger(UserDAO.class.getName()).log(Level.SEVERE, null, ex); } return userList; } }

    Read the article

  • Working with hibernate/DAO problems

    - by Gandalf StormCrow
    Hello everyone here is my DAO class : public class UsersDAO extends HibernateDaoSupport { private static final Log log = LogFactory.getLog(UsersDAO.class); protected void initDao() { //do nothing } public void save(User transientInstance) { log.debug("saving Users instance"); try { getHibernateTemplate().saveOrUpdate(transientInstance); log.debug("save successful"); } catch (RuntimeException re) { log.error("save failed", re); throw re; } } public void update(User transientInstance) { log.debug("updating User instance"); try { getHibernateTemplate().update(transientInstance); log.debug("update successful"); } catch (RuntimeException re) { log.error("update failed", re); throw re; } } public void delete(User persistentInstance) { log.debug("deleting Users instance"); try { getHibernateTemplate().delete(persistentInstance); log.debug("delete successful"); } catch (RuntimeException re) { log.error("delete failed", re); throw re; } } public User findById( java.lang.Integer id) { log.debug("getting Users instance with id: " + id); try { User instance = (User) getHibernateTemplate() .get("project.hibernate.Users", id); return instance; } catch (RuntimeException re) { log.error("get failed", re); throw re; } } } Now I wrote a test class(not a junit test) to test is everything working, my user has these fields in the database : userID which is 5characters long string and unique/primary key, and fields such as address, dob etc(total 15 columns in database table). Now in my test class I intanciated User added the values like : User user = new User; user.setAddress("some address"); and so I did for all 15 fields, than at the end of assigning data to User object I called in DAO to save that to database UsersDao.save(user); and save works just perfectly. My question is how do I update/delete users using the same logic? Fox example I tried this(to delete user from table users): User user = new User; user.setUserID("1s54f"); // which is unique key for users no two keys are the same UsersDao.delete(user); I wanted to delete user with this key but its obviously different can someone explain please how to do these. thank you

    Read the article

  • recommendations for firestorm dao replacement

    - by Casey
    I have taken over some code that has been using the Firestorm DAO code generator from CodeFutures. I believe that the license for this is going to be up soon, and was wondering if anyone could recommend any alternatives, open source or not, so that I can get an idea of what's out there to better make a decision.

    Read the article

  • DAO method retrieve single entry

    - by London
    Hello, How can I write DAO method which will return as a result only first entry from the database. For instance lets say I'm looking at Users table and I want to retrieve only the first entry, I'd declare method like: public User getFirstUser(){ //method logic } EDIT: User has primary key id if that matters at all. I apologize if this question is too simple/stupid/whatever I'm beginner with Java so I'm trying new things. thank you

    Read the article

  • dao as a member of a servlet - normal?

    - by EugeneP
    I guess, DAO is thread safe, does not use any class members. So can it be used without any problem as a private field of a Servlet ? We need only one copy, and multiple threads can access it simultaneously, so why bother creating a local variable, right?

    Read the article

  • Relationship DAO, Servlet, JSP and POJO

    - by John Hendrik
    I want to implement a JSP, POJO, DAO and Servlet in my J2EE program. However, I don't fully understand how the relationship between these elements should be. Is the following (MVC) setup the right way to do it? Main class creates servlet(controller) Servlet has a DAO defined in its class DAO has a POJO defined in its class Servlet communicates with the view (JSP page) Please give your feedback.

    Read the article

  • Opening a password encrypted access database using DAO VB.NET

    - by prasoon99
    I create a database like this: Sub Main() Dim wrkDefault As Workspace Dim dbE As DBEngine Dim dbs As Database 'Get default Workspace. dbE = New DBEngine wrkDefault = dbE.Workspaces(0) 'Set the database filename Dim DBFilename As String DBFilename = "c:\mydb.mdb" 'Make sure there isn't already a file with the same name of 'the new database file. If Dir(DBFilename) <> "" Then MsgBox("File already exists!") Exit Sub End If 'Create a new encrypted database with the specified 'collating order. 'lock database with the password 'hello' dbs = wrkDefault.CreateDatabase(DBFilename, _ LanguageConstants.dbLangGeneral & ";pwd=hello;", DatabaseTypeEnum.dbEncrypt) dbs.Close() End Sub How do I open this database again in VB.NET using DAO?

    Read the article

  • SpringMvc Annotations for DAO interface and DAO implementation

    - by dev_darin
    I would like to know if I am annotating these classes correctly, since I am new to the annotations: Country.java @Component public class Country { private int countryId; private String countryName; private String countryCode; /** * No args constructor */ public Country() { } /** * @param countryId * @param countryName * @param countryCode */ public Country(int countryId, String countryName, String countryCode) { this.countryId = countryId; this.countryName = countryName; this.countryCode = countryCode; } //getters and setters } CountryDAO.java @Repository public interface CountryDAO { public List<Country> getCountryList(); public void saveCountry(Country country); public void updateCountry(Country country); } JdbcCountryDAO.java @Component public class JdbcCountryDAO extends JdbcDaoSupport implements CountryDAO{ private final Logger logger = Logger.getLogger(getClass()); @Autowired public List<Country> getCountryList() { int countryId = 6; String countryCode = "AI"; logger.debug("In getCountryList()"); String sql = "SELECT * FROM TBLCOUNTRY WHERE countryId = ? AND countryCode = ?"; logger.debug("Executing getCountryList String "+sql); Object[] parameters = new Object[] {countryId, countryCode}; logger.info(sql); //List<Country> countryList = getJdbcTemplate().query(sql,new CountryMapper()); List<Country> countryList = getJdbcTemplate().query(sql, parameters,new CountryMapper()); return countryList; } CountryManagerIFace.java @Repository public interface CountryManagerIFace extends Serializable{ public void saveCountry(Country country); public List<Country> getCountries(); } CountryManager.java @Component public class CountryManager implements CountryManagerIFace{ @Autowired private CountryDAO countryDao; public void saveCountry(Country country) { countryDao.saveCountry(country); } public List<Country> getCountries() { return countryDao.getCountryList(); } public void setCountryDao(CountryDAO countryDao){ this.countryDao = countryDao; } }

    Read the article

  • Why put a DAO layer over a persistence layer (like JDO or Hibernate)

    - by Todd Owen
    Data Access Objects (DAOs) are a common design pattern, and recommended by Sun. But the earliest examples of Java DAOs interacted directly with relational databases -- they were, in essence, doing object-relational mapping (ORM). Nowadays, I see DAOs on top of mature ORM frameworks like JDO and Hibernate, and I wonder if that is really a good idea. I am developing a web service using JDO as the persistence layer, and am considering whether or not to introduce DAOs. I foresee a problem when dealing with a particular class which contains a map of other objects: public class Book { // Book description in various languages, indexed by ISO language codes private Map<String,BookDescription> descriptions; } JDO is clever enough to map this to a foreign key constraint between the "BOOKS" and "BOOKDESCRIPTIONS" tables. It transparently loads the BookDescription objects (using lazy loading, I believe), and persists them when the Book object is persisted. If I was to introduce a "data access layer" and write a class like BookDao, and encapsulate all the JDO code within this, then wouldn't this JDO's transparent loading of the child objects be circumventing the data access layer? For consistency, shouldn't all the BookDescription objects be loaded and persisted via some BookDescriptionDao object (or BookDao.loadDescription method)? Yet refactoring in that way would make manipulating the model needlessly complicated. So my question is, what's wrong with calling JDO (or Hibernate, or whatever ORM you fancy) directly in the business layer? Its syntax is already quite concise, and it is datastore-agnostic. What is the advantage, if any, of encapsulating it in Data Access Objects?

    Read the article

  • Avoid having a huge collection of ids by calling a DAO.getAll()

    - by Michael Bavin
    Instead of returning a List<Long> of ids when calling PersonDao.getAll() we wanted not to have an entire collection of ids in memory. Seems like returning a org.springframework.jdbc.support.rowset.SqlRowSet and iterate over this rowset would not hold every object in memory. The only problem here is i cannot cast this row to my entity. Is there a better way for this?

    Read the article

  • Data Access Objects old fashioned? [on hold]

    - by Bono
    A couple of weeks ago I delivered some work for a university project. After a code review with some teachers I got some snarky remarks about the fact that I was (still) using Data Access Objects. The teacher in question who said this mentions the use of DAO's in his classes and always says something along the lines of "Back then we always used DAO's". He's a big fan of Object Relational Mapping, which I also think is a great tool. When I was talking about this with some of my fellow students, they also mentioned that they prefer the use of ORM, which I can understand. It did make me wonder though, is using DAO's really so old fashioned? I know that at my work DAO's are still being used, but this is due to the fact that some of the code is rather old and therefor can't be coupled with ORM. We also do use ORM at my work. Trying to find some more information on Google or Stack Exchange sites didn't really enlighten me. Should I step away from the use of DAO's and only start implementing ORM? I just feel that ORM's can be a bit overkill for some simple projects. I'd love to hear your opinions (or facts) about this.

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >