com.xdev.jadoth.sqlengine.UPDATE Maven / Gradle / Ivy
package com.xdev.jadoth.sqlengine;
/*-
* #%L
* XDEV Application Framework
* %%
* Copyright (C) 2003 - 2020 XDEV Software
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import java.util.List;
import com.xdev.jadoth.sqlengine.exceptions.SQLEngineException;
import com.xdev.jadoth.sqlengine.exceptions.SQLEngineMissingFromClauseException;
import com.xdev.jadoth.sqlengine.interfaces.SqlExecutor;
import com.xdev.jadoth.sqlengine.internal.AssignmentList;
import com.xdev.jadoth.sqlengine.internal.ColumnValueAssignment;
import com.xdev.jadoth.sqlengine.internal.ColumnValueTuple;
import com.xdev.jadoth.sqlengine.internal.ConditionClause;
import com.xdev.jadoth.sqlengine.internal.DatabaseGateway;
import com.xdev.jadoth.sqlengine.internal.FROM;
import com.xdev.jadoth.sqlengine.internal.JoinClause;
import com.xdev.jadoth.sqlengine.internal.QueryListeners;
import com.xdev.jadoth.sqlengine.internal.SET;
import com.xdev.jadoth.sqlengine.internal.SqlClause;
import com.xdev.jadoth.sqlengine.internal.SqlColumn;
import com.xdev.jadoth.sqlengine.internal.WHERE;
import com.xdev.jadoth.sqlengine.internal.interfaces.TableExpression;
import com.xdev.jadoth.sqlengine.internal.tables.SqlTableIdentity;
import com.xdev.jadoth.sqlengine.types.ConditionalTableQuery;
import com.xdev.jadoth.sqlengine.types.ConditionalWritingTableQuery;
import com.xdev.jadoth.sqlengine.types.Query;
import com.xdev.jadoth.sqlengine.types.TableQuery;
import com.xdev.jadoth.sqlengine.types.ValueAssigningTableQuery;
/**
* The Class UPDATE.
*
* @author Thomas Muenz
*/
public class UPDATE extends TableQuery.Implementation implements ConditionalWritingTableQuery, ValueAssigningTableQuery
{
///////////////////////////////////////////////////////////////////////////
// constants //
/////////////////////
/**
*
*/
private static final long serialVersionUID = 763162177748106385L;
///////////////////////////////////////////////////////////////////////////
// instance fields //
/////////////////////
private final SuperValueAssigningQuery superValueAssigningQuery;
private final SuperConditionalQuery superConditionalQuery;
private final SET setClause;
///////////////////////////////////////////////////////////////////////////
// constructors //
/////////////////////
/**
* Instantiates a new UPDATE.
*
* @param table the table
*/
public UPDATE(final SqlTableIdentity table){
super();
this.superValueAssigningQuery = new SuperValueAssigningQuery(table);
this.superConditionalQuery = new SuperConditionalQuery();
this.setClause = new SET(this.superValueAssigningQuery.iterateAssignments());
}
/**
*
* @param copySource
*/
private UPDATE(final UPDATE copySource)
{
super(copySource);
this.superValueAssigningQuery = copySource.superValueAssigningQuery.copy();
this.superConditionalQuery = copySource.superConditionalQuery.copy();
this.setClause = copySource.setClause.copy();
}
/**
* Columns.
*
* @param columns the colum list
* @return the uPDATE
*/
public UPDATE columns(final Object... columns)
{
this.clearAssignments();
return this.addColumns(columns);
}
/**
* Sets the.
*
* @param column the column
* @param value the value
* @return the uPDATE
*/
public UPDATE SET(final ColumnValueTuple... keyValueTuples)
{
this.superValueAssigningQuery.assign(keyValueTuples);
return this;
}
/**
* Sets the.
*
* @param column the column
* @param value the value
* @return the uPDATE
*/
public UPDATE SET(final Object column, final Object value)
{
return this.assign(column, value);
}
@Override
public UPDATE assign(final Object column, final Object value)
{
this.superValueAssigningQuery.assign(column, value);
return this;
}
@Override
public UPDATE assign(final ColumnValueTuple... keyValueTuples)
{
this.superValueAssigningQuery.assign(keyValueTuples);
return this;
}
/**
* @return
* @see net.net.jadoth.sqlengine.interfaces.TableQuery#getTable()
*/
@Override
public SqlTableIdentity getTable() {
return this.superValueAssigningQuery.getTable();
}
public SET getSetClause()
{
return this.setClause;
}
/**
* @return
* @see net.net.jadoth.sqlengine.interfaces.TableQuery#keyword()
*/
@Override
public String keyword() {
return SQL.LANG.UPDATE;
}
private transient INSERT linkedINSERT = null;
/**
* Creates a new INSERT
object that uses the identical column-value assignment list as this
* UPDATE
object does. Changes to assignments of one of the UPDATE
/ INSERT
* objects will change those of the other one as well.
*
* @return a assignment-list-linked INSERT
object.
*/
public INSERT getLinkedINSERT()
{
if(this.linkedINSERT == null){
this.linkedINSERT = new INSERT(this.superValueAssigningQuery.getAssignmentList()).INTO(this.getTable());
}
return this.linkedINSERT;
}
/**
* @return
* @see com.xdev.jadoth.sqlengine.types.ValueAssigningTableQuery#iterateAssignments()
*/
@Override
public Iterable iterateAssignments()
{
return this.superValueAssigningQuery.iterateAssignments();
}
/**
* @return
* @see com.xdev.jadoth.sqlengine.types.ValueAssigningTableQuery#iterateColumns()
*/
@Override
public Iterable iterateColumns()
{
return this.superValueAssigningQuery.iterateColumns();
}
/**
* @return
* @see com.xdev.jadoth.sqlengine.types.ValueAssigningTableQuery#getAssignments()
*/
@Override
public ColumnValueAssignment[] getAssignments()
{
return this.superValueAssigningQuery.getAssignments();
}
/**
* @return
* @see com.xdev.jadoth.sqlengine.types.ValueAssigningTableQuery#getColumns()
*/
@Override
public SqlColumn[] getColumns()
{
return this.superValueAssigningQuery.getColumns();
}
/**
* @return
* @see com.xdev.jadoth.sqlengine.types.ValueAssigningTableQuery#getValues()
*/
@Override
public Object[] getValues()
{
return this.superValueAssigningQuery.getValues();
}
@Override
public UPDATE setName(final String name)
{
super.setName(name);
return this;
}
@Override
public UPDATE setComment(final String comment)
{
super.setComment(comment);
return this;
}
/**
* @param databaseGateway
* @return
*/
@Override
public UPDATE setDatabaseGateway(final DatabaseGateway> databaseGateway)
{
super.setDatabaseGateway(databaseGateway);
return this;
}
/**
* @param values
* @return
* @see com.xdev.jadoth.sqlengine.types.ValueAssigningTableQuery#setValues(java.lang.Object[])
*/
@Override
public UPDATE setValues(final Object... values)
{
this.superValueAssigningQuery.setValues(values);
return this;
}
/**
* @return
* @see com.xdev.jadoth.sqlengine.types.ValueAssigningTableQuery#iterateValues()
*/
@Override
public Iterable
© 2015 - 2025 Weber Informatics LLC | Privacy Policy