gvsig-mssqlserver / branches / org.gvsig.mssqlserver-1.0.1-SP / org.gvsig.mssqlserver.provider / src / main / java / org / gvsig / mssqlserver / dal / operations / MSSQLServerCanModifyTableOperation.java @ 26
History | View | Annotate | Download (2.13 KB)
1 |
package org.gvsig.mssqlserver.dal.operations; |
---|---|
2 |
|
3 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.*; |
4 |
import java.sql.Connection; |
5 |
import java.sql.ResultSet; |
6 |
import java.sql.SQLException; |
7 |
import java.sql.Statement; |
8 |
import org.gvsig.fmap.dal.SQLBuilder; |
9 |
import org.gvsig.fmap.dal.exception.DataException; |
10 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
11 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
12 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
13 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
14 |
import org.gvsig.mssqlserver.dal.MSSQLServerSQLBuilder; |
15 |
|
16 |
public class MSSQLServerCanModifyTableOperation extends CanModifyTableOperation { |
17 |
|
18 |
public MSSQLServerCanModifyTableOperation(
|
19 |
JDBCHelper helper |
20 |
) { |
21 |
this(helper, null, null, null); |
22 |
} |
23 |
|
24 |
public MSSQLServerCanModifyTableOperation(
|
25 |
JDBCHelper helper, |
26 |
String dbName,
|
27 |
String schemaName,
|
28 |
String tableName
|
29 |
) { |
30 |
super(helper,dbName,schemaName,tableName);
|
31 |
} |
32 |
|
33 |
@Override
|
34 |
public boolean canModifyTable(Connection conn, |
35 |
String dbName,
|
36 |
String schemaName,
|
37 |
String tableName
|
38 |
) throws DataException {
|
39 |
|
40 |
MSSQLServerSQLBuilder builder = (MSSQLServerSQLBuilder) this.helper.createSQLBuilder();
|
41 |
SQLBuilder.TableNameBuilder tableNameBuilder = builder.createTableNameBuilder(); |
42 |
String sql = "SELECT count(*) " + |
43 |
"FROM fn_my_permissions("+
|
44 |
"'"+dbName+"."+schemaName+'.'+tableName+"'" + |
45 |
", 'OBJECT') " +
|
46 |
"WHERE permission_name in ('UPDATE', 'INSERT', 'DELETE') AND subentity_name = ''";
|
47 |
Statement st = null; |
48 |
ResultSet rs = null; |
49 |
try {
|
50 |
st = conn.createStatement(); |
51 |
rs = JDBCUtils.executeQuery(st, sql); |
52 |
if (!rs.next()) {
|
53 |
return false; |
54 |
} |
55 |
return rs.getInt(1)==3; |
56 |
|
57 |
} catch (SQLException ex) { |
58 |
throw new JDBCSQLException(ex); |
59 |
} finally {
|
60 |
JDBCUtils.closeQuietly(st); |
61 |
JDBCUtils.closeQuietly(rs); |
62 |
} |
63 |
|
64 |
} |
65 |
|
66 |
} |