1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/*
* Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eike Stepper - initial API and implementation
* Stefan Winkler - 271444: [DB] Multiple refactorings bug 271444
*/
package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
* This is a list-table mapping for audit mode. It has ID and version columns and no delta support.
*
* @author Eike Stepper
* @since 2.0
*/
public class AuditListTableMapping extends AbstractListTableMapping
{
private FieldInfo[] keyFields;
private String sqlClear;
public AuditListTableMapping(IMappingStrategy mappingStrategy, EClass eClass, EStructuralFeature feature)
{
super(mappingStrategy, eClass, feature);
initSQLStrings();
}
private void initSQLStrings()
{
// ----------- clear list -------------------------
StringBuilder builder = new StringBuilder();
builder.append("DELETE FROM "); //$NON-NLS-1$
builder.append(getTable());
builder.append(" WHERE "); //$NON-NLS-1$
builder.append(CDODBSchema.LIST_REVISION_ID);
builder.append("=? AND "); //$NON-NLS-1$
builder.append(CDODBSchema.LIST_REVISION_VERSION);
builder.append("=? "); //$NON-NLS-1$
sqlClear = builder.toString();
}
@Override
protected FieldInfo[] getKeyFields()
{
if (keyFields == null)
{
keyFields = new FieldInfo[] {
new FieldInfo(CDODBSchema.LIST_REVISION_ID, getMappingStrategy().getStore().getIDHandler().getDBType()),
new FieldInfo(CDODBSchema.LIST_REVISION_VERSION, DBType.INTEGER) };
}
return keyFields;
}
@Override
protected void setKeyFields(PreparedStatement stmt, CDORevision revision) throws SQLException
{
getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, revision.getID());
stmt.setInt(2, revision.getVersion());
}
public void objectDetached(IDBStoreAccessor accessor, CDOID id, long revised)
{
// The audit list mapping does not care about revised references -> NOOP
}
@Override
public void rawDeleted(IDBStoreAccessor accessor, CDOID id, CDOBranch branch, int version)
{
IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement stmt = null;
try
{
stmt = statementCache.getPreparedStatement(sqlClear, ReuseProbability.HIGH);
getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, id);
stmt.setInt(2, version);
DBUtil.update(stmt, false);
}
catch (SQLException e)
{
throw new DBException(e);
}
finally
{
statementCache.releasePreparedStatement(stmt);
}
}
}
|