亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? testsyncsource.java

?? 通過SyncML對(duì)異構(gòu)數(shù)據(jù)庫復(fù)制的代碼。如何通過Sync4J作為服務(wù)進(jìn)行同步。
?? JAVA
字號(hào):
package test.sync4j;import sync4j.framework.engine.SyncItem;import sync4j.framework.engine.SyncItemImpl;import sync4j.framework.engine.SyncItemKey;import sync4j.framework.engine.SyncItemState;import sync4j.framework.engine.SyncProperty;import sync4j.framework.engine.source.AbstractSyncSource;import sync4j.framework.engine.source.SyncSource;import sync4j.framework.engine.source.SyncSourceException;import sync4j.framework.tools.beans.BeanInitializationException;import sync4j.framework.tools.beans.LazyInitBean;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.sql.DataSource;import java.security.Principal;import java.sql.Connection;import java.sql.DatabaseMetaData;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Timestamp;import java.text.MessageFormat;import java.util.ArrayList;import java.util.List;public class TestSyncSource extends AbstractSyncSource implements SyncSource, LazyInitBean{	private static final String JDBC_RECORDSET_MIMETYPE = "application/vnd.syncml+xmlrecordset";	private static final String METADATA_COLUMN_NAME = "COLUMN_NAME";	private static final int SQL_GET_ALL_ITEMS = 0;	private static final int SQL_GET_ALL_ITEMS_SINCE = 1;	private static final int SQL_GET_ITEMS = 2;	private static final int SQL_GET_ITEMS_SINCE = 3;	private static final int SQL_DELETE_ITEM = 4;	private static final int SQL_ADD_ITEM = 5;	private static final int SQL_UPDATE_ITEM = 6;	private DataSource dataSource;	private String[] columnNames;	private String[] sqlStatements;	private String jndiName;	private String jdbcDriver;	private String urlConnection;	private String userConnection;	private String passwordConnection;	private String tableName;	private String keyColumnName;	private String timestampColumnName;	private String stateColumnName;	private String catalogName;	private String schemaName;	public TestSyncSource(){		setType(JDBC_RECORDSET_MIMETYPE);	}	public void init() throws BeanInitializationException{		//Initialize the jndi datasource if provided		if(jndiName != null && jndiName.length() > 0){			try{				dataSource = (DataSource)new InitialContext().lookup(jndiName);			}			catch(NamingException e){				throw new BeanInitializationException("Data source not found: " + jndiName, e);			}		}		//Get the table's column names (excluding key, timestamp, state columns)		Connection connection = null;		try{			connection = getConnection();			columnNames = getColumnNames(connection.getMetaData(), catalogName, schemaName, tableName);		}		catch(SQLException e){			throw new BeanInitializationException("SQL exception initializing " + getClass().getName(), e);		}		finally{			closeConnection(connection);		}		//Prepare sql statements		sqlStatements = buildSql();	}	public String getJndiName(){		return jndiName;	}	public void setJndiName(String jndiName){		this.jndiName = jndiName;	}	public String getJdbcDriver(){		return jdbcDriver;	}	public void setJdbcDriver(String jdbcDriver){		this.jdbcDriver = jdbcDriver;	}	public String getUrlConnection(){		return urlConnection;	}	public void setUrlConnection(String urlConnection){		this.urlConnection = urlConnection;	}	public String getUserConnection(){		return userConnection;	}	public void setUserConnection(String userConnection){		this.userConnection = userConnection;	}	public String getPasswordConnection(){		return passwordConnection;	}	public void setPasswordConnection(String passwordConnection){		this.passwordConnection = passwordConnection;	}	public String getTableName(){		return tableName;	}	public void setTableName(String tableName){		this.tableName = tableName;	}	public String getKeyColumnName(){		return keyColumnName;	}	public void setKeyColumnName(String keyColumnName){		this.keyColumnName = keyColumnName;	}	public String getTimestampColumnName(){		return timestampColumnName;	}	public void setTimestampColumnName(String timestampColumnName){		this.timestampColumnName = timestampColumnName;	}	public String getStateColumnName(){		return stateColumnName;	}	public void setStateColumnName(String stateColumnName){		this.stateColumnName = stateColumnName;	}	public String getCatalogName(){		return catalogName;	}	public void setCatalogName(String catalogName){		this.catalogName = catalogName;	}	public String getSchemaName(){		return schemaName;	}	public void setSchemaName(String schemaName){		this.schemaName = schemaName;	}	public String toString(){		StringBuffer sb = new StringBuffer(super.toString());		sb.append(" - { ");		sb.append("name: ").append(name).append(", ");		sb.append("jndiName: ").append(jndiName).append(", ");		sb.append("jdbcDriver: ").append(jdbcDriver).append(", ");		sb.append("urlConnection: ").append(urlConnection).append(", ");		sb.append("userConnection: ").append(userConnection).append(", ");		sb.append("passwordConnection: ").append(passwordConnection).append(", ");		sb.append("tableName: ").append(tableName).append(", ");		sb.append("keyColumnName: ").append(keyColumnName).append(", ");		sb.append("timestampColumnName: ").append(timestampColumnName).append(", ");		sb.append("stateColumnName: ").append(stateColumnName).append(" }");		return sb.toString();	}	public boolean isModified(Principal principal, Timestamp since){		return true;	}	public SyncItem[] getAllSyncItems(Principal principal) throws SyncSourceException{		//Get all sync items		return getSyncItems(SyncItemState.UNKNOWN, null);	}	public SyncItemKey[] getDeletedSyncItemKeys(Principal principal, Timestamp since) throws SyncSourceException{		return null;	}	public SyncItem[] getDeletedSyncItems(Principal principal, Timestamp since) throws SyncSourceException{		//Get all deleted sync items since the specified date		return getSyncItems(SyncItemState.DELETED, since);	}	public SyncItemKey[] getNewSyncItemKeys(Principal principal, Timestamp since) throws SyncSourceException{		return null;	}	public SyncItem[] getNewSyncItems(Principal principal, Timestamp since) throws SyncSourceException{		//Get all new sync items since the specified date		return getSyncItems(SyncItemState.NEW, since);	}	public SyncItemKey[] getUpdatedSyncItemKeys(Principal principal, Timestamp since) throws SyncSourceException{		return null;	}	public SyncItem[] getUpdatedSyncItems(Principal principal, Timestamp since) throws SyncSourceException{		//Get all updated sync items since the specified date		return getSyncItems(SyncItemState.UPDATED, since);	}	public void removeSyncItem(Principal principal, SyncItem syncItem) throws SyncSourceException{		//Delete a sync item		Connection connection = null;		try{			connection = getConnection();			PreparedStatement statement = connection.prepareStatement(sqlStatements[SQL_DELETE_ITEM]);			statement.setTimestamp(1, new Timestamp(System.currentTimeMillis()));			statement.setString(2, syncItem.getKey().getKeyAsString());			statement.executeUpdate();		}		catch(SQLException e){			throw new SyncSourceException("Error removing item " +				syncItem.getKey().getKeyAsString(), e);		}		finally{			closeConnection(connection);		}	}	public void removeSyncItems(Principal principal, SyncItem[] syncItems) throws SyncSourceException{		if(syncItems != null){			for(int i = 0; i < syncItems.length; i++){				removeSyncItem(principal, syncItems[i]);			}		}	}	public SyncItem setSyncItem(Principal principal, SyncItem syncItem) throws SyncSourceException{		//Set a sync item with specified item data		String[] values = xmlToValues(new String((byte[])syncItem.getPropertyValue(SyncItem.PROPERTY_BINARY_CONTENT)));		Timestamp timestamp = (Timestamp)syncItem.getPropertyValue(SyncItem.PROPERTY_TIMESTAMP);		Connection connection = null;		try{			//Try to update item			connection = getConnection();			PreparedStatement statement = connection.prepareStatement(sqlStatements[SQL_UPDATE_ITEM]);			statement.setString(1, String.valueOf(SyncItemState.UPDATED));			statement.setTimestamp(2, timestamp);			for(int i = 0; i < values.length; ++i){				statement.setString(i + 3, values[i]);			}			statement.setString(values.length + 3, syncItem.getKey().getKeyAsString());			if(statement.executeUpdate() != 0){				return syncItem;			}			//Update failed, add new item			try{				statement.close();			}			catch(SQLException e){			}			statement = connection.prepareStatement(sqlStatements[SQL_ADD_ITEM]);			statement.setString(1, String.valueOf(SyncItemState.NEW));			statement.setTimestamp(2, timestamp);			statement.setString(3, syncItem.getKey().getKeyAsString());			for(int i = 0; i < columnNames.length; ++i){				statement.setString(i + 4, values[i]);			}			statement.executeUpdate();		}		catch(SQLException e){			throw new SyncSourceException("Error setting item " +				syncItem.getKey().getKeyAsString(), e);		}		finally{			closeConnection(connection);		}		return syncItem;	}	private static String[] xmlToValues(String xml){		//Extract values from xml		List values = new ArrayList();		for(int end, offset = 0; offset < xml.length(); offset = end + 8){			offset = xml.indexOf("<field>", offset);			if(offset < 0){				break;			}			offset += 7;			end = xml.indexOf("</field>", offset);			if(end < 0){				break;			}			values.add(xml.substring(offset, end));		}		return (String[])values.toArray(new String[values.size()]);	}	public SyncItem[] setSyncItems(Principal principal, SyncItem[] syncItems) throws SyncSourceException{		//Set sync items with specified data		if(syncItems != null){			for(int i = 0; i < syncItems.length; i++){				setSyncItem(principal, syncItems[i]);			}		}		return syncItems;	}	public SyncItem getSyncItemFromId(Principal principal, SyncItemKey syncItemKey) throws SyncSourceException{		return null;	}	public SyncItem[] getSyncItemsFromIds(Principal principal, SyncItemKey[] syncItemsKeys) throws SyncSourceException{		return new SyncItem[0];	}	public SyncItem getSyncItemFromTwin(Principal principal, SyncItem syncItem) throws SyncSourceException{		return null;	}	public SyncItem[] getSyncItemsFromTwins(Principal principal, SyncItem[] syncItem) throws SyncSourceException{		return new SyncItem[0];	}	private SyncItem[] getSyncItems(char state, Timestamp since) throws SyncSourceException{		//Get sync items based on state and last modification timestamp		List items = new ArrayList();		Connection connection = null;		try{			connection = getConnection();			PreparedStatement statement;			if(state == SyncItemState.UNKNOWN){				//Get all items				if(since == null){					statement = connection.prepareStatement(sqlStatements[SQL_GET_ALL_ITEMS]);				}				//Get all items since timestamp				else{					statement = connection.prepareStatement(sqlStatements[SQL_GET_ALL_ITEMS_SINCE]);					statement.setTimestamp(1, since);				}			}			else{				//Get items with state				if(since == null){					statement = connection.prepareStatement(sqlStatements[SQL_GET_ITEMS]);					statement.setString(1, String.valueOf(state));				}				//Get items with state since timestamp				else{					statement = connection.prepareStatement(sqlStatements[SQL_GET_ITEMS_SINCE]);					statement.setString(1, String.valueOf(state));					statement.setTimestamp(2, since);				}			}			//Build sync items from the resultset			for(ResultSet rs = statement.executeQuery(); rs.next();){				items.add(rowToSyncItem(rs));			}		}		catch(SQLException e){			throw new SyncSourceException("Error getting items", e);		}		finally{			closeConnection(connection);		}		return (SyncItem[])items.toArray(new SyncItem[items.size()]);	}	private SyncItem rowToSyncItem(ResultSet rs) throws SQLException{		//Convert a database record to a sync item		StringBuffer xml = new StringBuffer("<record>\n");		for(int i = 0; i < columnNames.length; i++){			xml.append("<field>").append(rs.getString(columnNames[i])).append("</field>\n");		}		xml.append("</record>\n");		SyncItem item = new SyncItemImpl(this, rs.getString(keyColumnName),			rs.getString(stateColumnName).charAt(0));		item.setProperty(new SyncProperty(SyncItem.PROPERTY_BINARY_CONTENT,			xml.toString().getBytes()));		return item;	}	private Connection getConnection() throws SQLException{		if(dataSource != null){			return dataSource.getConnection();		}		try{			Class.forName(jdbcDriver);		}		catch(ClassNotFoundException e){			e.printStackTrace();		}		return DriverManager.getConnection(urlConnection, userConnection, passwordConnection);	}	private static void closeConnection(Connection connection){		if(connection != null){			try{				connection.close();			}			catch(SQLException e){			}		}	}	private String[] getColumnNames(DatabaseMetaData metaData, String catalog, String schema, String tableName) throws SQLException{		String catalogName = (catalog == null || catalog.length() <= 0) ? null : catalog;		String schemaName = (schema == null || schema.length() <= 0) ? metaData.getUserName() : schema;		ResultSet rs = metaData.getColumns(catalogName, schemaName, tableName, "%");		List columnNames = new ArrayList();		while(rs.next()){			String columnName = rs.getString(METADATA_COLUMN_NAME);			//Skip key, timestamp and state columns			if(!(keyColumnName.equalsIgnoreCase(columnName) ||				timestampColumnName.equalsIgnoreCase(columnName) ||				stateColumnName.equalsIgnoreCase(columnName)) &&				!columnNames.contains(columnName)){				columnNames.add(columnName);			}		}		try{			rs.close();		}		catch(SQLException e){		}		return (String[])columnNames.toArray(new String[columnNames.size()]);	}	private String[] buildSql(){		StringBuffer columns = new StringBuffer();		StringBuffer columnValues = new StringBuffer();		StringBuffer columnAssignments = new StringBuffer();		for(int i = 0; i < columnNames.length; ++i){			columns.append(", ").append(columnNames[i]);			columnValues.append(", ?");			columnAssignments.append(", ").append(columnNames[i]).append(" = ?");		}		Object[] args = new Object[]{			tableName,			stateColumnName,			timestampColumnName,			keyColumnName,			columns.toString(),			columnValues.toString(),			columnAssignments.toString()		};		String[] sql = new String[]{			"select * from {0}",			"select * from {0} where {2} > ?",			"select * from {0} where {1} = ?",			"select * from {0} where {1} = ? and {2} > ?",			"update {0} set {1} = ''D'', {2} = ? where {3} = ?",			"insert into {0} ({1}, {2}, {3}{4}) values(?, ?, ?{5})",			"update {0} set {1} = ?, {2} = ?{6} where {3} = ?"		};		for(int i = 0; i < sql.length; i++){			sql[i] = MessageFormat.format(sql[i], args);		}		return sql;	}}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩欧美在线1卡| 欧美zozozo| 麻豆免费看一区二区三区| 国产网红主播福利一区二区| 欧美午夜电影在线播放| 国产精品一级片| 婷婷中文字幕综合| 国产精品精品国产色婷婷| 欧美一级久久久久久久大片| 色婷婷精品大视频在线蜜桃视频| 蜜臂av日日欢夜夜爽一区| 自拍偷拍亚洲欧美日韩| 久久综合色播五月| 7777精品伊人久久久大香线蕉完整版 | 亚洲欧美综合色| 91精品国产91久久久久久一区二区 | 色域天天综合网| 国内一区二区在线| 亚洲一级在线观看| 亚洲人一二三区| 久久日一线二线三线suv| 欧美三级三级三级| 99久久99久久久精品齐齐| 国产原创一区二区| 青娱乐精品在线视频| 一区二区三区在线视频观看58| 欧美国产一区在线| 精品久久国产老人久久综合| 欧美群妇大交群中文字幕| 91女神在线视频| 成人av在线资源网站| 国产福利一区二区三区视频在线| 人人狠狠综合久久亚洲| 亚洲成av人片在www色猫咪| 一区二区免费看| 亚洲美女视频在线| 亚洲天天做日日做天天谢日日欢 | 成人性色生活片| 国产一区二区在线看| 久久99国内精品| 人人狠狠综合久久亚洲| 日韩专区欧美专区| 日韩主播视频在线| 亚洲成年人网站在线观看| 亚洲一区二区三区不卡国产欧美| 一区二区三区电影在线播| 亚洲最新视频在线观看| 一级精品视频在线观看宜春院 | 91行情网站电视在线观看高清版| 成人激情小说乱人伦| 成人综合婷婷国产精品久久| 高清shemale亚洲人妖| 成人午夜激情在线| 99这里只有久久精品视频| 色综合天天狠狠| 欧美日韩亚洲高清一区二区| 在线不卡a资源高清| 日韩欧美一区在线| 久久久久成人黄色影片| 国产精品久久久久久久浪潮网站 | 免费人成精品欧美精品| 久久国产精品99久久久久久老狼| 91免费视频观看| 91久久国产综合久久| 欧美精品1区2区3区| 日韩一区二区三区精品视频| 亚洲精品一区二区三区福利| 久久一区二区三区四区| 中文av一区二区| 亚洲午夜在线观看视频在线| 蜜桃久久久久久| 成人一级视频在线观看| 99精品视频在线观看| 欧美福利视频导航| 国产丝袜在线精品| 亚洲精品写真福利| 狂野欧美性猛交blacked| 国产91丝袜在线播放0| 91国在线观看| 精品国产乱子伦一区| 国产精品国模大尺度视频| 亚洲gay无套男同| 国产高清精品在线| 欧美色综合影院| 久久综合九色综合97_久久久| 国产精品亲子乱子伦xxxx裸| 亚洲超碰97人人做人人爱| 国产在线精品一区二区三区不卡| 91在线视频官网| 日韩免费高清电影| 亚洲另类春色校园小说| 久久69国产一区二区蜜臀| 91麻豆精品秘密| 精品久久久影院| 亚洲夂夂婷婷色拍ww47| 国产一区二区三区四区五区入口| 91福利国产精品| 久久久亚洲综合| 亚洲不卡一区二区三区| av在线综合网| 久久蜜臀中文字幕| 日本免费新一区视频| 色综合久久99| 国产日韩欧美精品综合| 视频一区欧美日韩| 色香蕉成人二区免费| 欧美精品一区二区三区一线天视频| 亚洲精品水蜜桃| 国产91色综合久久免费分享| 欧美一区日本一区韩国一区| 亚洲免费观看高清| 国产91精品免费| 精品盗摄一区二区三区| 日本一区中文字幕| 在线观看日韩av先锋影音电影院| 国产日产欧美一区| 狠狠久久亚洲欧美| 日韩无一区二区| 视频一区二区三区入口| 欧美午夜精品久久久久久孕妇| 亚洲欧美综合色| 成人国产精品视频| 久久综合成人精品亚洲另类欧美 | 日本中文字幕一区二区视频| 色偷偷久久人人79超碰人人澡 | 午夜精品视频一区| 一本色道久久综合亚洲aⅴ蜜桃 | 欧美日韩免费观看一区二区三区| 国产精品美女久久久久av爽李琼 | 日本道精品一区二区三区 | 精品少妇一区二区三区视频免付费| 一区二区在线电影| 99天天综合性| 中文字幕不卡在线播放| 国内精品伊人久久久久av影院 | 欧美三级视频在线| 亚洲va韩国va欧美va精品| 91久久精品国产91性色tv| 亚洲精品国产精华液| 色婷婷综合久久久久中文 | 久久91精品国产91久久小草 | 欧美va亚洲va香蕉在线| 麻豆成人在线观看| 欧美成人高清电影在线| 精品亚洲国内自在自线福利| 精品国产一区二区三区av性色| 久久精品国产在热久久| 在线播放中文字幕一区| 蜜臀av一级做a爰片久久| 欧美成人免费网站| 国产成人一区二区精品非洲| 国产欧美视频一区二区三区| 粉嫩欧美一区二区三区高清影视| 中文字幕色av一区二区三区| 色一情一伦一子一伦一区| 亚洲观看高清完整版在线观看| 在线成人小视频| 国内精品免费**视频| 国产无人区一区二区三区| 91在线精品一区二区| 亚洲国产美女搞黄色| 91精选在线观看| 国产成人一区在线| 亚洲精品网站在线观看| 欧美一区二区在线不卡| 国产经典欧美精品| 亚洲精品乱码久久久久久| 51精品久久久久久久蜜臀| 国产精品亚洲专一区二区三区 | 一本久久综合亚洲鲁鲁五月天| 亚洲国产一二三| 欧美大片国产精品| 北条麻妃一区二区三区| 午夜视频久久久久久| 精品国产91乱码一区二区三区 | 国产精品久久久久影院色老大 | 青青青伊人色综合久久| 久久久夜色精品亚洲| 色老综合老女人久久久| 免费在线看成人av| 亚洲欧美在线高清| 91麻豆精品国产自产在线| 高清不卡在线观看| 日韩精品一二三区| 国产精品萝li| 3d动漫精品啪啪1区2区免费| 国产69精品久久久久毛片| 亚洲国产色一区| 日本一区二区三区四区在线视频| 在线亚洲精品福利网址导航| 韩国精品免费视频| 亚洲成av人片观看| 国产精品欧美经典| 日韩精品中文字幕一区二区三区| 97久久久精品综合88久久| 久久99国产精品久久99| 亚洲一区av在线| 国产精品三级视频| 日韩午夜在线影院| 欧美在线视频日韩|