List of usage examples for org.hibernate.dialect Dialect supportsSequences
public boolean supportsSequences()
From source file:com.clican.pluto.orm.tool.DatabaseMetadata.java
License:LGPL
private void initSequences(Connection connection, Dialect dialect) throws SQLException { if (dialect.supportsSequences()) { String sql = dialect.getQuerySequencesString(); if (sql != null) { Statement statement = null; ResultSet rs = null;//from w w w.jav a2 s . co m try { statement = connection.createStatement(); rs = statement.executeQuery(sql); while (rs.next()) { sequences.add(rs.getString(1).toLowerCase().trim()); } } finally { if (rs != null) rs.close(); if (statement != null) statement.close(); } } } }
From source file:com.expressui.core.util.TableNameSequenceGenerator.java
License:Open Source License
@Override public void configure(Type type, Properties params, Dialect dialect) throws MappingException { if (params.getProperty(SEQUENCE) == null || params.getProperty(SEQUENCE).length() == 0 && dialect.supportsSequences()) { String tableName = params.getProperty(PersistentIdentifierGenerator.TABLE); if (tableName != null) { String seqName = "SEQ_" + tableName; params.setProperty(SEQUENCE, seqName); }// w w w. ja v a 2 s .com } super.configure(type, params, dialect); }
From source file:org.agnitas.dao.impl.RecipientDaoImpl.java
License:Open Source License
/** * Gets new customerID from Database-Sequence an stores it in member-variable "customerID" * * @return true on success/* ww w . ja va 2s . c o m*/ */ @Override public int getNewCustomerID(int companyID) { String sqlStatement = null; int customerID = 0; Dialect dialect = AgnUtils.getHibernateDialect(); if (companyID == 0) { return customerID; } if (mayAdd(companyID, 1) == false) { return customerID; } try { if (dialect.supportsSequences()) { JdbcTemplate tmpl = new JdbcTemplate((DataSource) this.applicationContext.getBean("dataSource")); sqlStatement = "select customer_" + companyID + "_tbl_seq.nextval FROM dual"; customerID = tmpl.queryForInt(sqlStatement); } else { sqlStatement = "insert into customer_" + companyID + "_tbl_seq () values ()"; SqlUpdate updt = new SqlUpdate((DataSource) this.applicationContext.getBean("dataSource"), sqlStatement); updt.setReturnGeneratedKeys(true); GeneratedKeyHolder key = new GeneratedKeyHolder(); customerID = updt.update(null, key); customerID = key.getKey().intValue(); } } catch (Exception e) { customerID = 0; System.err.println("Exception:" + e); System.err.println(AgnUtils.getStackTrace(e)); } if (logger.isDebugEnabled()) { logger.debug("new customerID: " + customerID); } return customerID; }
From source file:org.apache.ode.daohib.NativeHiLoGenerator.java
License:Apache License
public void configure(Type type, Properties params, Dialect dialect) throws MappingException { Class generatorClass = null;//from ww w. ja v a2 s .c o m if (dialect.supportsSequences()) { __log.debug("Using SequenceHiLoGenerator"); generatorClass = SequenceHiLoGenerator.class; } else { generatorClass = TableHiLoGenerator.class; __log.debug("Using native dialect generator " + generatorClass); } IdentifierGenerator g = null; try { g = (IdentifierGenerator) generatorClass.newInstance(); } catch (Exception e) { throw new MappingException("", e); } if (g instanceof Configurable) ((Configurable) g).configure(type, params, dialect); this._proxy = g; }