void storeNamedParameter(final String name, final int position) { DbQueryNamedParameter p = lookupNamedParameter(name); if (p == null) { p = new DbQueryNamedParameter(name); p.indices = new int[] {position}; p.next = rootNP; rootNP = p; } else { p.add(position); } }
/** * Closes current session and remove the association from current thread. * @see jodd.db.DbSession#closeSession() */ @Override public void closeSession() { ThreadDbSessionHolder.remove(); super.closeSession(); }
protected DbQueryBase(final DbOom dbOom) { this.dbOom = dbOom; this.forcePreparedStatement = dbOom.queryConfig().isForcePreparedStatement(); this.type = dbOom.queryConfig().getType(); this.concurrencyType = dbOom.queryConfig().getConcurrencyType(); this.holdability = dbOom.queryConfig().getHoldability(); this.debug = dbOom.queryConfig().isDebug(); this.fetchSize = dbOom.queryConfig().getFetchSize(); this.maxRows = dbOom.queryConfig().getMaxRows(); }
/** * Creates new db session and assigns it to the current thread. * Closes already assigned session, if any exist. * @param connectionProvider connection provider */ public DbThreadSession(final ConnectionProvider connectionProvider) { super(connectionProvider); final DbSession session = ThreadDbSessionHolder.get(); if (session != null) { session.closeSession(); } ThreadDbSessionHolder.set(this); }
/** * @see #setObject(String, Object, Class, int) */ public Q setObject(final String param, final Object value, final Class<? extends SqlType> sqlTypeClass, final int dbSqlType) { init(); final int[] positions = query.getNamedParameterIndices(param); for (final int position : positions) { setObject(position, value, sqlTypeClass, dbSqlType); } return _this(); }
/** * Sets sql parameters from two arrays: names and values. */ public Q setObjects(final String[] names, final Object[] values) { init(); if (names.length != values.length) { throw new DbSqlException(this, "Different number of parameter names and values"); } for (int i = 0; i < names.length; i++) { setObject(names[i], values[i]); } return _this(); }
public Q setNull(final String param, final int value, final String typeName) { initPrepared(); final int[] positions = query.getNamedParameterIndices(param); try { for (final int position : positions) { preparedStatement.setNull(position, value, typeName); } } catch (SQLException sex) { throw new DbSqlException(this, "Failed to set null to parameter: " + param, sex); } return _this(); }
/** * Closes the query and all created results sets and detaches itself from the session. */ @Override @SuppressWarnings({"ClassReferencesSubclass"}) public void close() { final SQLException sqlException = closeQuery(); connection = null; if (this.session != null) { this.session.detachQuery(this); } if (sqlException != null) { throw new DbSqlException("Close query error", sqlException); } }
/** * Returns existing thread session, or new one if already not exist. If session doesn't exist, it will be created * using default connection provider. */ public static DbThreadSession getThreadSession() { DbThreadSession session = (DbThreadSession) ThreadDbSessionHolder.get(); if (session == null) { session = new DbThreadSession(); } return session; }
/** * Closes all result sets created by this query. Query remains active. */ public Q closeAllResultSets() { final SQLException sex = closeQueryResultSets(); if (sex != null) { throw new DbSqlException("Close associated ResultSets error", sex); } return _this(); }
/** * Closes thread session. */ public static void closeThreadSession() { DbThreadSession session = (DbThreadSession) ThreadDbSessionHolder.get(); if (session != null) { session.closeSession(); } }
private void initPrepared() { init(); if (preparedStatement == null) { throw new DbSqlException("Prepared statement not initialized."); } } private void initCallable() {
protected void assertTxIsActive() { assertSessionIsOpen(); if (!txActive) { throw new DbSqlException("TX not available for this session"); } } }
int[] getNamedParameterIndices(final String name) { final DbQueryNamedParameter p = lookupNamedParameter(name); if (p == null) { throw new DbSqlException("Named parameter not found: " + name + "\nQuery: " + sql); } return p.indices; }
/** * Creates a new query from {@link DbSession}. */ public DbQuery(final DbOom dbOom, final DbSession session, final String sqlString) { super(dbOom); initSession(session); this.session.attachQuery(this); this.sqlString = sqlString; }
/** * Initializes session. When not specified (i.e. is <code>null</code>), * session is fetched from session provider. */ protected void initSession(final DbSession session) { if (session != null) { this.session = session; return; } final DbSessionProvider dbSessionProvider = dbOom.sessionProvider(); this.session = dbSessionProvider.getDbSession(); }
public Q setNull(final String param, final int type) { initPrepared(); final int[] positions = query.getNamedParameterIndices(param); try { for (final int position : positions) { preparedStatement.setNull(position, type); } } catch (SQLException sex) { throw new DbSqlException(this, "Failed to set null to parameter: " + param, sex); } return _this(); }
private void initCallable() { init(); if (callableStatement == null) { throw new DbSqlException("Callable statement not initialized."); } }
protected void assertTxIsClosed() { assertSessionIsOpen(); if (txActive) { throw new DbSqlException("TX already started for this session"); } }