List of usage examples for org.hibernate.type StandardBasicTypes STRING
StringType STRING
To view the source code for org.hibernate.type StandardBasicTypes STRING.
Click Source Link
From source file:com.Module.BarModule.java
public static List getReplyOwnerInfo(String reply_id) { Session s = HibernateUtil.currentSession(); HibernateUtil.beginTransaction();// w w w. j a va 2 s. co m String sql = "Select user_name,reply.user_id,post_date from reply,user" + " where reply.user_id = user.user_id and reply_id = " + reply_id; // ArrayList<String> get = new ArrayList<String>(); // get.add("user_name"); // get.add("String"); // get.add("user_id"); // get.add("int"); // get.add("post_date"); // get.add("date"); List list = s.createSQLQuery(sql).addScalar("user_name", StandardBasicTypes.STRING) .addScalar("user_id", StandardBasicTypes.INTEGER).addScalar("post_date", StandardBasicTypes.DATE) .list(); HibernateUtil.commitTransaction();//?? HibernateUtil.closeSession(); return list; }
From source file:com.mysema.query.jpa.support.ExtendedDerbyDialect.java
License:Apache License
public ExtendedDerbyDialect() { registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "cast ((", "||", ") as varchar(128))")); registerFunction("cast", castFunction); }
From source file:com.mysema.query.jpa.support.ExtendedHSQLDialect.java
License:Apache License
public ExtendedHSQLDialect() { registerFunction("trim", new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(both from ?1)")); }
From source file:com.mysema.query.jpa.support.TeradataDialect.java
License:Open Source License
/** * Constructor/*from w w w . j a va 2 s.co m*/ */ public TeradataDialect() { super(); // registerColumnType data types registerColumnType(Types.NUMERIC, "NUMERIC($p,$s)"); registerColumnType(Types.DOUBLE, "DOUBLE PRECISION"); registerColumnType(Types.BIGINT, "NUMERIC(18,0)"); registerColumnType(Types.BIT, "BYTEINT"); registerColumnType(Types.TINYINT, "BYTEINT"); registerColumnType(Types.VARBINARY, "VARBYTE($l)"); registerColumnType(Types.BINARY, "BYTEINT"); registerColumnType(Types.LONGVARCHAR, "LONG VARCHAR"); registerColumnType(Types.CHAR, "CHAR(1)"); registerColumnType(Types.DECIMAL, "DECIMAL"); registerColumnType(Types.INTEGER, "INTEGER"); registerColumnType(Types.SMALLINT, "SMALLINT"); registerColumnType(Types.FLOAT, "FLOAT"); registerColumnType(Types.VARCHAR, "VARCHAR($l)"); registerColumnType(Types.DATE, "DATE"); registerColumnType(Types.TIME, "TIME"); registerColumnType(Types.TIMESTAMP, "TIMESTAMP"); registerColumnType(Types.BOOLEAN, "BYTEINT"); // hibernate seems to // ignore this type... registerColumnType(Types.BLOB, "BLOB"); registerColumnType(Types.CLOB, "CLOB"); registerFunction("year", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "extract(year from ?1)")); registerFunction("length", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "character_length(?1)")); registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "(", "||", ")")); registerFunction("substring", new SQLFunctionTemplate(StandardBasicTypes.STRING, "substring(?1 from ?2 for ?3)")); registerFunction("locate", new SQLFunctionTemplate(StandardBasicTypes.STRING, "position(?1 in ?2)")); registerFunction("mod", new SQLFunctionTemplate(StandardBasicTypes.STRING, "?1 mod ?2")); registerFunction("str", new SQLFunctionTemplate(StandardBasicTypes.STRING, "cast(?1 as varchar(255))")); // bit_length feels a bit broken to me. We have to cast to char in order // to // pass when a numeric value is supplied. But of course the answers // given will // be wildly different for these two datatypes. 1234.5678 will be 9 // bytes as // a char string but will be 8 or 16 bytes as a true numeric. // Jay Nance 2006-09-22 registerFunction("bit_length", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "octet_length(cast(?1 as char))*4")); // The preference here would be // SQLFunctionTemplate( Hibernate.TIMESTAMP, "current_timestamp(?1)", // false) // but this appears not to work. // Jay Nance 2006-09-22 registerFunction("current_timestamp", new SQLFunctionTemplate(StandardBasicTypes.TIMESTAMP, "current_timestamp")); registerFunction("current_time", new SQLFunctionTemplate(StandardBasicTypes.TIME, "current_time")); registerFunction("current_date", new SQLFunctionTemplate(StandardBasicTypes.DATE, "current_date")); // IBID for current_time and current_date registerKeyword("account"); registerKeyword("alias"); registerKeyword("class"); registerKeyword("column"); registerKeyword("first"); registerKeyword("map"); registerKeyword("month"); registerKeyword("password"); registerKeyword("role"); registerKeyword("summary"); registerKeyword("title"); registerKeyword("type"); registerKeyword("value"); registerKeyword("year"); // Tell hibernate to use getBytes instead of getBinaryStream getDefaultProperties().setProperty(Environment.USE_STREAMS_FOR_BINARY, "false"); // No batch statements getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH); }
From source file:com.openkm.dao.NodeBaseDAO.java
License:Open Source License
/** * Test for category in use/*from w w w .ja v a2 s. c om*/ */ public boolean isCategoryInUse(String catUuid) throws DatabaseException { log.debug("isCategoryInUse({}, {})", catUuid); final String qs = "from NodeBase nb where :category in elements(nb.categories)"; final String sql = "select NCT_NODE from OKM_NODE_CATEGORY where NCT_CATEGORY = :catUuid"; Session session = null; Transaction tx = null; boolean check; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); if (Config.NATIVE_SQL_OPTIMIZATIONS) { SQLQuery q = session.createSQLQuery(sql); // q.setCacheable(true); q.setString("catUuid", catUuid); q.addScalar("NCT_NODE", StandardBasicTypes.STRING); check = !q.list().isEmpty(); } else { Query q = session.createQuery(qs).setCacheable(true); q.setString("category", catUuid); check = !q.list().isEmpty(); } HibernateUtil.commit(tx); log.debug("isCategoryInUse: {}", check); return check; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.dao.NodeDocumentDAO.java
License:Open Source License
/** * Search nodes by category//from w w w. ja va 2 s.c o m */ @SuppressWarnings("unchecked") public List<NodeDocument> findByCategory(String catUuid) throws PathNotFoundException, DatabaseException { log.debug("findByCategory({})", catUuid); final String qs = "from NodeDocument nd where :category in elements(nd.categories) order by nd.name"; final String sql = "select NBS_UUID from OKM_NODE_CATEGORY, OKM_NODE_DOCUMENT " + "where NCT_CATEGORY = :catUuid and NCT_NODE = NBS_UUID"; List<NodeDocument> ret = new ArrayList<NodeDocument>(); Session session = null; Transaction tx = null; try { long begin = System.currentTimeMillis(); session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeBase catNode = (NodeBase) session.load(NodeBase.class, catUuid); SecurityHelper.checkRead(catNode); if (Config.NATIVE_SQL_OPTIMIZATIONS) { SQLQuery q = session.createSQLQuery(sql); q.setCacheable(true); q.setCacheRegion(CACHE_DOCUMENTS_BY_CATEGORY); q.setString("catUuid", catUuid); q.addScalar("NBS_UUID", StandardBasicTypes.STRING); for (String uuid : (List<String>) q.list()) { NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, uuid); ret.add(nDoc); } } else { Query q = session.createQuery(qs).setCacheable(true); q.setString("category", catUuid); ret = q.list(); } // Security Check SecurityHelper.pruneNodeList(ret); initialize(ret); HibernateUtil.commit(tx); SystemProfiling.log(catUuid, System.currentTimeMillis() - begin); log.trace("findByCategory.Time: {}", System.currentTimeMillis() - begin); log.debug("findByCategory: {}", ret); return ret; } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw e; } catch (DatabaseException e) { HibernateUtil.rollback(tx); throw e; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.dao.NodeDocumentDAO.java
License:Open Source License
/** * Search nodes by keyword//from ww w . j a va2 s. c o m */ @SuppressWarnings("unchecked") public List<NodeDocument> findByKeyword(String keyword) throws DatabaseException { log.debug("findByKeyword({})", keyword); final String qs = "from NodeDocument nd where :keyword in elements(nd.keywords) order by nd.name"; final String sql = "select NBS_UUID from OKM_NODE_KEYWORD, OKM_NODE_DOCUMENT " + "where NKW_KEYWORD = :keyword and NKW_NODE = NBS_UUID"; List<NodeDocument> ret = new ArrayList<NodeDocument>(); Session session = null; Transaction tx = null; try { long begin = System.currentTimeMillis(); session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); if (Config.NATIVE_SQL_OPTIMIZATIONS) { SQLQuery q = session.createSQLQuery(sql); q.setCacheable(true); q.setCacheRegion(CACHE_DOCUMENTS_BY_KEYWORD); q.setString("keyword", keyword); q.addScalar("NBS_UUID", StandardBasicTypes.STRING); for (String uuid : (List<String>) q.list()) { NodeDocument nDoc = (NodeDocument) session.load(NodeDocument.class, uuid); ret.add(nDoc); } } else { Query q = session.createQuery(qs).setCacheable(true); q.setString("keyword", keyword); ret = q.list(); } // Security Check SecurityHelper.pruneNodeList(ret); initialize(ret); HibernateUtil.commit(tx); SystemProfiling.log(keyword, System.currentTimeMillis() - begin); log.trace("findByKeyword.Time: {}", System.currentTimeMillis() - begin); log.debug("findByKeyword: {}", ret); return ret; } catch (DatabaseException e) { HibernateUtil.rollback(tx); throw e; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.dao.NodeFolderDAO.java
License:Open Source License
/** * Search nodes by category/*from w w w.ja v a 2s.c o m*/ */ @SuppressWarnings("unchecked") public List<NodeFolder> findByCategory(String catUuid) throws PathNotFoundException, DatabaseException { log.debug("findByCategory({})", catUuid); long begin = System.currentTimeMillis(); final String qs = "from NodeFolder nf where :category in elements(nf.categories) order by nf.name"; final String sql = "select NBS_UUID from OKM_NODE_CATEGORY, OKM_NODE_FOLDER " + "where NCT_CATEGORY = :catUuid and NCT_NODE = NBS_UUID"; List<NodeFolder> ret = new ArrayList<NodeFolder>(); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeBase catNode = (NodeBase) session.load(NodeBase.class, catUuid); SecurityHelper.checkRead(catNode); if (Config.NATIVE_SQL_OPTIMIZATIONS) { SQLQuery q = session.createSQLQuery(sql); q.setCacheable(true); q.setCacheRegion(CACHE_FOLDERS_BY_CATEGORY); q.setString("catUuid", catUuid); q.addScalar("NBS_UUID", StandardBasicTypes.STRING); for (String uuid : (List<String>) q.list()) { NodeFolder nFld = (NodeFolder) session.load(NodeFolder.class, uuid); ret.add(nFld); } } else { Query q = session.createQuery(qs).setCacheable(true); q.setString("category", catUuid); ret = q.list(); } // Security Check SecurityHelper.pruneNodeList(ret); initialize(ret); HibernateUtil.commit(tx); SystemProfiling.log(catUuid, System.currentTimeMillis() - begin); log.trace("findByCategory.Time: {}", System.currentTimeMillis() - begin); log.debug("findByCategory: {}", ret); return ret; } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw e; } catch (DatabaseException e) { HibernateUtil.rollback(tx); throw e; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.dao.NodeFolderDAO.java
License:Open Source License
/** * Search nodes by keyword/*from w w w.j av a 2 s . c o m*/ */ @SuppressWarnings("unchecked") public List<NodeFolder> findByKeyword(String keyword) throws DatabaseException { log.debug("findByKeyword({})", keyword); final String qs = "from NodeFolder nf where :keyword in elements(nf.keywords) order by nf.name"; final String sql = "select NBS_UUID from OKM_NODE_KEYWORD, OKM_NODE_FOLDER " + "where NKW_KEYWORD = :keyword and NKW_NODE = NBS_UUID"; List<NodeFolder> ret = new ArrayList<NodeFolder>(); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); if (Config.NATIVE_SQL_OPTIMIZATIONS) { SQLQuery q = session.createSQLQuery(sql); q.setCacheable(true); q.setCacheRegion(CACHE_FOLDERS_BY_KEYWORD); q.setString("keyword", keyword); q.addScalar("NBS_UUID", StandardBasicTypes.STRING); for (String uuid : (List<String>) q.list()) { NodeFolder nFld = (NodeFolder) session.load(NodeFolder.class, uuid); ret.add(nFld); } } else { Query q = session.createQuery(qs).setCacheable(true); q.setString("keyword", keyword); ret = q.list(); } // Security Check SecurityHelper.pruneNodeList(ret); initialize(ret); HibernateUtil.commit(tx); log.debug("findByKeyword: {}", ret); return ret; } catch (DatabaseException e) { HibernateUtil.rollback(tx); throw e; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.dao.NodeMailDAO.java
License:Open Source License
/** * Search nodes by category/*from w w w . j av a 2 s.co m*/ */ @SuppressWarnings("unchecked") public List<NodeMail> findByCategory(String catUuid) throws PathNotFoundException, DatabaseException { log.debug("findByCategory({})", catUuid); long begin = System.currentTimeMillis(); final String qs = "from NodeMail nm where :category in elements(nm.categories) order by nm.name"; final String sql = "select NBS_UUID from OKM_NODE_CATEGORY, OKM_NODE_MAIL " + "where NCT_CATEGORY = :catUuid and NCT_NODE = NBS_UUID"; List<NodeMail> ret = new ArrayList<NodeMail>(); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); // Security Check NodeBase catNode = (NodeBase) session.load(NodeBase.class, catUuid); SecurityHelper.checkRead(catNode); if (Config.NATIVE_SQL_OPTIMIZATIONS) { SQLQuery q = session.createSQLQuery(sql); q.setCacheable(true); q.setCacheRegion(CACHE_MAILS_BY_CATEGORY); q.setString("catUuid", catUuid); q.addScalar("NBS_UUID", StandardBasicTypes.STRING); for (String uuid : (List<String>) q.list()) { NodeMail nMail = (NodeMail) session.load(NodeMail.class, uuid); ret.add(nMail); } } else { Query q = session.createQuery(qs).setCacheable(true); q.setString("category", catUuid); ret = q.list(); } // Security Check SecurityHelper.pruneNodeList(ret); initialize(ret); HibernateUtil.commit(tx); SystemProfiling.log(catUuid, System.currentTimeMillis() - begin); log.trace("findByCategory.Time: {}", System.currentTimeMillis() - begin); log.debug("findByCategory: {}", ret); return ret; } catch (PathNotFoundException e) { HibernateUtil.rollback(tx); throw e; } catch (DatabaseException e) { HibernateUtil.rollback(tx); throw e; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }