📄 voicefacade.java
字号:
{
logger.info(ex.getMessage());
throw new VoiceException(ex.getMessage());
}
finally
{
DBHelper.cleanup(conn);
}
}
/**
* 按制定大类查找合乎条件的声音文件
*
* @param keyWord String
* @throws VoiceException
* @return VoiceValueObject
*/
public VoiceValueObject queryById(Integer id)
throws VoiceException
{
return this.getVoiceById(id);
}
/**
* 按照类型(大类)以及内容描述查询
* @param catalog Integer
* @param keyWord String
* @throws VoiceException
* @return VoiceValueObject[]
*/
static String sql_key = "SELECT A.ID, A.CATALOG_ID, A.DESCRIPTION, A.COUNT, A.CREATE_DATE, A.PRICE, A.TYPE, A.NAME, A.USER_ID FROM VOICE A ,small_catalog t WHERE a.catalog_id = t.id and t.big_id = ? and a.description like ?";
public VoiceValueObject[] queryByCatalog(Integer catalog,String keyWord)
throws VoiceException
{
Connection conn = null;
try
{
conn = DBHelper.getConn();
PreparedStatement ps = conn.prepareStatement(sql_key);
ps.setInt(1,catalog.intValue());
ps.setString(2,"%"+keyWord+"%");
List list = new LinkedList();
ResultSet rs = ps.executeQuery();
while(rs.next())
{
VoiceValueObject model = new VoiceValueObject();
int intID = rs.getInt("ID");
if(!rs.wasNull())model.setId(new Integer(intID));
int intCATALOG_ID = rs.getInt("CATALOG_ID");
if(!rs.wasNull())model.setCatalogId(new Integer(intCATALOG_ID));
String strDESCRIPTION = rs.getString("DESCRIPTION");
if(!rs.wasNull())model.setDescription(strDESCRIPTION.trim());
int intCOUNT = rs.getInt("COUNT");
if(!rs.wasNull())model.setCount(new Integer(intCOUNT));
model.setCreateDate(rs.getTimestamp("CREATE_DATE"));
int intPRICE = rs.getInt("PRICE");
if(!rs.wasNull())model.setPrice(new Integer(intPRICE));
int intTYPE = rs.getInt("TYPE");
if(!rs.wasNull())model.setType(new Integer(intTYPE));
String strNAME = rs.getString("NAME");
if(!rs.wasNull())model.setName(strNAME.trim());
int intUSER_ID = rs.getInt("USER_ID");
if(!rs.wasNull())model.setUserId(new Integer(intUSER_ID));
list.add(model);
}
rs.close();
ps.close();
return(VoiceValueObject[])list.toArray(new VoiceValueObject[list.size()]);
}
catch(Exception ex)
{
logger.info(ex.getMessage());
throw new VoiceException(ex.getMessage());
}
finally
{
DBHelper.cleanup(conn);
}
}
/**
* 查询用户对应的VoiceUser,用于验证
* @param userId String
* @throws VoiceException
* @return VoiceUserValueObject
*/
public VoiceUserValueObject getVoiceUser(String userName)
throws VoiceException
{
Connection conn = null;
try
{
conn = DBHelper.getConn();
VoiceUserDAO dao = new VoiceUserDAO();
VoiceUserValueObject vo = new VoiceUserValueObject();
vo.setName(userName);
List list = dao.supplement(conn,vo, -1, -1);
if(list.size() == 0)return null;
else
{
return(VoiceUserValueObject)list.get(0);
}
}
catch(Exception ex)
{
logger.info(ex.getMessage());
throw new VoiceException(ex.getMessage());
}
finally
{
DBHelper.cleanup(conn);
}
}
/**
* 查询用户对应的VoiceUser,用于验证
* @param userId String
* @throws VoiceException
* @return VoiceUserValueObject
*/
public VoiceUserValueObject getVoiceUser(String userName,Integer type)
throws VoiceException
{
Connection conn = null;
try
{
conn = DBHelper.getConn();
VoiceUserDAO dao = new VoiceUserDAO();
VoiceUserValueObject vo = new VoiceUserValueObject();
vo.setName(userName);
vo.setType(type);
List list = dao.supplement(conn,vo, -1, -1);
if(list.size() == 0)return null;
else
{
return(VoiceUserValueObject)list.get(0);
}
}
catch(Exception ex)
{
logger.info(ex.getMessage());
throw new VoiceException(ex.getMessage());
}
finally
{
DBHelper.cleanup(conn);
}
}
/**
* 注册新用户,如果用户已经存在,则抛出异常
* @param newUser VoiceUserValueObject
* @throws VoiceException
* @return Integer 用户id
*/
public Integer register(VoiceUserValueObject newUser)
throws VoiceException
{
Connection conn = null;
try
{
conn = DBHelper.getConn();
VoiceUserDAO dao = new VoiceUserDAO();
VoiceUserValueObject vo = new VoiceUserValueObject();
vo.setName(newUser.getName());
List list = dao.supplement(conn,vo, -1, -1);
if(list.size() != 0)
{
throw new VoiceException("用户已经存在:" + newUser.getName());
}
else
{
newUser.setId(new Integer(DBHelper.nextUserSeqId(conn)));
dao.insert(conn,newUser);
return newUser.getId();
}
}
catch(Exception ex)
{
logger.info(ex.getMessage());
throw new VoiceException(ex.getMessage());
}
finally
{
DBHelper.cleanup(conn);
}
}
/**
* 注册新用户,如果用户已经存在,则抛出异常
* @param newUser VoiceUserValueObject
* @throws VoiceException
* @return Integer 用户id
*/
public void update(VoiceUserValueObject user)
throws VoiceException
{
Connection conn = null;
try
{
conn = DBHelper.getConn();
VoiceUserDAO dao = new VoiceUserDAO();
if(user.getId()==null)
{
throw new VoiceException("用户ID为空");
}
dao.update(conn,user);
}
catch(Exception ex)
{
logger.info(ex.getMessage());
throw new VoiceException(ex.getMessage());
}
finally
{
DBHelper.cleanup(conn);
}
}
/**
* 得到用户上传的声音文件
* @param userId Integer
* @return VoiceUserValueObject
*/
public VoiceValueObject[] getUserVoice(Integer userId)
throws VoiceException
{
Connection conn = null;
try
{
conn = DBHelper.getConn();
VoiceDAO dao = new VoiceDAO();
VoiceQueryValue vo = new VoiceQueryValue();
vo.setUserId(userId);
//用户类型
vo.setType(new Integer(2));
List list = dao.selectByQueryValue(conn,vo, -1, -1);
return(VoiceValueObject[])list.toArray(new VoiceValueObject[list.size()]);
}
catch(Exception ex)
{
logger.info(ex.getMessage());
throw new VoiceException(ex.getMessage());
}
finally
{
DBHelper.cleanup(conn);
}
}
public VoiceValueObject getVoiceById(Integer id)
throws VoiceException
{
Connection conn = null;
try
{
conn = DBHelper.getConn();
VoiceDAO dao = new VoiceDAO();
return dao.getByPrimaryKey(conn,id);
}
catch(Exception ex)
{
logger.info(ex.getMessage());
throw new VoiceException(ex.getMessage());
}
finally
{
DBHelper.cleanup(conn);
}
}
public Integer addUserVoiceById(VoiceValueObject voice)
throws VoiceException
{
Connection conn = null;
try
{
conn = DBHelper.getConn();
VoiceDAO dao = new VoiceDAO();
//用户上传类型
voice.setCatalogId(new Integer(0));
voice.setType(Consts.VOICE_TYPE_USER);
Integer id = new Integer(DBHelper.nextVoiceSeqId(conn));
voice.setId(id);
dao.insert(conn,voice);
return id;
}
catch(Exception ex)
{
logger.info(ex.getMessage());
throw new VoiceException(ex.getMessage());
}
finally
{
DBHelper.cleanup(conn);
}
}
public static void main(String[] args) throws VoiceException{
VoiceFacade f = new VoiceFacade();
// int size = f.getVoiceSizeBySmallCatalog(new Integer(1));
// System.out.println(size);
// int size = f.getVoiceSizeByBigCatalog(new Integer(1));
// System.out.println(size);
// VoiceValueObject[] vos = f.getVoiceByBigCatalog(new Integer(1),1,size);
// System.out.println(vos.length);
// System.out.println(Arrays.asList(vos));
DBHelper.isDebug = true ;
int size = f.getVoiceSizeByBigCatalog(null);
System.out.println(size);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -