Package com.pugh.sockso.db

Examples of com.pugh.sockso.db.Database


        ResultSet rs = null;
        PreparedStatement st = null;
       
        try {
           
            final Database db = getDatabase();
            final String sql = Track.getSelectFromSql() +
                  " where t.album_id = ? " +
                  " order by t.track_no asc ";
            st = db.prepare( sql );
            st.setInt( 1, albumId );
            rs = st.executeQuery();

            return Track.createListFromResultSet( rs );
           
View Full Code Here


        ResultSet rs = null;
        PreparedStatement st = null;
       
        try {
           
            final Database db = getDatabase();
            final String sql = " select ar.id as artistId, ar.name as artistName, " +
                        " al.id as albumId, al.name as albumName, al.year as albumYear, " +
                        " al.date_added, ( " +
                            " select count(*) " +
                            " from play_log l " +
                                " inner join tracks t " +
                                " on t.id = l.track_id " +
                            " where t.album_id = al.id " +
                        " ) as playCount " +
                    " from albums al " +
                        " inner join artists ar " +
                        " on ar.id = al.artist_id " +
                    " where al.id = ? " +
                    " limit 1 ";
            st = db.prepare( sql );
            st.setInt( 1, id );
            rs = st.executeQuery();
            if ( !rs.next() )
                throw new BadRequestException( "album not found", 404 );

View Full Code Here

        ResultSet rs = null;
        PreparedStatement st = null;
       
        try {
           
            final Database db = getDatabase();
            final String sql = " select ar.id as artistId, ar.name as artistName, " +
                        " al.id as albumId, al.name as albumName, al.year as albumYear, count(t.id) as trackCount " +
                        " from albums al " +
                            " inner join artists ar " +
                            " on ar.id = al.artist_id " +
                            " left outer join tracks t " +
                            " on t.album_id = al.id " +
                        " where (t.artist_id = ? or al.artist_id = ?) " +
                        " group by artistId, artistName, albumId, albumYear, albumName " +
                        " order by al.year desc, al.name asc ";
            st = db.prepare( sql );
            st.setInt( 1, artistId );
            st.setInt( 2, artistId );
            rs = st.executeQuery();

            final List<Album> albums = new ArrayList<Album>();
View Full Code Here

        ResultSet rs = null;
        PreparedStatement st = null;
       
        try {

            final Database db = getDatabase();
            final String sql = " select ar.id as id, ar.name as name, ar.date_added as date_added, " +
                        " count(t.id) as trackCount, " +
                        " ( " +
                            " select count(*) as playCount " +
                            " from play_log l " +
                                " inner join tracks t " +
                                " on t.id = l.track_id " +
                            " where t.artist_id = ar.id " +
                        " ) as playCount " +
                  " from artists ar " +
                       " left outer join tracks t " +
                       " on t.artist_id = ar.id " +
                  " where ar.id = ? " +
                  " group by ar.id, ar.name, ar.date_added " +
                  " limit 1 ";
            st = db.prepare( sql );
            st.setInt( 1, artistId );
            rs = st.executeQuery();
            if ( !rs.next() )
                throw new BadRequestException( "artist not found", 404 );
           
View Full Code Here

    private ResultSet getLatestMusic( final String type, final String totalPropertyName ) throws SQLException {
   
        PreparedStatement st = null;
       
        final Properties p = getProperties();
        final Database db = getDatabase();
        final String sql = " select ar.id, ar.name, max(t.date_added) as mostRecent " +
                    " from tracks t " +
                        " inner join " +type+ "s ar " +
                        " on ar.id = t." +type+ "_id " +
                    " group by ar.id, ar.name " +
                    " order by mostRecent desc " +
                    " limit ? ";
        st = db.prepare( sql );
        st.setInt( 1, (int) p.get(totalPropertyName,10) );

        return st.executeQuery();

    }
View Full Code Here

       
    }
   
    public void testGetAlbumTracksQuery() throws Exception {
       
        final Database db = new TestDatabase();
        final Albumer b = new Albumer();
       
        b.setDatabase( db );
        b.getAlbumTracks( -1 );
       
View Full Code Here

       
    }
   
    public void testGetAlbumQuery() throws Exception {
       
        final Database db = new TestDatabase();
        final Albumer b = new Albumer();
       
        b.setDatabase( db );
        try {
            b.getAlbum( -1 );
View Full Code Here

        final PreparedStatement st = createMock( PreparedStatement.class );
        expect( st.executeQuery() ).andReturn( rs ).times( 1 );
        st.close();
        replay( st );

        final Database db = createMock( Database.class );
        expect( db.prepare((String)anyObject()) ).andReturn( st ).times( 1 );
        replay( db );
       
        final File playlistFile = new File( "myPlaylist.m3u" );
        final ImportPlaylist ip = new ImportPlaylist( null, db, null, null, new TestLocale() );
       
View Full Code Here

        st.setNull( 2, Types.INTEGER );
        expect( st.execute() ).andReturn( true );
        st.close();
        replay( st );
       
        final Database db = createMock( Database.class );
        expect( db.prepare((String)anyObject()) ).andReturn( st ).times( 1 );
        replay( db );
       
        final Streamer s = new Streamer();
        s.setDatabase( db );
       
View Full Code Here

        st.setInt( 2, user.getId() );
        expect( st.execute() ).andReturn( true );
        st.close();
        replay( st );
       
        final Database db = createMock( Database.class );
        expect( db.prepare((String)anyObject()) ).andReturn( st ).times( 1 );
        replay( db );
       
        final Streamer s = new Streamer();
        s.setDatabase( db );
        s.setUser( user );
View Full Code Here

TOP

Related Classes of com.pugh.sockso.db.Database

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.