Package com.pugh.sockso.db

Examples of com.pugh.sockso.db.Database


       
        try {
           
            final User user = getUser();
            final Request req = getRequest();
            final Database db = getDatabase();
            final String sql = " update users " +
                               " set email = ?, " +
                                   " pass = ? " +
                               " where id = ? ";
           
            st = db.prepare( sql );
            st.setString( 1, req.getArgument("email") );
            st.setString( 2, Utils.md5(req.getArgument("pass1")) );
            st.setInt( 3, user.getId() );
            st.execute();
           
View Full Code Here


        final String name = req.getArgument( "name" ).trim();
        final String pass1 = req.getArgument( "pass1" );
        final String pass2 = req.getArgument( "pass2" );
        final String email = req.getArgument( "email" ).trim();
       
        final Database db = getDatabase();
        final Validater v = new Validater( db );
       
        if ( !v.checkRequiredFields(new String[]{name,pass1,email}) )
            throw new BadRequestException( locale.getString("www.error.missingField") );
        if ( !pass1.equals(pass2) )
View Full Code Here

        ResultSet rs = null;
        PreparedStatement st = null;

        try {

            final Database db = getDatabase();
            final String sql = " select id, name " +
                               " from users " +
                               " where name = ? " +
                               " limit 1 ";

            st = db.prepare( sql );
            st.setString( 1, name );
            rs = st.executeQuery();

            if ( rs.next() ) {
                return new User( rs.getInt("id"), rs.getString("name") );
View Full Code Here

        final User user = getUser();
        final Locale locale = getLocale();

        if ( user == null ) throw new BadRequestException( locale.getString("www.json.error.notLoggedIn"), 403 );

        final Database db = getDatabase();
        final int id = Integer.parseInt( req.getUrlParam(2) );
        final String sql = " select 1 " +
                           " from playlists p " +
                           " where p.id = ? " +
                               " and p.user_id = ? ";

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

            // check user owns playlist before deleting it
            st = db.prepare( sql );
            st.setInt( 1, id );
            st.setInt( 2, user.getId() );
            rs = st.executeQuery();
            if ( !rs.next() )
                throw new BadRequestException( "You don't own that playlist", 403 );
View Full Code Here

        ResultSet rs = null;
        PreparedStatement st = null;
       
        try {
       
            final Database db = getDatabase();
            final Request req = getRequest();
            final String path = req.getArgument( "path" );
           
            final TTracksForPath tpl = new TTracksForPath();
            tpl.setTracks( Track.getTracksFromPath(db,path) );
View Full Code Here

        ResultSet rs = null;
        PreparedStatement st = null;

        try {
           
            final Database db = getDatabase();
            final Locale locale = getLocale();
            final Request req = getRequest();
            final String path = convertPath( req.getArgument("path") );
            final String sql = Track.getSelectFromSql() +
                    " where t.path = ? ";
           
            st = db.prepare( sql );
            st.setString( 1, path );
            rs = st.executeQuery();
           
            if ( !rs.next() )
                throw new BadRequestException( locale.getString("www.error.trackNotFound"), 404 );
View Full Code Here

                path += "/" + req.getUrlParam( i );
        }
               
        try {

            final Database db = getDatabase();
            final String sql = " select c.path " +
                               " from collection c " +
                               " where c.id = ? ";
            st = db.prepare( sql );
            st.setInt( 1, collectionId );
            rs = st.executeQuery();

            // check the collection exists and we got it's root path
            if ( rs.next() ) {
View Full Code Here

            result = locale.getString("www.json.error.noArguments");
        else if ( user == null )
            result = locale.getString("www.json.error.notLoggedIn");
        else {
           
            final Database db = getDatabase();
            final List<Track> vTracks = Track.getTracksFromPlayArgs( db, args );
            final Track[] tracks = new Track[ vTracks.size() ];
           
            for ( int i=0; i<vTracks.size(); i++ )
                tracks[i] = vTracks.get( i );
View Full Code Here

     *
     */
   
    public void handleRequest() throws IOException, SQLException, BadRequestException {
       
        final Database db = getDatabase();
        final Playlist playlist = Playlist.find( db, Integer.parseInt( getRequest().getUrlParam(2) ) );
       
        if ( playlist == null ) {
            throw new BadRequestException( "Invalid playlist ID" );
        }
View Full Code Here

        PreparedStatement st = null;
        ResultSet rs = null;

        try {

            final Database db = getDatabase();
            final String sql = " select ar.id as id, ar.name as name, count(t.id) as playCount " +
                    " from play_log l " +
                        " inner join tracks t " +
                        " on t.id = l.track_id " +
                        " inner join artists ar " +
                        " on ar.id = t.artist_id " +
                    " group by ar.id, ar.name " +
                    " order by playCount desc " +
                    " limit ? ";
           
            st = db.prepare( sql );
            st.setInt( 1, total );
            rs = st.executeQuery();
           
            final List<Artist> topArtists = new ArrayList<Artist>();
           
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.