implemented very simple ad rotation support, good enough for our rotating
quote banners - also included quote banners (20 from Webb, 4 new)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.core;
|
||||
|
||||
public interface Advertisement
|
||||
{
|
||||
// Image path style values.
|
||||
public static final short CONTEXT_RELATIVE = 0;
|
||||
|
||||
public abstract int getAdID();
|
||||
|
||||
public abstract String getImagePath();
|
||||
|
||||
public abstract short getImagePathStyle();
|
||||
|
||||
public abstract String getCaption();
|
||||
|
||||
public abstract String getLinkURL();
|
||||
|
||||
public abstract void hit(String remote_addr);
|
||||
|
||||
} // end interface Advertisement
|
||||
@@ -107,4 +107,6 @@ public interface UserContext extends SearchMode
|
||||
|
||||
public abstract boolean authenticateWithToken(String token) throws DataException;
|
||||
|
||||
public abstract Advertisement selectAd();
|
||||
|
||||
} // end interface UserContext
|
||||
|
||||
@@ -77,4 +77,8 @@ public interface VeniceEngine extends SearchMode
|
||||
|
||||
public abstract int getNumAuditRecordsPerPage();
|
||||
|
||||
public abstract Advertisement getAdByID(int id);
|
||||
|
||||
public abstract Advertisement selectAd();
|
||||
|
||||
} // end interface VeniceEngine
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.core.impl;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Random;
|
||||
import com.silverwrist.util.cachemap.*;
|
||||
import com.silverwrist.venice.core.*;
|
||||
import com.silverwrist.venice.db.*;
|
||||
|
||||
class AdvertisementImpl implements Advertisement
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private static Random rng = new Random(System.currentTimeMillis());
|
||||
private static CacheMap ad_cache = new CacheMap(500);
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private DataPool datapool;
|
||||
private int adid;
|
||||
private String imagepath;
|
||||
private short style;
|
||||
private String caption;
|
||||
private String linkurl;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
protected AdvertisementImpl(DataPool datapool, ResultSet rs) throws SQLException
|
||||
{
|
||||
this.datapool = datapool;
|
||||
this.adid = rs.getInt("adid");
|
||||
this.imagepath = rs.getString("imagepath");
|
||||
this.style = rs.getShort("pathstyle");
|
||||
this.caption = rs.getString("caption");
|
||||
this.linkurl = rs.getString("linkurl");
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal functions
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private static Advertisement getTheAd(DataPool datapool, Statement stmt, int ad_id) throws SQLException
|
||||
{
|
||||
Integer my_ad_id = new Integer(ad_id);
|
||||
Advertisement rc = (Advertisement)(ad_cache.get(my_ad_id));
|
||||
if (rc!=null)
|
||||
return rc;
|
||||
|
||||
ResultSet rs = stmt.executeQuery("SELECT * From adverts WHERE adid = " + ad_id + ";");
|
||||
if (!(rs.next()))
|
||||
return null;
|
||||
rc = new AdvertisementImpl(datapool,rs);
|
||||
ad_cache.put(my_ad_id,rc);
|
||||
return rc;
|
||||
|
||||
} // end getTheAd
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface Advertisement
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public int getAdID()
|
||||
{
|
||||
return adid;
|
||||
|
||||
} // end getAdID
|
||||
|
||||
public String getImagePath()
|
||||
{
|
||||
return imagepath;
|
||||
|
||||
} // end getImagePath
|
||||
|
||||
public short getImagePathStyle()
|
||||
{
|
||||
return style;
|
||||
|
||||
} // end getImagePathStyle
|
||||
|
||||
public String getCaption()
|
||||
{
|
||||
return caption;
|
||||
|
||||
} // end getCaption
|
||||
|
||||
public String getLinkURL()
|
||||
{
|
||||
return linkurl;
|
||||
|
||||
} // end getLinkURL
|
||||
|
||||
public void hit(String remote_addr)
|
||||
{ // this does nothing right now
|
||||
} // end hit
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static functions for use within package
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static Advertisement getAdByID(DataPool datapool, int id)
|
||||
{
|
||||
Connection conn = null;
|
||||
|
||||
try
|
||||
{ // get a database connection and call the internal function
|
||||
conn = datapool.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
return getTheAd(datapool,stmt,id);
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // database error - no ad
|
||||
return null;
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // make sure the connection is released before we go
|
||||
if (conn!=null)
|
||||
datapool.releaseConnection(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end getAdByID
|
||||
|
||||
static Advertisement getRandomAd(DataPool datapool)
|
||||
{
|
||||
Connection conn = null;
|
||||
|
||||
try
|
||||
{ // get a database connection and call the internal function
|
||||
conn = datapool.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT MAX(adid) FROM adverts;");
|
||||
if (!(rs.next()))
|
||||
throw new InternalStateError("getRandomAd() must be able to find MAX(adid)!");
|
||||
int maximum = rs.getInt(1);
|
||||
|
||||
for (int i=0; i<100; i++)
|
||||
{ // select an ad ID
|
||||
int ad_id = rng.nextInt(maximum) + 1;
|
||||
Advertisement rc = getTheAd(datapool,stmt,ad_id);
|
||||
if (rc!=null)
|
||||
return rc;
|
||||
|
||||
} // end for
|
||||
|
||||
// else just dump out and return null
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // database error - no ad
|
||||
return null;
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // make sure the connection is released before we go
|
||||
if (conn!=null)
|
||||
datapool.releaseConnection(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
return null; // no ad
|
||||
|
||||
} // end getRandomAd
|
||||
|
||||
} // end class AdvertisementImpl
|
||||
@@ -1345,6 +1345,13 @@ class UserContextImpl implements UserContext, UserBackend
|
||||
|
||||
} // end authenticateWithToken
|
||||
|
||||
public Advertisement selectAd()
|
||||
{
|
||||
// just get a random ad for now
|
||||
return AdvertisementImpl.getRandomAd(datapool);
|
||||
|
||||
} // end selectAd
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface UserBackend
|
||||
*--------------------------------------------------------------------------------
|
||||
|
||||
@@ -1567,6 +1567,19 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||
|
||||
} // end getNumAuditRecordsPerPage
|
||||
|
||||
public Advertisement getAdByID(int id)
|
||||
{
|
||||
return AdvertisementImpl.getAdByID(datapool,id);
|
||||
|
||||
} // end getAdByID
|
||||
|
||||
public Advertisement selectAd()
|
||||
{
|
||||
// just get a random ad for now
|
||||
return AdvertisementImpl.getRandomAd(datapool);
|
||||
|
||||
} // end selectAd
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface EngineBackend
|
||||
*--------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user