diff options
author | Eike Stepper | 2007-07-07 09:36:24 +0000 |
---|---|---|
committer | Eike Stepper | 2007-07-07 09:36:24 +0000 |
commit | 7ed99801715e435108708ddf721820ccf576af00 (patch) | |
tree | 7248d26532f7635897ee5d89a33279ababacdfa6 /plugins/org.eclipse.net4j.db/src/org | |
parent | 1f5ddf4721a15bc9a0b755b9a1352a6f757fae62 (diff) | |
download | cdo-7ed99801715e435108708ddf721820ccf576af00.tar.gz cdo-7ed99801715e435108708ddf721820ccf576af00.tar.xz cdo-7ed99801715e435108708ddf721820ccf576af00.zip |
task 1: Develop 0.8.0
Diffstat (limited to 'plugins/org.eclipse.net4j.db/src/org')
16 files changed, 390 insertions, 147 deletions
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java index ce4a704040..f799a4a029 100644 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java @@ -10,7 +10,7 @@ **************************************************************************/ package org.eclipse.net4j.db; -import org.eclipse.net4j.internal.db.Schema; +import org.eclipse.net4j.internal.db.DBSchema; import org.eclipse.net4j.internal.db.bundle.OM; import org.eclipse.net4j.util.ReflectUtil; @@ -27,9 +27,9 @@ public final class DBUtil { } - public static ISchema createSchema(String name) + public static IDBSchema createSchema(String name) { - return new Schema(name); + return new DBSchema(name); } public static DataSource createDataSource(Map<Object, Object> properties) diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java index b3ffba055c..0fd3ce7c56 100644 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java @@ -11,7 +11,7 @@ package org.eclipse.net4j.db; import org.eclipse.net4j.internal.db.DBAdapterRegistry; -import org.eclipse.net4j.internal.db.Table; +import org.eclipse.net4j.internal.db.DBTable; import org.eclipse.net4j.util.registry.IRegistry; import java.sql.Driver; @@ -30,5 +30,5 @@ public interface IDBAdapter public Driver getJDBCDriver(); - public void createTable(Table table, Statement statement); + public void createTable(DBTable table, Statement statement); } diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IField.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBField.java index d644e6c99d..ba001fad6f 100644 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IField.java +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBField.java @@ -13,11 +13,11 @@ package org.eclipse.net4j.db; /** * @author Eike Stepper */ -public interface IField +public interface IDBField { public static final int DEFAULT = -1; - public ITable geTable(); + public IDBTable geTable(); public String getName(); diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IIndex.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBIndex.java index 6347ff7345..c9ed339ae9 100644 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IIndex.java +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBIndex.java @@ -13,17 +13,17 @@ package org.eclipse.net4j.db; /** * @author Eike Stepper */ -public interface IIndex +public interface IDBIndex { - public ITable geTable(); + public IDBTable geTable(); public Type geType(); - public IField getField(int index); + public IDBField getField(int index); public int getFieldCount(); - public IField[] getFields(); + public IDBField[] getFields(); public int getPosition(); diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ISchema.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBSchema.java index 36515c8132..09466b3097 100644 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ISchema.java +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBSchema.java @@ -15,15 +15,15 @@ import javax.sql.DataSource; /** * @author Eike Stepper */ -public interface ISchema +public interface IDBSchema { public String getName(); - public ITable addTable(String name); + public IDBTable addTable(String name); - public ITable getTable(String name); + public IDBTable getTable(String name); - public ITable[] getTables(); + public IDBTable[] getTables(); public void create(IDBAdapter dbAdapter, DataSource dataSource); } diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBStoreManager.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBStoreManager.java new file mode 100644 index 0000000000..57cc73e9bf --- /dev/null +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBStoreManager.java @@ -0,0 +1,33 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2007 Eike Stepper, Germany. + * 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 + **************************************************************************/ +package org.eclipse.net4j.db; + +import org.eclipse.net4j.util.store.IStoreManager; + +import javax.sql.DataSource; + +import java.sql.Connection; + +/** + * @author Eike Stepper + */ +public interface IDBStoreManager<TRANSACTION extends IDBStoreTransaction> extends IStoreManager<TRANSACTION> +{ + public static final String STORE_TYPE = "JDBC"; + + public IDBAdapter getDBAdapter(); + + public DataSource getDataSource(); + + public Connection getConnection(); + + public void initDatabase(); +} diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBStoreTransaction.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBStoreTransaction.java new file mode 100644 index 0000000000..f3b36d84a2 --- /dev/null +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBStoreTransaction.java @@ -0,0 +1,23 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2007 Eike Stepper, Germany. + * 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 + **************************************************************************/ +package org.eclipse.net4j.db; + +import org.eclipse.net4j.util.store.IStoreTransaction; + +import java.sql.Connection; + +/** + * @author Eike Stepper + */ +public interface IDBStoreTransaction extends IStoreTransaction +{ + public Connection getConnection(); +}
\ No newline at end of file diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBTable.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBTable.java new file mode 100644 index 0000000000..71e626e9bf --- /dev/null +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBTable.java @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2007 Eike Stepper, Germany. + * 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 + **************************************************************************/ +package org.eclipse.net4j.db; + +import org.eclipse.net4j.internal.db.DBField; + +/** + * @author Eike Stepper + */ +public interface IDBTable +{ + public IDBSchema getSchema(); + + public String getName(); + + public IDBField addField(String name, IDBField.Type type); + + public DBField addField(String name, IDBField.Type type, boolean notNull); + + public DBField addField(String name, IDBField.Type type, int precision); + + public DBField addField(String name, IDBField.Type type, int precision, boolean notNull); + + public DBField addField(String name, IDBField.Type type, int precision, int scale); + + public DBField addField(String name, IDBField.Type type, int precision, int scale, boolean notNull); + + public IDBField getField(String name); + + public IDBField getField(int index); + + public int getFieldCount(); + + public IDBField[] getFields(); + + public IDBIndex addIndex(IDBIndex.Type type, IDBField field); + + public IDBIndex addIndex(IDBIndex.Type type, IDBField[] fields); + + public int getIndexCount(); + + public IDBIndex[] getIndices(); + + public IDBIndex getPrimaryKeyIndex(); +} diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ITable.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ITable.java deleted file mode 100644 index 221b192133..0000000000 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ITable.java +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2007 Eike Stepper, Germany. - * 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 - **************************************************************************/ -package org.eclipse.net4j.db; - -import org.eclipse.net4j.internal.db.Field; - -/** - * @author Eike Stepper - */ -public interface ITable -{ - public ISchema getSchema(); - - public String getName(); - - public IField addField(String name, IField.Type type); - - public Field addField(String name, IField.Type type, boolean notNull); - - public Field addField(String name, IField.Type type, int precision); - - public Field addField(String name, IField.Type type, int precision, boolean notNull); - - public Field addField(String name, IField.Type type, int precision, int scale); - - public Field addField(String name, IField.Type type, int precision, int scale, boolean notNull); - - public IField getField(String name); - - public IField getField(int index); - - public int getFieldCount(); - - public IField[] getFields(); - - public IIndex addIndex(IIndex.Type type, IField field); - - public IIndex addIndex(IIndex.Type type, IField[] fields); - - public int getIndexCount(); - - public IIndex[] getIndices(); - - public IIndex getPrimaryKeyIndex(); -} diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/AbstractDBAdapter.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBAdapter.java index 552e77f15d..647a0af970 100644 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/AbstractDBAdapter.java +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBAdapter.java @@ -12,7 +12,7 @@ package org.eclipse.net4j.internal.db; import org.eclipse.net4j.db.DBException; import org.eclipse.net4j.db.IDBAdapter; -import org.eclipse.net4j.db.IField.Type; +import org.eclipse.net4j.db.IDBField.Type; import java.sql.ResultSet; import java.sql.ResultSetMetaData; @@ -22,13 +22,13 @@ import java.sql.Statement; /** * @author Eike Stepper */ -public abstract class AbstractDBAdapter implements IDBAdapter +public abstract class DBAdapter implements IDBAdapter { private String name; private String version; - public AbstractDBAdapter(String name, String version) + public DBAdapter(String name, String version) { this.name = name; this.version = version; @@ -44,7 +44,7 @@ public abstract class AbstractDBAdapter implements IDBAdapter return version; } - public void createTable(Table table, Statement statement) + public void createTable(DBTable table, Statement statement) { try { @@ -64,7 +64,7 @@ public abstract class AbstractDBAdapter implements IDBAdapter return getName() + "-" + getVersion(); } - protected void doCreateTable(Table table, Statement statement) throws SQLException + protected void doCreateTable(DBTable table, Statement statement) throws SQLException { StringBuilder builder = new StringBuilder(); builder.append("CREATE TABLE "); @@ -84,17 +84,17 @@ public abstract class AbstractDBAdapter implements IDBAdapter statement.execute(sql); } - protected String createConstraints(Table table) + protected String createConstraints(DBTable table) { return null; } - protected String createFieldDefinition(Field field) + protected String createFieldDefinition(DBField field) { return getTypeName(field) + (field.isNotNull() ? " NOT NULL" : ""); } - protected String getTypeName(Field field) + protected String getTypeName(DBField field) { Type type = field.getType(); switch (type) @@ -131,7 +131,7 @@ public abstract class AbstractDBAdapter implements IDBAdapter throw new IllegalArgumentException("Unknown type: " + type); } - protected void validateTable(Table table, Statement statement) + protected void validateTable(DBTable table, Statement statement) { try { @@ -147,18 +147,18 @@ public abstract class AbstractDBAdapter implements IDBAdapter int columnCount = metaData.getColumnCount(); if (columnCount != table.getFieldCount()) { - throw new DBException("Table " + table.getName() + " has " + columnCount + " columns instead of " + throw new DBException("DBTable " + table.getName() + " has " + columnCount + " columns instead of " + table.getFieldCount()); } for (int i = 0; i < columnCount; i++) { int existingCode = metaData.getColumnType(i + 1); - Field field = table.getField(i); + DBField field = table.getField(i); int code = field.getType().getCode(); if (code != existingCode) { - throw new DBException("Field " + field.getFullName() + " has type " + existingCode + " instead of " + code + throw new DBException("DBField " + field.getFullName() + " has type " + existingCode + " instead of " + code + " (" + field.getType() + ")"); } } @@ -169,15 +169,15 @@ public abstract class AbstractDBAdapter implements IDBAdapter } } - private String[] createFieldDefinitions(Table table) + private String[] createFieldDefinitions(DBTable table) { - Field[] fields = table.getFields(); + DBField[] fields = table.getFields(); int fieldCount = fields.length; String[] result = new String[fieldCount]; for (int i = 0; i < fieldCount; i++) { - Field field = fields[i]; + DBField field = fields[i]; result[i] = createFieldDefinition(field); } diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/Field.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBField.java index 461d41c8ea..8d09d7cd02 100644 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/Field.java +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBField.java @@ -10,16 +10,16 @@ **************************************************************************/ package org.eclipse.net4j.internal.db; -import org.eclipse.net4j.db.IField; +import org.eclipse.net4j.db.IDBField; /** * @author Eike Stepper */ -public class Field implements IField +public class DBField implements IDBField { private static final int DEFAULT_PRECISION = 255; - private Table table; + private DBTable table; private String name; @@ -33,7 +33,7 @@ public class Field implements IField private int position; - public Field(Table table, String name, Type type, int precision, int scale, boolean notNull, int position) + public DBField(DBTable table, String name, Type type, int precision, int scale, boolean notNull, int position) { this.table = table; this.name = name; @@ -44,7 +44,7 @@ public class Field implements IField this.position = position; } - public Table geTable() + public DBTable geTable() { return table; } diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/Index.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBIndex.java index a950e600df..6a6b3cbb11 100644 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/Index.java +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBIndex.java @@ -10,23 +10,23 @@ **************************************************************************/ package org.eclipse.net4j.internal.db; -import org.eclipse.net4j.db.IField; -import org.eclipse.net4j.db.IIndex; +import org.eclipse.net4j.db.IDBField; +import org.eclipse.net4j.db.IDBIndex; /** * @author Eike Stepper */ -public class Index implements IIndex +public class DBIndex implements IDBIndex { - private Table table; + private DBTable table; private Type type; - private IField[] fields; + private IDBField[] fields; public int position; - public Index(Table table, Type type, IField[] fields, int position) + public DBIndex(DBTable table, Type type, IDBField[] fields, int position) { this.table = table; this.type = type; @@ -34,7 +34,7 @@ public class Index implements IIndex this.position = position; } - public Table geTable() + public DBTable geTable() { return table; } @@ -44,7 +44,7 @@ public class Index implements IIndex return type; } - public IField getField(int index) + public IDBField getField(int index) { return fields[index]; } @@ -54,7 +54,7 @@ public class Index implements IIndex return fields.length; } - public IField[] getFields() + public IDBField[] getFields() { return fields; } diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/Schema.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBSchema.java index 04bd7dfbac..5ecabe3c60 100644 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/Schema.java +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBSchema.java @@ -12,7 +12,7 @@ package org.eclipse.net4j.internal.db; import org.eclipse.net4j.db.DBException; import org.eclipse.net4j.db.IDBAdapter; -import org.eclipse.net4j.db.ISchema; +import org.eclipse.net4j.db.IDBSchema; import javax.sql.DataSource; @@ -25,15 +25,15 @@ import java.util.Map; /** * @author Eike Stepper */ -public class Schema implements ISchema +public class DBSchema implements IDBSchema { private String name; - private Map<String, Table> tables = new HashMap(); + private Map<String, DBTable> tables = new HashMap(); private boolean locked; - public Schema(String name) + public DBSchema(String name) { this.name = name; } @@ -43,27 +43,27 @@ public class Schema implements ISchema return name; } - public Table addTable(String name) + public DBTable addTable(String name) { assertUnlocked(); if (tables.containsKey(name)) { - throw new IllegalStateException("Table exists: " + name); + throw new IllegalStateException("DBTable exists: " + name); } - Table table = new Table(this, name); + DBTable table = new DBTable(this, name); tables.put(name, table); return table; } - public Table getTable(String name) + public DBTable getTable(String name) { return tables.get(name); } - public Table[] getTables() + public DBTable[] getTables() { - return tables.values().toArray(new Table[tables.size()]); + return tables.values().toArray(new DBTable[tables.size()]); } public boolean isLocked() @@ -82,7 +82,7 @@ public class Schema implements ISchema { Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement(); - for (Table table : tables.values()) + for (DBTable table : tables.values()) { dbAdapter.createTable(table, statement); } @@ -103,7 +103,7 @@ public class Schema implements ISchema { if (locked) { - throw new IllegalStateException("Schema locked: " + name); + throw new IllegalStateException("DBSchema locked: " + name); } } } diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBStoreManager.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBStoreManager.java new file mode 100644 index 0000000000..92c2f99ed7 --- /dev/null +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBStoreManager.java @@ -0,0 +1,145 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2007 Eike Stepper, Germany. + * 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 + **************************************************************************/ +package org.eclipse.net4j.internal.db; + +import org.eclipse.net4j.db.IDBAdapter; +import org.eclipse.net4j.db.IDBStoreManager; +import org.eclipse.net4j.db.IDBSchema; +import org.eclipse.net4j.internal.util.store.StoreManager; +import org.eclipse.net4j.util.store.StoreException; + +import javax.sql.DataSource; + +import java.sql.Connection; +import java.sql.SQLException; + +/** + * @author Eike Stepper + */ +public abstract class DBStoreManager<TRANSACTION extends DBStoreTransaction> extends StoreManager<TRANSACTION> + implements IDBStoreManager<TRANSACTION> +{ + private static final String STORE_TYPE = "JDBC"; + + private IDBSchema schema; + + private IDBAdapter dbAdapter; + + private DataSource dataSource; + + public DBStoreManager(IDBSchema schema, IDBAdapter dbAdapter, DataSource dataSource) + { + super(STORE_TYPE); + if (dbAdapter == null) + { + throw new IllegalArgumentException("dbAdapter == null"); + } + + if (dataSource == null) + { + throw new IllegalArgumentException("dataSource == null"); + } + + this.schema = schema; + this.dbAdapter = dbAdapter; + this.dataSource = dataSource; + } + + public IDBSchema getSchema() + { + return schema; + } + + public IDBAdapter getDBAdapter() + { + return dbAdapter; + } + + public DataSource getDataSource() + { + return dataSource; + } + + public Connection getConnection() + { + try + { + return dataSource.getConnection(); + } + catch (SQLException ex) + { + throw new StoreException(ex); + } + } + + public void initDatabase() + { + schema.create(dbAdapter, dataSource); + } + + public TRANSACTION startTransaction() throws StoreException + { + try + { + Connection connection = getConnection(); + connection.setAutoCommit(false); + return createTransaction(connection); + } + catch (SQLException ex) + { + throw new StoreException(ex); + } + } + + public void commitTransaction(TRANSACTION transaction) throws StoreException + { + try + { + Connection connection = transaction.getConnection(); + connection.commit(); + } + catch (StoreException ex) + { + throw ex; + } + catch (Exception ex) + { + throw new StoreException(ex); + } + finally + { + transaction.dispose(); + } + } + + public void rollbackTransaction(TRANSACTION transaction) throws StoreException + { + try + { + Connection connection = transaction.getConnection(); + connection.rollback(); + } + catch (StoreException ex) + { + throw ex; + } + catch (Exception ex) + { + throw new StoreException(ex); + } + finally + { + transaction.dispose(); + } + } + + protected abstract TRANSACTION createTransaction(Connection connection); +} diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBStoreTransaction.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBStoreTransaction.java new file mode 100644 index 0000000000..5109625fdc --- /dev/null +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBStoreTransaction.java @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2007 Eike Stepper, Germany. + * 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 + **************************************************************************/ +package org.eclipse.net4j.internal.db; + +import org.eclipse.net4j.db.IDBStoreTransaction; +import org.eclipse.net4j.internal.util.store.StoreTransaction; +import org.eclipse.net4j.util.store.IStoreManager; +import org.eclipse.net4j.util.store.IStoreTransaction; + +import java.sql.Connection; + +/** + * @author Eike Stepper + */ +public class DBStoreTransaction extends StoreTransaction implements IDBStoreTransaction +{ + private Connection connection; + + public DBStoreTransaction(IStoreManager<? extends IStoreTransaction> storeManager, Connection connection) + { + super(storeManager); + this.connection = connection; + } + + public Connection getConnection() + { + return connection; + } + + public void dispose() + { + connection = null; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/Table.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBTable.java index f119586bd8..3c15211f7f 100644 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/Table.java +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBTable.java @@ -10,10 +10,10 @@ **************************************************************************/ package org.eclipse.net4j.internal.db; -import org.eclipse.net4j.db.IField; -import org.eclipse.net4j.db.IIndex; -import org.eclipse.net4j.db.ITable; -import org.eclipse.net4j.db.IIndex.Type; +import org.eclipse.net4j.db.IDBField; +import org.eclipse.net4j.db.IDBIndex; +import org.eclipse.net4j.db.IDBTable; +import org.eclipse.net4j.db.IDBIndex.Type; import java.io.IOException; import java.util.ArrayList; @@ -22,23 +22,23 @@ import java.util.List; /** * @author Eike Stepper */ -public class Table implements ITable +public class DBTable implements IDBTable { - private Schema schema; + private DBSchema schema; private String name; - private List<Field> fields = new ArrayList(); + private List<DBField> fields = new ArrayList(); - private List<Index> indices = new ArrayList(); + private List<DBIndex> indices = new ArrayList(); - public Table(Schema schema, String name) + public DBTable(DBSchema schema, String name) { this.schema = schema; this.name = name; } - public Schema getSchema() + public DBSchema getSchema() { return schema; } @@ -48,47 +48,47 @@ public class Table implements ITable return name; } - public Field addField(String name, IField.Type type) + public DBField addField(String name, IDBField.Type type) { - return addField(name, type, IField.DEFAULT, IField.DEFAULT, false); + return addField(name, type, IDBField.DEFAULT, IDBField.DEFAULT, false); } - public Field addField(String name, IField.Type type, boolean notNull) + public DBField addField(String name, IDBField.Type type, boolean notNull) { - return addField(name, type, IField.DEFAULT, IField.DEFAULT, notNull); + return addField(name, type, IDBField.DEFAULT, IDBField.DEFAULT, notNull); } - public Field addField(String name, IField.Type type, int precision) + public DBField addField(String name, IDBField.Type type, int precision) { - return addField(name, type, precision, IField.DEFAULT, false); + return addField(name, type, precision, IDBField.DEFAULT, false); } - public Field addField(String name, IField.Type type, int precision, boolean notNull) + public DBField addField(String name, IDBField.Type type, int precision, boolean notNull) { - return addField(name, type, precision, IField.DEFAULT, notNull); + return addField(name, type, precision, IDBField.DEFAULT, notNull); } - public Field addField(String name, IField.Type type, int precision, int scale) + public DBField addField(String name, IDBField.Type type, int precision, int scale) { return addField(name, type, precision, scale, false); } - public Field addField(String name, IField.Type type, int precision, int scale, boolean notNull) + public DBField addField(String name, IDBField.Type type, int precision, int scale, boolean notNull) { schema.assertUnlocked(); if (getField(name) != null) { - throw new IllegalStateException("Field exists: " + name); + throw new IllegalStateException("DBField exists: " + name); } - Field field = new Field(this, name, type, precision, scale, notNull, fields.size()); + DBField field = new DBField(this, name, type, precision, scale, notNull, fields.size()); fields.add(field); return field; } - public Field getField(String name) + public DBField getField(String name) { - for (Field field : fields) + for (DBField field : fields) { if (name.equals(field.getName())) { @@ -99,7 +99,7 @@ public class Table implements ITable return null; } - public Field getField(int index) + public DBField getField(int index) { return fields.get(index); } @@ -109,21 +109,21 @@ public class Table implements ITable return fields.size(); } - public Field[] getFields() + public DBField[] getFields() { - return fields.toArray(new Field[fields.size()]); + return fields.toArray(new DBField[fields.size()]); } - public Index addIndex(Type type, IField field) + public DBIndex addIndex(Type type, IDBField field) { - IField[] fields = { field }; + IDBField[] fields = { field }; return addIndex(type, fields); } - public Index addIndex(Type type, IField[] fields) + public DBIndex addIndex(Type type, IDBField[] fields) { schema.assertUnlocked(); - Index index = new Index(this, type, fields, indices.size()); + DBIndex index = new DBIndex(this, type, fields, indices.size()); indices.add(index); return index; } @@ -133,16 +133,16 @@ public class Table implements ITable return indices.size(); } - public Index[] getIndices() + public DBIndex[] getIndices() { - return indices.toArray(new Index[indices.size()]); + return indices.toArray(new DBIndex[indices.size()]); } - public IIndex getPrimaryKeyIndex() + public IDBIndex getPrimaryKeyIndex() { - for (IIndex index : indices) + for (IDBIndex index : indices) { - if (index.geType() == IIndex.Type.PRIMARY_KEY) + if (index.geType() == IDBIndex.Type.PRIMARY_KEY) { return index; } @@ -156,7 +156,7 @@ public class Table implements ITable try { boolean first = true; - for (Field field : fields) + for (DBField field : fields) { if (first) { @@ -181,7 +181,7 @@ public class Table implements ITable { for (int i = 0; i < fields.size(); i++) { - Field field = fields.get(i); + DBField field = fields.get(i); if (i != 0) { appendable.append(", "); |